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