3 # Copyright 2022 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 LLVM 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 _GLF_MAKE_IN_BOUNDS_INT(IDX, SZ) clamp(IDX, 0, SZ - 1)
30 # #define _int_0 _GLF_uniform_int_values[0]
31 # #define _int_1 _GLF_uniform_int_values[1]
32 # #define _float_1_0 _GLF_uniform_float_values[0]
33 # #define _float_0_0 _GLF_uniform_float_values[1]
35 # precision highp float;
36 # precision highp int;
38 # // Contents of _GLF_uniform_float_values: [1.0, 0.0]
39 # layout(set = 0, binding = 0) uniform buf0
41 # float _GLF_uniform_float_values[2];
43 # // Contents of _GLF_uniform_int_values: [0, 1]
44 # layout(set = 0, binding = 1) uniform buf1
46 # int _GLF_uniform_int_values[2];
48 # layout(location = 0) out vec4 _GLF_color;
55 # // Iterates i = 4..1. Decreases v.w by two (because of the clamp) and v.y and v.z by one.
56 # for(int i = a; i > 0; i--)
58 # for(int j = a; j > 0; j--)
60 # // Indices used: 3, 3, 2, 1.
61 # v[_GLF_MAKE_IN_BOUNDS_INT(i, 4)] -= _float_1_0;
64 # if(gl_FragCoord.x < _float_0_0)
75 # if(v == vec4(1, 0, 0, -1))
77 # _GLF_color = vec4(1, _int_0, _int_0, _int_1);
81 # _GLF_color = vec4(_int_0);
84 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
87 ; Generator: Khronos Glslang Reference Front End; 10
91 %1 = OpExtInstImport "GLSL.std.450"
92 OpMemoryModel Logical GLSL450
93 OpEntryPoint Fragment %4 "main" %54 %83
94 OpExecutionMode %4 OriginUpperLeft
102 OpMemberName %42 0 "_GLF_uniform_float_values"
104 OpName %54 "gl_FragCoord"
105 OpName %83 "_GLF_color"
107 OpMemberName %85 0 "_GLF_uniform_int_values"
109 OpDecorate %41 ArrayStride 16
110 OpMemberDecorate %42 0 Offset 0
112 OpDecorate %44 DescriptorSet 0
113 OpDecorate %44 Binding 0
114 OpDecorate %54 BuiltIn FragCoord
115 OpDecorate %83 Location 0
116 OpDecorate %84 ArrayStride 16
117 OpMemberDecorate %85 0 Offset 0
119 OpDecorate %87 DescriptorSet 0
120 OpDecorate %87 Binding 1
122 %3 = OpTypeFunction %2
124 %7 = OpTypePointer Function %6
127 %11 = OpTypeVector %10 4
128 %12 = OpTypePointer Function %11
129 %14 = OpConstant %10 1
130 %15 = OpConstantComposite %11 %14 %14 %14 %14
131 %24 = OpConstant %6 0
133 %37 = OpConstant %6 3
135 %40 = OpConstant %39 2
136 %41 = OpTypeArray %10 %40
137 %42 = OpTypeStruct %41
138 %43 = OpTypePointer Uniform %42
139 %44 = OpVariable %43 Uniform
140 %45 = OpTypePointer Uniform %10
141 %48 = OpTypePointer Function %10
142 %53 = OpTypePointer Input %11
143 %54 = OpVariable %53 Input
144 %55 = OpConstant %39 0
145 %56 = OpTypePointer Input %10
146 %59 = OpConstant %6 1
147 %74 = OpConstant %10 0
148 %75 = OpConstant %10 -1
149 %76 = OpConstantComposite %11 %14 %74 %74 %75
150 %77 = OpTypeVector %25 4
151 %82 = OpTypePointer Output %11
152 %83 = OpVariable %82 Output
153 %84 = OpTypeArray %6 %40
154 %85 = OpTypeStruct %84
155 %86 = OpTypePointer Uniform %85
156 %87 = OpVariable %86 Uniform
157 %88 = OpTypePointer Uniform %6
158 %4 = OpFunction %2 None %3
160 %8 = OpVariable %7 Function
161 %13 = OpVariable %12 Function
162 %16 = OpVariable %7 Function
163 %27 = OpVariable %7 Function
170 OpLoopMerge %20 %21 None
174 %26 = OpSGreaterThan %25 %23 %24
175 OpBranchConditional %26 %19 %20
181 OpLoopMerge %31 %32 None
185 %35 = OpSGreaterThan %25 %34 %24
186 OpBranchConditional %35 %30 %31
189 %38 = OpExtInst %6 %1 SClamp %36 %24 %37
190 %46 = OpAccessChain %45 %44 %24 %24
192 %49 = OpAccessChain %48 %13 %38
194 %51 = OpFSub %10 %50 %47
195 %52 = OpAccessChain %48 %13 %38
197 %57 = OpAccessChain %56 %54 %55
199 %60 = OpAccessChain %45 %44 %24 %59
201 %62 = OpFOrdLessThan %25 %58 %61
202 OpSelectionMerge %64 None
203 OpBranchConditional %62 %63 %64
208 %67 = OpIAdd %6 %66 %59
213 %70 = OpISub %6 %69 %59
220 %72 = OpISub %6 %71 %59
225 %78 = OpFOrdEqual %77 %73 %76
227 OpSelectionMerge %81 None
228 OpBranchConditional %79 %80 %99
230 %89 = OpAccessChain %88 %87 %24 %24
232 %91 = OpConvertSToF %10 %90
233 %92 = OpAccessChain %88 %87 %24 %24
235 %94 = OpConvertSToF %10 %93
236 %95 = OpAccessChain %88 %87 %24 %59
238 %97 = OpConvertSToF %10 %96
239 %98 = OpCompositeConstruct %11 %14 %91 %94 %97
243 %100 = OpAccessChain %88 %87 %24 %24
244 %101 = OpLoad %6 %100
245 %102 = OpConvertSToF %10 %101
246 %103 = OpCompositeConstruct %11 %102 %102 %102 %102
254 # uniforms for variant
256 # _GLF_uniform_int_values
257 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
260 # _GLF_uniform_float_values
261 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
265 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
267 PIPELINE graphics variant_pipeline
268 ATTACH variant_vertex_shader
269 ATTACH variant_fragment_shader
270 FRAMEBUFFER_SIZE 32 32
271 BIND BUFFER variant_framebuffer AS color LOCATION 0
272 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
273 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
275 CLEAR_COLOR variant_pipeline 0 0 0 255
277 CLEAR variant_pipeline
278 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
280 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255