• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#!amber
2
3# Copyright 2022 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
24# Optimized using spirv-opt with the following arguments:
25# '-Os'
26# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
27
28
29
30SHADER vertex variant_vertex_shader PASSTHROUGH
31
32# variant_fragment_shader is derived from the following GLSL:
33# #version 320 es
34# #define _int_0 _GLF_uniform_int_values[0]
35# #define _int_1 _GLF_uniform_int_values[1]
36# #define _float_0_25 _GLF_uniform_float_values[0]
37# #define _float_1_0 _GLF_uniform_float_values[1]
38#
39# precision highp float;
40# precision highp int;
41#
42# // Contents of _GLF_uniform_float_values: [0.25, 1.0]
43# layout(set = 0, binding = 0) uniform buf0
44# {
45#     float _GLF_uniform_float_values[2];
46# };
47#
48# // Contents of _GLF_uniform_int_values: [0, 1]
49# layout(set = 0, binding = 1) uniform buf1
50# {
51#     int _GLF_uniform_int_values[2];
52# };
53#
54# layout(location = 0) out vec4 _GLF_color;
55#
56# float func(vec2 v)
57# {
58#     switch(1)
59#     {
60#         case 0:
61#             return 1.0;
62#         case 1:
63#             // Trasposing an identity matrix has no effect. The line below simplifies to
64#             // clamp(vec2(0.25, 0.25, vec2(0.5, 0.5), vec2(1.0, 1.0))).x = vec2(0.5, 0.5).x = 0.5
65#             return clamp(vec2(transpose(mat4(_float_0_25))), v, vec2(transpose(mat4(_float_1_0)))).x;
66#     }
67# }
68#
69# void main()
70# {
71#     // The fraction parts of gl_FragCoord components are always 0.5 (the center of the pixel).
72#     // The function returns 0.5.
73#     if(func(fract(gl_FragCoord.xy)) == 0.5)
74#     {
75#         _GLF_color = vec4(1, _int_0, _int_0, _int_1);
76#     }
77#     else
78#     {
79#         _GLF_color = vec4(_int_0);
80#     }
81# }
82SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
83; SPIR-V
84; Version: 1.0
85; Generator: Khronos Glslang Reference Front End; 10
86; Bound: 124
87; Schema: 0
88               OpCapability Shader
89          %1 = OpExtInstImport "GLSL.std.450"
90               OpMemoryModel Logical GLSL450
91               OpEntryPoint Fragment %4 "main" %61 %73
92               OpExecutionMode %4 OriginUpperLeft
93               OpSource ESSL 320
94               OpName %4 "main"
95               OpName %23 "buf0"
96               OpMemberName %23 0 "_GLF_uniform_float_values"
97               OpName %25 ""
98               OpName %61 "gl_FragCoord"
99               OpName %73 "_GLF_color"
100               OpName %75 "buf1"
101               OpMemberName %75 0 "_GLF_uniform_int_values"
102               OpName %77 ""
103               OpDecorate %22 ArrayStride 16
104               OpMemberDecorate %23 0 Offset 0
105               OpDecorate %23 Block
106               OpDecorate %25 DescriptorSet 0
107               OpDecorate %25 Binding 0
108               OpDecorate %61 BuiltIn FragCoord
109               OpDecorate %73 Location 0
110               OpDecorate %74 ArrayStride 16
111               OpMemberDecorate %75 0 Offset 0
112               OpDecorate %75 Block
113               OpDecorate %77 DescriptorSet 0
114               OpDecorate %77 Binding 1
115          %2 = OpTypeVoid
116          %3 = OpTypeFunction %2
117          %6 = OpTypeFloat 32
118          %7 = OpTypeVector %6 2
119         %13 = OpTypeInt 32 1
120         %14 = OpConstant %13 1
121         %18 = OpConstant %6 1
122         %20 = OpTypeInt 32 0
123         %21 = OpConstant %20 2
124         %22 = OpTypeArray %6 %21
125         %23 = OpTypeStruct %22
126         %24 = OpTypePointer Uniform %23
127         %25 = OpVariable %24 Uniform
128         %26 = OpConstant %13 0
129         %27 = OpTypePointer Uniform %6
130         %30 = OpTypeVector %6 4
131         %31 = OpTypeMatrix %30 4
132         %32 = OpConstant %6 0
133         %60 = OpTypePointer Input %30
134         %61 = OpVariable %60 Input
135         %67 = OpConstant %6 0.5
136         %68 = OpTypeBool
137         %72 = OpTypePointer Output %30
138         %73 = OpVariable %72 Output
139         %74 = OpTypeArray %13 %21
140         %75 = OpTypeStruct %74
141         %76 = OpTypePointer Uniform %75
142         %77 = OpVariable %76 Uniform
143         %78 = OpTypePointer Uniform %13
144        %123 = OpUndef %6
145          %4 = OpFunction %2 None %3
146          %5 = OpLabel
147         %62 = OpLoad %30 %61
148         %63 = OpVectorShuffle %7 %62 %62 0 1
149         %64 = OpExtInst %7 %1 Fract %63
150         %98 = OpAccessChain %27 %25 %26 %26
151         %99 = OpLoad %6 %98
152        %100 = OpCompositeConstruct %30 %99 %32 %32 %32
153        %101 = OpCompositeConstruct %30 %32 %99 %32 %32
154        %102 = OpCompositeConstruct %30 %32 %32 %99 %32
155        %103 = OpCompositeConstruct %30 %32 %32 %32 %99
156        %104 = OpCompositeConstruct %31 %100 %101 %102 %103
157        %105 = OpTranspose %31 %104
158        %106 = OpCompositeExtract %6 %105 0 0
159        %108 = OpCompositeConstruct %7 %106 %123
160        %110 = OpAccessChain %27 %25 %26 %14
161        %111 = OpLoad %6 %110
162        %112 = OpCompositeConstruct %30 %111 %32 %32 %32
163        %113 = OpCompositeConstruct %30 %32 %111 %32 %32
164        %114 = OpCompositeConstruct %30 %32 %32 %111 %32
165        %115 = OpCompositeConstruct %30 %32 %32 %32 %111
166        %116 = OpCompositeConstruct %31 %112 %113 %114 %115
167        %117 = OpTranspose %31 %116
168        %118 = OpCompositeExtract %6 %117 0 0
169        %120 = OpCompositeConstruct %7 %118 %123
170        %121 = OpExtInst %7 %1 FClamp %108 %64 %120
171        %122 = OpCompositeExtract %6 %121 0
172         %69 = OpFOrdEqual %68 %122 %67
173               OpSelectionMerge %71 None
174               OpBranchConditional %69 %70 %89
175         %89 = OpLabel
176         %90 = OpAccessChain %78 %77 %26 %26
177         %91 = OpLoad %13 %90
178         %92 = OpConvertSToF %6 %91
179         %93 = OpCompositeConstruct %30 %92 %92 %92 %92
180               OpStore %73 %93
181               OpBranch %71
182         %70 = OpLabel
183         %79 = OpAccessChain %78 %77 %26 %26
184         %80 = OpLoad %13 %79
185         %81 = OpConvertSToF %6 %80
186         %85 = OpAccessChain %78 %77 %26 %14
187         %86 = OpLoad %13 %85
188         %87 = OpConvertSToF %6 %86
189         %88 = OpCompositeConstruct %30 %18 %81 %81 %87
190               OpStore %73 %88
191               OpBranch %71
192         %71 = OpLabel
193               OpReturn
194               OpFunctionEnd
195END
196
197# uniforms for variant
198
199# _GLF_uniform_int_values
200BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
201 0 1
202END
203# _GLF_uniform_float_values
204BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
205 0.25 1.0
206END
207
208BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
209
210PIPELINE graphics variant_pipeline
211  ATTACH variant_vertex_shader
212  ATTACH variant_fragment_shader
213  FRAMEBUFFER_SIZE 32 32
214  BIND BUFFER variant_framebuffer AS color LOCATION 0
215  BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1
216  BIND BUFFER variant__GLF_uniform_float_values AS uniform DESCRIPTOR_SET 0 BINDING 0
217END
218CLEAR_COLOR variant_pipeline 0 0 0 255
219
220CLEAR variant_pipeline
221RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32
222
223EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255
224