3 # Copyright 2020 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 a specific floating point code path
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_768 _GLF_uniform_int_values[2]
31 # #define _int_1792 _GLF_uniform_int_values[3]
32 # #define _int_45056 _GLF_uniform_int_values[4]
33 # #define _float_0_1 _GLF_uniform_float_values[0]
34 # #define _float_0_5 _GLF_uniform_float_values[1]
35 # #define _float_2_0 _GLF_uniform_float_values[2]
37 # precision highp float;
38 # precision highp int;
40 # // Contents of _GLF_uniform_int_values: [1, 0, 768, 1792, 45056]
41 # layout(set = 0, binding = 0) uniform buf0
43 # int _GLF_uniform_int_values[5];
46 # // Contents of _GLF_uniform_float_values: [0.1, 0.5, 2.0]
47 # layout(set = 0, binding = 1) uniform buf1
49 # float _GLF_uniform_float_values[3];
52 # layout(location = 0) out vec4 _GLF_color;
56 # // All components of I are denormalized.
57 # vec4 I = uintBitsToFloat(uvec4(_int_768, _int_1792, _int_45056, 0x16b39));
58 # vec4 N = vec4(_float_0_5);
60 # // Whether or not denormalized values are supported or flushed to zero,
61 # // the result of "reflect" should match the reference result.
62 # vec4 R = reflect(I, vec4(0.5));
63 # vec4 ref = I - _float_2_0 * dot(N, I) * N;
65 # if (distance(R, ref) < _float_0_1)
67 # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
71 # _GLF_color = vec4(_int_0);
74 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
77 ; Generator: Khronos Glslang Reference Front End; 8
81 %1 = OpExtInstImport "GLSL.std.450"
82 OpMemoryModel Logical GLSL450
83 OpEntryPoint Fragment %4 "main" %72
84 OpExecutionMode %4 OriginUpperLeft
89 OpMemberName %14 0 "_GLF_uniform_int_values"
93 OpMemberName %38 0 "_GLF_uniform_float_values"
97 OpName %72 "_GLF_color"
98 OpDecorate %13 ArrayStride 16
99 OpMemberDecorate %14 0 Offset 0
101 OpDecorate %16 DescriptorSet 0
102 OpDecorate %16 Binding 0
103 OpDecorate %37 ArrayStride 16
104 OpMemberDecorate %38 0 Offset 0
106 OpDecorate %40 DescriptorSet 0
107 OpDecorate %40 Binding 1
108 OpDecorate %72 Location 0
110 %3 = OpTypeFunction %2
112 %7 = OpTypeVector %6 4
113 %8 = OpTypePointer Function %7
116 %12 = OpConstant %11 5
117 %13 = OpTypeArray %10 %12
118 %14 = OpTypeStruct %13
119 %15 = OpTypePointer Uniform %14
120 %16 = OpVariable %15 Uniform
121 %17 = OpConstant %10 0
122 %18 = OpConstant %10 2
123 %19 = OpTypePointer Uniform %10
124 %23 = OpConstant %10 3
125 %27 = OpConstant %10 4
126 %31 = OpConstant %11 92985
127 %32 = OpTypeVector %11 4
128 %36 = OpConstant %11 3
129 %37 = OpTypeArray %6 %36
130 %38 = OpTypeStruct %37
131 %39 = OpTypePointer Uniform %38
132 %40 = OpVariable %39 Uniform
133 %41 = OpConstant %10 1
134 %42 = OpTypePointer Uniform %6
135 %48 = OpConstant %6 0.5
136 %49 = OpConstantComposite %7 %48 %48 %48 %48
138 %71 = OpTypePointer Output %7
139 %72 = OpVariable %71 Output
140 %4 = OpFunction %2 None %3
142 %9 = OpVariable %8 Function
143 %35 = OpVariable %8 Function
144 %46 = OpVariable %8 Function
145 %51 = OpVariable %8 Function
146 %20 = OpAccessChain %19 %16 %17 %18
148 %22 = OpBitcast %11 %21
149 %24 = OpAccessChain %19 %16 %17 %23
151 %26 = OpBitcast %11 %25
152 %28 = OpAccessChain %19 %16 %17 %27
154 %30 = OpBitcast %11 %29
155 %33 = OpCompositeConstruct %32 %22 %26 %30 %31
156 %34 = OpBitcast %7 %33
158 %43 = OpAccessChain %42 %40 %17 %41
160 %45 = OpCompositeConstruct %7 %44 %44 %44 %44
163 %50 = OpExtInst %7 %1 Reflect %47 %49
166 %53 = OpAccessChain %42 %40 %17 %18
170 %57 = OpDot %6 %55 %56
171 %58 = OpFMul %6 %54 %57
173 %60 = OpVectorTimesScalar %7 %59 %58
174 %61 = OpFSub %7 %52 %60
178 %64 = OpExtInst %6 %1 Distance %62 %63
179 %65 = OpAccessChain %42 %40 %17 %17
181 %68 = OpFOrdLessThan %67 %64 %66
182 OpSelectionMerge %70 None
183 OpBranchConditional %68 %69 %86
185 %73 = OpAccessChain %19 %16 %17 %17
187 %75 = OpConvertSToF %6 %74
188 %76 = OpAccessChain %19 %16 %17 %41
190 %78 = OpConvertSToF %6 %77
191 %79 = OpAccessChain %19 %16 %17 %41
193 %81 = OpConvertSToF %6 %80
194 %82 = OpAccessChain %19 %16 %17 %17
196 %84 = OpConvertSToF %6 %83
197 %85 = OpCompositeConstruct %7 %75 %78 %81 %84
201 %87 = OpAccessChain %19 %16 %17 %41
203 %89 = OpConvertSToF %6 %88
204 %90 = OpCompositeConstruct %7 %89 %89 %89 %89
212 # uniforms for variant
214 # _GLF_uniform_float_values
215 BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
218 # _GLF_uniform_int_values
219 BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
223 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
225 PIPELINE graphics variant_pipeline
226 ATTACH variant_vertex_shader
227 ATTACH variant_fragment_shader
228 FRAMEBUFFER_SIZE 16 16
229 BIND BUFFER variant_framebuffer AS color LOCATION 0
230 BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
231 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
233 CLEAR_COLOR variant_pipeline 0 0 0 255
235 CLEAR variant_pipeline
236 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 16 16
238 EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255