1#!amber
2
3# Copyright 2021 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 specific LLVM code paths
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 320 es
28#
29# #define _int_0 _GLF_uniform_int_values[0]
30# #define _int_1 _GLF_uniform_int_values[1]
31# #define _float_0_0 _GLF_uniform_float_values[0]
32#
33# precision highp int;
34# precision highp float;
35#
36# // Contents of _GLF_uniform_int_values: [0, 1]
37# layout(set = 0, binding = 0) uniform buf0
38# {
39#     int _GLF_uniform_int_values[2];
40# };
41#
42# // Contents of _GLF_uniform_float_values: 0.0
43# layout(set = 0, binding = 1) uniform buf1
44# {
45#     float _GLF_uniform_float_values[1];
46# };
47#
48# layout(location = 0) out vec4 _GLF_color;
49#
50# void main()
51# {
52#     // fract(trunc(x)) is always 0.
53#     float f = fract(trunc(float(_int_1)));
54#
55#     // Always true.
56#     if(f == _float_0_0)
57#     {
58#         _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1);
59#     }
60#     else
61#     {
62#         _GLF_color = vec4(_int_0);
63#     }
64# }
65SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
66; SPIR-V
67; Version: 1.0
68; Generator: Khronos Glslang Reference Front End; 10
69; Bound: 58
70; Schema: 0
71               OpCapability Shader
72          %1 = OpExtInstImport "GLSL.std.450"
73               OpMemoryModel Logical GLSL450
74               OpEntryPoint Fragment %4 "main" %39
75               OpExecutionMode %4 OriginUpperLeft
76               OpSource ESSL 320
77               OpName %4 "main"
78               OpName %8 "f"
79               OpName %13 "buf0"
80               OpMemberName %13 0 "_GLF_uniform_int_values"
81               OpName %15 ""
82               OpName %27 "buf1"
83               OpMemberName %27 0 "_GLF_uniform_float_values"
84               OpName %29 ""
85               OpName %39 "_GLF_color"
86               OpDecorate %12 ArrayStride 16
87               OpMemberDecorate %13 0 Offset 0
88               OpDecorate %13 Block
89               OpDecorate %15 DescriptorSet 0
90               OpDecorate %15 Binding 0
91               OpDecorate %26 ArrayStride 16
92               OpMemberDecorate %27 0 Offset 0
93               OpDecorate %27 Block
94               OpDecorate %29 DescriptorSet 0
95               OpDecorate %29 Binding 1
96               OpDecorate %39 Location 0
97          %2 = OpTypeVoid
98          %3 = OpTypeFunction %2
99          %6 = OpTypeFloat 32
100          %7 = OpTypePointer Function %6
101          %9 = OpTypeInt 32 1
102         %10 = OpTypeInt 32 0
103         %11 = OpConstant %10 2
104         %12 = OpTypeArray %9 %11
105         %13 = OpTypeStruct %12
106         %14 = OpTypePointer Uniform %13
107         %15 = OpVariable %14 Uniform
108         %16 = OpConstant %9 0
109         %17 = OpConstant %9 1
110         %18 = OpTypePointer Uniform %9
111         %25 = OpConstant %10 1
112         %26 = OpTypeArray %6 %25
113         %27 = OpTypeStruct %26
114         %28 = OpTypePointer Uniform %27
115         %29 = OpVariable %28 Uniform
116         %30 = OpTypePointer Uniform %6
117         %33 = OpTypeBool
118         %37 = OpTypeVector %6 4
119         %38 = OpTypePointer Output %37
120         %39 = OpVariable %38 Output
121          %4 = OpFunction %2 None %3
122          %5 = OpLabel
123          %8 = OpVariable %7 Function
124         %19 = OpAccessChain %18 %15 %16 %17
125         %20 = OpLoad %9 %19
126         %21 = OpConvertSToF %6 %20
127         %22 = OpExtInst %6 %1 Trunc %21
128         %23 = OpExtInst %6 %1 Fract %22
129               OpStore %8 %23
130         %24 = OpLoad %6 %8
131         %31 = OpAccessChain %30 %29 %16 %16
132         %32 = OpLoad %6 %31
133         %34 = OpFOrdEqual %33 %24 %32
134               OpSelectionMerge %36 None
135               OpBranchConditional %34 %35 %53
136         %35 = OpLabel
137         %40 = OpAccessChain %18 %15 %16 %17
138         %41 = OpLoad %9 %40
139         %42 = OpConvertSToF %6 %41
140         %43 = OpAccessChain %18 %15 %16 %16
141         %44 = OpLoad %9 %43
142         %45 = OpConvertSToF %6 %44
143         %46 = OpAccessChain %18 %15 %16 %16
144         %47 = OpLoad %9 %46
145         %48 = OpConvertSToF %6 %47
146         %49 = OpAccessChain %18 %15 %16 %17
147         %50 = OpLoad %9 %49
148         %51 = OpConvertSToF %6 %50
149         %52 = OpCompositeConstruct %37 %42 %45 %48 %51
150               OpStore %39 %52
151               OpBranch %36
152         %53 = OpLabel
153         %54 = OpAccessChain %18 %15 %16 %16
154         %55 = OpLoad %9 %54
155         %56 = OpConvertSToF %6 %55
156         %57 = OpCompositeConstruct %37 %56 %56 %56 %56
157               OpStore %39 %57
158               OpBranch %36
159         %36 = OpLabel
160               OpReturn
161               OpFunctionEnd
162END
163
164# uniforms for variant
165
166# _GLF_uniform_float_values
167BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
168 0.0
169END
170# _GLF_uniform_int_values
171BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
172 0 1
173END
174
175BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
176
177PIPELINE graphics variant_pipeline
178  ATTACH variant_vertex_shader
179  ATTACH variant_fragment_shader
180  FRAMEBUFFER_SIZE 256 256
181  BIND BUFFER variant_framebuffer AS color LOCATION 0
182  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 1
183  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0
184END
185CLEAR_COLOR variant_pipeline 0 0 0 255
186
187CLEAR variant_pipeline
188RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
189
190EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
191