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: Covers a specific schedule dag register reduction list 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 _float_0_0446 _GLF_uniform_float_values[0]
29# #define _float_0_0448 _GLF_uniform_float_values[1]
30# #define _float_4_6 _GLF_uniform_float_values[2]
31# #define _float_1_0 _GLF_uniform_float_values[3]
32# #define _float_0_0 _GLF_uniform_float_values[4]
33#
34# precision highp float;
35#
36# // Contents of _GLF_uniform_float_values: [0.0446, 0.0448, 4.6, 1.0, 0.0]
37# layout(set = 0, binding = 0) uniform buf0
38# {
39#     float _GLF_uniform_float_values[5];
40# };
41#
42# layout(location = 0) out vec4 _GLF_color;
43#
44# void main()
45# {
46#     // a becomes 4.6.
47#     float a = mix(_float_4_6, _float_1_0, _float_1_0 > _float_4_6);
48#
49#     float b = cos(log(a));
50#
51#     _GLF_color = vec4(b);
52#
53#     if (b > _float_0_0446 && b < _float_0_0448)
54#     {
55#         _GLF_color = vec4(_float_1_0, _float_0_0, _float_0_0, _float_1_0);
56#     }
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: 64
63; Schema: 0
64               OpCapability Shader
65          %1 = OpExtInstImport "GLSL.std.450"
66               OpMemoryModel Logical GLSL450
67               OpEntryPoint Fragment %4 "main" %37
68               OpExecutionMode %4 OriginUpperLeft
69               OpSource ESSL 310
70               OpName %4 "main"
71               OpName %8 "a"
72               OpName %12 "buf0"
73               OpMemberName %12 0 "_GLF_uniform_float_values"
74               OpName %14 ""
75               OpName %31 "b"
76               OpName %37 "_GLF_color"
77               OpDecorate %11 ArrayStride 16
78               OpMemberDecorate %12 0 Offset 0
79               OpDecorate %12 Block
80               OpDecorate %14 DescriptorSet 0
81               OpDecorate %14 Binding 0
82               OpDecorate %37 Location 0
83          %2 = OpTypeVoid
84          %3 = OpTypeFunction %2
85          %6 = OpTypeFloat 32
86          %7 = OpTypePointer Function %6
87          %9 = OpTypeInt 32 0
88         %10 = OpConstant %9 5
89         %11 = OpTypeArray %6 %10
90         %12 = OpTypeStruct %11
91         %13 = OpTypePointer Uniform %12
92         %14 = OpVariable %13 Uniform
93         %15 = OpTypeInt 32 1
94         %16 = OpConstant %15 0
95         %17 = OpConstant %15 2
96         %18 = OpTypePointer Uniform %6
97         %21 = OpConstant %15 3
98         %28 = OpTypeBool
99         %35 = OpTypeVector %6 4
100         %36 = OpTypePointer Output %35
101         %37 = OpVariable %36 Output
102         %47 = OpConstant %15 1
103         %56 = OpConstant %15 4
104          %4 = OpFunction %2 None %3
105          %5 = OpLabel
106          %8 = OpVariable %7 Function
107         %31 = OpVariable %7 Function
108         %19 = OpAccessChain %18 %14 %16 %17
109         %20 = OpLoad %6 %19
110         %22 = OpAccessChain %18 %14 %16 %21
111         %23 = OpLoad %6 %22
112         %24 = OpAccessChain %18 %14 %16 %21
113         %25 = OpLoad %6 %24
114         %26 = OpAccessChain %18 %14 %16 %17
115         %27 = OpLoad %6 %26
116         %29 = OpFOrdGreaterThan %28 %25 %27
117         %30 = OpSelect %6 %29 %23 %20
118               OpStore %8 %30
119         %32 = OpLoad %6 %8
120         %33 = OpExtInst %6 %1 Log %32
121         %34 = OpExtInst %6 %1 Cos %33
122               OpStore %31 %34
123         %38 = OpLoad %6 %31
124         %39 = OpCompositeConstruct %35 %38 %38 %38 %38
125               OpStore %37 %39
126         %40 = OpLoad %6 %31
127         %41 = OpAccessChain %18 %14 %16 %16
128         %42 = OpLoad %6 %41
129         %43 = OpFOrdGreaterThan %28 %40 %42
130               OpSelectionMerge %45 None
131               OpBranchConditional %43 %44 %45
132         %44 = OpLabel
133         %46 = OpLoad %6 %31
134         %48 = OpAccessChain %18 %14 %16 %47
135         %49 = OpLoad %6 %48
136         %50 = OpFOrdLessThan %28 %46 %49
137               OpBranch %45
138         %45 = OpLabel
139         %51 = OpPhi %28 %43 %5 %50 %44
140               OpSelectionMerge %53 None
141               OpBranchConditional %51 %52 %53
142         %52 = OpLabel
143         %54 = OpAccessChain %18 %14 %16 %21
144         %55 = OpLoad %6 %54
145         %57 = OpAccessChain %18 %14 %16 %56
146         %58 = OpLoad %6 %57
147         %59 = OpAccessChain %18 %14 %16 %56
148         %60 = OpLoad %6 %59
149         %61 = OpAccessChain %18 %14 %16 %21
150         %62 = OpLoad %6 %61
151         %63 = OpCompositeConstruct %35 %55 %58 %60 %62
152               OpStore %37 %63
153               OpBranch %53
154         %53 = OpLabel
155               OpReturn
156               OpFunctionEnd
157END
158
159# uniforms for variant
160
161# _GLF_uniform_float_values
162BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
163 0.0446 0.0448 4.6 1.0 0.0
164END
165
166BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
167
168PIPELINE graphics variant_pipeline
169  ATTACH variant_vertex_shader
170  ATTACH variant_fragment_shader
171  FRAMEBUFFER_SIZE 16 16
172  BIND BUFFER variant_framebuffer AS color LOCATION 0
173  BIND BUFFER variant__GLF_uniform_float_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 16 16
179
180EXPECT variant_framebuffer IDX 0 0 SIZE 16 16 EQ_RGBA 255 0 0 255
181