• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 GraphicsFuzz.
19
20# Short description: A fragment shader that covers a specific basic block code path
21
22# The test passes because shader always writes red.
23
24# Optimized using spirv-opt with the following arguments:
25# '--vector-dce'
26# '--combine-access-chains'
27# '--eliminate-local-multi-store'
28# '--scalar-replacement=100'
29# '--simplify-instructions'
30# '--eliminate-dead-branches'
31# '--merge-return'
32# '--combine-access-chains'
33# '--simplify-instructions'
34# '--eliminate-dead-branches'
35# '--merge-blocks'
36# spirv-opt commit hash: 9215c1b7df0029f27807e8c8d7ec80532ce90a87
37
38
39
40SHADER vertex variant_vertex_shader PASSTHROUGH
41
42# variant_fragment_shader is derived from the following GLSL:
43# #version 310 es
44# precision highp float;
45# precision highp int;
46#
47# layout(set = 0, binding = 0) uniform buf0
48# {
49#     int zero;
50# };
51#
52# layout(location = 0) out vec4 _GLF_color;
53#
54# int func(int x)
55# {
56#     if (x == 10) // Always false.
57#         discard;
58#
59#     return x;
60# }
61#
62# void main()
63# {
64#     int a = 0;
65#     int b = zero;
66#
67#     do
68#     {
69#         a = func(b);
70#         b++;
71#     }
72#     while(b < 4);
73#
74#     if (a == 3)
75#         _GLF_color = vec4(1, 0, 0, 1);
76#     else
77#         _GLF_color = vec4(0);
78# }
79SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
80; SPIR-V
81; Version: 1.0
82; Generator: Khronos Glslang Reference Front End; 8
83; Bound: 59
84; Schema: 0
85               OpCapability Shader
86          %1 = OpExtInstImport "GLSL.std.450"
87               OpMemoryModel Logical GLSL450
88               OpEntryPoint Fragment %4 "main" %52
89               OpExecutionMode %4 OriginUpperLeft
90               OpSource ESSL 310
91               OpName %4 "main"
92               OpName %10 "func(i1;"
93               OpName %9 "x"
94               OpName %22 "a"
95               OpName %24 "b"
96               OpName %25 "buf0"
97               OpMemberName %25 0 "zero"
98               OpName %27 ""
99               OpName %35 "param"
100               OpName %52 "_GLF_color"
101               OpMemberDecorate %25 0 Offset 0
102               OpDecorate %25 Block
103               OpDecorate %27 DescriptorSet 0
104               OpDecorate %27 Binding 0
105               OpDecorate %52 Location 0
106          %2 = OpTypeVoid
107          %3 = OpTypeFunction %2
108          %6 = OpTypeInt 32 1
109          %7 = OpTypePointer Function %6
110          %8 = OpTypeFunction %6 %7
111         %13 = OpConstant %6 10
112         %14 = OpTypeBool
113         %23 = OpConstant %6 0
114         %25 = OpTypeStruct %6
115         %26 = OpTypePointer Uniform %25
116         %27 = OpVariable %26 Uniform
117         %28 = OpTypePointer Uniform %6
118         %39 = OpConstant %6 1
119         %42 = OpConstant %6 4
120         %45 = OpConstant %6 3
121         %49 = OpTypeFloat 32
122         %50 = OpTypeVector %49 4
123         %51 = OpTypePointer Output %50
124         %52 = OpVariable %51 Output
125         %53 = OpConstant %49 1
126         %54 = OpConstant %49 0
127         %55 = OpConstantComposite %50 %53 %54 %54 %53
128         %57 = OpConstantComposite %50 %54 %54 %54 %54
129          %4 = OpFunction %2 None %3
130          %5 = OpLabel
131         %22 = OpVariable %7 Function
132         %24 = OpVariable %7 Function
133         %35 = OpVariable %7 Function
134               OpStore %22 %23
135         %29 = OpAccessChain %28 %27 %23
136         %30 = OpLoad %6 %29
137               OpStore %24 %30
138               OpBranch %31
139         %31 = OpLabel
140         %58 = OpPhi %6 %30 %5 %40 %31
141               OpStore %35 %58
142         %37 = OpFunctionCall %6 %10 %35
143               OpStore %22 %37
144         %40 = OpIAdd %6 %58 %39
145               OpStore %24 %40
146         %43 = OpSLessThan %14 %40 %42
147               OpLoopMerge %33 %31 None
148               OpBranchConditional %43 %31 %33
149         %33 = OpLabel
150         %46 = OpIEqual %14 %37 %45
151               OpSelectionMerge %48 None
152               OpBranchConditional %46 %47 %56
153         %47 = OpLabel
154               OpStore %52 %55
155               OpBranch %48
156         %56 = OpLabel
157               OpStore %52 %57
158               OpBranch %48
159         %48 = OpLabel
160               OpReturn
161               OpFunctionEnd
162         %10 = OpFunction %6 None %8
163          %9 = OpFunctionParameter %7
164         %11 = OpLabel
165         %12 = OpLoad %6 %9
166         %15 = OpIEqual %14 %12 %13
167               OpSelectionMerge %17 None
168               OpBranchConditional %15 %16 %17
169         %16 = OpLabel
170               OpKill
171         %17 = OpLabel
172         %19 = OpLoad %6 %9
173               OpReturnValue %19
174               OpFunctionEnd
175END
176
177# uniforms for variant
178
179# zero
180BUFFER variant_zero DATA_TYPE int32 DATA
181 0
182END
183
184BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
185
186PIPELINE graphics variant_pipeline
187  ATTACH variant_vertex_shader
188  ATTACH variant_fragment_shader
189  FRAMEBUFFER_SIZE 256 256
190  BIND BUFFER variant_framebuffer AS color LOCATION 0
191  BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 0
192END
193CLEAR_COLOR variant_pipeline 0 0 0 255
194
195CLEAR variant_pipeline
196RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
197
198EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
199