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: Calls a function containing a discard
22 # The test passes because main always writes the color red.
24 # Optimized using spirv-opt with the following arguments:
25 # '--eliminate-dead-branches'
27 # '--eliminate-dead-branches'
29 # '--eliminate-local-single-block'
30 # '--eliminate-dead-branches'
33 # '--scalar-replacement=100'
34 # '--eliminate-local-single-block'
35 # '--simplify-instructions'
36 # '--redundancy-elimination'
37 # '--eliminate-local-multi-store'
38 # '--private-to-local'
40 # '--private-to-local'
41 # spirv-opt commit hash: 18b3b94567a9251a6f8491a6d07c4422abadd22c
45 SHADER vertex variant_vertex_shader PASSTHROUGH
47 # variant_fragment_shader is derived from the following GLSL:
49 # precision highp float;
51 # layout(location = 0) out vec4 _GLF_color;
53 # layout(set = 0, binding = 0) uniform buf0
60 # if (1.0 > one) // Always false
68 # _GLF_color = vec4(0);
73 # _GLF_color = vec4(1, 0, 0, 1);
75 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
78 ; Generator: Khronos Glslang Reference Front End; 8
82 %1 = OpExtInstImport "GLSL.std.450"
83 OpMemoryModel Logical GLSL450
84 OpEntryPoint Fragment %4 "main" %25
85 OpExecutionMode %4 OriginUpperLeft
90 OpMemberName %10 0 "one"
92 OpName %25 "_GLF_color"
93 OpMemberDecorate %10 0 Offset 0
95 OpDecorate %12 DescriptorSet 0
96 OpDecorate %12 Binding 0
97 OpDecorate %25 Location 0
99 %3 = OpTypeFunction %2
102 %10 = OpTypeStruct %8
103 %11 = OpTypePointer Uniform %10
104 %12 = OpVariable %11 Uniform
106 %14 = OpConstant %13 0
107 %15 = OpTypePointer Uniform %8
109 %23 = OpTypeVector %8 4
110 %24 = OpTypePointer Output %23
111 %25 = OpVariable %24 Output
112 %26 = OpConstant %8 0
113 %27 = OpConstantComposite %23 %26 %26 %26 %26
114 %33 = OpConstantFalse %18
115 %34 = OpConstantComposite %23 %9 %26 %26 %9
116 %4 = OpFunction %2 None %3
121 %32 = OpFunctionCall %2 %6
122 OpLoopMerge %30 %28 None
123 OpBranchConditional %33 %28 %30
128 %6 = OpFunction %2 None %3
130 %16 = OpAccessChain %15 %12 %14
132 %19 = OpFOrdGreaterThan %18 %9 %17
133 OpSelectionMerge %21 None
134 OpBranchConditional %19 %20 %21
142 # uniforms for variant
145 BUFFER variant_one DATA_TYPE float DATA
149 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
151 PIPELINE graphics variant_pipeline
152 ATTACH variant_vertex_shader
153 ATTACH variant_fragment_shader
154 FRAMEBUFFER_SIZE 256 256
155 BIND BUFFER variant_framebuffer AS color LOCATION 0
156 BIND BUFFER variant_one AS uniform DESCRIPTOR_SET 0 BINDING 0
158 CLEAR_COLOR variant_pipeline 0 0 0 255
160 CLEAR variant_pipeline
161 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
163 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255