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 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
29 # #define _int_2 _GLF_uniform_int_values[0]
30 # #define _int_0 _GLF_uniform_int_values[1]
31 # #define _int_1 _GLF_uniform_int_values[2]
32 # #define _int_3 _GLF_uniform_int_values[3]
34 # precision highp int;
35 # precision highp float;
37 # // Contents of _GLF_uniform_int_values: [2, 0, 1, 3]
38 # layout(set = 0, binding = 0) uniform buf0
40 # int _GLF_uniform_int_values[4];
43 # layout(location = 0) out vec4 _GLF_color;
53 # // Uses an undefined value, but this is never executed.
57 # // Initialize all matrix elements in a loop.
58 # for(int i = _int_0; i < _int_2; i++)
60 # for(int j = _int_0; j < _int_2; j++)
62 # m[i][j] = float(i * _int_2 + j);
67 # if(m == mat2(_int_0, _int_1, _int_2, _int_3))
69 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
73 # _GLF_color = vec4(_int_0);
76 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
79 ; Generator: Khronos Glslang Reference Front End; 10
83 %1 = OpExtInstImport "GLSL.std.450"
84 OpMemoryModel Logical GLSL450
85 OpEntryPoint Fragment %4 "main" %106
86 OpExecutionMode %4 OriginUpperLeft
90 OpMemberName %10 0 "_GLF_uniform_int_values"
96 OpName %106 "_GLF_color"
97 OpDecorate %9 ArrayStride 16
98 OpMemberDecorate %10 0 Offset 0
100 OpDecorate %12 DescriptorSet 0
101 OpDecorate %12 Binding 0
102 OpDecorate %106 Location 0
104 %3 = OpTypeFunction %2
108 %9 = OpTypeArray %6 %8
109 %10 = OpTypeStruct %9
110 %11 = OpTypePointer Uniform %10
111 %12 = OpVariable %11 Uniform
112 %13 = OpConstant %6 0
113 %14 = OpConstant %6 1
114 %15 = OpTypePointer Uniform %6
117 %23 = OpTypeVector %22 2
118 %24 = OpTypeMatrix %23 2
119 %25 = OpTypePointer Function %24
120 %27 = OpTypePointer Function %22
121 %30 = OpConstant %22 1
122 %31 = OpConstant %22 0
123 %35 = OpTypePointer Function %6
124 %78 = OpConstant %6 2
125 %85 = OpConstant %6 3
126 %94 = OpTypeVector %18 2
127 %104 = OpTypeVector %22 4
128 %105 = OpTypePointer Output %104
129 %106 = OpVariable %105 Output
130 %4 = OpFunction %2 None %3
132 %26 = OpVariable %25 Function
133 %28 = OpVariable %27 Function
134 %36 = OpVariable %35 Function
135 %48 = OpVariable %35 Function
136 %16 = OpAccessChain %15 %12 %13 %14
138 %19 = OpIEqual %18 %17 %14
139 OpSelectionMerge %21 None
140 OpBranchConditional %19 %20 %21
143 %32 = OpCompositeConstruct %23 %29 %31
144 %33 = OpCompositeConstruct %23 %31 %29
145 %34 = OpCompositeConstruct %24 %32 %33
149 %37 = OpAccessChain %15 %12 %13 %14
154 OpLoopMerge %41 %42 None
158 %45 = OpAccessChain %15 %12 %13 %13
160 %47 = OpSLessThan %18 %44 %46
161 OpBranchConditional %47 %40 %41
163 %49 = OpAccessChain %15 %12 %13 %14
168 OpLoopMerge %53 %54 None
172 %57 = OpAccessChain %15 %12 %13 %13
174 %59 = OpSLessThan %18 %56 %58
175 OpBranchConditional %59 %52 %53
180 %63 = OpAccessChain %15 %12 %13 %13
182 %65 = OpIMul %6 %62 %64
184 %67 = OpIAdd %6 %65 %66
185 %68 = OpConvertSToF %22 %67
186 %69 = OpAccessChain %27 %26 %60 %61
191 %71 = OpIAdd %6 %70 %14
198 %73 = OpIAdd %6 %72 %14
203 %75 = OpAccessChain %15 %12 %13 %14
205 %77 = OpConvertSToF %22 %76
206 %79 = OpAccessChain %15 %12 %13 %78
208 %81 = OpConvertSToF %22 %80
209 %82 = OpAccessChain %15 %12 %13 %13
211 %84 = OpConvertSToF %22 %83
212 %86 = OpAccessChain %15 %12 %13 %85
214 %88 = OpConvertSToF %22 %87
215 %89 = OpCompositeConstruct %23 %77 %81
216 %90 = OpCompositeConstruct %23 %84 %88
217 %91 = OpCompositeConstruct %24 %89 %90
218 %92 = OpCompositeExtract %23 %74 0
219 %93 = OpCompositeExtract %23 %91 0
220 %95 = OpFOrdEqual %94 %92 %93
222 %97 = OpCompositeExtract %23 %74 1
223 %98 = OpCompositeExtract %23 %91 1
224 %99 = OpFOrdEqual %94 %97 %98
226 %101 = OpLogicalAnd %18 %96 %100
227 OpSelectionMerge %103 None
228 OpBranchConditional %101 %102 %120
230 %107 = OpAccessChain %15 %12 %13 %78
231 %108 = OpLoad %6 %107
232 %109 = OpConvertSToF %22 %108
233 %110 = OpAccessChain %15 %12 %13 %14
234 %111 = OpLoad %6 %110
235 %112 = OpConvertSToF %22 %111
236 %113 = OpAccessChain %15 %12 %13 %14
237 %114 = OpLoad %6 %113
238 %115 = OpConvertSToF %22 %114
239 %116 = OpAccessChain %15 %12 %13 %78
240 %117 = OpLoad %6 %116
241 %118 = OpConvertSToF %22 %117
242 %119 = OpCompositeConstruct %104 %109 %112 %115 %118
246 %121 = OpAccessChain %15 %12 %13 %14
247 %122 = OpLoad %6 %121
248 %123 = OpConvertSToF %22 %122
249 %124 = OpCompositeConstruct %104 %123 %123 %123 %123
257 # uniforms for variant
259 # _GLF_uniform_int_values
260 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
264 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
266 PIPELINE graphics variant_pipeline
267 ATTACH variant_vertex_shader
268 ATTACH variant_fragment_shader
269 FRAMEBUFFER_SIZE 256 256
270 BIND BUFFER variant_framebuffer AS color LOCATION 0
271 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
273 CLEAR_COLOR variant_pipeline 0 0 0 255
275 CLEAR variant_pipeline
276 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
278 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255