• 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 undefined expression
21
22# The test passes because main always writes the color red
23
24# Optimized using spirv-opt with the following arguments:
25# '--redundancy-elimination'
26# '--eliminate-local-multi-store'
27# '--private-to-local'
28# '--ccp'
29# '--eliminate-dead-branches'
30# '--merge-return'
31# '--scalar-replacement=100'
32# '--redundancy-elimination'
33# '--redundancy-elimination'
34# '--inline-entry-points-exhaustive'
35# '--eliminate-dead-branches'
36# '--merge-return'
37# '--vector-dce'
38# '--simplify-instructions'
39# '--private-to-local'
40# '--inline-entry-points-exhaustive'
41# '--vector-dce'
42# '--ccp'
43# '--eliminate-local-single-store'
44# '--copy-propagate-arrays'
45# '--eliminate-local-multi-store'
46# spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
47
48
49
50SHADER vertex variant_vertex_shader PASSTHROUGH
51
52# variant_fragment_shader is derived from the following GLSL:
53# #version 310 es
54# precision highp float;
55#
56# layout(location = 0) out vec4 _GLF_color;
57#
58# int search(int target)
59# {
60#   if (1 == target)
61#   {
62#     return 1;
63#   }
64#   return 1;
65# }
66#
67# void main()
68# {
69#   _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Writes the color red
70#
71#   for (int i = 0; i < 1; i++)
72#   {
73#     int result;
74#     search(1);
75#     switch (result)
76#     {
77#     case 0:
78#       return;
79#     }
80#   }
81# }
82SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
83; SPIR-V
84; Version: 1.0
85; Generator: Khronos Glslang Reference Front End; 7
86; Bound: 86
87; Schema: 0
88               OpCapability Shader
89          %1 = OpExtInstImport "GLSL.std.450"
90               OpMemoryModel Logical GLSL450
91               OpEntryPoint Fragment %4 "main" %24
92               OpExecutionMode %4 OriginUpperLeft
93               OpSource ESSL 310
94               OpName %4 "main"
95               OpName %10 "search(i1;"
96               OpName %9 "target"
97               OpName %24 "_GLF_color"
98               OpName %28 "i"
99               OpName %37 "param"
100               OpName %39 "result"
101               OpDecorate %10 RelaxedPrecision
102               OpDecorate %9 RelaxedPrecision
103               OpDecorate %13 RelaxedPrecision
104               OpDecorate %24 Location 0
105               OpDecorate %28 RelaxedPrecision
106               OpDecorate %39 RelaxedPrecision
107               OpDecorate %46 RelaxedPrecision
108               OpDecorate %47 RelaxedPrecision
109               OpDecorate %61 RelaxedPrecision
110               OpDecorate %68 RelaxedPrecision
111               OpDecorate %69 RelaxedPrecision
112          %2 = OpTypeVoid
113          %3 = OpTypeFunction %2
114          %6 = OpTypeInt 32 1
115          %7 = OpTypePointer Function %6
116          %8 = OpTypeFunction %6 %7
117         %12 = OpConstant %6 1
118         %14 = OpTypeBool
119         %21 = OpTypeFloat 32
120         %22 = OpTypeVector %21 4
121         %23 = OpTypePointer Output %22
122         %24 = OpVariable %23 Output
123         %25 = OpConstant %21 1
124         %26 = OpConstant %21 0
125         %27 = OpConstantComposite %22 %25 %26 %26 %25
126         %29 = OpConstant %6 0
127         %49 = OpUndef %6
128         %50 = OpConstantTrue %14
129         %55 = OpConstantFalse %14
130         %56 = OpTypePointer Function %14
131         %83 = OpUndef %14
132          %4 = OpFunction %2 None %3
133          %5 = OpLabel
134         %67 = OpVariable %56 Function %55
135         %68 = OpVariable %7 Function
136         %69 = OpVariable %7 Function
137         %57 = OpVariable %56 Function %55
138         %28 = OpVariable %7 Function
139         %37 = OpVariable %7 Function
140         %39 = OpVariable %7 Function
141               OpBranch %52
142         %52 = OpLabel
143         %82 = OpPhi %14 %55 %5 %83 %54
144               OpLoopMerge %51 %54 None
145               OpBranch %53
146         %53 = OpLabel
147               OpStore %24 %27
148               OpStore %28 %29
149               OpBranch %30
150         %30 = OpLabel
151         %81 = OpPhi %14 %82 %53 %85 %33
152         %47 = OpPhi %6 %29 %53 %46 %33
153               OpLoopMerge %32 %33 None
154               OpBranch %34
155         %34 = OpLabel
156         %36 = OpSLessThan %14 %47 %12
157               OpBranchConditional %36 %31 %32
158         %31 = OpLabel
159               OpStore %37 %12
160               OpStore %67 %55
161               OpBranch %70
162         %70 = OpLabel
163         %85 = OpPhi %14 %81 %31 %83 %72
164               OpLoopMerge %71 %72 None
165               OpBranch %73
166         %73 = OpLabel
167         %75 = OpIEqual %14 %12 %12
168               OpSelectionMerge %76 None
169               OpBranchConditional %75 %77 %76
170         %77 = OpLabel
171               OpStore %67 %50
172               OpStore %68 %12
173               OpBranch %71
174         %76 = OpLabel
175               OpStore %67 %50
176               OpStore %68 %12
177               OpBranch %71
178         %72 = OpLabel
179               OpBranch %70
180         %71 = OpLabel
181               OpStore %69 %12
182               OpSelectionMerge %42 None
183               OpSwitch %49 %42 0 %41
184         %41 = OpLabel
185               OpStore %57 %50
186               OpBranch %32
187         %42 = OpLabel
188               OpBranch %33
189         %33 = OpLabel
190         %46 = OpIAdd %6 %47 %12
191               OpStore %28 %46
192               OpBranch %30
193         %32 = OpLabel
194         %80 = OpPhi %14 %81 %34 %50 %41
195               OpSelectionMerge %58 None
196               OpBranchConditional %80 %51 %58
197         %58 = OpLabel
198               OpStore %57 %50
199               OpBranch %51
200         %54 = OpLabel
201               OpBranch %52
202         %51 = OpLabel
203               OpReturn
204               OpFunctionEnd
205         %10 = OpFunction %6 None %8
206          %9 = OpFunctionParameter %7
207         %11 = OpLabel
208         %66 = OpVariable %56 Function %55
209         %61 = OpVariable %7 Function
210               OpBranch %63
211         %63 = OpLabel
212               OpLoopMerge %60 %65 None
213               OpBranch %64
214         %64 = OpLabel
215         %13 = OpLoad %6 %9
216         %15 = OpIEqual %14 %12 %13
217               OpSelectionMerge %17 None
218               OpBranchConditional %15 %16 %17
219         %16 = OpLabel
220               OpStore %66 %50
221               OpStore %61 %12
222               OpBranch %60
223         %17 = OpLabel
224               OpStore %66 %50
225               OpStore %61 %12
226               OpBranch %60
227         %65 = OpLabel
228               OpBranch %63
229         %60 = OpLabel
230               OpReturnValue %12
231               OpFunctionEnd
232END
233
234
235BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
236
237PIPELINE graphics variant_pipeline
238  ATTACH variant_vertex_shader
239  ATTACH variant_fragment_shader
240  FRAMEBUFFER_SIZE 256 256
241  BIND BUFFER variant_framebuffer AS color LOCATION 0
242END
243CLEAR_COLOR variant_pipeline 0 0 0 255
244
245CLEAR variant_pipeline
246RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
247
248EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
249