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 two nested for loops
22 # The test passes because main always outputs 42.0.
24 # Optimized using spirv-opt with the following arguments:
25 # '--private-to-local'
26 # '--eliminate-local-multi-store'
27 # '--simplify-instructions'
28 # '--eliminate-dead-inserts'
29 # '--eliminate-dead-branches'
30 # spirv-opt commit hash: 4a00a80c40484a6f6f72f48c9d34943cf8f180d4
34 # variant_compute_shader is derived from the following GLSL:
37 # precision highp float;
39 # layout(std430, binding = 0) buffer doesNotMatter
41 # float _compute_data[];
48 # // Loop is entered, but we always return 42.0 during the first iteration.
54 # int GLF_live1_looplimiter2;
56 # // Loop is entered and we possibly return.
62 # // GLF_live1_looplimiter2 is undefined, so we may break; doesn't matter.
63 # if (GLF_live1_looplimiter2 >= 5)
68 # // If we didn't break, we return 42.0 here.
72 # if (float(i) <= s) // Always false: s is 0.0 or 1.0.
76 # // We return 42.0 and we don't loop.
79 # // Unreachable at runtime.
85 # _compute_data[0] = nb_mod(); // Always returns 42.0.
87 SHADER compute variant_compute_shader SPIRV-ASM TARGET_ENV spv1.0
90 ; Generator: Khronos Glslang Reference Front End; 7
94 %1 = OpExtInstImport "GLSL.std.450"
95 OpMemoryModel Logical GLSL450
96 OpEntryPoint GLCompute %4 "main"
97 OpExecutionMode %4 LocalSize 1 1 1
103 OpName %26 "GLF_live1i"
104 OpName %36 "GLF_live1_looplimiter2"
105 OpName %64 "doesNotMatter"
106 OpMemberName %64 0 "_compute_data"
108 OpDecorate %63 ArrayStride 4
109 OpMemberDecorate %64 0 Offset 0
110 OpDecorate %64 BufferBlock
111 OpDecorate %66 DescriptorSet 0
112 OpDecorate %66 Binding 0
114 %3 = OpTypeFunction %2
116 %7 = OpTypeFunction %6
117 %10 = OpTypePointer Function %6
118 %12 = OpConstant %6 0
120 %14 = OpTypePointer Function %13
121 %16 = OpConstant %13 5
122 %23 = OpConstant %13 800
124 %27 = OpConstant %13 0
125 %34 = OpConstant %13 20
126 %42 = OpConstant %6 1
127 %45 = OpConstant %6 42
128 %48 = OpConstant %13 1
129 %63 = OpTypeRuntimeArray %6
130 %64 = OpTypeStruct %63
131 %65 = OpTypePointer Uniform %64
132 %66 = OpVariable %65 Uniform
133 %68 = OpTypePointer Uniform %6
136 %4 = OpFunction %2 None %3
138 %67 = OpFunctionCall %6 %8
139 %69 = OpAccessChain %68 %66 %27 %27
143 %8 = OpFunction %6 None %7
145 %11 = OpVariable %10 Function
146 %15 = OpVariable %14 Function
147 %26 = OpVariable %14 Function
148 %36 = OpVariable %14 Function
153 OpLoopMerge %19 %20 None
156 %25 = OpSLessThan %24 %16 %23
157 OpBranchConditional %25 %18 %19
162 OpLoopMerge %30 %31 None
165 %35 = OpSLessThan %24 %27 %34
166 OpBranchConditional %35 %29 %30
168 %38 = OpSGreaterThanEqual %24 %74 %16
169 OpSelectionMerge %40 None
170 OpBranchConditional %38 %39 %40
172 %43 = OpFAdd %6 %12 %42
180 %79 = OpPhi %6 %12 %32 %43 %39
181 %51 = OpConvertSToF %6 %16
182 %53 = OpFOrdLessThanEqual %24 %51 %79
183 OpSelectionMerge %55 None
184 OpBranchConditional %53 %54 %55
192 %80 = OpPhi %6 %12 %21 %79 %54
197 # uniforms for variant
200 BUFFER variant_ssbo DATA_TYPE float DATA
201 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0 0.0
204 PIPELINE compute variant_pipeline
205 ATTACH variant_compute_shader
206 BIND BUFFER variant_ssbo AS storage DESCRIPTOR_SET 0 BINDING 0
209 RUN variant_pipeline 7 3 4
211 EXPECT variant_ssbo IDX 0 EQ 42.0