blob: 48976b98f2d2dae6713c0bf596bb36522a6ac21f [file] [log] [blame]
#!amber
# Copyright 2019 Google LLC
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# A test for a bug found by GraphicsFuzz.
# Short description: A fragment shader with early return from loop in function
# The test passes because the fragment shader writes red. The f function always
# returns 1.0, so c is unchanged.
# Optimized using spirv-opt with the following arguments:
# '--merge-blocks'
# spirv-opt commit hash: 4a00a80c40484a6f6f72f48c9d34943cf8f180d4
# Derived from the following GLSL.
# Fragment shader GLSL:
# #version 310 es
#
# precision highp float;
#
# layout(location = 0) out vec4 _GLF_color;
#
# float f()
# {
# for(
# int i = 1;
# i < 10;
# i ++
# )
# {
# if(float(i) >= 1.0)
# {
# return 1.0;
# }
# }
# return 1.0;
# }
# void main()
# {
# vec4 c = vec4(1.0, 0.0, 0.0, 1.0);
# for(
# int i = 0;
# i < 1;
# i ++
# )
# {
# c.x = f();
# }
# _GLF_color = c;
# }
SHADER vertex variant_vertex_shader PASSTHROUGH
SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 59
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main" %56
OpExecutionMode %4 OriginUpperLeft
OpSource ESSL 310
OpName %4 "main"
OpName %8 "f("
OpName %12 "i"
OpName %36 "c"
OpName %39 "i"
OpName %56 "_GLF_color"
OpDecorate %12 RelaxedPrecision
OpDecorate %19 RelaxedPrecision
OpDecorate %23 RelaxedPrecision
OpDecorate %30 RelaxedPrecision
OpDecorate %31 RelaxedPrecision
OpDecorate %39 RelaxedPrecision
OpDecorate %46 RelaxedPrecision
OpDecorate %53 RelaxedPrecision
OpDecorate %54 RelaxedPrecision
OpDecorate %56 Location 0
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypeFunction %6
%10 = OpTypeInt 32 1
%11 = OpTypePointer Function %10
%13 = OpConstant %10 1
%20 = OpConstant %10 10
%21 = OpTypeBool
%25 = OpConstant %6 1
%34 = OpTypeVector %6 4
%35 = OpTypePointer Function %34
%37 = OpConstant %6 0
%38 = OpConstantComposite %34 %25 %37 %37 %25
%40 = OpConstant %10 0
%49 = OpTypeInt 32 0
%50 = OpConstant %49 0
%51 = OpTypePointer Function %6
%55 = OpTypePointer Output %34
%56 = OpVariable %55 Output
%4 = OpFunction %2 None %3
%5 = OpLabel
%36 = OpVariable %35 Function
%39 = OpVariable %11 Function
OpStore %36 %38
OpStore %39 %40
OpBranch %41
%41 = OpLabel
%46 = OpLoad %10 %39
%47 = OpSLessThan %21 %46 %13
OpLoopMerge %43 %42 None
OpBranchConditional %47 %42 %43
%42 = OpLabel
%48 = OpFunctionCall %6 %8
%52 = OpAccessChain %51 %36 %50
OpStore %52 %48
%53 = OpLoad %10 %39
%54 = OpIAdd %10 %53 %13
OpStore %39 %54
OpBranch %41
%43 = OpLabel
%57 = OpLoad %34 %36
OpStore %56 %57
OpReturn
OpFunctionEnd
%8 = OpFunction %6 None %7
%9 = OpLabel
%12 = OpVariable %11 Function
OpStore %12 %13
OpBranch %14
%14 = OpLabel
%19 = OpLoad %10 %12
%22 = OpSLessThan %21 %19 %20
OpLoopMerge %16 %28 None
OpBranchConditional %22 %15 %16
%15 = OpLabel
%23 = OpLoad %10 %12
%24 = OpConvertSToF %6 %23
%26 = OpFOrdGreaterThanEqual %21 %24 %25
OpSelectionMerge %58 None
OpBranchConditional %26 %27 %28
%27 = OpLabel
OpReturnValue %25
%58 = OpLabel
OpBranch %28
%28 = OpLabel
%30 = OpLoad %10 %12
%31 = OpIAdd %10 %30 %13
OpStore %12 %31
OpBranch %14
%16 = OpLabel
OpReturnValue %25
OpFunctionEnd
END
BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM
PIPELINE graphics variant_pipeline
ATTACH variant_vertex_shader
ATTACH variant_fragment_shader
FRAMEBUFFER_SIZE 256 256
BIND BUFFER variant_framebuffer AS color LOCATION 0
END
CLEAR_COLOR variant_pipeline 0 0 0 255
CLEAR variant_pipeline
RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255