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 two nested for loops with return
22 # The test passes because the shader always writes the color red.
24 # Optimized using spirv-opt with the following arguments:
25 # '--private-to-local'
27 # '--eliminate-dead-inserts'
28 # '--eliminate-dead-branches'
29 # '--reduce-load-size'
32 # '--redundancy-elimination'
33 # '--convert-local-access-chains'
34 # '--eliminate-dead-inserts'
36 # '--eliminate-dead-branches'
38 # '--eliminate-local-single-block'
39 # '--eliminate-local-single-block'
40 # '--copy-propagate-arrays'
41 # '--inline-entry-points-exhaustive'
43 # '--eliminate-local-multi-store'
44 # '--inline-entry-points-exhaustive'
45 # '--reduce-load-size'
47 # '--eliminate-local-single-block'
48 # '--eliminate-dead-branches'
49 # spirv-opt commit hash: 230c9e437146e48ec58adb4433890403c23c98fa
53 SHADER vertex variant_vertex_shader PASSTHROUGH
55 # variant_fragment_shader is derived from the following GLSL:
57 # precision highp float;
59 # layout(location = 0) out vec4 _GLF_color;
61 # float nb_mod(float limit)
63 # if (float(1) >= limit)
68 # int _injected_loop_counter = 0;
69 # _injected_loop_counter < 2;
70 # ++_injected_loop_counter)
73 # int _injected_loop_counter = 0;
74 # _injected_loop_counter < 1;
75 # ++_injected_loop_counter)
83 # nb_mod(gl_FragCoord.x);
84 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
86 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
89 ; Generator: Khronos Glslang Reference Front End; 7
93 %1 = OpExtInstImport "GLSL.std.450"
94 OpMemoryModel Logical GLSL450
95 OpEntryPoint Fragment %4 "main" %48 %57
96 OpExecutionMode %4 OriginUpperLeft
99 OpName %10 "nb_mod(f1;"
101 OpName %21 "_injected_loop_counter"
102 OpName %31 "_injected_loop_counter"
103 OpName %48 "gl_FragCoord"
105 OpName %57 "_GLF_color"
106 OpDecorate %21 RelaxedPrecision
107 OpDecorate %31 RelaxedPrecision
108 OpDecorate %48 BuiltIn FragCoord
109 OpDecorate %57 Location 0
111 %3 = OpTypeFunction %2
113 %7 = OpTypePointer Function %6
114 %8 = OpTypeFunction %6 %7
115 %12 = OpConstant %6 1
118 %20 = OpTypePointer Function %19
119 %22 = OpConstant %19 0
120 %29 = OpConstant %19 2
121 %38 = OpConstant %19 1
122 %46 = OpTypeVector %6 4
123 %47 = OpTypePointer Input %46
124 %48 = OpVariable %47 Input
126 %51 = OpConstant %50 0
127 %52 = OpTypePointer Input %6
128 %56 = OpTypePointer Output %46
129 %57 = OpVariable %56 Output
130 %58 = OpConstant %6 0
131 %59 = OpConstantComposite %46 %12 %58 %58 %12
133 %64 = OpConstantTrue %14
134 %4 = OpFunction %2 None %3
136 %49 = OpVariable %7 Function
137 %53 = OpAccessChain %52 %48 %51
140 %55 = OpFunctionCall %6 %10 %49
144 %10 = OpFunction %6 None %8
145 %9 = OpFunctionParameter %7
147 %21 = OpVariable %20 Function
148 %31 = OpVariable %20 Function
150 %15 = OpFOrdGreaterThanEqual %14 %12 %13
151 OpSelectionMerge %17 None
152 OpBranchConditional %15 %16 %17
159 %30 = OpSLessThan %14 %22 %29
160 OpLoopMerge %25 %34 None
166 %39 = OpSLessThan %14 %22 %38
167 OpLoopMerge %65 %35 None
182 # uniforms for variant
185 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
187 PIPELINE graphics variant_pipeline
188 ATTACH variant_vertex_shader
189 ATTACH variant_fragment_shader
190 FRAMEBUFFER_SIZE 256 256
191 BIND BUFFER variant_framebuffer AS color LOCATION 0
193 CLEAR_COLOR variant_pipeline 0 0 0 255
195 CLEAR variant_pipeline
196 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
198 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255