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