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