3 # Copyright 2021 Google LLC
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # A test for a coverage-gap found by the GraphicsFuzz project.
20 # Short description: A fragment shader that covers specific NIR code paths
22 # The test passes because the shader always writes red.
24 # Optimized using spirv-opt with the following arguments:
25 # '--reduce-load-size'
28 # '--combine-access-chains'
29 # '--eliminate-dead-branches'
31 # '--eliminate-dead-branches'
34 # '--eliminate-local-single-store'
35 # '--redundancy-elimination'
36 # '--private-to-local'
37 # '--combine-access-chains'
39 # '--eliminate-local-multi-store'
41 # '--convert-local-access-chains'
42 # '--combine-access-chains'
43 # '--reduce-load-size'
45 # '--eliminate-dead-inserts'
46 # '--simplify-instructions'
47 # '--eliminate-dead-code-aggressive'
48 # spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
52 SHADER vertex variant_vertex_shader PASSTHROUGH
54 # variant_fragment_shader is derived from the following GLSL:
56 # #define _int_0 _GLF_uniform_int_values[0]
57 # #define _int_1 _GLF_uniform_int_values[1]
58 # #define _int_2 _GLF_uniform_int_values[2]
59 # #define _float_1_0 _GLF_uniform_float_values[0]
60 # #define _float_0_0 _GLF_uniform_float_values[1]
62 # precision highp int;
63 # precision highp float;
65 # // Contents of _GLF_uniform_int_values: [0, 1, 2]
66 # layout(set = 0, binding = 0) uniform buf0
68 # int _GLF_uniform_int_values[3];
70 # // Contents of _GLF_uniform_float_values: [1.0, 0.0]
71 # layout(set = 0, binding = 1) uniform buf1
73 # float _GLF_uniform_float_values[2];
76 # layout(location = 0) out vec4 _GLF_color;
80 # mat3x2 m32 = mat3x2(_float_1_0);
86 # // Indexing past the matrix elements, but this
87 # // code is never executed and the values are not
88 # // used for the final results.
89 # m32[a][_int_0] = _float_1_0;
92 # float sums[3] = float[3](_float_1_0, _float_1_0, _float_1_0);
94 # for(int c = _int_0; c < _int_2; c ++)
96 # // This value is still unused later.
97 # sums[_int_2] += m32[c][_int_0];
100 # // This only depends on the initialized constant values.
101 # _GLF_color = vec4(sums[_int_0], _float_0_0, _float_0_0, sums[_int_1]);
103 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
106 ; Generator: Khronos Glslang Reference Front End; 10
110 %1 = OpExtInstImport "GLSL.std.450"
111 OpMemoryModel Logical GLSL450
112 OpEntryPoint Fragment %4 "main" %89
113 OpExecutionMode %4 OriginUpperLeft
118 OpMemberName %14 0 "_GLF_uniform_float_values"
121 OpMemberName %33 0 "_GLF_uniform_int_values"
124 OpName %89 "_GLF_color"
125 OpDecorate %13 ArrayStride 16
126 OpMemberDecorate %14 0 Offset 0
128 OpDecorate %16 DescriptorSet 0
129 OpDecorate %16 Binding 1
130 OpDecorate %32 ArrayStride 16
131 OpMemberDecorate %33 0 Offset 0
133 OpDecorate %35 DescriptorSet 0
134 OpDecorate %35 Binding 0
135 OpDecorate %89 Location 0
137 %3 = OpTypeFunction %2
139 %7 = OpTypeVector %6 2
140 %8 = OpTypeMatrix %7 3
141 %9 = OpTypePointer Function %8
143 %12 = OpConstant %11 2
144 %13 = OpTypeArray %6 %12
145 %14 = OpTypeStruct %13
146 %15 = OpTypePointer Uniform %14
147 %16 = OpVariable %15 Uniform
149 %18 = OpConstant %17 0
150 %19 = OpTypePointer Uniform %6
151 %23 = OpConstant %6 0
152 %30 = OpConstant %17 3
153 %31 = OpConstant %11 3
154 %32 = OpTypeArray %17 %31
155 %33 = OpTypeStruct %32
156 %34 = OpTypePointer Uniform %33
157 %35 = OpVariable %34 Uniform
158 %36 = OpTypePointer Uniform %17
159 %39 = OpConstant %17 1
161 %49 = OpTypePointer Function %6
162 %51 = OpTypeArray %6 %31
163 %52 = OpTypePointer Function %51
164 %70 = OpConstant %17 2
165 %87 = OpTypeVector %6 4
166 %88 = OpTypePointer Output %87
167 %89 = OpVariable %88 Output
168 %103 = OpConstantComposite %7 %23 %23
169 %4 = OpFunction %2 None %3
171 %10 = OpVariable %9 Function
172 %53 = OpVariable %52 Function
173 %20 = OpAccessChain %19 %16 %18 %18
175 %24 = OpCompositeConstruct %7 %21 %23
176 %25 = OpCompositeConstruct %7 %23 %21
177 %27 = OpCompositeConstruct %8 %24 %25 %103
179 %37 = OpAccessChain %36 %35 %18 %18
181 %41 = OpIEqual %40 %38 %39
182 OpSelectionMerge %43 None
183 OpBranchConditional %41 %42 %43
185 %50 = OpAccessChain %49 %10 %30 %38
189 %60 = OpCompositeConstruct %51 %21 %21 %21
193 %104 = OpPhi %17 %38 %43 %86 %65
194 %71 = OpAccessChain %36 %35 %18 %70
196 %73 = OpSLessThan %40 %104 %72
197 OpLoopMerge %66 %65 None
198 OpBranchConditional %73 %65 %66
200 %79 = OpAccessChain %49 %10 %104 %38
202 %81 = OpAccessChain %49 %53 %72
204 %83 = OpFAdd %6 %82 %80
206 %86 = OpIAdd %17 %104 %39
209 %92 = OpAccessChain %49 %53 %38
211 %94 = OpAccessChain %19 %16 %18 %39
213 %98 = OpAccessChain %36 %35 %18 %39
215 %100 = OpAccessChain %49 %53 %99
216 %101 = OpLoad %6 %100
217 %102 = OpCompositeConstruct %87 %93 %95 %95 %101
223 # uniforms for variant
225 # _GLF_uniform_float_values
226 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
229 # _GLF_uniform_int_values
230 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
234 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
236 PIPELINE graphics variant_pipeline
237 ATTACH variant_vertex_shader
238 ATTACH variant_fragment_shader
239 FRAMEBUFFER_SIZE 256 256
240 BIND BUFFER variant_framebuffer AS color LOCATION 0
241 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
242 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
244 CLEAR_COLOR variant_pipeline 0 0 0 255
246 CLEAR variant_pipeline
247 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
249 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255