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 BRW 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_33 _GLF_uniform_int_values[0]
29# #define _int_0 _GLF_uniform_int_values[1]
30# #define _int_1 _GLF_uniform_int_values[2]
31# #define _float_1_0 _GLF_uniform_float_values[0]
32# #define _float_23_0 _GLF_uniform_float_values[1]
33# #define _float_24_0 _GLF_uniform_float_values[2]
34#
35# precision highp int;
36# precision highp float;
37#
38# // Contents of _GLF_uniform_float_values: [1.0, 23.0, 24.0]
39# layout(set = 0, binding = 0) uniform buf0
40# {
41#     float _GLF_uniform_float_values[3];
42# };
43# // Contents of _GLF_uniform_int_values: [33, 0, 1]
44# layout(set = 0, binding = 1) uniform buf1
45# {
46#     int _GLF_uniform_int_values[3];
47# };
48# layout(location = 0) out vec4 _GLF_color;
49#
50# void main()
51# {
52#     float f0 = _float_1_0;
53#     float f1 = _float_1_0;
54#
55#     for (int i = _int_0; i < _int_33; i++)
56#     {
57#         f0 = abs(1.1 * f0);
58#         f1 = f0;
59#     }
60#
61#     // Always true.
62#     if (f1 > _float_23_0 && f1 < _float_24_0)
63#     {
64#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
65#     }
66#     else
67#     {
68#         _GLF_color = vec4(_int_0);
69#     }
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: 85
76; Schema: 0
77               OpCapability Shader
78          %1 = OpExtInstImport "GLSL.std.450"
79               OpMemoryModel Logical GLSL450
80               OpEntryPoint Fragment %4 "main" %66
81               OpExecutionMode %4 OriginUpperLeft
82               OpSource ESSL 320
83               OpName %4 "main"
84               OpName %8 "f0"
85               OpName %12 "buf0"
86               OpMemberName %12 0 "_GLF_uniform_float_values"
87               OpName %14 ""
88               OpName %20 "f1"
89               OpName %24 "i"
90               OpName %26 "buf1"
91               OpMemberName %26 0 "_GLF_uniform_int_values"
92               OpName %28 ""
93               OpName %66 "_GLF_color"
94               OpDecorate %11 ArrayStride 16
95               OpMemberDecorate %12 0 Offset 0
96               OpDecorate %12 Block
97               OpDecorate %14 DescriptorSet 0
98               OpDecorate %14 Binding 0
99               OpDecorate %25 ArrayStride 16
100               OpMemberDecorate %26 0 Offset 0
101               OpDecorate %26 Block
102               OpDecorate %28 DescriptorSet 0
103               OpDecorate %28 Binding 1
104               OpDecorate %66 Location 0
105          %2 = OpTypeVoid
106          %3 = OpTypeFunction %2
107          %6 = OpTypeFloat 32
108          %7 = OpTypePointer Function %6
109          %9 = OpTypeInt 32 0
110         %10 = OpConstant %9 3
111         %11 = OpTypeArray %6 %10
112         %12 = OpTypeStruct %11
113         %13 = OpTypePointer Uniform %12
114         %14 = OpVariable %13 Uniform
115         %15 = OpTypeInt 32 1
116         %16 = OpConstant %15 0
117         %17 = OpTypePointer Uniform %6
118         %23 = OpTypePointer Function %15
119         %25 = OpTypeArray %15 %10
120         %26 = OpTypeStruct %25
121         %27 = OpTypePointer Uniform %26
122         %28 = OpVariable %27 Uniform
123         %29 = OpConstant %15 1
124         %30 = OpTypePointer Uniform %15
125         %41 = OpTypeBool
126         %43 = OpConstant %6 1.10000002
127         %57 = OpConstant %15 2
128         %64 = OpTypeVector %6 4
129         %65 = OpTypePointer Output %64
130         %66 = OpVariable %65 Output
131          %4 = OpFunction %2 None %3
132          %5 = OpLabel
133          %8 = OpVariable %7 Function
134         %20 = OpVariable %7 Function
135         %24 = OpVariable %23 Function
136         %18 = OpAccessChain %17 %14 %16 %16
137         %19 = OpLoad %6 %18
138               OpStore %8 %19
139         %21 = OpAccessChain %17 %14 %16 %16
140         %22 = OpLoad %6 %21
141               OpStore %20 %22
142         %31 = OpAccessChain %30 %28 %16 %29
143         %32 = OpLoad %15 %31
144               OpStore %24 %32
145               OpBranch %33
146         %33 = OpLabel
147               OpLoopMerge %35 %36 None
148               OpBranch %37
149         %37 = OpLabel
150         %38 = OpLoad %15 %24
151         %39 = OpAccessChain %30 %28 %16 %16
152         %40 = OpLoad %15 %39
153         %42 = OpSLessThan %41 %38 %40
154               OpBranchConditional %42 %34 %35
155         %34 = OpLabel
156         %44 = OpLoad %6 %8
157         %45 = OpFMul %6 %43 %44
158         %46 = OpExtInst %6 %1 FAbs %45
159               OpStore %8 %46
160         %47 = OpLoad %6 %8
161               OpStore %20 %47
162               OpBranch %36
163         %36 = OpLabel
164         %48 = OpLoad %15 %24
165         %49 = OpIAdd %15 %48 %29
166               OpStore %24 %49
167               OpBranch %33
168         %35 = OpLabel
169         %50 = OpLoad %6 %20
170         %51 = OpAccessChain %17 %14 %16 %29
171         %52 = OpLoad %6 %51
172         %53 = OpFOrdGreaterThan %41 %50 %52
173               OpSelectionMerge %55 None
174               OpBranchConditional %53 %54 %55
175         %54 = OpLabel
176         %56 = OpLoad %6 %20
177         %58 = OpAccessChain %17 %14 %16 %57
178         %59 = OpLoad %6 %58
179         %60 = OpFOrdLessThan %41 %56 %59
180               OpBranch %55
181         %55 = OpLabel
182         %61 = OpPhi %41 %53 %35 %60 %54
183               OpSelectionMerge %63 None
184               OpBranchConditional %61 %62 %80
185         %62 = OpLabel
186         %67 = OpAccessChain %30 %28 %16 %57
187         %68 = OpLoad %15 %67
188         %69 = OpConvertSToF %6 %68
189         %70 = OpAccessChain %30 %28 %16 %29
190         %71 = OpLoad %15 %70
191         %72 = OpConvertSToF %6 %71
192         %73 = OpAccessChain %30 %28 %16 %29
193         %74 = OpLoad %15 %73
194         %75 = OpConvertSToF %6 %74
195         %76 = OpAccessChain %30 %28 %16 %57
196         %77 = OpLoad %15 %76
197         %78 = OpConvertSToF %6 %77
198         %79 = OpCompositeConstruct %64 %69 %72 %75 %78
199               OpStore %66 %79
200               OpBranch %63
201         %80 = OpLabel
202         %81 = OpAccessChain %30 %28 %16 %29
203         %82 = OpLoad %15 %81
204         %83 = OpConvertSToF %6 %82
205         %84 = OpCompositeConstruct %64 %83 %83 %83 %83
206               OpStore %66 %84
207               OpBranch %63
208         %63 = OpLabel
209               OpReturn
210               OpFunctionEnd
211END
212
213# uniforms for variant
214
215# _GLF_uniform_int_values
216BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
217 33 0 1
218END
219# _GLF_uniform_float_values
220BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
221 1.0 23.0 24.0
222END
223
224BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
225
226PIPELINE graphics variant_pipeline
227  ATTACH variant_vertex_shader
228  ATTACH variant_fragment_shader
229  FRAMEBUFFER_SIZE 256 256
230  BIND BUFFER variant_framebuffer AS color LOCATION 0
231  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
232  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
233END
234CLEAR_COLOR variant_pipeline 0 0 0 255
235
236CLEAR variant_pipeline
237RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
238
239EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
240