KhronosGroup / KhronosGroup/SPIRV-Tools
validate: should not be able to write to non-BufferBlock variables in Uniform storage class
- Dominant language
- C++
- Stars
- 1.4k
- Forks
- 709
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 28
Description
From https://gitlab.khronos.org/spirv/spirv-tools/issues/33
From the Khrons-internal bug report:
-------------------------
I found that a SPIR-V shader that does the following is not detected in the validator as invalid:
```
[...]
%arr_vec4_16 = OpTypeArray %vec4 %uint_16
%arr_vec4_16_ptr = OpTypePointer Uniform %arr_vec4_16
%Output = OpTypeStruct %arr_vec4_16
%_ptr_Uniform_Output = OpTypePointer Uniform %Output
%dataOutput = OpVariable %_ptr_Uniform_Output Uniform
%func0_decl = OpTypeFunction %void %arr_vec4_16_ptr %_ptr_Function_uint
%_ptr_Uniform_vec4 = OpTypePointer Uniform %vec4
[...]
%ptr0 = OpAccessChain %arr_vec4_16_ptr %dataOutput %int_0
%ret0 = OpFunctionCall %void %func0 %ptr0 %idx
[...]
%func0 = OpFunction %void None %func0_decl
%f0 = OpFunctionParameter %arr_vec4_16_ptr
%i0 = OpFunctionParameter %_ptr_Function_uint
%func0_entry = OpLabel
%idx0 = OpLoad %uint %i0
%out_ptr0 = OpAccessChain %_ptr_Uniform_vec4 %f0 %idx0
OpStore %out_ptr0 %vec4_5
OpReturn
OpFunctionEnd
```
The shader defines a UBO-like block (no BufferBlock decoration), with one member which is an array of vec4. It defines a function where the first parameter is a uniform pointer to that array. Inside that function, we try to write to one element of that array.
As it is Uniform, it should not be allowed to write to it unless it is a struct decorated with BufferBlock, but the validator doesn't complain.
Contributor guide
Research direction
No source file or test is named. Start by reproducing the supplied SPIR-V shader with the validator, then trace validation of writes through Uniform pointers and BufferBlock handling; done means the validator rejects the non-BufferBlock write.
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
- Clearly specified
- Newbie friendliness
- 35/100