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 expression used in two discard guards
22 # The test passes because most of the code never executes; the shader just 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;
29 # precision highp int;
31 # layout(set = 0, binding = 0) uniform buf0
33 # vec2 injectionSwitch;
35 # layout(location = 0) out vec4 _GLF_color;
41 # if (injectionSwitch.x > 2.0) // always false
43 # int temp = int(max(mix(vec4(1.0), vec4(1.0), gv), 8.6)[1]);
55 # _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
57 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
60 ; Generator: Khronos Glslang Reference Front End; 7
64 %1 = OpExtInstImport "GLSL.std.450"
65 OpMemoryModel Logical GLSL450
66 OpEntryPoint Fragment %4 "main" %51
67 OpExecutionMode %4 OriginUpperLeft
71 OpMemberName %8 0 "injectionSwitch"
75 OpName %51 "_GLF_color"
76 OpMemberDecorate %8 0 Offset 0
78 OpDecorate %10 DescriptorSet 0
79 OpDecorate %10 Binding 0
80 OpDecorate %29 RelaxedPrecision
81 OpDecorate %30 RelaxedPrecision
82 OpDecorate %31 RelaxedPrecision
83 OpDecorate %33 RelaxedPrecision
84 OpDecorate %34 RelaxedPrecision
85 OpDecorate %36 RelaxedPrecision
86 OpDecorate %51 Location 0
88 %3 = OpTypeFunction %2
90 %7 = OpTypeVector %6 2
92 %9 = OpTypePointer Uniform %8
93 %10 = OpVariable %9 Uniform
95 %12 = OpConstant %11 0
97 %14 = OpConstant %13 0
98 %15 = OpTypePointer Uniform %6
101 %23 = OpTypePointer Function %11
102 %25 = OpTypeVector %6 4
103 %26 = OpConstant %6 1
104 %27 = OpConstantComposite %25 %26 %26 %26 %26
105 %28 = OpTypePointer Private %25
106 %29 = OpVariable %28 Private
107 %32 = OpConstant %6 8.60000038
108 %35 = OpConstant %13 1
109 %39 = OpConstant %11 150
110 %45 = OpConstant %11 180
111 %50 = OpTypePointer Output %25
112 %51 = OpVariable %50 Output
113 %52 = OpConstant %6 0
114 %53 = OpConstantComposite %25 %26 %52 %52 %26
115 %4 = OpFunction %2 None %3
117 %24 = OpVariable %23 Function
118 %16 = OpAccessChain %15 %10 %12 %14
120 %20 = OpFOrdGreaterThan %19 %17 %18
121 OpSelectionMerge %22 None
122 OpBranchConditional %20 %21 %22
125 %31 = OpExtInst %25 %1 FMix %27 %27 %30
126 %33 = OpCompositeConstruct %25 %32 %32 %32 %32
127 %34 = OpExtInst %25 %1 FMax %31 %33
128 %36 = OpCompositeExtract %6 %34 1
129 %37 = OpConvertFToS %11 %36
132 %40 = OpSLessThan %19 %38 %39
133 OpSelectionMerge %42 None
134 OpBranchConditional %40 %41 %42
139 %46 = OpSLessThan %19 %44 %45
140 OpSelectionMerge %48 None
141 OpBranchConditional %46 %47 %48
152 # uniforms for variant
155 BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
159 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
161 PIPELINE graphics variant_pipeline
162 ATTACH variant_vertex_shader
163 ATTACH variant_fragment_shader
164 FRAMEBUFFER_SIZE 256 256
165 BIND BUFFER variant_framebuffer AS color LOCATION 0
166 BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 0
168 CLEAR_COLOR variant_pipeline 0 0 0 255
170 CLEAR variant_pipeline
171 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
173 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255