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 a switch inside while always return
22 # The test passes because main always writes the color red.
24 SHADER vertex variant_vertex_shader PASSTHROUGH
26 # variant_fragment_shader is derived from the following GLSL:
28 # precision highp float;
30 # layout(location = 0) out vec4 _GLF_color;
32 # layout(set = 0, binding = 0) uniform buf0
47 # _GLF_color = vec4(1, 0, 0, 1);
53 # return; // We always end up here
58 # _GLF_color = vec4(int(res));
60 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
63 ; Generator: Khronos Glslang Reference Front End; 8
67 %1 = OpExtInstImport "GLSL.std.450"
68 OpMemoryModel Logical GLSL450
69 OpEntryPoint Fragment %4 "main" %27
70 OpExecutionMode %4 OriginUpperLeft
75 OpMemberName %11 0 "zero"
77 OpName %27 "_GLF_color"
79 OpDecorate %8 RelaxedPrecision
80 OpMemberDecorate %11 0 Offset 0
82 OpDecorate %13 DescriptorSet 0
83 OpDecorate %13 Binding 0
84 OpDecorate %27 Location 0
85 OpDecorate %43 RelaxedPrecision
86 OpDecorate %44 RelaxedPrecision
87 OpDecorate %45 RelaxedPrecision
89 %3 = OpTypeFunction %2
91 %7 = OpTypeFunction %6
93 %11 = OpTypeStruct %10
94 %12 = OpTypePointer Uniform %11
95 %13 = OpVariable %12 Uniform
97 %15 = OpTypePointer Uniform %10
98 %18 = OpConstant %10 0
100 %25 = OpTypeVector %10 4
101 %26 = OpTypePointer Output %25
102 %27 = OpVariable %26 Output
103 %28 = OpConstant %10 1
104 %29 = OpConstantComposite %25 %28 %18 %18 %28
105 %41 = OpConstantFalse %19
106 %42 = OpTypePointer Function %6
107 %4 = OpFunction %2 None %3
109 %43 = OpVariable %42 Function
113 OpLoopMerge %32 %33 None
116 %34 = OpAccessChain %15 %13 %14
118 %36 = OpConvertFToS %6 %35
119 OpSelectionMerge %38 None
120 OpSwitch %36 %38 0 %37
126 OpBranchConditional %41 %30 %32
128 %44 = OpFunctionCall %6 %8
131 %46 = OpConvertSToF %10 %45
132 %47 = OpCompositeConstruct %25 %46 %46 %46 %46
136 %8 = OpFunction %6 None %7
138 %16 = OpAccessChain %15 %13 %14
140 %20 = OpFOrdLessThan %19 %17 %18
141 OpSelectionMerge %22 None
142 OpBranchConditional %20 %21 %22
151 # uniforms for variant
154 BUFFER variant_zero DATA_TYPE float DATA
158 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
160 PIPELINE graphics variant_pipeline
161 ATTACH variant_vertex_shader
162 ATTACH variant_fragment_shader
163 FRAMEBUFFER_SIZE 256 256
164 BIND BUFFER variant_framebuffer AS color LOCATION 0
165 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 0
167 CLEAR_COLOR variant_pipeline 0 0 0 255
169 CLEAR variant_pipeline
170 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
172 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255