3 # Copyright 2019 Google LLC
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
18 # A test for a bug found by GraphicsFuzz.
20 # Short description: A fragment shader with unreachable discard statement
22 # The test passes because the shader always writes the color red. The discard statement is never reached.
24 # Optimized using spirv-opt with the following arguments:
25 # '--scalar-replacement=100'
26 # '--private-to-local'
27 # '--eliminate-dead-branches'
29 # '--eliminate-dead-branches'
30 # '--private-to-local'
31 # '--copy-propagate-arrays'
32 # '--scalar-replacement=100'
33 # '--combine-access-chains'
35 # '--convert-local-access-chains'
37 # '--eliminate-dead-branches'
40 # '--eliminate-dead-branches'
41 # '--eliminate-dead-branches'
43 # '--combine-access-chains'
44 # '--eliminate-local-single-block'
45 # '--copy-propagate-arrays'
47 # '--private-to-local'
48 # '--private-to-local'
49 # spirv-opt commit hash: 06407250a169c6a03b3765e86619075af1a8c187
53 SHADER vertex variant_vertex_shader PASSTHROUGH
55 # variant_fragment_shader is derived from the following GLSL:
57 # precision highp float;
59 # layout(location = 0) out vec4 _GLF_color;
63 # for (int k = 0; k < 1000; k++)
66 # discard; // This statement is never reached
72 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
74 # for (int i = 0; i < 4; i++)
78 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
81 ; Generator: Khronos Glslang Reference Front End; 7
85 %1 = OpExtInstImport "GLSL.std.450"
86 OpMemoryModel Logical GLSL450
87 OpEntryPoint Fragment %4 "main" %35
88 OpExecutionMode %4 OriginUpperLeft
93 OpName %35 "_GLF_color"
95 OpDecorate %13 RelaxedPrecision
96 OpDecorate %20 RelaxedPrecision
97 OpDecorate %35 Location 0
98 OpDecorate %38 RelaxedPrecision
99 OpDecorate %44 RelaxedPrecision
100 OpDecorate %48 RelaxedPrecision
101 OpDecorate %49 RelaxedPrecision
103 %3 = OpTypeFunction %2
105 %7 = OpTypeVector %6 3
106 %8 = OpTypeFunction %7
108 %12 = OpTypePointer Function %11
109 %14 = OpConstant %11 0
110 %21 = OpConstant %11 1000
112 %24 = OpConstant %6 1
113 %25 = OpConstantComposite %7 %24 %24 %24
114 %28 = OpConstant %11 1
115 %33 = OpTypeVector %6 4
116 %34 = OpTypePointer Output %33
117 %35 = OpVariable %34 Output
118 %36 = OpConstant %6 0
119 %37 = OpConstantComposite %33 %24 %36 %36 %24
120 %45 = OpConstant %11 4
121 %51 = OpTypePointer Function %7
122 %57 = OpConstantFalse %22
123 %58 = OpTypePointer Function %22
124 %60 = OpConstantTrue %22
125 %4 = OpFunction %2 None %3
127 %38 = OpVariable %12 Function
133 %46 = OpSLessThan %22 %44 %45
134 OpLoopMerge %41 %40 None
135 OpBranchConditional %46 %40 %41
137 %47 = OpFunctionCall %7 %9
139 %49 = OpIAdd %11 %48 %28
145 %9 = OpFunction %7 None %8
147 %59 = OpVariable %58 Function %57
148 %52 = OpVariable %51 Function
149 %13 = OpVariable %12 Function
153 OpLoopMerge %50 %56 None
157 %23 = OpSLessThan %22 %20 %21
158 OpLoopMerge %17 %18 None
159 OpBranchConditional %23 %16 %17
168 OpSelectionMerge %61 None
169 OpBranchConditional %62 %50 %61
180 # uniforms for variant
183 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
185 PIPELINE graphics variant_pipeline
186 ATTACH variant_vertex_shader
187 ATTACH variant_fragment_shader
188 FRAMEBUFFER_SIZE 256 256
189 BIND BUFFER variant_framebuffer AS color LOCATION 0
191 CLEAR_COLOR variant_pipeline 0 0 0 255
193 CLEAR variant_pipeline
194 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
196 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255