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 return inside 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 # '--private-to-local'
27 # '--eliminate-dead-inserts'
31 # '--inline-entry-points-exhaustive'
32 # '--eliminate-dead-branches'
34 # '--eliminate-dead-inserts'
35 # '--redundancy-elimination'
36 # '--eliminate-dead-branches'
37 # '--eliminate-dead-branches'
38 # '--inline-entry-points-exhaustive'
39 # '--eliminate-dead-inserts'
40 # '--private-to-local'
41 # '--eliminate-dead-inserts'
42 # '--convert-local-access-chains'
43 # '--eliminate-local-multi-store'
44 # '--simplify-instructions'
45 # '--convert-local-access-chains'
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 # vec3 GLF_live4drawShape()
60 # for (int i = 0; i < 0; i++)
68 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Writes the color red
69 # GLF_live4drawShape();
71 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
74 ; Generator: Khronos Glslang Reference Front End; 7
78 %1 = OpExtInstImport "GLSL.std.450"
79 OpMemoryModel Logical GLSL450
80 OpEntryPoint Fragment %4 "main" %32
81 OpExecutionMode %4 OriginUpperLeft
84 OpName %9 "GLF_live4drawShape("
86 OpName %32 "_GLF_color"
87 OpDecorate %13 RelaxedPrecision
88 OpDecorate %32 Location 0
89 OpDecorate %51 RelaxedPrecision
90 OpDecorate %68 RelaxedPrecision
91 OpDecorate %79 RelaxedPrecision
93 %3 = OpTypeFunction %2
95 %7 = OpTypeVector %6 3
96 %8 = OpTypeFunction %7
98 %12 = OpTypePointer Function %11
99 %14 = OpConstant %11 0
101 %23 = OpConstant %6 1
102 %24 = OpConstantComposite %7 %23 %23 %23
103 %27 = OpConstant %11 1
104 %30 = OpTypeVector %6 4
105 %31 = OpTypePointer Output %30
106 %32 = OpVariable %31 Output
107 %33 = OpConstant %6 0
108 %34 = OpConstantComposite %30 %23 %33 %33 %23
109 %37 = OpTypePointer Function %7
110 %43 = OpConstantFalse %21
111 %44 = OpTypePointer Function %21
112 %46 = OpConstantTrue %21
119 %4 = OpFunction %2 None %3
121 %49 = OpVariable %44 Function %43
122 %50 = OpVariable %37 Function
123 %51 = OpVariable %12 Function
124 %52 = OpVariable %37 Function
129 %71 = OpPhi %21 %43 %5 %78 %55
130 OpLoopMerge %54 %55 None
136 %70 = OpPhi %21 %71 %56 %78 %59
137 %68 = OpPhi %11 %14 %56 %77 %59
138 OpLoopMerge %58 %59 None
141 %62 = OpSLessThan %21 %68 %14
142 OpBranchConditional %62 %63 %58
150 %73 = OpPhi %7 %76 %60 %24 %63
151 %69 = OpPhi %21 %70 %60 %46 %63
152 OpSelectionMerge %65 None
153 OpBranchConditional %69 %54 %65
161 %72 = OpPhi %7 %73 %58 %66 %65
165 %9 = OpFunction %7 None %8
167 %45 = OpVariable %44 Function %43
168 %38 = OpVariable %37 Function
169 %13 = OpVariable %12 Function
172 %82 = OpPhi %21 %43 %10 %89 %42
173 OpLoopMerge %36 %42 None
179 %81 = OpPhi %21 %82 %41 %89 %18
180 %79 = OpPhi %11 %14 %41 %88 %18
181 OpLoopMerge %17 %18 None
184 %22 = OpSLessThan %21 %79 %14
185 OpBranchConditional %22 %16 %17
193 %84 = OpPhi %7 %87 %19 %24 %16
194 %80 = OpPhi %21 %81 %19 %46 %16
195 OpSelectionMerge %47 None
196 OpBranchConditional %80 %36 %47
204 %83 = OpPhi %7 %84 %17 %29 %47
210 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
212 PIPELINE graphics variant_pipeline
213 ATTACH variant_vertex_shader
214 ATTACH variant_fragment_shader
215 FRAMEBUFFER_SIZE 256 256
216 BIND BUFFER variant_framebuffer AS color LOCATION 0
218 CLEAR_COLOR variant_pipeline 0 0 0 255
220 CLEAR variant_pipeline
221 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
223 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255