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:
28 # #define _int_1 _GLF_uniform_int_values[0]
29 # #define _int_0 _GLF_uniform_int_values[1]
30 # #define _int_2 _GLF_uniform_int_values[2]
31 # #define _float_1_0 _GLF_uniform_float_values[0]
32 # #define _float_2_0 _GLF_uniform_float_values[1]
34 # precision highp float;
35 # precision highp int;
37 # // Contents of _GLF_uniform_float_values: [1.0, 2.0]
38 # layout(set = 0, binding = 0) uniform buf0
40 # float _GLF_uniform_float_values[2];
43 # // Contents of _GLF_uniform_int_values: [1, 0, 2]
44 # layout(set = 0, binding = 1) uniform buf1
46 # int _GLF_uniform_int_values[3];
49 # layout(location = 0) out vec4 _GLF_color;
53 # float sums[3] = float[3](_float_1_0, _float_1_0, _float_1_0);
55 # for(int i = 0; i < clamp(_int_1, _int_1, 2); i ++)
57 # // Increments by one.
58 # sums[_int_2] += mat2x4(_float_1_0)[i][_int_0];
62 # if(sums[_int_2] == _float_2_0)
64 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
68 # _GLF_color = vec4(_int_0);
71 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
74 ; Generator: Khronos Glslang Reference Front End; 10
78 %1 = OpExtInstImport "GLSL.std.450"
79 OpMemoryModel Logical GLSL450
80 OpEntryPoint Fragment %4 "main" %84
81 OpExecutionMode %4 OriginUpperLeft
86 OpMemberName %14 0 "_GLF_uniform_float_values"
90 OpMemberName %36 0 "_GLF_uniform_int_values"
92 OpName %64 "indexable"
93 OpName %84 "_GLF_color"
94 OpDecorate %13 ArrayStride 16
95 OpMemberDecorate %14 0 Offset 0
97 OpDecorate %16 DescriptorSet 0
98 OpDecorate %16 Binding 0
99 OpDecorate %35 ArrayStride 16
100 OpMemberDecorate %36 0 Offset 0
102 OpDecorate %38 DescriptorSet 0
103 OpDecorate %38 Binding 1
104 OpDecorate %84 Location 0
106 %3 = OpTypeFunction %2
110 %9 = OpTypeArray %6 %8
111 %10 = OpTypePointer Function %9
112 %12 = OpConstant %7 2
113 %13 = OpTypeArray %6 %12
114 %14 = OpTypeStruct %13
115 %15 = OpTypePointer Uniform %14
116 %16 = OpVariable %15 Uniform
118 %18 = OpConstant %17 0
119 %19 = OpTypePointer Uniform %6
120 %27 = OpTypePointer Function %17
121 %35 = OpTypeArray %17 %8
122 %36 = OpTypeStruct %35
123 %37 = OpTypePointer Uniform %36
124 %38 = OpVariable %37 Uniform
125 %39 = OpTypePointer Uniform %17
126 %44 = OpConstant %17 2
128 %52 = OpTypeVector %6 4
129 %53 = OpTypeMatrix %52 2
130 %54 = OpConstant %6 1
131 %55 = OpConstant %6 0
132 %60 = OpConstant %17 1
133 %63 = OpTypePointer Function %53
134 %65 = OpTypePointer Function %6
135 %83 = OpTypePointer Output %52
136 %84 = OpVariable %83 Output
137 %4 = OpFunction %2 None %3
139 %11 = OpVariable %10 Function
140 %28 = OpVariable %27 Function
141 %64 = OpVariable %63 Function
142 %20 = OpAccessChain %19 %16 %18 %18
144 %22 = OpAccessChain %19 %16 %18 %18
146 %24 = OpAccessChain %19 %16 %18 %18
148 %26 = OpCompositeConstruct %9 %21 %23 %25
153 OpLoopMerge %31 %32 None
157 %40 = OpAccessChain %39 %38 %18 %18
159 %42 = OpAccessChain %39 %38 %18 %18
161 %45 = OpExtInst %17 %1 SClamp %41 %43 %44
162 %47 = OpSLessThan %46 %34 %45
163 OpBranchConditional %47 %30 %31
165 %48 = OpAccessChain %39 %38 %18 %44
167 %50 = OpAccessChain %19 %16 %18 %18
169 %56 = OpCompositeConstruct %52 %51 %55 %55 %55
170 %57 = OpCompositeConstruct %52 %55 %51 %55 %55
171 %58 = OpCompositeConstruct %53 %56 %57
173 %61 = OpAccessChain %39 %38 %18 %60
176 %66 = OpAccessChain %65 %64 %59 %62
178 %68 = OpAccessChain %65 %11 %49
180 %70 = OpFAdd %6 %69 %67
181 %71 = OpAccessChain %65 %11 %49
186 %73 = OpIAdd %17 %72 %60
190 %74 = OpAccessChain %39 %38 %18 %44
192 %76 = OpAccessChain %65 %11 %75
194 %78 = OpAccessChain %19 %16 %18 %60
196 %80 = OpFOrdEqual %46 %77 %79
197 OpSelectionMerge %82 None
198 OpBranchConditional %80 %81 %98
200 %85 = OpAccessChain %39 %38 %18 %18
202 %87 = OpConvertSToF %6 %86
203 %88 = OpAccessChain %39 %38 %18 %60
205 %90 = OpConvertSToF %6 %89
206 %91 = OpAccessChain %39 %38 %18 %60
208 %93 = OpConvertSToF %6 %92
209 %94 = OpAccessChain %39 %38 %18 %18
211 %96 = OpConvertSToF %6 %95
212 %97 = OpCompositeConstruct %52 %87 %90 %93 %96
216 %99 = OpAccessChain %39 %38 %18 %60
217 %100 = OpLoad %17 %99
218 %101 = OpConvertSToF %6 %100
219 %102 = OpCompositeConstruct %52 %101 %101 %101 %101
227 # uniforms for variant
229 # _GLF_uniform_int_values
230 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
233 # _GLF_uniform_float_values
234 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
238 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
240 PIPELINE graphics variant_pipeline
241 ATTACH variant_vertex_shader
242 ATTACH variant_fragment_shader
243 FRAMEBUFFER_SIZE 256 256
244 BIND BUFFER variant_framebuffer AS color LOCATION 0
245 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
246 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
248 CLEAR_COLOR variant_pipeline 0 0 0 255
250 CLEAR variant_pipeline
251 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
253 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255