3 # Copyright 2020 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 fragment shader with two for loops over a global matrix
22 # The test passes because the shader always writes red.
24 # Optimized using spirv-opt with the following arguments:
25 # '--eliminate-dead-code-aggressive'
29 # '--eliminate-dead-code-aggressive'
30 # '--eliminate-local-multi-store'
31 # '--eliminate-dead-branches'
32 # '--inline-entry-points-exhaustive'
33 # '--copy-propagate-arrays'
34 # '--eliminate-local-single-store'
35 # '--eliminate-local-multi-store'
36 # '--convert-local-access-chains'
37 # '--inline-entry-points-exhaustive'
38 # '--convert-local-access-chains'
40 # '--redundancy-elimination'
41 # spirv-opt commit hash: 18b3b94567a9251a6f8491a6d07c4422abadd22c
45 SHADER vertex variant_vertex_shader PASSTHROUGH
47 # variant_fragment_shader is derived from the following GLSL:
49 # precision highp float;
51 # layout(set = 0, binding = 0) uniform buf0 {
52 # vec2 injectionSwitch;
55 # layout(location = 0) out vec4 _GLF_color;
62 # if (injectionSwitch.x < 1.0) {
66 # 9.0, 10.0, 11.0, 12.0,
67 # 13.0, 14.0, 15.0, 16.0
81 # // 0 iteration loop.
90 # // Always true (1+2+3+4==10).
92 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
94 # _GLF_color = vec4(0.0, 0.0, 0.0, 1.0);
96 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
99 ; Generator: Khronos Glslang Reference Front End; 8
103 %1 = OpExtInstImport "GLSL.std.450"
104 OpMemoryModel Logical GLSL450
105 OpEntryPoint Fragment %4 "main" %92
106 OpExecutionMode %4 OriginUpperLeft
110 OpMemberName %8 0 "injectionSwitch"
117 OpName %92 "_GLF_color"
118 OpMemberDecorate %8 0 Offset 0
120 OpDecorate %10 DescriptorSet 0
121 OpDecorate %10 Binding 0
122 OpDecorate %51 RelaxedPrecision
123 OpDecorate %52 RelaxedPrecision
124 OpDecorate %70 RelaxedPrecision
125 OpDecorate %71 RelaxedPrecision
126 OpDecorate %86 RelaxedPrecision
127 OpDecorate %92 Location 0
128 OpDecorate %96 RelaxedPrecision
130 %3 = OpTypeFunction %2
132 %7 = OpTypeVector %6 2
134 %9 = OpTypePointer Uniform %8
135 %10 = OpVariable %9 Uniform
137 %12 = OpConstant %11 0
139 %14 = OpConstant %13 0
140 %15 = OpTypePointer Uniform %6
141 %18 = OpConstant %6 1
143 %23 = OpTypeVector %6 4
144 %24 = OpTypeMatrix %23 4
145 %25 = OpTypePointer Private %24
146 %26 = OpVariable %25 Private
147 %27 = OpConstant %6 2
148 %28 = OpConstant %6 3
149 %29 = OpConstant %6 4
150 %30 = OpConstantComposite %23 %18 %27 %28 %29
151 %31 = OpConstant %6 5
152 %32 = OpConstant %6 6
153 %33 = OpConstant %6 7
154 %34 = OpConstant %6 8
155 %35 = OpConstantComposite %23 %31 %32 %33 %34
156 %36 = OpConstant %6 9
157 %37 = OpConstant %6 10
158 %38 = OpConstant %6 11
159 %39 = OpConstant %6 12
160 %40 = OpConstantComposite %23 %36 %37 %38 %39
161 %41 = OpConstant %6 13
162 %42 = OpConstant %6 14
163 %43 = OpConstant %6 15
164 %44 = OpConstant %6 16
165 %45 = OpConstantComposite %23 %41 %42 %43 %44
166 %46 = OpConstantComposite %24 %30 %35 %40 %45
167 %47 = OpTypePointer Function %6
168 %49 = OpConstant %6 0
169 %50 = OpTypePointer Function %11
170 %59 = OpConstant %11 4
171 %63 = OpTypePointer Private %6
172 %69 = OpConstant %11 1
173 %91 = OpTypePointer Output %23
174 %92 = OpVariable %91 Output
175 %93 = OpConstantComposite %23 %18 %49 %49 %18
176 %95 = OpConstantComposite %23 %49 %49 %49 %18
177 %102 = OpConstantTrue %19
178 %103 = OpConstantFalse %19
179 %4 = OpFunction %2 None %3
181 %48 = OpVariable %47 Function
182 %51 = OpVariable %50 Function
183 %52 = OpVariable %50 Function
184 %71 = OpVariable %50 Function
185 %16 = OpAccessChain %15 %10 %12 %14
187 %20 = OpFOrdLessThan %19 %17 %18
188 OpSelectionMerge %22 None
189 OpBranchConditional %20 %21 %22
199 %99 = OpPhi %6 %49 %22 %67 %56
200 %96 = OpPhi %11 %12 %22 %70 %56
201 OpLoopMerge %55 %56 None
204 %60 = OpSLessThan %19 %96 %59
205 OpBranchConditional %60 %54 %55
207 %64 = OpAccessChain %63 %26 %12 %96
209 %67 = OpFAdd %6 %99 %65
213 %70 = OpIAdd %11 %96 %69
220 %98 = OpPhi %6 %99 %55 %84 %75
221 %97 = OpPhi %11 %59 %55 %86 %75
222 OpLoopMerge %74 %75 None
225 %78 = OpSLessThan %19 %59 %59
226 OpBranchConditional %103 %73 %74
228 %81 = OpAccessChain %63 %26 %12 %59
230 %84 = OpFAdd %6 %98 %82
234 %86 = OpIAdd %11 %59 %69
238 %88 = OpFOrdEqual %19 %98 %37
239 OpSelectionMerge %90 None
240 OpBranchConditional %88 %89 %94
252 # uniforms for variant
255 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
259 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
261 PIPELINE graphics variant_pipeline
262 ATTACH variant_vertex_shader
263 ATTACH variant_fragment_shader
264 FRAMEBUFFER_SIZE 256 256
265 BIND BUFFER variant_framebuffer AS color LOCATION 0
266 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
268 CLEAR_COLOR variant_pipeline 0 0 0 255
270 CLEAR variant_pipeline
271 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
273 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255