3 # Copyright 2019 Google LLC
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 # A test for a bug found by GraphicsFuzz.
20 # Short description: A compute shader with loops, breaks, returns
22 # The test passes because the shader immediately writes 42 to the 0th position
23 # in the SSBO and that is the only thing we check. All loops terminate. All
24 # other writes to the SSBO are at indices greater than 0.
26 # Optimized using spirv-opt with the following arguments:
27 # '--eliminate-dead-code-aggressive'
28 # '--simplify-instructions'
29 # '--redundancy-elimination'
30 # '--copy-propagate-arrays'
31 # '--convert-local-access-chains'
32 # '--eliminate-dead-branches'
33 # '--eliminate-local-multi-store'
34 # '--eliminate-local-multi-store'
35 # '--eliminate-dead-inserts'
36 # '--eliminate-local-single-block'
37 # '--redundancy-elimination'
38 # '--eliminate-dead-branches'
39 # spirv-opt commit hash: 4a00a80c40484a6f6f72f48c9d34943cf8f180d4
43 # variant_compute_shader is derived from the following GLSL:
46 # layout(std430, binding = 0) buffer theSSBO
51 # layout(set = 0, binding = 1) uniform buf0 {
52 # vec2 injectionSwitch;
55 # layout(local_size_x = 100, local_size_y = 1, local_size_z = 1) in;
60 # uint gid = uint(injectionSwitch.y); // 1
63 # if (1u != gid) // always false
76 # for (int i = 0; i < 1; ++i)
84 # data_out[gid] = 7u; // gid == 1
86 SHADER compute variant_compute_shader SPIRV-ASM TARGET_ENV spv1.0
89 ; Generator: Khronos Glslang Reference Front End; 7
93 %1 = OpExtInstImport "GLSL.std.450"
94 OpMemoryModel Logical GLSL450
95 OpEntryPoint GLCompute %4 "main"
96 OpExecutionMode %4 LocalSize 100 1 1
100 OpMemberName %9 0 "data_out"
104 OpMemberName %21 0 "injectionSwitch"
108 OpDecorate %8 ArrayStride 4
109 OpMemberDecorate %9 0 Offset 0
110 OpDecorate %9 BufferBlock
111 OpDecorate %11 DescriptorSet 0
112 OpDecorate %11 Binding 0
113 OpMemberDecorate %21 0 Offset 0
115 OpDecorate %23 DescriptorSet 0
116 OpDecorate %23 Binding 1
117 OpDecorate %76 BuiltIn WorkgroupSize
119 %3 = OpTypeFunction %2
122 %8 = OpTypeArray %6 %7
124 %10 = OpTypePointer Uniform %9
125 %11 = OpVariable %10 Uniform
127 %13 = OpConstant %12 0
128 %14 = OpConstant %6 42
129 %15 = OpTypePointer Uniform %6
130 %17 = OpTypePointer Function %6
132 %20 = OpTypeVector %19 2
133 %21 = OpTypeStruct %20
134 %22 = OpTypePointer Uniform %21
135 %23 = OpVariable %22 Uniform
136 %24 = OpConstant %6 1
137 %25 = OpTypePointer Uniform %19
139 %38 = OpConstant %12 1
140 %41 = OpConstantFalse %34
141 %47 = OpConstantTrue %34
142 %50 = OpConstant %6 0
143 %54 = OpConstant %6 2
144 %56 = OpTypePointer Function %12
145 %65 = OpConstant %6 3
146 %72 = OpConstant %6 7
147 %74 = OpTypeVector %6 3
148 %75 = OpConstant %6 100
149 %76 = OpConstantComposite %74 %75 %24 %24
152 %4 = OpFunction %2 None %3
154 %18 = OpVariable %17 Function
155 %48 = OpVariable %17 Function
156 %57 = OpVariable %56 Function
157 %16 = OpAccessChain %15 %11 %13 %13
159 %26 = OpAccessChain %25 %23 %13 %24
161 %28 = OpConvertFToU %6 %27
165 OpLoopMerge %31 %32 None
168 %35 = OpINotEqual %34 %24 %28
169 OpSelectionMerge %37 None
170 OpBranchConditional %35 %36 %37
172 %39 = OpAccessChain %15 %11 %13 %38
178 OpBranchConditional %41 %29 %31
182 OpLoopMerge %44 %45 None
187 %51 = OpINotEqual %34 %80 %50
188 OpSelectionMerge %53 None
189 OpBranchConditional %51 %52 %53
191 %55 = OpAccessChain %15 %11 %13 %38
196 OpLoopMerge %60 %61 None
199 %64 = OpSLessThan %34 %13 %38
200 OpBranchConditional %64 %59 %60
209 %82 = OpPhi %6 %28 %43 %28 %60
214 %73 = OpAccessChain %15 %11 %13 %82
220 # uniforms for variant
223 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
227 BUFFER variant_ssbo DATA_TYPE uint32 DATA
231 PIPELINE compute variant_pipeline
232 ATTACH variant_compute_shader
233 BIND BUFFER variant_ssbo AS storage DESCRIPTOR_SET 0 BINDING 0
234 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 1
237 RUN variant_pipeline 1 1 1
239 EXPECT variant_ssbo IDX 0 EQ 42