• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Copyright 2021 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 coverage-gap found by the GraphicsFuzz project.
19
20# Short description: A fragment shader that covers specific NIR code paths
21
22# The test passes because the shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 320 es
28# #define _int_0 _GLF_uniform_int_values[0]
29# #define _int_1 _GLF_uniform_int_values[1]
30#
31# precision highp float;
32# precision highp int;
33#
34# // Contents of _GLF_uniform_int_values: [0, 1]
35# layout(set = 0, binding = 0) uniform buf0
36# {
37#     int _GLF_uniform_int_values[2];
38# };
39#
40# const int _GLF_global_loop_bound = 100;
41# int _GLF_global_loop_count = 0;
42#
43# layout(location = 0) out vec4 _GLF_color;
44#
45# void main()
46# {
47#     _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
48#
49#     while (_GLF_global_loop_count < _GLF_global_loop_bound)
50#     {
51#         _GLF_global_loop_count++;
52#
53#         // Always false.
54#         if (!(true || _int_0 == _int_1))
55#         {
56#             break;
57#         }
58#     }
59#
60#     // This loop will not be iterated since the loop bound
61#     // has already been reached with the previous loop.
62#     while (_GLF_global_loop_count < _GLF_global_loop_bound)
63#     {
64#         _GLF_global_loop_count++;
65#         _GLF_color = vec4(_int_0);
66#     }
67#
68#     // The output color still remains red beacuse the loop above
69#     // was not executed.
70# }
71SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
72; SPIR-V
73; Version: 1.0
74; Generator: Khronos Glslang Reference Front End; 10
75; Bound: 73
76; Schema: 0
77               OpCapability Shader
78          %1 = OpExtInstImport "GLSL.std.450"
79               OpMemoryModel Logical GLSL450
80               OpEntryPoint Fragment %4 "main" %13
81               OpExecutionMode %4 OriginUpperLeft
82               OpSource ESSL 320
83               OpName %4 "main"
84               OpName %8 "_GLF_global_loop_count"
85               OpName %13 "_GLF_color"
86               OpName %17 "buf0"
87               OpMemberName %17 0 "_GLF_uniform_int_values"
88               OpName %19 ""
89               OpDecorate %13 Location 0
90               OpDecorate %16 ArrayStride 16
91               OpMemberDecorate %17 0 Offset 0
92               OpDecorate %17 Block
93               OpDecorate %19 DescriptorSet 0
94               OpDecorate %19 Binding 0
95          %2 = OpTypeVoid
96          %3 = OpTypeFunction %2
97          %6 = OpTypeInt 32 1
98          %7 = OpTypePointer Private %6
99          %8 = OpVariable %7 Private
100          %9 = OpConstant %6 0
101         %10 = OpTypeFloat 32
102         %11 = OpTypeVector %10 4
103         %12 = OpTypePointer Output %11
104         %13 = OpVariable %12 Output
105         %14 = OpTypeInt 32 0
106         %15 = OpConstant %14 2
107         %16 = OpTypeArray %6 %15
108         %17 = OpTypeStruct %16
109         %18 = OpTypePointer Uniform %17
110         %19 = OpVariable %18 Uniform
111         %20 = OpConstant %6 1
112         %21 = OpTypePointer Uniform %6
113         %41 = OpConstant %6 100
114         %42 = OpTypeBool
115         %46 = OpConstantTrue %42
116          %4 = OpFunction %2 None %3
117          %5 = OpLabel
118               OpStore %8 %9
119         %22 = OpAccessChain %21 %19 %9 %20
120         %23 = OpLoad %6 %22
121         %24 = OpConvertSToF %10 %23
122         %25 = OpAccessChain %21 %19 %9 %9
123         %26 = OpLoad %6 %25
124         %27 = OpConvertSToF %10 %26
125         %28 = OpAccessChain %21 %19 %9 %9
126         %29 = OpLoad %6 %28
127         %30 = OpConvertSToF %10 %29
128         %31 = OpAccessChain %21 %19 %9 %20
129         %32 = OpLoad %6 %31
130         %33 = OpConvertSToF %10 %32
131         %34 = OpCompositeConstruct %11 %24 %27 %30 %33
132               OpStore %13 %34
133               OpBranch %35
134         %35 = OpLabel
135               OpLoopMerge %37 %38 None
136               OpBranch %39
137         %39 = OpLabel
138         %40 = OpLoad %6 %8
139         %43 = OpSLessThan %42 %40 %41
140               OpBranchConditional %43 %36 %37
141         %36 = OpLabel
142         %44 = OpLoad %6 %8
143         %45 = OpIAdd %6 %44 %20
144               OpStore %8 %45
145         %47 = OpLogicalNot %42 %46
146               OpSelectionMerge %49 None
147               OpBranchConditional %47 %48 %49
148         %48 = OpLabel
149         %50 = OpAccessChain %21 %19 %9 %9
150         %51 = OpLoad %6 %50
151         %52 = OpAccessChain %21 %19 %9 %20
152         %53 = OpLoad %6 %52
153         %54 = OpIEqual %42 %51 %53
154               OpBranch %49
155         %49 = OpLabel
156         %55 = OpPhi %42 %46 %36 %54 %48
157         %56 = OpLogicalNot %42 %55
158               OpSelectionMerge %58 None
159               OpBranchConditional %56 %57 %58
160         %57 = OpLabel
161               OpBranch %37
162         %58 = OpLabel
163               OpBranch %38
164         %38 = OpLabel
165               OpBranch %35
166         %37 = OpLabel
167               OpBranch %60
168         %60 = OpLabel
169               OpLoopMerge %62 %63 None
170               OpBranch %64
171         %64 = OpLabel
172         %65 = OpLoad %6 %8
173         %66 = OpSLessThan %42 %65 %41
174               OpBranchConditional %66 %61 %62
175         %61 = OpLabel
176         %67 = OpLoad %6 %8
177         %68 = OpIAdd %6 %67 %20
178               OpStore %8 %68
179         %69 = OpAccessChain %21 %19 %9 %9
180         %70 = OpLoad %6 %69
181         %71 = OpConvertSToF %10 %70
182         %72 = OpCompositeConstruct %11 %71 %71 %71 %71
183               OpStore %13 %72
184               OpBranch %63
185         %63 = OpLabel
186               OpBranch %60
187         %62 = OpLabel
188               OpReturn
189               OpFunctionEnd
190END
191
192# uniforms for variant
193
194# _GLF_uniform_int_values
195BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
196 0 1
197END
198
199BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
200
201PIPELINE graphics variant_pipeline
202  ATTACH variant_vertex_shader
203  ATTACH variant_fragment_shader
204  FRAMEBUFFER_SIZE 256 256
205  BIND BUFFER variant_framebuffer AS color LOCATION 0
206  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
207END
208CLEAR_COLOR variant_pipeline 0 0 0 255
209
210CLEAR variant_pipeline
211RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
212
213EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
214