rendy icon indicating copy to clipboard operation
rendy copied to clipboard

Uniform buffer in vertex shader "disappears" when adding uniforms to fragment shader

Open maroider opened this issue 6 years ago • 7 comments

I'm currently trying to "port" glium's incomplete tutorial to rendy by looking at rendy's examples and API docs. I've unfortunately hit a roadblock on part 6 "Uploading a texture". The uniform buffer I was already using successfully "dissapears" when I add uniform texture2D and uniform sampler colorsampler to the fragment shader. ShaderReflection.layout().unwrap() returns

Layout {
    sets: [
        SetLayout {
            bindings: [
                DescriptorSetLayoutBinding {
                    binding: 1,
                    ty: SampledImage,
                    count: 1,
                    stage_flags: FRAGMENT,
                    immutable_samplers: false,
                },
                DescriptorSetLayoutBinding {
                    binding: 2,
                    ty: Sampler,
                    count: 1,
                    stage_flags: FRAGMENT,
                    immutable_samplers: false,
                },
            ],
        },
    ],
    push_constants: [],
}

even though I haven't removed the uniform buffer that on its own is detected as

Layout {
    sets: [
        SetLayout {
            bindings: [
                DescriptorSetLayoutBinding {
                    binding: 0,
                    ty: UniformBuffer,
                    count: 1,
                    stage_flags: VERTEX,
                    immutable_samplers: false,
                },
            ],
        },
    ],
    push_constants: [],
}

It doesn't work properly when I set the descriptor layout manually either. The relevant code can be found here along with the vertex and fragment shaders. The bits that make it break in various ways are commented out.

maroider avatar Oct 13 '19 10:10 maroider

Sounds like a bug in reflection. But you're saying it doesn't work when you specify layout manually which is odd. Try stick with manual layout for now and validate descriptor set is properly populated with RenderDoc.

zakarumych avatar Oct 14 '19 08:10 zakarumych

The descriptor set seems fine when I specify the layout manually. image

maroider avatar Oct 18 '19 17:10 maroider

But you still read zeros in vertex shader instead of expected data?

zakarumych avatar Oct 20 '19 08:10 zakarumych

I'm not sure what you mean by that, but the uniform buffer gets uploaded correctly to the vertex shader.

While poking around in RenderDoc, I also noticed that the texture doesn't get uploaded correctly. It lacks any color data and is completely transparent. This is likely what makes the triangle I'm trying to render invisible.

Annotation 2019-10-31 215445

What causes this isn't obvious to me and it doesn't help that RenderDoc doesn't emit any warnings now even though (I think) I haven't changed the code at all (there used to be "11 Errors and Warnings").

maroider avatar Oct 31 '19 21:10 maroider

Can you share code that reproduces this bug? It would be much more effective that way.

zakarumych avatar Nov 02 '19 21:11 zakarumych

Here are all the files that should be relevant:

path link
Cargo.toml https://github.com/maroider/glium_tutorial_but_its_rendy/blob/spooky_buffers/Cargo.toml
assets/opengl.png https://github.com/maroider/glium_tutorial_but_its_rendy/blob/spooky_buffers/assets/opengl.png
src/bin/06.rs https://github.com/maroider/glium_tutorial_but_its_rendy/blob/spooky_buffers/src/bin/06.rs
src/bin/06.shader.frag https://github.com/maroider/glium_tutorial_but_its_rendy/blob/spooky_buffers/src/bin/06.shader.frag
src/bin/06.shader.vert https://github.com/maroider/glium_tutorial_but_its_rendy/blob/spooky_buffers/src/bin/06.shader.vert

maroider avatar Nov 06 '19 17:11 maroider

I've managed to resolve the issue that was causing the texture to not upload. I forgot to call factory.maintain(..) before running the graph. The issue with shader reflection still remains.

maroider avatar Dec 27 '19 22:12 maroider