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