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 an always false while function
22 # The test passes because the shader always writes the color red (while function in the shader is always false)
24 # Optimized using spirv-opt with the following arguments:
25 # '--redundancy-elimination'
26 # '--reduce-load-size'
27 # '--eliminate-dead-branches'
30 # '--eliminate-dead-branches'
31 # spirv-opt commit hash: 230c9e437146e48ec58adb4433890403c23c98fa
35 SHADER vertex variant_vertex_shader PASSTHROUGH
37 # variant_fragment_shader is derived from the following GLSL:
39 # precision highp float;
41 # layout(location = 0) out vec4 _GLF_color;
42 # layout(set = 0, binding = 0) uniform buf0 {
43 # vec2 injectionSwitch;
47 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
51 # int j = int(injectionSwitch.x);
59 # while(0.0 > injectionSwitch.y);
60 # int(injectionSwitch.y);
62 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
65 ; Generator: Khronos Glslang Reference Front End; 7
69 %1 = OpExtInstImport "GLSL.std.450"
70 OpMemoryModel Logical GLSL450
71 OpEntryPoint Fragment %4 "main" %9
72 OpExecutionMode %4 OriginUpperLeft
75 OpName %9 "_GLF_color"
78 OpMemberName %21 0 "injectionSwitch"
80 OpDecorate %9 Location 0
81 OpDecorate %19 RelaxedPrecision
82 OpMemberDecorate %21 0 Offset 0
84 OpDecorate %23 DescriptorSet 0
85 OpDecorate %23 Binding 0
86 OpDecorate %30 RelaxedPrecision
87 OpDecorate %36 RelaxedPrecision
89 %3 = OpTypeFunction %2
91 %7 = OpTypeVector %6 4
92 %8 = OpTypePointer Output %7
93 %9 = OpVariable %8 Output
96 %12 = OpConstantComposite %7 %10 %11 %11 %10
98 %18 = OpTypePointer Function %17
99 %20 = OpTypeVector %6 2
100 %21 = OpTypeStruct %20
101 %22 = OpTypePointer Uniform %21
102 %23 = OpVariable %22 Uniform
103 %24 = OpConstant %17 0
105 %26 = OpConstant %25 0
106 %27 = OpTypePointer Uniform %6
107 %37 = OpConstant %17 2
109 %42 = OpConstant %17 1
110 %44 = OpConstant %25 1
111 %4 = OpFunction %2 None %3
113 %19 = OpVariable %18 Function
117 %28 = OpAccessChain %27 %23 %24 %26
119 %30 = OpConvertFToS %17 %29
121 OpLoopMerge %15 %33 None
125 %39 = OpSLessThan %38 %36 %37
126 OpLoopMerge %51 %34 None
127 OpBranchConditional %39 %32 %51
135 %45 = OpAccessChain %27 %23 %24 %44
137 %47 = OpFOrdGreaterThan %38 %11 %46
138 OpBranchConditional %47 %13 %15
140 %50 = OpConvertFToS %17 %46
145 # uniforms for variant
148 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
152 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
154 PIPELINE graphics variant_pipeline
155 ATTACH variant_vertex_shader
156 ATTACH variant_fragment_shader
157 FRAMEBUFFER_SIZE 256 256
158 BIND BUFFER variant_framebuffer AS color LOCATION 0
159 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
161 CLEAR_COLOR variant_pipeline 0 0 0 255
163 CLEAR variant_pipeline
164 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
166 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255