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 fragment shader with uniform comparison in loop
22 # The test passes because main always writes the color red
24 # Optimized using spirv-opt with the following arguments:
25 # '--eliminate-dead-inserts'
26 # '--combine-access-chains'
27 # '--eliminate-local-single-block'
29 # '--eliminate-dead-branches'
31 # '--eliminate-dead-branches'
33 # '--eliminate-local-multi-store'
34 # '--simplify-instructions'
35 # '--private-to-local'
36 # '--combine-access-chains'
37 # '--simplify-instructions'
39 # '--eliminate-dead-code-aggressive'
40 # '--eliminate-dead-code-aggressive'
42 # '--copy-propagate-arrays'
44 # '--private-to-local'
45 # '--eliminate-dead-code-aggressive'
46 # spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
50 SHADER vertex variant_vertex_shader PASSTHROUGH
52 # variant_fragment_shader is derived from the following GLSL:
54 # precision highp float;
56 # layout(location = 0) out vec4 _GLF_color;
58 # layout(set = 0, binding = 0) uniform buf0
60 # vec2 injectionSwitch;
65 # for (int i = 0; i < 1; i++)
67 # for (int _injected_loop_counter = 0; 1 < int(injectionSwitch.y); 1)
78 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Writes the color red
80 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
83 ; Generator: Khronos Glslang Reference Front End; 7
87 %1 = OpExtInstImport "GLSL.std.450"
88 OpMemoryModel Logical GLSL450
89 OpEntryPoint Fragment %4 "main" %49
90 OpExecutionMode %4 OriginUpperLeft
93 OpName %8 "makeFrame("
95 OpMemberName %30 0 "injectionSwitch"
97 OpName %49 "_GLF_color"
98 OpMemberDecorate %30 0 Offset 0
100 OpDecorate %32 DescriptorSet 0
101 OpDecorate %32 Binding 0
102 OpDecorate %43 RelaxedPrecision
103 OpDecorate %49 Location 0
104 OpDecorate %67 RelaxedPrecision
105 OpDecorate %73 RelaxedPrecision
107 %3 = OpTypeFunction %2
109 %7 = OpTypeFunction %6
111 %13 = OpConstant %10 0
112 %20 = OpConstant %10 1
114 %29 = OpTypeVector %6 2
115 %30 = OpTypeStruct %29
116 %31 = OpTypePointer Uniform %30
117 %32 = OpVariable %31 Uniform
119 %34 = OpConstant %33 1
120 %35 = OpTypePointer Uniform %6
121 %40 = OpConstant %6 1
122 %47 = OpTypeVector %6 4
123 %48 = OpTypePointer Output %47
124 %49 = OpVariable %48 Output
125 %50 = OpConstant %6 0
126 %51 = OpConstantComposite %47 %40 %50 %50 %40
127 %59 = OpConstantFalse %21
128 %62 = OpConstantTrue %21
132 %4 = OpFunction %2 None %3
134 %46 = OpFunctionCall %6 %8
138 %8 = OpFunction %6 None %7
142 OpLoopMerge %52 %58 None
147 %70 = OpPhi %21 %59 %57 %68 %63
148 %67 = OpPhi %10 %13 %57 %43 %63
149 %77 = OpPhi %6 %79 %57 %80 %63
150 %22 = OpSLessThan %21 %67 %20
151 OpLoopMerge %16 %63 None
152 OpBranchConditional %22 %15 %16
156 %81 = OpPhi %6 %77 %15 %79 %27
157 %73 = OpPhi %10 %67 %15 %83 %27
158 %69 = OpPhi %21 %70 %15 %82 %27
159 %36 = OpAccessChain %35 %32 %13 %34
161 %38 = OpConvertFToS %10 %37
162 %39 = OpSLessThan %21 %20 %38
163 OpLoopMerge %26 %27 None
164 OpBranchConditional %39 %25 %26
170 %80 = OpPhi %6 %81 %24 %40 %25
171 %68 = OpPhi %21 %69 %24 %62 %25
172 OpSelectionMerge %84 None
173 OpBranchConditional %68 %16 %84
177 %43 = OpIAdd %10 %73 %20
180 %76 = OpPhi %6 %77 %14 %80 %26
181 %74 = OpPhi %21 %70 %14 %68 %26
182 OpSelectionMerge %65 None
183 OpBranchConditional %74 %52 %65
189 %75 = OpPhi %6 %76 %16 %40 %65
194 # uniforms for variant
197 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
201 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
203 PIPELINE graphics variant_pipeline
204 ATTACH variant_vertex_shader
205 ATTACH variant_fragment_shader
206 FRAMEBUFFER_SIZE 256 256
207 BIND BUFFER variant_framebuffer AS color LOCATION 0
208 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
210 CLEAR_COLOR variant_pipeline 0 0 0 255
212 CLEAR variant_pipeline
213 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
215 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255