8000 SDL3 GPU - Unable to create color target textures · Issue #13033 · libsdl-org/SDL · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
SDL3 GPU - Unable to create color target textures #13033
Closed
@Gibbon99

Description

@Gibbon99

When attempting to create three color target textures - I get a crash.

Create the color targets

bool Renderer::createGBuffers()
{
    SDL_GPUTexture *texture = nullptr;

    for (auto i = 0; i != GBUFFER_NAME::NUM_GBUFFERS; ++i)
    {
        //
        // Create a texture to hold the deferred rendering information
        SDL_GPUTextureCreateInfo textureCreateInfo{};
        textureCreateInfo.type                 = SDL_GPU_TEXTURETYPE_2D;
        textureCreateInfo.width                = m_windowWidth;
        textureCreateInfo.height               = m_windowHeight;
        textureCreateInfo.layer_count_or_depth = 1;
        textureCreateInfo.num_levels           = 1;
        textureCreateInfo.sample_count         = SDL_GPU_SAMPLECOUNT_1;
        textureCreateInfo.format               = SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM;
        textureCreateInfo.usage                = SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER;

        texture = SDL_CreateGPUTexture(m_device, &textureCreateInfo);
        if (texture == nullptr)
        {
            m_errorString = getString("Failed to create GBuffer texture [ %s ]", SDL_GetError());
            return false;
        }
        m_Gbuffers.push_back(texture);
    }
    return true;
}

Add them as targets at the render pass

    std::vector<SDL_GPUColorTargetInfo> colorTargetInfos;
    colorTargetInfos.clear();

    for (auto i = 0; i != NUM_GBUFFERS; ++i)
    {
        SDL_GPUColorTargetInfo colorTargetInfo = {nullptr};
        colorTargetInfo.texture                = renderer.m_Gbuffers[i];
        colorTargetInfo.clear_color            = (SDL_FColor){1, 0, 0, 1};
        colorTargetInfo.load_op                = SDL_GPU_LOADOP_CLEAR;
        colorTargetInfo.store_op               = SDL_GPU_STOREOP_STORE;
        colorTargetInfo.layer_or_depth_plane   = 1;

        colorTargetInfos.push_back(colorTargetInfo);
    }

    if (!renderer.beginRenderPass(colorTargetInfos.data(), colorTargetInfos.size(), nullptr))
    {
        printf("Failed to begin startFrame pass [ %s ]\n", SDL_GetError());
        return false;
    }

write to them in the fragment shader

#version 450 core

layout(set = 2, binding = 0) uniform sampler2D Texture;
layout(set = 2, binding = 1) uniform sampler2D Lightmap;

layout(location = 0) in vec3 Position_IN;
layout(location = 1) in vec3 Normal_IN;
layout(location = 2) in vec2 TexCoord_IN;
layout(location = 3) in vec2 LightmapCoords_IN;

layout(set = 2, location = 0) out vec3 gPosition;
layout(set = 2, location = 1) out vec3 gNormal;
layout(set = 2, location = 2) out vec3 gAlbedo;

void main()
{
    // Write position to gBuffer
    gPosition.rgb = vec3(Position_IN.xyz);

    // Write normal to gBuffer
    gNormal.rgb = normalize(vec3(gNormal.xyz));

    vec4 texel = texture(Texture, TexCoord_IN);
    texel = texel * texture(Lightmap, LightmapCoords_IN);

    // Write texture color to gBuffer
    gAlbedo.rgb = texel.rgb;
}

Get a crash here

static VulkanTextureUsageMode VULKAN_INTERNAL_DefaultTextureUsageMode(
    VulkanTexture *texture)
{
    // NOTE: order matters here!
    // NOTE: graphics storage bits and sampler bit are mutually exclusive!

    if (texture->usage & SDL_GPU_TEXTUREUSAGE_SAMPLER) {   <--- Texture is a bad value ( 0x71 )
        return VULKAN_TEXTURE_USAGE_MODE_SAMPLER;

Here is the call stack

main
renderDeferred
Renderer::beginRenderPass
SDL_BeginGPURenderPass
SDL_BeginGPURenderPass_REAL
VULKAN_BeginRenderPass
VULKAN_INTERNAL_PrepareTextureSubresourceForWrite ( SDL_gpu_vulkan.c:6002 )
VULKAN_INTERNAL_TextureSubresourceTransitionFromDefaultUsage ( SDL_gpu_vulkan.c:2790 )
VULKAN_INTERNAL_DefaultTextureUsageMode ( SDL_gou_vulkan.c:2742 )

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0