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: Fragment shader with struct and unreachable infinite loop
22 # The test passes because 'tree[0].rightIndex' is set to 1, so that the infinite loop is not reached and the output colour red is written
24 # Optimized using spirv-opt with the following arguments:
25 # '--redundancy-elimination'
26 # '--eliminate-dead-inserts'
27 # '--combine-access-chains'
30 # '--eliminate-dead-branches'
32 # '--private-to-local'
33 # '--simplify-instructions'
34 # '--simplify-instructions'
35 # '--eliminate-dead-branches'
37 # '--eliminate-local-multi-store'
38 # '--eliminate-local-single-store'
39 # '--eliminate-local-single-block'
40 # '--simplify-instructions'
41 # '--copy-propagate-arrays'
43 # '--simplify-instructions'
44 # '--reduce-load-size'
46 # '--eliminate-dead-branches'
48 # '--redundancy-elimination'
49 # '--simplify-instructions'
50 # '--eliminate-dead-branches'
51 # '--private-to-local'
53 # '--convert-local-access-chains'
54 # '--eliminate-dead-branches'
56 # '--private-to-local'
57 # '--private-to-local'
58 # spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
62 SHADER vertex variant_vertex_shader PASSTHROUGH
64 # variant_fragment_shader is derived from the following GLSL:
66 # precision highp float;
76 # layout(location = 0) out vec4 _GLF_color;
78 # void makeTreeNode(inout BST tree)
80 # tree.rightIndex = 1;
84 # makeTreeNode(tree[0]);
85 # if (tree[0].rightIndex == 0) {
91 # _GLF_color = vec4(float(tree[0].rightIndex), 0.0, 0.0, 1.0);
94 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
97 ; Generator: Khronos Glslang Reference Front End; 7
101 %1 = OpExtInstImport "GLSL.std.450"
102 OpMemoryModel Logical GLSL450
103 OpEntryPoint Fragment %4 "main" %46
104 OpExecutionMode %4 OriginUpperLeft
108 OpMemberName %7 0 "data"
109 OpMemberName %7 1 "leftIndex"
110 OpMemberName %7 2 "rightIndex"
111 OpName %11 "makeTreeNode(struct-BST-i1-i1-i11;"
115 OpName %46 "_GLF_color"
116 OpMemberDecorate %7 0 RelaxedPrecision
117 OpMemberDecorate %7 1 RelaxedPrecision
118 OpMemberDecorate %7 2 RelaxedPrecision
119 OpDecorate %32 RelaxedPrecision
120 OpDecorate %46 Location 0
121 OpDecorate %48 RelaxedPrecision
122 OpDecorate %57 RelaxedPrecision
123 OpDecorate %58 RelaxedPrecision
125 %3 = OpTypeFunction %2
127 %7 = OpTypeStruct %6 %6 %6
128 %8 = OpTypePointer Function %7
129 %9 = OpTypeFunction %2 %8
130 %13 = OpConstant %6 2
131 %14 = OpConstant %6 1
132 %15 = OpTypePointer Function %6
134 %18 = OpConstant %17 10
135 %19 = OpTypeArray %7 %18
136 %20 = OpTypePointer Private %19
137 %22 = OpConstant %6 0
138 %24 = OpTypePointer Private %7
139 %30 = OpTypePointer Private %6
141 %42 = OpConstantTrue %33
143 %44 = OpTypeVector %43 4
144 %45 = OpTypePointer Output %44
145 %46 = OpVariable %45 Output
146 %50 = OpConstant %43 0
147 %51 = OpConstant %43 1
148 %53 = OpTypePointer Function %19
149 %4 = OpFunction %2 None %3
151 %21 = OpVariable %53 Function
152 %23 = OpVariable %8 Function
154 %26 = OpCompositeExtract %7 %54 0
156 %27 = OpFunctionCall %2 %11 %23
159 %56 = OpCompositeInsert %19 %28 %55 0
161 %31 = OpAccessChain %15 %21 %22 %13
163 %32 = OpCompositeExtract %6 %57 0 2
164 %34 = OpIEqual %33 %32 %22
165 OpSelectionMerge %36 None
166 OpBranchConditional %34 %35 %36
170 OpLoopMerge %39 %37 None
176 %48 = OpCompositeExtract %6 %58 0 2
177 %49 = OpConvertSToF %43 %48
178 %52 = OpCompositeConstruct %44 %49 %50 %50 %51
182 %11 = OpFunction %2 None %9
183 %10 = OpFunctionParameter %8
185 %16 = OpAccessChain %15 %10 %13
191 # uniforms for variant
194 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
196 PIPELINE graphics variant_pipeline
197 ATTACH variant_vertex_shader
198 ATTACH variant_fragment_shader
199 FRAMEBUFFER_SIZE 256 256
200 BIND BUFFER variant_framebuffer AS color LOCATION 0
202 CLEAR_COLOR variant_pipeline 0 0 0 255
204 CLEAR variant_pipeline
205 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
207 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255