1#!amber
2
3# Copyright 2020 Google LLC
4#
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
8#
9#     http://www.apache.org/licenses/LICENSE-2.0
10#
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.
16
17
18# A test for a coverage-gap found by the GraphicsFuzz project.
19
20# Short description: A fragment shader that covers a specific floating point code path
21
22# The test passes because the shader always writes red.
23
24SHADER vertex variant_vertex_shader PASSTHROUGH
25
26# variant_fragment_shader is derived from the following GLSL:
27# #version 310 es
28# #define _int_1 _GLF_uniform_int_values[0]
29# #define _int_0 _GLF_uniform_int_values[1]
30# #define _float_0_0 _GLF_uniform_float_values[0]
31#
32# precision highp float;
33#
34# // Contents of _GLF_uniform_float_values: 0.0
35# layout(set = 0, binding = 0) uniform buf0
36# {
37#     float _GLF_uniform_float_values[1];
38# };
39#
40# // Contents of _GLF_uniform_int_values: [1, 0]
41# layout(set = 0, binding = 1) uniform buf1
42# {
43#     int _GLF_uniform_int_values[3];
44# };
45# layout(location = 0) out vec4 _GLF_color;
46#
47# void main()
48# {
49#     // This results in an undefined value, but not in undefined behavior.
50#     float undefined = mod(5.0, 0.0);
51#     if (_int_1 == (_int_1 + _int_0) || undefined > _float_0_0)
52#     {
53#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
54#     }
55#     else
56#     {
57#         _GLF_color = vec4(_int_0);
58#     }
59# }
60SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
61; SPIR-V
62; Version: 1.0
63; Generator: Khronos Glslang Reference Front End; 8
64; Bound: 68
65; Schema: 0
66               OpCapability Shader
67          %1 = OpExtInstImport "GLSL.std.450"
68               OpMemoryModel Logical GLSL450
69               OpEntryPoint Fragment %4 "main" %49
70               OpExecutionMode %4 OriginUpperLeft
71               OpSource ESSL 310
72               OpName %4 "main"
73               OpName %8 "undefined"
74               OpName %17 "buf1"
75               OpMemberName %17 0 "_GLF_uniform_int_values"
76               OpName %19 ""
77               OpName %37 "buf0"
78               OpMemberName %37 0 "_GLF_uniform_float_values"
79               OpName %39 ""
80               OpName %49 "_GLF_color"
81               OpDecorate %16 ArrayStride 16
82               OpMemberDecorate %17 0 RelaxedPrecision
83               OpMemberDecorate %17 0 Offset 0
84               OpDecorate %17 Block
85               OpDecorate %19 DescriptorSet 0
86               OpDecorate %19 Binding 1
87               OpDecorate %23 RelaxedPrecision
88               OpDecorate %25 RelaxedPrecision
89               OpDecorate %28 RelaxedPrecision
90               OpDecorate %29 RelaxedPrecision
91               OpDecorate %36 ArrayStride 16
92               OpMemberDecorate %37 0 Offset 0
93               OpDecorate %37 Block
94               OpDecorate %39 DescriptorSet 0
95               OpDecorate %39 Binding 0
96               OpDecorate %49 Location 0
97               OpDecorate %51 RelaxedPrecision
98               OpDecorate %54 RelaxedPrecision
99               OpDecorate %57 RelaxedPrecision
100               OpDecorate %60 RelaxedPrecision
101               OpDecorate %65 RelaxedPrecision
102          %2 = OpTypeVoid
103          %3 = OpTypeFunction %2
104          %6 = OpTypeFloat 32
105          %7 = OpTypePointer Function %6
106          %9 = OpConstant %6 5
107         %10 = OpConstant %6 0
108         %12 = OpTypeBool
109         %13 = OpTypeInt 32 1
110         %14 = OpTypeInt 32 0
111         %15 = OpConstant %14 3
112         %16 = OpTypeArray %13 %15
113         %17 = OpTypeStruct %16
114         %18 = OpTypePointer Uniform %17
115         %19 = OpVariable %18 Uniform
116         %20 = OpConstant %13 0
117         %21 = OpTypePointer Uniform %13
118         %26 = OpConstant %13 1
119         %35 = OpConstant %14 1
120         %36 = OpTypeArray %6 %35
121         %37 = OpTypeStruct %36
122         %38 = OpTypePointer Uniform %37
123         %39 = OpVariable %38 Uniform
124         %40 = OpTypePointer Uniform %6
125         %47 = OpTypeVector %6 4
126         %48 = OpTypePointer Output %47
127         %49 = OpVariable %48 Output
128          %4 = OpFunction %2 None %3
129          %5 = OpLabel
130          %8 = OpVariable %7 Function
131         %11 = OpFMod %6 %9 %10
132               OpStore %8 %11
133         %22 = OpAccessChain %21 %19 %20 %20
134         %23 = OpLoad %13 %22
135         %24 = OpAccessChain %21 %19 %20 %20
136         %25 = OpLoad %13 %24
137         %27 = OpAccessChain %21 %19 %20 %26
138         %28 = OpLoad %13 %27
139         %29 = OpIAdd %13 %25 %28
140         %30 = OpIEqual %12 %23 %29
141         %31 = OpLogicalNot %12 %30
142               OpSelectionMerge %33 None
143               OpBranchConditional %31 %32 %33
144         %32 = OpLabel
145         %34 = OpLoad %6 %8
146         %41 = OpAccessChain %40 %39 %20 %20
147         %42 = OpLoad %6 %41
148         %43 = OpFOrdGreaterThan %12 %34 %42
149               OpBranch %33
150         %33 = OpLabel
151         %44 = OpPhi %12 %30 %5 %43 %32
152               OpSelectionMerge %46 None
153               OpBranchConditional %44 %45 %63
154         %45 = OpLabel
155         %50 = OpAccessChain %21 %19 %20 %20
156         %51 = OpLoad %13 %50
157         %52 = OpConvertSToF %6 %51
158         %53 = OpAccessChain %21 %19 %20 %26
159         %54 = OpLoad %13 %53
160         %55 = OpConvertSToF %6 %54
161         %56 = OpAccessChain %21 %19 %20 %26
162         %57 = OpLoad %13 %56
163         %58 = OpConvertSToF %6 %57
164         %59 = OpAccessChain %21 %19 %20 %20
165         %60 = OpLoad %13 %59
166         %61 = OpConvertSToF %6 %60
167         %62 = OpCompositeConstruct %47 %52 %55 %58 %61
168               OpStore %49 %62
169               OpBranch %46
170         %63 = OpLabel
171         %64 = OpAccessChain %21 %19 %20 %26
172         %65 = OpLoad %13 %64
173         %66 = OpConvertSToF %6 %65
174         %67 = OpCompositeConstruct %47 %66 %66 %66 %66
175               OpStore %49 %67
176               OpBranch %46
177         %46 = OpLabel
178               OpReturn
179               OpFunctionEnd
180END
181
182# uniforms for variant
183
184# _GLF_uniform_int_values
185BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
186 1 0
187END
188# _GLF_uniform_float_values
189BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
190 0.0
191END
192
193BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
194
195PIPELINE graphics variant_pipeline
196  ATTACH variant_vertex_shader
197  ATTACH variant_fragment_shader
198  FRAMEBUFFER_SIZE 256 256
199  BIND BUFFER variant_framebuffer AS color LOCATION 0
200  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
201  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
202END
203CLEAR_COLOR variant_pipeline 0 0 0 255
204
205CLEAR variant_pipeline
206RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
207
208EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
209