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_100 _GLF_uniform_int_values[2]
31 # #define _float_99_0 _GLF_uniform_float_values[0]
32 # #define _float_1_0 _GLF_uniform_float_values[1]
33 # #define _float_5_0 _GLF_uniform_float_values[2]
35 # precision highp int;
36 # precision highp float;
38 # // Contents of _GLF_uniform_float_values: [99.0, 1.0, 5.0]
39 # layout(set = 0, binding = 0) uniform buf0
41 # float _GLF_uniform_float_values[3];
44 # // Contents of _GLF_uniform_int_values: [1, 0, 100]
45 # layout(set = 0, binding = 1) uniform buf1
47 # int _GLF_uniform_int_values[3];
50 # const int _GLF_global_loop_bound = 100;
51 # int _GLF_global_loop_count = 0;
53 # layout(location = 0) out vec4 _GLF_color;
57 # float f = _float_1_0;
59 # for (int i = _int_0; i < _int_100; i ++)
66 # f = (1.0 - clamp(_float_5_0, 1.0, f)) + float(i);
70 # if (f == _float_99_0)
72 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
76 # _GLF_color = vec4(_int_0);
79 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
82 ; Generator: Khronos Glslang Reference Front End; 10
86 %1 = OpExtInstImport "GLSL.std.450"
87 OpMemoryModel Logical GLSL450
88 OpEntryPoint Fragment %4 "main" %68
89 OpExecutionMode %4 OriginUpperLeft
92 OpName %8 "_GLF_global_loop_count"
95 OpMemberName %16 0 "_GLF_uniform_float_values"
99 OpMemberName %26 0 "_GLF_uniform_int_values"
101 OpName %68 "_GLF_color"
102 OpDecorate %15 ArrayStride 16
103 OpMemberDecorate %16 0 Offset 0
105 OpDecorate %18 DescriptorSet 0
106 OpDecorate %18 Binding 0
107 OpDecorate %25 ArrayStride 16
108 OpMemberDecorate %26 0 Offset 0
110 OpDecorate %28 DescriptorSet 0
111 OpDecorate %28 Binding 1
112 OpDecorate %68 Location 0
114 %3 = OpTypeFunction %2
116 %7 = OpTypePointer Private %6
117 %8 = OpVariable %7 Private
120 %11 = OpTypePointer Function %10
122 %14 = OpConstant %13 3
123 %15 = OpTypeArray %10 %14
124 %16 = OpTypeStruct %15
125 %17 = OpTypePointer Uniform %16
126 %18 = OpVariable %17 Uniform
127 %19 = OpConstant %6 1
128 %20 = OpTypePointer Uniform %10
129 %23 = OpTypePointer Function %6
130 %25 = OpTypeArray %6 %14
131 %26 = OpTypeStruct %25
132 %27 = OpTypePointer Uniform %26
133 %28 = OpVariable %27 Uniform
134 %29 = OpTypePointer Uniform %6
135 %38 = OpConstant %6 2
137 %49 = OpConstant %10 1
138 %66 = OpTypeVector %10 4
139 %67 = OpTypePointer Output %66
140 %68 = OpVariable %67 Output
141 %87 = OpConstant %6 100
142 %4 = OpFunction %2 None %3
144 %12 = OpVariable %11 Function
145 %24 = OpVariable %23 Function
147 %21 = OpAccessChain %20 %18 %9 %19
150 %30 = OpAccessChain %29 %28 %9 %19
155 OpLoopMerge %34 %35 None
159 %39 = OpAccessChain %29 %28 %9 %38
161 %42 = OpSLessThan %41 %37 %40
162 OpBranchConditional %42 %33 %34
165 %44 = OpAccessChain %20 %18 %9 %19
167 %46 = OpFOrdGreaterThan %41 %43 %45
168 OpSelectionMerge %48 None
169 OpBranchConditional %46 %47 %48
174 %50 = OpAccessChain %20 %18 %9 %38
177 %53 = OpExtInst %10 %1 FClamp %51 %49 %52
178 %54 = OpFSub %10 %49 %53
180 %56 = OpConvertSToF %10 %55
181 %57 = OpFAdd %10 %54 %56
186 %59 = OpIAdd %6 %58 %19
191 %61 = OpAccessChain %20 %18 %9 %9
193 %63 = OpFOrdEqual %41 %60 %62
194 OpSelectionMerge %65 None
195 OpBranchConditional %63 %64 %82
197 %69 = OpAccessChain %29 %28 %9 %9
199 %71 = OpConvertSToF %10 %70
200 %72 = OpAccessChain %29 %28 %9 %19
202 %74 = OpConvertSToF %10 %73
203 %75 = OpAccessChain %29 %28 %9 %19
205 %77 = OpConvertSToF %10 %76
206 %78 = OpAccessChain %29 %28 %9 %9
208 %80 = OpConvertSToF %10 %79
209 %81 = OpCompositeConstruct %66 %71 %74 %77 %80
213 %83 = OpAccessChain %29 %28 %9 %19
215 %85 = OpConvertSToF %10 %84
216 %86 = OpCompositeConstruct %66 %85 %85 %85 %85
224 # uniforms for variant
226 # _GLF_uniform_int_values
227 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
230 # _GLF_uniform_float_values
231 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
235 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
237 PIPELINE graphics variant_pipeline
238 ATTACH variant_vertex_shader
239 ATTACH variant_fragment_shader
240 FRAMEBUFFER_SIZE 16 16
241 BIND BUFFER variant_framebuffer AS color LOCATION 0
242 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
243 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
245 CLEAR_COLOR variant_pipeline 0 0 0 255
247 CLEAR variant_pipeline
248 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 16 16
250 EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255