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_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_245_0 _GLF_uniform_float_values[1]
33 # #define _float_246_0 _GLF_uniform_float_values[2]
34 # #define _float_1_1 _GLF_uniform_float_values[3]
36 # precision highp int;
37 # precision highp float;
39 # // Contents of _GLF_uniform_float_values: [1.0, 245.0, 246.0, 1.1]
40 # layout(set = 0, binding = 0) uniform buf0
42 # float _GLF_uniform_float_values[4];
45 # // Contents of _GLF_uniform_int_values: [33, 0, 1]
46 # layout(set = 0, binding = 1) uniform buf1
48 # int _GLF_uniform_int_values[3];
51 # layout(location = 0) out vec4 _GLF_color;
55 # float f = _float_1_0;
57 # for(int i = _int_0; i < _int_33; i++)
59 # f = abs(- _float_1_1 * f) + _float_1_0;
63 # if(f > _float_245_0 && f < _float_246_0)
65 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
69 # _GLF_color = vec4(_int_0);
72 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
75 ; Generator: Khronos Glslang Reference Front End; 10
79 %1 = OpExtInstImport "GLSL.std.450"
80 OpMemoryModel Logical GLSL450
81 OpEntryPoint Fragment %4 "main" %69
82 OpExecutionMode %4 OriginUpperLeft
87 OpMemberName %12 0 "_GLF_uniform_float_values"
91 OpMemberName %24 0 "_GLF_uniform_int_values"
93 OpName %69 "_GLF_color"
94 OpDecorate %11 ArrayStride 16
95 OpMemberDecorate %12 0 Offset 0
97 OpDecorate %14 DescriptorSet 0
98 OpDecorate %14 Binding 0
99 OpDecorate %23 ArrayStride 16
100 OpMemberDecorate %24 0 Offset 0
102 OpDecorate %26 DescriptorSet 0
103 OpDecorate %26 Binding 1
104 OpDecorate %69 Location 0
106 %3 = OpTypeFunction %2
108 %7 = OpTypePointer Function %6
110 %10 = OpConstant %9 4
111 %11 = OpTypeArray %6 %10
112 %12 = OpTypeStruct %11
113 %13 = OpTypePointer Uniform %12
114 %14 = OpVariable %13 Uniform
116 %16 = OpConstant %15 0
117 %17 = OpTypePointer Uniform %6
118 %20 = OpTypePointer Function %15
119 %22 = OpConstant %9 3
120 %23 = OpTypeArray %15 %22
121 %24 = OpTypeStruct %23
122 %25 = OpTypePointer Uniform %24
123 %26 = OpVariable %25 Uniform
124 %27 = OpConstant %15 1
125 %28 = OpTypePointer Uniform %15
127 %41 = OpConstant %15 3
128 %60 = OpConstant %15 2
129 %67 = OpTypeVector %6 4
130 %68 = OpTypePointer Output %67
131 %69 = OpVariable %68 Output
132 %4 = OpFunction %2 None %3
134 %8 = OpVariable %7 Function
135 %21 = OpVariable %20 Function
136 %18 = OpAccessChain %17 %14 %16 %16
139 %29 = OpAccessChain %28 %26 %16 %27
144 OpLoopMerge %33 %34 None
148 %37 = OpAccessChain %28 %26 %16 %16
150 %40 = OpSLessThan %39 %36 %38
151 OpBranchConditional %40 %32 %33
153 %42 = OpAccessChain %17 %14 %16 %41
155 %44 = OpFNegate %6 %43
157 %46 = OpFMul %6 %44 %45
158 %47 = OpExtInst %6 %1 FAbs %46
159 %48 = OpAccessChain %17 %14 %16 %16
161 %50 = OpFAdd %6 %47 %49
166 %52 = OpIAdd %15 %51 %27
171 %54 = OpAccessChain %17 %14 %16 %27
173 %56 = OpFOrdGreaterThan %39 %53 %55
174 OpSelectionMerge %58 None
175 OpBranchConditional %56 %57 %58
178 %61 = OpAccessChain %17 %14 %16 %60
180 %63 = OpFOrdLessThan %39 %59 %62
183 %64 = OpPhi %39 %56 %33 %63 %57
184 OpSelectionMerge %66 None
185 OpBranchConditional %64 %65 %83
187 %70 = OpAccessChain %28 %26 %16 %60
189 %72 = OpConvertSToF %6 %71
190 %73 = OpAccessChain %28 %26 %16 %27
192 %75 = OpConvertSToF %6 %74
193 %76 = OpAccessChain %28 %26 %16 %27
195 %78 = OpConvertSToF %6 %77
196 %79 = OpAccessChain %28 %26 %16 %60
198 %81 = OpConvertSToF %6 %80
199 %82 = OpCompositeConstruct %67 %72 %75 %78 %81
203 %84 = OpAccessChain %28 %26 %16 %27
205 %86 = OpConvertSToF %6 %85
206 %87 = OpCompositeConstruct %67 %86 %86 %86 %86
214 # uniforms for variant
216 # _GLF_uniform_int_values
217 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
220 # _GLF_uniform_float_values
221 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
225 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
227 PIPELINE graphics variant_pipeline
228 ATTACH variant_vertex_shader
229 ATTACH variant_fragment_shader
230 FRAMEBUFFER_SIZE 256 256
231 BIND BUFFER variant_framebuffer AS color LOCATION 0
232 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
233 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
235 CLEAR_COLOR variant_pipeline 0 0 0 255
237 CLEAR variant_pipeline
238 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
240 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255