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 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# layout(location = 0) out vec4 _GLF_color;
41#
42# void main()
43# {
44#     int a = 1;
45#
46#     do
47#     {
48#         // Always true.
49#         if(a >= _int_0)
50#         {
51#             break;
52#         }
53#
54#         // Never executed as the break above is always hit.
55#         if (true)
56#         {
57#             discard;
58#         }
59#
60#         a++;
61#     }
62#     while(a != 1);
63#
64#     // Always true.
65#     if(a == 1)
66#     {
67#         _GLF_color = vec4(1, _int_0, _int_0, _int_1);
68#     }
69#     else
70#     {
71#         _GLF_color = vec4(_int_0);
72#     }
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; 10
78; Bound: 62
79; Schema: 0
80               OpCapability Shader
81          %1 = OpExtInstImport "GLSL.std.450"
82               OpMemoryModel Logical GLSL450
83               OpEntryPoint Fragment %4 "main" %45
84               OpExecutionMode %4 OriginUpperLeft
85               OpSource ESSL 320
86               OpName %4 "main"
87               OpName %8 "a"
88               OpName %18 "buf0"
89               OpMemberName %18 0 "_GLF_uniform_int_values"
90               OpName %20 ""
91               OpName %45 "_GLF_color"
92               OpDecorate %17 ArrayStride 16
93               OpMemberDecorate %18 0 Offset 0
94               OpDecorate %18 Block
95               OpDecorate %20 DescriptorSet 0
96               OpDecorate %20 Binding 0
97               OpDecorate %45 Location 0
98          %2 = OpTypeVoid
99          %3 = OpTypeFunction %2
100          %6 = OpTypeInt 32 1
101          %7 = OpTypePointer Function %6
102          %9 = OpConstant %6 1
103         %15 = OpTypeInt 32 0
104         %16 = OpConstant %15 2
105         %17 = OpTypeArray %6 %16
106         %18 = OpTypeStruct %17
107         %19 = OpTypePointer Uniform %18
108         %20 = OpVariable %19 Uniform
109         %21 = OpConstant %6 0
110         %22 = OpTypePointer Uniform %6
111         %25 = OpTypeBool
112         %30 = OpConstantTrue %25
113         %42 = OpTypeFloat 32
114         %43 = OpTypeVector %42 4
115         %44 = OpTypePointer Output %43
116         %45 = OpVariable %44 Output
117         %46 = OpConstant %42 1
118          %4 = OpFunction %2 None %3
119          %5 = OpLabel
120          %8 = OpVariable %7 Function
121               OpStore %8 %9
122               OpBranch %10
123         %10 = OpLabel
124               OpLoopMerge %12 %13 None
125               OpBranch %11
126         %11 = OpLabel
127         %14 = OpLoad %6 %8
128         %23 = OpAccessChain %22 %20 %21 %21
129         %24 = OpLoad %6 %23
130         %26 = OpSGreaterThanEqual %25 %14 %24
131               OpSelectionMerge %28 None
132               OpBranchConditional %26 %27 %28
133         %27 = OpLabel
134               OpBranch %12
135         %28 = OpLabel
136               OpSelectionMerge %32 None
137               OpBranchConditional %30 %31 %32
138         %31 = OpLabel
139               OpKill
140         %32 = OpLabel
141         %34 = OpLoad %6 %8
142         %35 = OpIAdd %6 %34 %9
143               OpStore %8 %35
144               OpBranch %13
145         %13 = OpLabel
146         %36 = OpLoad %6 %8
147         %37 = OpINotEqual %25 %36 %9
148               OpBranchConditional %37 %10 %12
149         %12 = OpLabel
150         %38 = OpLoad %6 %8
151         %39 = OpIEqual %25 %38 %9
152               OpSelectionMerge %41 None
153               OpBranchConditional %39 %40 %57
154         %40 = OpLabel
155         %47 = OpAccessChain %22 %20 %21 %21
156         %48 = OpLoad %6 %47
157         %49 = OpConvertSToF %42 %48
158         %50 = OpAccessChain %22 %20 %21 %21
159         %51 = OpLoad %6 %50
160         %52 = OpConvertSToF %42 %51
161         %53 = OpAccessChain %22 %20 %21 %9
162         %54 = OpLoad %6 %53
163         %55 = OpConvertSToF %42 %54
164         %56 = OpCompositeConstruct %43 %46 %49 %52 %55
165               OpStore %45 %56
166               OpBranch %41
167         %57 = OpLabel
168         %58 = OpAccessChain %22 %20 %21 %21
169         %59 = OpLoad %6 %58
170         %60 = OpConvertSToF %42 %59
171         %61 = OpCompositeConstruct %43 %60 %60 %60 %60
172               OpStore %45 %61
173               OpBranch %41
174         %41 = OpLabel
175               OpReturn
176               OpFunctionEnd
177END
178
179# uniforms for variant
180
181# _GLF_uniform_int_values
182BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
183 0 1
184END
185
186BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
187
188PIPELINE graphics variant_pipeline
189  ATTACH variant_vertex_shader
190  ATTACH variant_fragment_shader
191  FRAMEBUFFER_SIZE 256 256
192  BIND BUFFER variant_framebuffer AS color LOCATION 0
193  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
194END
195CLEAR_COLOR variant_pipeline 0 0 0 255
196
197CLEAR variant_pipeline
198RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
199
200EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
201