• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Copyright 2019 Google LLC
4#
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
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16
17
18# A test for a bug found by GraphicsFuzz.
19
20# Short description: A fragment shader with a do while that always returns
21
22# The test passes because the shader always writes the color red. The do while returns on first iteration.
23
24# Optimized using spirv-opt with the following arguments:
25# '--redundancy-elimination'
26# '--reduce-load-size'
27# '--combine-access-chains'
28# '--eliminate-dead-code-aggressive'
29# '--eliminate-dead-branches'
30# spirv-opt commit hash: 06407250a169c6a03b3765e86619075af1a8c187
31
32
33
34SHADER vertex variant_vertex_shader PASSTHROUGH
35
36# variant_fragment_shader is derived from the following GLSL:
37# #version 310 es
38# precision highp float;
39#
40# layout(location = 0) out vec4 _GLF_color;
41#
42# struct _GLF_struct_12
43# {
44#   int count;
45# };
46#
47# bool puzzlelize(vec2 pos)
48# {
49#   return true;
50# }
51#
52# void main()
53# {
54#   _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
55#
56#   vec2 grid;
57#   _GLF_struct_12 _GLF_struct_replacement_12;
58#
59#   do
60#   {
61#     if (gl_FragCoord.y > -1.0) // Always true
62#     {
63#       return;
64#     }
65#   } while (_GLF_struct_replacement_12.count != 1);
66#
67#   grid += vec2(1, _GLF_struct_replacement_12.count);
68#   vec2 position;
69#   position = grid;
70#   vec4(puzzlelize(position));
71#
72#   _GLF_color = vec4(1.0, 1.0, 1.0, 1.0); // This should not be reached
73# }
74SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
75; SPIR-V
76; Version: 1.0
77; Generator: Khronos Glslang Reference Front End; 7
78; Bound: 64
79; Schema: 0
80               OpCapability Shader
81          %1 = OpExtInstImport "GLSL.std.450"
82               OpMemoryModel Logical GLSL450
83               OpEntryPoint Fragment %4 "main" %19 %28
84               OpExecutionMode %4 OriginUpperLeft
85               OpSource ESSL 310
86               OpName %4 "main"
87               OpName %12 "puzzlelize(vf2;"
88               OpName %11 "pos"
89               OpName %19 "_GLF_color"
90               OpName %28 "gl_FragCoord"
91               OpName %40 "_GLF_struct_12"
92               OpMemberName %40 0 "count"
93               OpName %42 "_GLF_struct_replacement_12"
94               OpName %49 "grid"
95               OpName %56 "position"
96               OpName %58 "param"
97               OpDecorate %19 Location 0
98               OpDecorate %28 BuiltIn FragCoord
99               OpMemberDecorate %40 0 RelaxedPrecision
100               OpDecorate %46 RelaxedPrecision
101               OpDecorate %51 RelaxedPrecision
102          %2 = OpTypeVoid
103          %3 = OpTypeFunction %2
104          %6 = OpTypeFloat 32
105          %7 = OpTypeVector %6 2
106          %8 = OpTypePointer Function %7
107          %9 = OpTypeBool
108         %10 = OpTypeFunction %9 %8
109         %14 = OpConstantTrue %9
110         %17 = OpTypeVector %6 4
111         %18 = OpTypePointer Output %17
112         %19 = OpVariable %18 Output
113         %20 = OpConstant %6 1
114         %21 = OpConstant %6 0
115         %22 = OpConstantComposite %17 %20 %21 %21 %20
116         %27 = OpTypePointer Input %17
117         %28 = OpVariable %27 Input
118         %29 = OpTypeInt 32 0
119         %30 = OpConstant %29 1
120         %31 = OpTypePointer Input %6
121         %34 = OpConstant %6 -1
122         %39 = OpTypeInt 32 1
123         %40 = OpTypeStruct %39
124         %41 = OpTypePointer Function %40
125         %43 = OpConstant %39 0
126         %44 = OpTypePointer Function %39
127         %47 = OpConstant %39 1
128         %63 = OpConstantComposite %17 %20 %20 %20 %20
129          %4 = OpFunction %2 None %3
130          %5 = OpLabel
131         %42 = OpVariable %41 Function
132         %49 = OpVariable %8 Function
133         %56 = OpVariable %8 Function
134         %58 = OpVariable %8 Function
135               OpStore %19 %22
136               OpBranch %23
137         %23 = OpLabel
138               OpLoopMerge %25 %26 None
139               OpBranch %24
140         %24 = OpLabel
141         %32 = OpAccessChain %31 %28 %30
142         %33 = OpLoad %6 %32
143         %35 = OpFOrdGreaterThan %9 %33 %34
144               OpSelectionMerge %37 None
145               OpBranchConditional %35 %36 %37
146         %36 = OpLabel
147               OpReturn
148         %37 = OpLabel
149               OpBranch %26
150         %26 = OpLabel
151         %45 = OpAccessChain %44 %42 %43
152         %46 = OpLoad %39 %45
153         %48 = OpINotEqual %9 %46 %47
154               OpBranchConditional %48 %23 %25
155         %25 = OpLabel
156         %51 = OpLoad %39 %45
157         %52 = OpConvertSToF %6 %51
158         %53 = OpCompositeConstruct %7 %20 %52
159         %54 = OpLoad %7 %49
160         %55 = OpFAdd %7 %54 %53
161               OpStore %49 %55
162         %57 = OpLoad %7 %49
163               OpStore %56 %57
164         %59 = OpLoad %7 %56
165               OpStore %58 %59
166         %60 = OpFunctionCall %9 %12 %58
167               OpStore %19 %63
168               OpReturn
169               OpFunctionEnd
170         %12 = OpFunction %9 None %10
171         %11 = OpFunctionParameter %8
172         %13 = OpLabel
173               OpReturnValue %14
174               OpFunctionEnd
175END
176
177# uniforms for variant
178
179
180BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
181
182PIPELINE graphics variant_pipeline
183  ATTACH variant_vertex_shader
184  ATTACH variant_fragment_shader
185  FRAMEBUFFER_SIZE 256 256
186  BIND BUFFER variant_framebuffer AS color LOCATION 0
187END
188CLEAR_COLOR variant_pipeline 0 0 0 255
189
190CLEAR variant_pipeline
191RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
192
193EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
194