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_0 _GLF_uniform_int_values[0]
29 # #define _int_1 _GLF_uniform_int_values[1]
30 # #define _float_0_4 _GLF_uniform_float_values[0]
31 # #define _float_1_0 _GLF_uniform_float_values[1]
32 # #define _float_256_0 _GLF_uniform_float_values[2]
34 # precision highp int;
35 # precision highp float;
37 # // Contents of _GLF_uniform_int_values: [0, 1]
38 # layout(set = 0, binding = 0) uniform buf0
40 # int _GLF_uniform_int_values[2];
42 # // Contents of _GLF_uniform_float_values: [0.4, 1.0, 256.0]
43 # layout(set = 0, binding = 1) uniform buf1
45 # float _GLF_uniform_float_values[3];
47 # layout(location = 0) out vec4 _GLF_color;
52 # if(gl_FragCoord.y < _float_0_4)
54 # _GLF_color = vec4(_int_0);
58 # // gl_FragCoord has the decimal part of 0.5. If we name the integer part
59 # // of gl_FragCoord (X, Y) it can be expressed as (X + 0.5, Y + 0.5).
61 # // The value of v is calculated as follows:
62 # // v = ((X + 0.5, Y + 0.5) - (1.0, 0.4)) * 256
63 # // = (X - 1 + 0.5, Y + 0.5 - 0.4) * 256
64 # // = (X - 0.5, Y + 0.1) * 256
65 # // = (X * 256 - 128, Y * 256 + 25.6)
67 # // X * 256 is always an even number, and substracting 128 still keeps it even.
68 # // Y * 256 is always and even number, but adding 25.6 (and converting to an integer)
69 # // makes it always odd.
70 # ivec2 v = ivec2((gl_FragCoord.xy - vec2(_float_1_0, _float_0_4)) * _float_256_0);
72 # // v.x is even and v.y is odd. We substract one from v.y making it even too.
73 # // Doing a bitwise AND with an even number always resuls in zero.
74 # _GLF_color = vec4(_float_1_0, (v.y - _int_1) & _int_1, v.x & _int_1, _float_1_0);
77 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
80 ; Generator: Khronos Glslang Reference Front End; 10
84 %1 = OpExtInstImport "GLSL.std.450"
85 OpMemoryModel Logical GLSL450
86 OpEntryPoint Fragment %4 "main" %9 %30
87 OpExecutionMode %4 OriginUpperLeft
90 OpName %9 "gl_FragCoord"
92 OpMemberName %17 0 "_GLF_uniform_float_values"
94 OpName %30 "_GLF_color"
96 OpMemberName %33 0 "_GLF_uniform_int_values"
99 OpDecorate %9 BuiltIn FragCoord
100 OpDecorate %16 ArrayStride 16
101 OpMemberDecorate %17 0 Offset 0
103 OpDecorate %19 DescriptorSet 0
104 OpDecorate %19 Binding 1
105 OpDecorate %30 Location 0
106 OpDecorate %32 ArrayStride 16
107 OpMemberDecorate %33 0 Offset 0
109 OpDecorate %35 DescriptorSet 0
110 OpDecorate %35 Binding 0
112 %3 = OpTypeFunction %2
114 %7 = OpTypeVector %6 4
115 %8 = OpTypePointer Input %7
116 %9 = OpVariable %8 Input
118 %11 = OpConstant %10 1
119 %12 = OpTypePointer Input %6
120 %15 = OpConstant %10 3
121 %16 = OpTypeArray %6 %15
122 %17 = OpTypeStruct %16
123 %18 = OpTypePointer Uniform %17
124 %19 = OpVariable %18 Uniform
126 %21 = OpConstant %20 0
127 %22 = OpTypePointer Uniform %6
129 %29 = OpTypePointer Output %7
130 %30 = OpVariable %29 Output
131 %31 = OpConstant %10 2
132 %32 = OpTypeArray %20 %31
133 %33 = OpTypeStruct %32
134 %34 = OpTypePointer Uniform %33
135 %35 = OpVariable %34 Uniform
136 %36 = OpTypePointer Uniform %20
137 %42 = OpTypeVector %20 2
138 %43 = OpTypePointer Function %42
139 %45 = OpTypeVector %6 2
140 %48 = OpConstant %20 1
141 %55 = OpConstant %20 2
142 %62 = OpTypePointer Function %20
143 %72 = OpConstant %10 0
144 %4 = OpFunction %2 None %3
146 %44 = OpVariable %43 Function
147 %13 = OpAccessChain %12 %9 %11
149 %23 = OpAccessChain %22 %19 %21 %21
151 %26 = OpFOrdLessThan %25 %14 %24
152 OpSelectionMerge %28 None
153 OpBranchConditional %26 %27 %41
155 %37 = OpAccessChain %36 %35 %21 %21
157 %39 = OpConvertSToF %6 %38
158 %40 = OpCompositeConstruct %7 %39 %39 %39 %39
163 %47 = OpVectorShuffle %45 %46 %46 0 1
164 %49 = OpAccessChain %22 %19 %21 %48
166 %51 = OpAccessChain %22 %19 %21 %21
168 %53 = OpCompositeConstruct %45 %50 %52
169 %54 = OpFSub %45 %47 %53
170 %56 = OpAccessChain %22 %19 %21 %55
172 %58 = OpVectorTimesScalar %45 %54 %57
173 %59 = OpConvertFToS %42 %58
175 %60 = OpAccessChain %22 %19 %21 %48
177 %63 = OpAccessChain %62 %44 %11
179 %65 = OpAccessChain %36 %35 %21 %48
181 %67 = OpISub %20 %64 %66
182 %68 = OpAccessChain %36 %35 %21 %48
184 %70 = OpBitwiseAnd %20 %67 %69
185 %71 = OpConvertSToF %6 %70
186 %73 = OpAccessChain %62 %44 %72
188 %75 = OpAccessChain %36 %35 %21 %48
190 %77 = OpBitwiseAnd %20 %74 %76
191 %78 = OpConvertSToF %6 %77
192 %79 = OpAccessChain %22 %19 %21 %48
194 %81 = OpCompositeConstruct %7 %61 %71 %78 %80
202 # uniforms for variant
204 # _GLF_uniform_float_values
205 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
208 # _GLF_uniform_int_values
209 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
213 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
215 PIPELINE graphics variant_pipeline
216 ATTACH variant_vertex_shader
217 ATTACH variant_fragment_shader
218 FRAMEBUFFER_SIZE 256 256
219 BIND BUFFER variant_framebuffer AS color LOCATION 0
220 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
221 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
223 CLEAR_COLOR variant_pipeline 0 0 0 255
225 CLEAR variant_pipeline
226 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
228 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255