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 nested do while
22 # The test passes because the shader always writes color red. main() writes red and then returns at the end.
24 # Optimized using spirv-opt with the following arguments:
26 # '--redundancy-elimination'
27 # '--eliminate-dead-branches'
29 # '--eliminate-dead-branches'
30 # '--simplify-instructions'
31 # '--eliminate-dead-branches'
32 # spirv-opt commit hash: ad7f2c5c4c7f51360e9e079109a9217aa5ba5cc0
36 SHADER vertex variant_vertex_shader PASSTHROUGH
38 # variant_fragment_shader is derived from the following GLSL:
40 # precision highp float;
42 # precision highp int;
44 # layout(set = 0, binding = 0) uniform buf0
46 # vec2 injectionSwitch;
49 # layout(location = 0) out vec4 _GLF_color;
53 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Write color red
56 # if (injectionSwitch.y < 0.0) // Always false
61 # if (gl_FragCoord.y < -1.0) // Always false
68 # if (i >= 256) // Always false
74 # for (int i = 0; i < 1; i++)
76 # if (gl_FragCoord.y < -1.0) // Always false
78 # for (int i = 0; i < 1; i++)
90 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
93 ; Generator: Khronos Glslang Reference Front End; 7
97 %1 = OpExtInstImport "GLSL.std.450"
98 OpMemoryModel Logical GLSL450
99 OpEntryPoint Fragment %4 "main" %9 %32
100 OpExecutionMode %4 OriginUpperLeft
103 OpName %9 "_GLF_color"
106 OpMemberName %18 0 "injectionSwitch"
108 OpName %32 "gl_FragCoord"
111 OpDecorate %9 Location 0
112 OpMemberDecorate %18 0 Offset 0
114 OpDecorate %20 DescriptorSet 0
115 OpDecorate %20 Binding 0
116 OpDecorate %32 BuiltIn FragCoord
118 %3 = OpTypeFunction %2
120 %7 = OpTypeVector %6 4
121 %8 = OpTypePointer Output %7
122 %9 = OpVariable %8 Output
123 %10 = OpConstant %6 1
124 %11 = OpConstant %6 0
125 %12 = OpConstantComposite %7 %10 %11 %11 %10
127 %14 = OpTypePointer Function %13
128 %16 = OpConstant %13 0
129 %17 = OpTypeVector %6 2
130 %18 = OpTypeStruct %17
131 %19 = OpTypePointer Uniform %18
132 %20 = OpVariable %19 Uniform
134 %22 = OpConstant %21 1
135 %23 = OpTypePointer Uniform %6
137 %31 = OpTypePointer Input %7
138 %32 = OpVariable %31 Input
139 %33 = OpTypePointer Input %6
140 %36 = OpConstant %6 -1
141 %46 = OpConstant %13 256
142 %62 = OpConstant %13 1
143 %83 = OpConstantFalse %26
144 %4 = OpFunction %2 None %3
146 %15 = OpVariable %14 Function
147 %55 = OpVariable %14 Function
148 %69 = OpVariable %14 Function
151 %24 = OpAccessChain %23 %20 %16 %22
153 %27 = OpFOrdLessThan %26 %25 %11
154 OpSelectionMerge %29 None
155 OpBranchConditional %27 %28 %30
159 %34 = OpAccessChain %33 %32 %22
161 %37 = OpFOrdLessThan %26 %35 %36
162 OpSelectionMerge %39 None
163 OpBranchConditional %37 %38 %40
169 OpLoopMerge %43 %53 None
173 %47 = OpSGreaterThanEqual %26 %45 %46
174 OpSelectionMerge %49 None
175 OpBranchConditional %47 %48 %49
182 OpLoopMerge %84 %58 None
186 %63 = OpSLessThan %26 %61 %62
187 OpLoopMerge %85 %72 None
188 OpBranchConditional %63 %57 %85
190 OpSelectionMerge %68 None
191 OpBranchConditional %37 %67 %68
197 %76 = OpSLessThan %26 %75 %62
198 OpLoopMerge %86 %71 None
199 OpBranchConditional %76 %71 %86
202 %78 = OpIAdd %13 %77 %62
209 %82 = OpIAdd %13 %81 %62
217 OpBranchConditional %83 %51 %84
221 OpBranchConditional %83 %41 %43
231 # uniforms for variant
234 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
238 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
240 PIPELINE graphics variant_pipeline
241 ATTACH variant_vertex_shader
242 ATTACH variant_fragment_shader
243 FRAMEBUFFER_SIZE 256 256
244 BIND BUFFER variant_framebuffer AS color LOCATION 0
245 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
247 CLEAR_COLOR variant_pipeline 0 0 0 255
249 CLEAR variant_pipeline
250 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
252 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255