1#!amber
2
3# Copyright 2019 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 bug found by GraphicsFuzz.
19
20# Short description: A fragment shader with a discard, continue, and return
21
22# The test passes because main always writes the color red.
23
24# Optimized using spirv-opt with the following arguments:
25# '-O'
26# spirv-opt commit hash: 06407250a169c6a03b3765e86619075af1a8c187
27
28
29
30SHADER vertex variant_vertex_shader PASSTHROUGH
31
32# variant_fragment_shader is derived from the following GLSL:
33# #version 310 es
34# precision highp float;
35#
36# layout(set = 0, binding = 0) uniform buf0 {
37#  vec2 injectionSwitch;
38# };
39#
40# layout(location = 0) out vec4 _GLF_color;
41#
42# vec3 mand()
43# {
44#  do
45#   {
46#    if(gl_FragCoord.x < 0.0)
47#     {
48#      if(1.0 > injectionSwitch.y)
49#       {
50#        discard;
51#       }
52#      continue;
53#     }
54#    return vec3(1.0);
55#   }
56#  while(false);
57#  return vec3(1.0);
58# }
59# void main()
60# {
61#  mand();
62#  _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
63# }
64SHADER fragment variant_fragment_shader SPIRV-ASM
65; SPIR-V
66; Version: 1.0
67; Generator: Khronos Glslang Reference Front End; 7
68; Bound: 96
69; Schema: 0
70               OpCapability Shader
71          %1 = OpExtInstImport "GLSL.std.450"
72               OpMemoryModel Logical GLSL450
73               OpEntryPoint Fragment %4 "main" %17 %51
74               OpExecutionMode %4 OriginUpperLeft
75               OpSource ESSL 310
76               OpName %4 "main"
77               OpName %17 "gl_FragCoord"
78               OpName %30 "buf0"
79               OpMemberName %30 0 "injectionSwitch"
80               OpName %32 ""
81               OpName %51 "_GLF_color"
82               OpDecorate %17 BuiltIn FragCoord
83               OpMemberDecorate %30 0 Offset 0
84               OpDecorate %30 Block
85               OpDecorate %32 DescriptorSet 0
86               OpDecorate %32 Binding 0
87               OpDecorate %51 Location 0
88          %2 = OpTypeVoid
89          %3 = OpTypeFunction %2
90          %6 = OpTypeFloat 32
91         %15 = OpTypeVector %6 4
92         %16 = OpTypePointer Input %15
93         %17 = OpVariable %16 Input
94         %18 = OpTypeInt 32 0
95         %19 = OpConstant %18 0
96         %20 = OpTypePointer Input %6
97         %23 = OpConstant %6 0
98         %24 = OpTypeBool
99         %28 = OpConstant %6 1
100         %29 = OpTypeVector %6 2
101         %30 = OpTypeStruct %29
102         %31 = OpTypePointer Uniform %30
103         %32 = OpVariable %31 Uniform
104         %33 = OpTypeInt 32 1
105         %34 = OpConstant %33 0
106         %35 = OpConstant %18 1
107         %36 = OpTypePointer Uniform %6
108         %46 = OpConstantFalse %24
109         %50 = OpTypePointer Output %15
110         %51 = OpVariable %50 Output
111         %52 = OpConstantComposite %15 %28 %23 %23 %28
112         %65 = OpConstantTrue %24
113          %4 = OpFunction %2 None %3
114          %5 = OpLabel
115               OpBranch %71
116         %71 = OpLabel
117               OpLoopMerge %72 %73 None
118               OpBranch %75
119         %75 = OpLabel
120               OpLoopMerge %76 %87 None
121               OpBranch %78
122         %78 = OpLabel
123         %79 = OpAccessChain %20 %17 %19
124         %80 = OpLoad %6 %79
125         %81 = OpFOrdLessThan %24 %80 %23
126               OpSelectionMerge %82 None
127               OpBranchConditional %81 %83 %82
128         %83 = OpLabel
129         %84 = OpAccessChain %36 %32 %34 %35
130         %85 = OpLoad %6 %84
131         %86 = OpFOrdGreaterThan %24 %28 %85
132               OpSelectionMerge %95 None
133               OpBranchConditional %86 %88 %87
134         %88 = OpLabel
135               OpKill
136         %95 = OpLabel
137	       OpBranch %87
138         %87 = OpLabel
139               OpBranchConditional %46 %75 %76
140         %82 = OpLabel
141               OpBranch %76
142         %76 = OpLabel
143         %94 = OpPhi %24 %65 %82 %46 %87
144               OpSelectionMerge %91 None
145               OpBranchConditional %94 %72 %91
146         %91 = OpLabel
147               OpBranch %72
148         %73 = OpLabel
149               OpBranch %71
150         %72 = OpLabel
151               OpStore %51 %52
152               OpReturn
153               OpFunctionEnd
154END
155
156# uniforms for variant
157
158# injectionSwitch
159BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
160 0.0 1.0
161END
162
163BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
164
165PIPELINE graphics variant_pipeline
166  ATTACH variant_vertex_shader
167  ATTACH variant_fragment_shader
168  FRAMEBUFFER_SIZE 256 256
169  BIND BUFFER variant_framebuffer AS color LOCATION 0
170  BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
171END
172CLEAR_COLOR variant_pipeline 0 0 0 255
173
174CLEAR variant_pipeline
175RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
176
177EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255
178