Skip to content

Vulkan: PixelShader always fails on CreateGraphicsPipeline() #234

@HemmingsChris

Description

@HemmingsChris

When I try to create a graphics pipeline the pixel shader always fails with this message: Bind group info mismatches the shader source for symbol FontAtlas.

This is my glsl before it is compiled into a SPIRV:

#version 450

layout(location = 0) in vec4 in_var_COLOR;
layout(location = 1) in vec2 in_var_TEXCOORD0;

layout(location = 0) out vec4 out_var_SV_TARGET;

// Separate bindings, exactly as declared in VS
layout(set = 0, binding = 0) uniform texture2D FontAtlas;
layout(set = 0, binding = 1) uniform sampler FontAtlasSampler;

void main()
{
// Correct Vulkan GLSL syntax for separate texture + sampler
vec4 texColor = texture(sampler2D(FontAtlas, FontAtlasSampler), in_var_TEXCOORD0);
out_var_SV_TARGET = texColor * in_var_COLOR;
}

This is the method that fails:

    private GraphicsPipelineState GetOrCreateTextPipelineState(GraphicsContext graphicsContext, SwapChain swapChain)
    {
        // --- Vertex input layout: matches VertexPositionColorTexture ---
        var layoutDesc = new LayoutDescription()
            .Add(new ElementDescription(ElementFormat.Float3, ElementSemanticType.Position, 0, 0))
            .Add(new ElementDescription(ElementFormat.Float4, ElementSemanticType.Color, 0, 12))
            .Add(new ElementDescription(ElementFormat.Float2, ElementSemanticType.TexCoord, 0, 28));

        var inputLayouts = new InputLayouts();
        inputLayouts.Add(layoutDesc);

        // --- Load shaders ---
        Shader vertexShader = LoadShader(graphicsContext, ShaderStages.Vertex, "TextVertexShader");
        Shader pixelShader = LoadShader(graphicsContext, ShaderStages.Pixel, "TextPixelShader");

        // --- Resource layout: must match GLSL bindings ---
        // GLSL declares:
        //   layout(set = 0, binding = 0) uniform texture2D FontAtlas;
        //   layout(set = 0, binding = 1) uniform sampler FontAtlasSampler;
        var resourceLayoutDesc = new ResourceLayoutDescription
        {
            Elements = new[]
            {
                new LayoutElementDescription(0, ResourceType.Texture, ShaderStages.Pixel), // FontAtlas
                new LayoutElementDescription(1, ResourceType.Sampler, ShaderStages.Pixel)  // FontAtlasSampler
            }
        };
        ResourceLayout resourceLayout = graphicsContext.Factory.CreateResourceLayout(ref resourceLayoutDesc);

        // --- Pipeline description ---
        var pipelineDesc = new GraphicsPipelineDescription
        {
            PrimitiveTopology = PrimitiveTopology.TriangleList,
            InputLayouts = inputLayouts,
            ResourceLayouts = new[] { resourceLayout },
            Shaders = new GraphicsShaderStateDescription
            {
                VertexShader = vertexShader,
                PixelShader = pixelShader
            },
            RenderStates = new RenderStateDescription
            {
                RasterizerState = RasterizerStates.CullBack,
                BlendState = BlendStates.AlphaBlend,
                DepthStencilState = DepthStencilStates.None
            },
            Outputs = swapChain.FrameBuffer.OutputDescription
        };

        return graphicsContext.Factory.CreateGraphicsPipeline(ref pipelineDesc);
    }

The same method works perfectly on WIndows. It always fails on Android. I would welcome any advice

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions