3 # Copyright 2020 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 that finds MSB from LSB
22 # The test passes because shader always writes 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(location = 0) out vec4 _GLF_color;
35 # // State of variables/expressions after "result += x;".
37 # // i x i >> x findLSB findMSB result
44 # for (int i = 0; i < 2; i++)
46 # for (int x = 0; x < 2; x++)
48 # // findMSB(findLSB(i >> x)) is always -1.
49 # for ( ; x > findMSB(findLSB(i >> x)) && x < 2; x++)
56 # _GLF_color = vec4(1, 0, 0, 1);
58 # _GLF_color = vec4(0, 0, 0, 1);
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" %60
70 OpExecutionMode %4 OriginUpperLeft
76 OpName %60 "_GLF_color"
77 OpDecorate %60 Location 0
79 %3 = OpTypeFunction %2
81 %7 = OpTypePointer Function %6
87 %58 = OpTypeVector %57 4
88 %59 = OpTypePointer Output %58
89 %60 = OpVariable %59 Output
90 %61 = OpConstant %57 1
91 %62 = OpConstant %57 0
92 %63 = OpConstantComposite %58 %61 %62 %62 %61
93 %65 = OpConstantComposite %58 %62 %62 %62 %61
94 %4 = OpFunction %2 None %3
96 %8 = OpVariable %7 Function
97 %10 = OpVariable %7 Function
98 %20 = OpVariable %7 Function
103 OpLoopMerge %13 %14 None
107 %19 = OpSLessThan %18 %16 %17
108 OpBranchConditional %19 %12 %13
113 OpLoopMerge %23 %24 None
117 %27 = OpSLessThan %18 %26 %17
118 OpBranchConditional %27 %22 %23
122 OpLoopMerge %30 %31 None
128 %36 = OpShiftRightArithmetic %6 %34 %35
129 %37 = OpExtInst %6 %1 FindILsb %36
130 %38 = OpExtInst %6 %1 FindSMsb %37
131 %39 = OpSGreaterThan %18 %33 %38
133 %41 = OpSLessThan %18 %40 %17
134 %42 = OpLogicalAnd %18 %39 %41
135 OpBranchConditional %42 %29 %30
139 %45 = OpIAdd %6 %44 %43
144 %48 = OpIAdd %6 %46 %47
151 %50 = OpIAdd %6 %49 %47
158 %52 = OpIAdd %6 %51 %47
163 %54 = OpIEqual %18 %53 %17
164 OpSelectionMerge %56 None
165 OpBranchConditional %54 %55 %64
178 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
180 PIPELINE graphics variant_pipeline
181 ATTACH variant_vertex_shader
182 ATTACH variant_fragment_shader
183 FRAMEBUFFER_SIZE 256 256
184 BIND BUFFER variant_framebuffer AS color LOCATION 0
186 CLEAR_COLOR variant_pipeline 0 0 0 255
188 CLEAR variant_pipeline
189 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
191 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255