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 nested if
22 # The test passes because main always writes color red.
23 # Running code after writing red does not matter.
25 # Optimized using spirv-opt with the following arguments:
26 # '--copy-propagate-arrays'
28 # '--convert-local-access-chains'
29 # '--convert-local-access-chains'
31 # '--reduce-load-size'
32 # '--reduce-load-size'
33 # '--eliminate-dead-branches'
35 # '--inline-entry-points-exhaustive'
36 # '--redundancy-elimination'
37 # '--private-to-local'
38 # '--eliminate-dead-code-aggressive'
40 # '--simplify-instructions'
41 # '--eliminate-dead-branches'
42 # '--inline-entry-points-exhaustive'
43 # '--eliminate-dead-inserts'
44 # '--eliminate-dead-branches'
45 # spirv-opt commit hash: 6b072126595dd8c2448eb1fda616251c5e6d7079
49 SHADER vertex variant_vertex_shader PASSTHROUGH
51 # variant_fragment_shader is derived from the following GLSL:
53 # precision highp float;
55 # layout(location = 0) out vec4 _GLF_color;
57 # layout(set = 0, binding = 0) uniform buf0
59 # vec2 injectionSwitch;
63 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Write color red
67 # if (injectionSwitch.y < 0.0) // Always false
69 # bool GLF_live12c5 = false;
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" %9
88 OpExecutionMode %4 OriginUpperLeft
91 OpName %9 "_GLF_color"
93 OpMemberName %18 0 "injectionSwitch"
95 OpName %33 "GLF_live12c5"
96 OpDecorate %9 Location 0
97 OpMemberDecorate %18 0 Offset 0
99 OpDecorate %20 DescriptorSet 0
100 OpDecorate %20 Binding 0
102 %3 = OpTypeFunction %2
104 %7 = OpTypeVector %6 4
105 %8 = OpTypePointer Output %7
106 %9 = OpVariable %8 Output
107 %10 = OpConstant %6 1
108 %11 = OpConstant %6 0
109 %12 = OpConstantComposite %7 %10 %11 %11 %10
110 %17 = OpTypeVector %6 2
111 %18 = OpTypeStruct %17
112 %19 = OpTypePointer Uniform %18
113 %20 = OpVariable %19 Uniform
115 %22 = OpConstant %21 0
117 %24 = OpConstant %23 1
118 %25 = OpTypePointer Uniform %6
120 %32 = OpTypePointer Function %28
121 %34 = OpConstantFalse %28
122 %4 = OpFunction %2 None %3
124 %33 = OpVariable %32 Function
128 OpLoopMerge %15 %37 None
131 %26 = OpAccessChain %25 %20 %22 %24
133 %29 = OpFOrdLessThan %28 %27 %11
134 OpSelectionMerge %31 None
135 OpBranchConditional %29 %30 %31
139 OpSelectionMerge %38 None
140 OpBranchConditional %35 %36 %37
146 OpBranchConditional %34 %13 %15
154 # uniforms for variant
157 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
161 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
163 PIPELINE graphics variant_pipeline
164 ATTACH variant_vertex_shader
165 ATTACH variant_fragment_shader
166 FRAMEBUFFER_SIZE 256 256
167 BIND BUFFER variant_framebuffer AS color LOCATION 0
168 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
170 CLEAR_COLOR variant_pipeline 0 0 0 255
172 CLEAR variant_pipeline
173 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
175 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255