• 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 an always false if.
21
22# The test passes because the shader always writes color red.
23# Function brick() writes red in the beginning and returns in the end.
24
25# Optimized using spirv-opt with the following arguments:
26# '--eliminate-dead-branches'
27# '--merge-blocks'
28# '--inline-entry-points-exhaustive'
29# '--scalar-replacement=100'
30# '--eliminate-local-single-block'
31# '--eliminate-local-single-block'
32# '--eliminate-dead-branches'
33# '--merge-blocks'
34# '--eliminate-dead-code-aggressive'
35# '--eliminate-dead-branches'
36# '--convert-local-access-chains'
37# '--scalar-replacement=100'
38# '--reduce-load-size'
39# '--scalar-replacement=100'
40# '--redundancy-elimination'
41# '--convert-local-access-chains'
42# '--eliminate-dead-branches'
43# '--merge-blocks'
44# '--eliminate-dead-branches'
45# '--vector-dce'
46# '--eliminate-local-single-block'
47# '--private-to-local'
48# '--copy-propagate-arrays'
49# '--eliminate-dead-branches'
50# '--redundancy-elimination'
51# '--vector-dce'
52# '--scalar-replacement=100'
53# '--eliminate-local-multi-store'
54# '--scalar-replacement=100'
55# '--redundancy-elimination'
56# '--redundancy-elimination'
57# '--copy-propagate-arrays'
58# spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
59
60
61
62SHADER vertex variant_vertex_shader PASSTHROUGH
63
64# variant_fragment_shader is derived from the following GLSL:
65# #version 310 es
66# precision highp float;
67#
68# layout(set = 0, binding = 0) uniform buf0
69# {
70#     vec2 injectionSwitch;
71# };
72#
73# layout(location = 0) out vec4 _GLF_color;
74#
75# vec2 brick(vec2 uv)
76# {
77#     _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Write color red
78#
79#     int a;
80#     do
81#     {
82#         if (injectionSwitch.y < 0.0) // Always false
83#         {
84#             return vec2(1.0);
85#         }
86#         uv.y -= 1.0;
87#     } while (false);
88#
89#     uv.y -= 1.0;
90#     return vec2(1.0);
91# }
92#
93# void main()
94# {
95#     brick(vec2(1.0));
96# }
97SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
98; SPIR-V
99; Version: 1.0
100; Generator: Khronos Glslang Reference Front End; 7
101; Bound: 54
102; Schema: 0
103               OpCapability Shader
104          %1 = OpExtInstImport "GLSL.std.450"
105               OpMemoryModel Logical GLSL450
106               OpEntryPoint Fragment %4 "main" %15
107               OpExecutionMode %4 OriginUpperLeft
108               OpSource ESSL 310
109               OpName %4 "main"
110               OpName %11 "brick(vf2;"
111               OpName %10 "uv"
112               OpName %15 "_GLF_color"
113               OpName %23 "buf0"
114               OpMemberName %23 0 "injectionSwitch"
115               OpName %25 ""
116               OpName %51 "param"
117               OpDecorate %15 Location 0
118               OpMemberDecorate %23 0 Offset 0
119               OpDecorate %23 Block
120               OpDecorate %25 DescriptorSet 0
121               OpDecorate %25 Binding 0
122          %2 = OpTypeVoid
123          %3 = OpTypeFunction %2
124          %6 = OpTypeFloat 32
125          %7 = OpTypeVector %6 2
126          %8 = OpTypePointer Function %7
127          %9 = OpTypeFunction %7 %8
128         %13 = OpTypeVector %6 4
129         %14 = OpTypePointer Output %13
130         %15 = OpVariable %14 Output
131         %16 = OpConstant %6 1
132         %17 = OpConstant %6 0
133         %18 = OpConstantComposite %13 %16 %17 %17 %16
134         %23 = OpTypeStruct %7
135         %24 = OpTypePointer Uniform %23
136         %25 = OpVariable %24 Uniform
137         %26 = OpTypeInt 32 1
138         %27 = OpConstant %26 0
139         %28 = OpTypeInt 32 0
140         %29 = OpConstant %28 1
141         %30 = OpTypePointer Uniform %6
142         %33 = OpTypeBool
143         %37 = OpConstantComposite %7 %16 %16
144         %39 = OpTypePointer Function %6
145         %44 = OpConstantFalse %33
146          %4 = OpFunction %2 None %3
147          %5 = OpLabel
148         %51 = OpVariable %8 Function
149               OpStore %51 %37
150         %52 = OpFunctionCall %7 %11 %51
151               OpReturn
152               OpFunctionEnd
153         %11 = OpFunction %7 None %9
154         %10 = OpFunctionParameter %8
155         %12 = OpLabel
156               OpStore %15 %18
157               OpBranch %19
158         %19 = OpLabel
159               OpLoopMerge %21 %36 None
160               OpBranch %20
161         %20 = OpLabel
162         %31 = OpAccessChain %30 %25 %27 %29
163         %32 = OpLoad %6 %31
164         %34 = OpFOrdLessThan %33 %32 %17
165               OpSelectionMerge %53 None
166               OpBranchConditional %34 %35 %36
167         %35 = OpLabel
168               OpReturnValue %37
169         %53 = OpLabel
170               OpBranch %36
171         %36 = OpLabel
172         %40 = OpAccessChain %39 %10 %29
173         %41 = OpLoad %6 %40
174         %42 = OpFSub %6 %41 %16
175               OpStore %40 %42
176               OpBranchConditional %44 %19 %21
177         %21 = OpLabel
178         %46 = OpLoad %6 %40
179         %47 = OpFSub %6 %46 %16
180               OpStore %40 %47
181               OpReturnValue %37
182               OpFunctionEnd
183END
184
185# uniforms for variant
186
187# injectionSwitch
188BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
189 0.0 1.0
190END
191
192BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
193
194PIPELINE graphics variant_pipeline
195  ATTACH variant_vertex_shader
196  ATTACH variant_fragment_shader
197  FRAMEBUFFER_SIZE 256 256
198  BIND BUFFER variant_framebuffer AS color LOCATION 0
199  BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
200END
201CLEAR_COLOR variant_pipeline 0 0 0 255
202
203CLEAR variant_pipeline
204RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
205
206EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
207