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.
17 # A test for a bug found by GraphicsFuzz.
19 # Short description: A fragment shader with early return from loop in function
21 # The test passes because the fragment shader writes red. The f function always
22 # returns 1.0, so c is unchanged.
24 # Optimized using spirv-opt with the following arguments:
26 # spirv-opt commit hash: 4a00a80c40484a6f6f72f48c9d34943cf8f180d4
28 # Derived from the following GLSL.
30 # Fragment shader GLSL:
33 # precision highp float;
35 # layout(location = 0) out vec4 _GLF_color;
54 # vec4 c = vec4(1.0, 0.0, 0.0, 1.0);
66 SHADER vertex variant_vertex_shader PASSTHROUGH
68 SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
71 ; Generator: Khronos Glslang Reference Front End; 7
75 %1 = OpExtInstImport "GLSL.std.450"
76 OpMemoryModel Logical GLSL450
77 OpEntryPoint Fragment %4 "main" %56
78 OpExecutionMode %4 OriginUpperLeft
85 OpName %56 "_GLF_color"
86 OpDecorate %12 RelaxedPrecision
87 OpDecorate %19 RelaxedPrecision
88 OpDecorate %23 RelaxedPrecision
89 OpDecorate %30 RelaxedPrecision
90 OpDecorate %31 RelaxedPrecision
91 OpDecorate %39 RelaxedPrecision
92 OpDecorate %46 RelaxedPrecision
93 OpDecorate %53 RelaxedPrecision
94 OpDecorate %54 RelaxedPrecision
95 OpDecorate %56 Location 0
97 %3 = OpTypeFunction %2
99 %7 = OpTypeFunction %6
101 %11 = OpTypePointer Function %10
102 %13 = OpConstant %10 1
103 %20 = OpConstant %10 10
105 %25 = OpConstant %6 1
106 %34 = OpTypeVector %6 4
107 %35 = OpTypePointer Function %34
108 %37 = OpConstant %6 0
109 %38 = OpConstantComposite %34 %25 %37 %37 %25
110 %40 = OpConstant %10 0
112 %50 = OpConstant %49 0
113 %51 = OpTypePointer Function %6
114 %55 = OpTypePointer Output %34
115 %56 = OpVariable %55 Output
116 %4 = OpFunction %2 None %3
118 %36 = OpVariable %35 Function
119 %39 = OpVariable %11 Function
125 %47 = OpSLessThan %21 %46 %13
126 OpLoopMerge %43 %42 None
127 OpBranchConditional %47 %42 %43
129 %48 = OpFunctionCall %6 %8
130 %52 = OpAccessChain %51 %36 %50
133 %54 = OpIAdd %10 %53 %13
141 %8 = OpFunction %6 None %7
143 %12 = OpVariable %11 Function
148 %22 = OpSLessThan %21 %19 %20
149 OpLoopMerge %16 %28 None
150 OpBranchConditional %22 %15 %16
153 %24 = OpConvertSToF %6 %23
154 %26 = OpFOrdGreaterThanEqual %21 %24 %25
155 OpSelectionMerge %58 None
156 OpBranchConditional %26 %27 %28
163 %31 = OpIAdd %10 %30 %13
171 BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
173 PIPELINE graphics variant_pipeline
174 ATTACH variant_vertex_shader
175 ATTACH variant_fragment_shader
176 FRAMEBUFFER_SIZE 256 256
177 BIND BUFFER variant_framebuffer AS color LOCATION 0
179 CLEAR_COLOR variant_pipeline 0 0 0 255
181 CLEAR variant_pipeline
182 RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
184 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255