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