KhronosGroup / KhronosGroup/SPIRV-Tools

Validator does not catch for images which are stored to stack

Open
#2,043 0 comments 0 reactions 0 assignees View on GitHub
component:validation
Dominant language
C++
Stars
1.4k
Forks
709
Avg merge
1d 22h
Merged PRs (30d)
28

Description

A shader like this will pass the validator, even though an image is loaded, stored to a function variable and passed around as a parameter:

```
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 60
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %Main "Main" %_entryPointOutput
OpExecutionMode %Main OriginUpperLeft
OpSource HLSL 500
OpName %Main "Main"
OpName %A_t21_ "A(t21;"
OpName %_texture "_texture"
OpName %Sum_t21_ "Sum(t21;"
OpName %_texture_0 "_texture"
OpName %_Main_ "@Main("
OpName %Sampler "Sampler"
OpName %param "param"
OpName %a "a"
OpName %Texture0 "Texture0"
OpName %param_0 "param"
OpName %Texture1 "Texture1"
OpName %param_1 "param"
OpName %_entryPointOutput "@entryPointOutput"
OpDecorate %Sampler DescriptorSet 0
OpDecorate %Sampler Binding 2
OpDecorate %Texture0 DescriptorSet 0
OpDecorate %Texture0 Binding 0
OpDecorate %Texture1 DescriptorSet 0
OpDecorate %Texture1 Binding 1
OpDecorate %_entryPointOutput Location 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%7 = OpTypeImage %float 2D 0 0 0 1 Unknown
%_ptr_Function_7 = OpTypePointer Function %7
%9 = OpTypeFunction %float %_ptr_Function_7
%16 = OpTypeFunction %float
%20 = OpTypeSampler
%_ptr_UniformConstant_20 = OpTypePointer UniformConstant %20
%Sampler = OpVariable %_ptr_UniformConstant_20 UniformConstant
%24 = OpTypeSampledImage %7
%v2float = OpTypeVector %float 2
%float_0 = OpConstant %float 0
%28 = OpConstantComposite %v2float %float_0 %float_0
%v4float = OpTypeVector %float 4
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_Function_float = OpTypePointer Function %float
%_ptr_UniformConstant_7 = OpTypePointer UniformConstant %7
%Texture0 = OpVariable %_ptr_UniformConstant_7 UniformConstant
%Texture1 = OpVariable %_ptr_UniformConstant_7 UniformConstant
%_ptr_Output_float = OpTypePointer Output %float
%_entryPointOutput = OpVariable %_ptr_Output_float Output
%Main = OpFunction %void None %3
%5 = OpLabel
%59 = OpFunctionCall %float %_Main_
OpStore %_entryPointOutput %59
OpReturn
OpFunctionEnd
%A_t21_ = OpFunction %float None %9
%_texture = OpFunctionParameter %_ptr_Function_7
%12 = OpLabel
%19 = OpLoad %7 %_texture
%23 = OpLoad %20 %Sampler
%25 = OpSampledImage %24 %19 %23
%30 = OpImageSampleImplicitLod %v4float %25 %28
%33 = OpCompositeExtract %float %30 0
OpReturnValue %33
OpFunctionEnd
%Sum_t21_ = OpFunction %float None %9
%_texture_0 = OpFunctionParameter %_ptr_Function_7
%15 = OpLabel
%param = OpVariable %_ptr_Function_7 Function
%37 = OpLoad %7 %_texture_0
OpStore %param %37
%38 = OpFunctionCall %float %A_t21_ %param
OpReturnValue %38
OpFunctionEnd
%_Main_ = OpFunction %float None %16
%18 = OpLabel
%a = OpVariable %_ptr_Function_float Function
%param_0 = OpVariable %_ptr_Function_7 Function
%param_1 = OpVariable %_ptr_Function_7 Function
%46 = OpLoad %7 %Texture0
OpStore %param_0 %46
%47 = OpFunctionCall %float %Sum_t21_ %param_0
OpStore %a %47
%50 = OpLoad %7 %Texture1
OpStore %param_1 %50
%51 = OpFunctionCall %float %Sum_t21_ %param_1
%52 = OpLoad %float %a
%53 = OpFAdd %float %52 %51
OpStore %a %53
%54 = OpLoad %float %a
OpReturnValue %54
OpFunctionEnd
```

Contributor guide

Open the contributing guide

Research direction

Use the supplied SPIR-V shader as the reproduction input and trace the validator's handling of images loaded into function variables and passed as parameters. Confirm the behavior with this example and identify the validator entry point or tests that cover it; done means the validator catches this shader pattern instead of allowing it through.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.