• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Copyright 2022 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 LLVM 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_2 _GLF_uniform_int_values[0]
29# #define _int_1 _GLF_uniform_int_values[1]
30# #define _int_0 _GLF_uniform_int_values[2]
31#
32# precision highp float;
33# precision highp int;
34#
35# // Contents of _GLF_uniform_int_values: [2, 1, 0]
36# layout(set = 0, binding = 0) uniform buf0
37# {
38#     int _GLF_uniform_int_values[3];
39# };
40#
41# // Contents of v0: [0, 1]
42# layout(set = 0, binding = 1) uniform buf1
43# {
44#     ivec2 v0;
45# };
46#
47# // Contents of v1: [2, 3]
48# layout(set = 0, binding = 2) uniform buf2
49# {
50#     ivec2 v1;
51# };
52#
53# layout(location = 0) out vec4 _GLF_color;
54#
55# struct S
56# {
57#     int arr[10];
58# };
59#
60# void main()
61# {
62#     S obj = S(int[10](_int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0, _int_0));
63#
64#     // Sets obj.arr[0..1] to 2.
65#     for(int i = v0.x; i < _int_2; i++)
66#     {
67#         obj.arr[i] = _int_2;
68#     }
69#
70#     // a = 2 * 1 = 2.
71#     int a = obj.arr[_int_1] * (v0.x < _int_1 ? v0 : v1).y;
72#
73#     // Always true.
74#     if(a == _int_2)
75#     {
76#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
77#     }
78#     else
79#     {
80#         _GLF_color = vec4(_int_0);
81#     }
82# }
83SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
84; SPIR-V
85; Version: 1.0
86; Generator: Khronos Glslang Reference Front End; 10
87; Bound: 124
88; Schema: 0
89               OpCapability Shader
90          %1 = OpExtInstImport "GLSL.std.450"
91               OpMemoryModel Logical GLSL450
92               OpEntryPoint Fragment %4 "main" %105
93               OpExecutionMode %4 OriginUpperLeft
94               OpSource ESSL 320
95               OpName %4 "main"
96               OpName %10 "S"
97               OpMemberName %10 0 "arr"
98               OpName %12 "obj"
99               OpName %15 "buf0"
100               OpMemberName %15 0 "_GLF_uniform_int_values"
101               OpName %17 ""
102               OpName %44 "i"
103               OpName %46 "buf1"
104               OpMemberName %46 0 "v0"
105               OpName %48 ""
106               OpName %69 "a"
107               OpName %87 "buf2"
108               OpMemberName %87 0 "v1"
109               OpName %89 ""
110               OpName %105 "_GLF_color"
111               OpDecorate %14 ArrayStride 16
112               OpMemberDecorate %15 0 Offset 0
113               OpDecorate %15 Block
114               OpDecorate %17 DescriptorSet 0
115               OpDecorate %17 Binding 0
116               OpMemberDecorate %46 0 Offset 0
117               OpDecorate %46 Block
118               OpDecorate %48 DescriptorSet 0
119               OpDecorate %48 Binding 1
120               OpMemberDecorate %87 0 Offset 0
121               OpDecorate %87 Block
122               OpDecorate %89 DescriptorSet 0
123               OpDecorate %89 Binding 2
124               OpDecorate %105 Location 0
125          %2 = OpTypeVoid
126          %3 = OpTypeFunction %2
127          %6 = OpTypeInt 32 1
128          %7 = OpTypeInt 32 0
129          %8 = OpConstant %7 10
130          %9 = OpTypeArray %6 %8
131         %10 = OpTypeStruct %9
132         %11 = OpTypePointer Function %10
133         %13 = OpConstant %7 3
134         %14 = OpTypeArray %6 %13
135         %15 = OpTypeStruct %14
136         %16 = OpTypePointer Uniform %15
137         %17 = OpVariable %16 Uniform
138         %18 = OpConstant %6 0
139         %19 = OpConstant %6 2
140         %20 = OpTypePointer Uniform %6
141         %43 = OpTypePointer Function %6
142         %45 = OpTypeVector %6 2
143         %46 = OpTypeStruct %45
144         %47 = OpTypePointer Uniform %46
145         %48 = OpVariable %47 Uniform
146         %49 = OpConstant %7 0
147         %60 = OpTypeBool
148         %67 = OpConstant %6 1
149         %79 = OpTypePointer Function %45
150         %83 = OpTypePointer Uniform %45
151         %87 = OpTypeStruct %45
152         %88 = OpTypePointer Uniform %87
153         %89 = OpVariable %88 Uniform
154         %92 = OpConstant %7 1
155        %102 = OpTypeFloat 32
156        %103 = OpTypeVector %102 4
157        %104 = OpTypePointer Output %103
158        %105 = OpVariable %104 Output
159          %4 = OpFunction %2 None %3
160          %5 = OpLabel
161         %12 = OpVariable %11 Function
162         %44 = OpVariable %43 Function
163         %69 = OpVariable %43 Function
164         %80 = OpVariable %79 Function
165         %21 = OpAccessChain %20 %17 %18 %19
166         %22 = OpLoad %6 %21
167         %23 = OpAccessChain %20 %17 %18 %19
168         %24 = OpLoad %6 %23
169         %25 = OpAccessChain %20 %17 %18 %19
170         %26 = OpLoad %6 %25
171         %27 = OpAccessChain %20 %17 %18 %19
172         %28 = OpLoad %6 %27
173         %29 = OpAccessChain %20 %17 %18 %19
174         %30 = OpLoad %6 %29
175         %31 = OpAccessChain %20 %17 %18 %19
176         %32 = OpLoad %6 %31
177         %33 = OpAccessChain %20 %17 %18 %19
178         %34 = OpLoad %6 %33
179         %35 = OpAccessChain %20 %17 %18 %19
180         %36 = OpLoad %6 %35
181         %37 = OpAccessChain %20 %17 %18 %19
182         %38 = OpLoad %6 %37
183         %39 = OpAccessChain %20 %17 %18 %19
184         %40 = OpLoad %6 %39
185         %41 = OpCompositeConstruct %9 %22 %24 %26 %28 %30 %32 %34 %36 %38 %40
186         %42 = OpCompositeConstruct %10 %41
187               OpStore %12 %42
188         %50 = OpAccessChain %20 %48 %18 %49
189         %51 = OpLoad %6 %50
190               OpStore %44 %51
191               OpBranch %52
192         %52 = OpLabel
193               OpLoopMerge %54 %55 None
194               OpBranch %56
195         %56 = OpLabel
196         %57 = OpLoad %6 %44
197         %58 = OpAccessChain %20 %17 %18 %18
198         %59 = OpLoad %6 %58
199         %61 = OpSLessThan %60 %57 %59
200               OpBranchConditional %61 %53 %54
201         %53 = OpLabel
202         %62 = OpLoad %6 %44
203         %63 = OpAccessChain %20 %17 %18 %18
204         %64 = OpLoad %6 %63
205         %65 = OpAccessChain %43 %12 %18 %62
206               OpStore %65 %64
207               OpBranch %55
208         %55 = OpLabel
209         %66 = OpLoad %6 %44
210         %68 = OpIAdd %6 %66 %67
211               OpStore %44 %68
212               OpBranch %52
213         %54 = OpLabel
214         %70 = OpAccessChain %20 %17 %18 %67
215         %71 = OpLoad %6 %70
216         %72 = OpAccessChain %43 %12 %18 %71
217         %73 = OpLoad %6 %72
218         %74 = OpAccessChain %20 %48 %18 %49
219         %75 = OpLoad %6 %74
220         %76 = OpAccessChain %20 %17 %18 %67
221         %77 = OpLoad %6 %76
222         %78 = OpSLessThan %60 %75 %77
223               OpSelectionMerge %82 None
224               OpBranchConditional %78 %81 %86
225         %81 = OpLabel
226         %84 = OpAccessChain %83 %48 %18
227         %85 = OpLoad %45 %84
228               OpStore %80 %85
229               OpBranch %82
230         %86 = OpLabel
231         %90 = OpAccessChain %83 %89 %18
232         %91 = OpLoad %45 %90
233               OpStore %80 %91
234               OpBranch %82
235         %82 = OpLabel
236         %93 = OpAccessChain %43 %80 %92
237         %94 = OpLoad %6 %93
238         %95 = OpIMul %6 %73 %94
239               OpStore %69 %95
240         %96 = OpLoad %6 %69
241         %97 = OpAccessChain %20 %17 %18 %18
242         %98 = OpLoad %6 %97
243         %99 = OpIEqual %60 %96 %98
244               OpSelectionMerge %101 None
245               OpBranchConditional %99 %100 %119
246        %100 = OpLabel
247        %106 = OpAccessChain %20 %17 %18 %67
248        %107 = OpLoad %6 %106
249        %108 = OpConvertSToF %102 %107
250        %109 = OpAccessChain %20 %17 %18 %19
251        %110 = OpLoad %6 %109
252        %111 = OpConvertSToF %102 %110
253        %112 = OpAccessChain %20 %17 %18 %19
254        %113 = OpLoad %6 %112
255        %114 = OpConvertSToF %102 %113
256        %115 = OpAccessChain %20 %17 %18 %67
257        %116 = OpLoad %6 %115
258        %117 = OpConvertSToF %102 %116
259        %118 = OpCompositeConstruct %103 %108 %111 %114 %117
260               OpStore %105 %118
261               OpBranch %101
262        %119 = OpLabel
263        %120 = OpAccessChain %20 %17 %18 %19
264        %121 = OpLoad %6 %120
265        %122 = OpConvertSToF %102 %121
266        %123 = OpCompositeConstruct %103 %122 %122 %122 %122
267               OpStore %105 %123
268               OpBranch %101
269        %101 = OpLabel
270               OpReturn
271               OpFunctionEnd
272END
273
274# uniforms for variant
275
276# v0
277BUFFER variant_v0 DATA_TYPE vec2<int32> STD140 DATA
278 0 1
279END
280# v1
281BUFFER variant_v1 DATA_TYPE vec2<int32> STD140 DATA
282 2 3
283END
284# _GLF_uniform_int_values
285BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
286 2 1 0
287END
288
289BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
290
291PIPELINE graphics variant_pipeline
292  ATTACH variant_vertex_shader
293  ATTACH variant_fragment_shader
294  FRAMEBUFFER_SIZE 32 32
295  BIND BUFFER variant_framebuffer AS color LOCATION 0
296  BIND BUFFER variant_v0 AS uniform DESCRIPTOR_SET 0 BINDING 1
297  BIND BUFFER variant_v1 AS uniform DESCRIPTOR_SET 0 BINDING 2
298  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
299END
300CLEAR_COLOR variant_pipeline 0 0 0 255
301
302CLEAR variant_pipeline
303RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
304
305EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255
306