google/amber

[Vulkan Conformance] Amber creates an incorrect pipeline when there are gaps in descriptor set bindings

Closed this issue · 2 comments

Consider the following shader that adds 1 to an int contained within a struct:

; Magic:     0x07230203 (SPIR-V)
; Version:   0x00010400 (Version: 1.4.0)
; Generator: 0x00220001 (SPIRVSmith)
; Schema:    0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %main "main"
OpExecutionMode %main LocalSize 1 1 1
OpDecorate %struct_t Block
OpDecorate %struct_variable DescriptorSet 0
OpDecorate %struct_variable Binding 1
OpMemberDecorate %struct_t 0 Offset 0
%void_t = OpTypeVoid
%main_t = OpTypeFunction %void_t
%int_t = OpTypeInt 32 1
%struct_t = OpTypeStruct %int_t
%int_ptr_t = OpTypePointer StorageBuffer %int_t
%struct_ptr_t = OpTypePointer StorageBuffer %struct_t
%const_zero = OpConstant %int_t 0
%const_one = OpConstant %int_t 1
%struct_variable = OpVariable %struct_ptr_t StorageBuffer
%main = OpFunction %void_t DontInline %main_t
%main_label = OpLabel
%struct_element_ptr = OpAccessChain %int_ptr_t %struct_variable %const_zero
%struct_element = OpLoad %int_t %struct_element_ptr
%op_mod = OpIAdd %int_t %struct_element %const_one
OpStore %struct_element_ptr %op_mod
OpReturn
OpFunctionEnd

In particular, the struct is stored at binding 1:

OpDecorate %struct_variable DescriptorSet 0
OpDecorate %struct_variable Binding 1

Wrapping this shader with Amberscript and running it triggers the following validation layer error:

[ERROR] validation layer (Validation):
Validation Error: [ VUID-VkComputePipelineCreateInfo-layout-00703 ] Object 0: handle = 0x55b8f9df86b8, type = VK_OBJECT_TYPE_DEVICE; | MessageID = 0xe63c2d8b | Shader uses descriptor slot 0.1 (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 the layout of the compute shader specified in stage (https://vulkan.lunarg.com/doc/view/1.3.204.1/linux/1.3-extensions/vkspec.html#VUID-VkComputePipelineCreateInfo-layout-00703)
[ERROR] validation layer (Validation):
Validation Error: [ VUID-vkCmdDispatch-None-02699 ] Object 0: handle = 0xec4bec000000000b, type = VK_OBJECT_TYPE_DESCRIPTOR_SET; | MessageID = 0xe5d1743c | VkDescriptorSet 0xec4bec000000000b[] encountered the following validation error at vkCmdDispatch time: Attempting to validate DrawState for binding #2  which is an invalid binding for this descriptor set. The Vulkan spec states: Descriptors in each bound descriptor set, specified via vkCmdBindDescriptorSets, must be valid if they are statically used by the VkPipeline bound to the pipeline bind point used by this command (https://vulkan.lunarg.com/doc/view/1.3.204.1/linux/1.3-extensions/vkspec.html#VUID-vkCmdDispatch-None-02699)
dj2 commented

Can you provide the amberscript that you're using as well?

@dj2 Whoops, my Amberscripts are auto-generated and I'm the one who had a bug where I was binding the struct at buffer 0 in Amberscript even though the shader described it as binding 1 🤦🤦🤦. Closing this