KhronosGroup / KhronosGroup/glslang
Auto binds mapping not generating bindings for unused accelerationStructureNVs
- Dominant language
- C++
- Stars
- 3.6k
- Forks
- 989
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 31
Description
``` glsl
#version 460
#extension GL_NV_ray_tracing : require
uniform accelerationStructureNV myUnusedAccStruct;
uniform myUnusedUniformStruct { int myUnusedUniformData; };
buffer myUnusedBufferStruct { int myUnusedBufferData; };
void main() {}
```
yields this SPIRV:
```
; SPIR-V
; Version: 1.3
; Generator: Google Shaderc over Glslang; 7
; Bound: 16
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %4 "main"
OpExecutionMode %4 LocalSize 1 1 1
OpSource GLSL 460
OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
OpSourceExtension "GL_GOOGLE_include_directive"
OpSourceExtension "GL_NV_ray_tracing"
OpName %4 "main"
OpName %8 "myUnusedAccStruct"
OpName %10 "myUnusedUniformStruct"
OpMemberName %10 0 "myUnusedUniformData"
OpName %12 ""
OpName %13 "myUnusedBufferStruct"
OpMemberName %13 0 "myUnusedBufferData"
OpName %15 ""
OpDecorate %8 DescriptorSet 0
OpMemberDecorate %10 0 Offset 0
OpDecorate %10 Block
OpDecorate %12 DescriptorSet 0
OpDecorate %12 Binding 0
OpMemberDecorate %13 0 Offset 0
OpDecorate %13 Block
OpDecorate %15 DescriptorSet 0
OpDecorate %15 Binding 0
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeAccelerationStructureNV
%7 = OpTypePointer UniformConstant %6
%8 = OpVariable %7 UniformConstant
%9 = OpTypeInt 32 1
%10 = OpTypeStruct %9
%11 = OpTypePointer Uniform %10
%12 = OpVariable %11 Uniform
%13 = OpTypeStruct %9
%14 = OpTypePointer StorageBuffer %13
%15 = OpVariable %14 StorageBuffer
%4 = OpFunction %2 None %3
%5 = OpLabel
OpReturn
OpFunctionEnd
```
As you can see, `myUnusedBufferStruct` and `myUnusedUniformStruct` both got assigned binding 0. This is correct - these bindings are unused by the shader. However, you also notice that `myUnusedAccStruct` did _not_ get decorated with a binding or set decoration.
I tried looking into the glslang code responsible for this, but couldn't exactly pinpoint what is causing this.
Another thing which possibly could be related to this: when compiling the shader without auto binds mapping turned on, I only get two errors telling me that `myUnusedUniformStruct` and `myUnusedBufferStruct` don't have binding declared in the shader, but there is no error telling me that `myUnusedAccStruct` doesn't have an explicit binding declared.
In fact, if I write the shader like this:
``` glsl
#version 460
#extension GL_NV_ray_tracing : require
uniform accelerationStructureNV myUnusedAccStruct;
layout(binding = 0) uniform myUnusedUniformStruct { int myUnusedUniformData; };
layout(binding = 1) buffer myUnusedBufferStruct { int myUnusedBufferData; };
void main() {}
```
...and compile it without auto binds mapping turned on.. I get no errors whatsoever! It successfully compiles the shader into SPIRV, looking like this:
```
; SPIR-V
; Version: 1.3
; Generator: Google Shaderc over Glslang; 7
; Bound: 16
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint GLCompute %4 "main"
OpExecutionMode %4 LocalSize 1 1 1
OpSource GLSL 460
OpSourceExtension "GL_GOOGLE_cpp_style_line_directive"
OpSourceExtension "GL_GOOGLE_include_directive"
OpSourceExtension "GL_NV_ray_tracing"
OpName %4 "main"
OpName %8 "myUnusedAccStruct"
OpName %10 "myUnusedUniformStruct"
OpMemberName %10 0 "myUnusedUniformData"
OpName %12 ""
OpName %13 "myUnusedBufferStruct"
OpMemberName %13 0 "myUnusedBufferData"
OpName %15 ""
OpMemberDecorate %10 0 Offset 0
OpDecorate %10 Block
OpDecorate %12 DescriptorSet 0
OpDecorate %12 Binding 0
OpMemberDecorate %13 0 Offset 0
OpDecorate %13 Block
OpDecorate %15 DescriptorSet 0
OpDecorate %15 Binding 1
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeAccelerationStructureNV
%7 = OpTypePointer UniformConstant %6
%8 = OpVariable %7 UniformConstant
%9 = OpTypeInt 32 1
%10 = OpTypeStruct %9
%11 = OpTypePointer Uniform %10
%12 = OpVariable %11 Uniform
%13 = OpTypeStruct %9
%14 = OpTypePointer StorageBuffer %13
%15 = OpVariable %14 StorageBuffer
%4 = OpFunction %2 None %3
%5 = OpLabel
OpReturn
OpFunctionEnd
```
Contributor guide
Research direction
Start with the auto binds mapping path for unused accelerationStructureNV declarations and compare it with the uniform and storage-buffer cases shown in the issue. Use the provided GLSL reproducer and inspect the generated SPIR-V decorations; done when the unused accelerationStructureNV receives the expected DescriptorSet and Binding behavior consistently.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100