Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect automatic pipeline layout creation #2203

Closed
wahfl2 opened this issue May 10, 2023 · 6 comments · Fixed by #2284
Closed

Incorrect automatic pipeline layout creation #2203

wahfl2 opened this issue May 10, 2023 · 6 comments · Fixed by #2284

Comments

@wahfl2
Copy link

wahfl2 commented May 10, 2023

  • Version of vulkano: 0.33.0
  • OS: Windows 10

Issue

According to the validation layers, the automatic pipeline creator created an invalid pipeline.

This code

let raytracing = GraphicsPipeline::start()
    .vertex_shader(block_shader.vertex.entry_point("main").unwrap(), ())
    .fragment_shader(block_shader.fragment.entry_point("main").unwrap(), ())

    .color_blend_state(ColorBlendState::new(1).blend_alpha())
    .input_assembly_state(InputAssemblyState::new())
    .vertex_input_state(Vertex2D::per_vertex())
    .viewport_state(ViewportState::viewport_fixed_scissor_irrelevant([viewport.clone()]))

    .render_pass(Subpass::from(render_pass.clone(), 0).unwrap())
    .build(device.clone()).unwrap();

threw this error:

MessageID = 0x45717876 | Set 4 Binding 0 in shader (VK_SHADER_STAGE_FRAGMENT_BIT) uses descriptor slot (expected `VK_DESCRIPTOR_TYPE_STORAGE_BUFFER, VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC`) but not declared in pipeline layout The Vulkan spec states: layout must be consistent with all shaders specified in pStages (https://vulkan.lunarg.com/doc/view/1.3.239.0/windows/1.3-extensions/vkspec.html#VUID-VkGraphicsPipelineCreateInfo-layout-00756)
    Objects: 2
        [0] 0x27d60e0000000019, type: 15, name: NULL
        [1] 0x301e6c0000000022, type: 17, name: NULL

The buffer definitions in GLSL look like

layout(set = 0, binding = 0) uniform sampler2D tex;

layout(set = 1, binding = 0) readonly buffer AtlasMap {
    Texture textures[];
} atlas_map;

layout(set = 7, binding = 0) readonly buffer BlockTextureMap {
    uint textures[];
} block_texture_map;

layout(set = 2, binding = 0) uniform View {
    mat4 camera;
    uvec2 resolution;
    float fov;
} view;

layout(set = 3, binding = 0) uniform ProgramInfo {
    uint frame_number;
    uint start;
} program_info;

layout(set = 4, binding = 0) readonly buffer BrickmapBuffer {
    Brickmap maps[];
} brickmap_buffer;

layout(set = 5, binding = 0) readonly buffer Brickgrid {
    uvec3 size;
    uint _pad;
    uint pointers[];
} brickgrid;

layout(set = 6, binding = 0) readonly buffer TextureBuffer {
    uint textures[];
} block_texture_buffer;

The whole file can be viewed here.
It may be worth noting that the shader is compiled at runtime with shaderc and opt level 2.

@marc0246
Copy link
Contributor

marc0246 commented May 10, 2023

Yeah this is for sure a bug in the automatic pipeline layout creation and will need some investigation. In the meantime you can create the pipeline layout by hand.

@Rua
Copy link
Contributor

Rua commented Aug 6, 2023

This is very likely caused by using a non-constant index into an arrayed descriptor binding. The shader reflection can only use information that is present in the shader, it doesn't know anything about the inputs to the shader. So this can't really be fixed.

@Rua
Copy link
Contributor

Rua commented Aug 6, 2023

Actually, if I try it out on the current master, the automatic layout creation correctly includes set 4 binding 0:

DescriptorSetLayoutCreateInfo {
      flags: empty(),
      bindings: {
          0: DescriptorSetLayoutBinding {
              binding_flags: empty(),
              descriptor_type: StorageBuffer,
              descriptor_count: 1,
              stages: FRAGMENT,
              immutable_samplers: [],
              _ne: NonExhaustive(
                  (),
              ),
          },
      },
      _ne: NonExhaustive(
          (),
      ),
  },

So is this issue already fixed then?

@marc0246
Copy link
Contributor

marc0246 commented Aug 8, 2023

@Rua you didn't turn on optimizations. The issue only exists then.

@Rua
Copy link
Contributor

Rua commented Aug 9, 2023

I still can't reproduce it by compiling in release mode. glslc doesn't have an opt-level 2 so I couldn't check that.

@Rua
Copy link
Contributor

Rua commented Aug 9, 2023

Ah never mind, it's not release mode that matters, but the optimizations on the shader. I can reproduce it now, and I think I figured out where the bug lies.

Rua added a commit to Rua/vulkano that referenced this issue Aug 9, 2023
marc0246 pushed a commit that referenced this issue Aug 9, 2023
hakolao pushed a commit to hakolao/vulkano that referenced this issue Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants