blob: ecdde7d1405fca33bc34bae32c034af55d1fedad [file] [log] [blame]
# Copyright 2018 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.
# A fragment shader that uses a while loop inside a switch.
# Derived from the following GLSL fragment shader.
# We check that the top-left pixel is red. The test passes because the
# first if statement checks if the x coordinate is less than 10 and if so writes
# red to _GLF_color and then returns.
# #version 310 es
#
# precision highp float;
# precision highp int;
#
# layout(location = 0) out vec4 _GLF_color;
#
# layout(set = 0, binding = 0) uniform buf0 {
# vec2 injectionSwitch;
# };
#
# void main()
# {
# if (gl_FragCoord.x < 10.0) {
# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
# return;
# }
# switch(int(injectionSwitch.x))
# {
# case 0:
# while(bool(1.0))
# {
# discard;
# }
# }
# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
# return;
# }
[vertex shader passthrough]
[fragment shader spirv]
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 51
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %gl_FragCoord %_GLF_color
OpExecutionMode %main OriginUpperLeft
OpSource ESSL 310
OpName %main "main"
OpName %gl_FragCoord "gl_FragCoord"
OpName %_GLF_color "_GLF_color"
OpName %buf0 "buf0"
OpMemberName %buf0 0 "injectionSwitch"
OpName %_ ""
OpDecorate %gl_FragCoord BuiltIn FragCoord
OpDecorate %_GLF_color Location 0
OpMemberDecorate %buf0 0 Offset 0
OpDecorate %buf0 Block
OpDecorate %_ DescriptorSet 0
OpDecorate %_ Binding 0
%void = OpTypeVoid
%3 = OpTypeFunction %void
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Input_v4float = OpTypePointer Input %v4float
%gl_FragCoord = OpVariable %_ptr_Input_v4float Input
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%_ptr_Input_float = OpTypePointer Input %float
%float_10 = OpConstant %float 10
%bool = OpTypeBool
%_ptr_Output_v4float = OpTypePointer Output %v4float
%_GLF_color = OpVariable %_ptr_Output_v4float Output
%float_1 = OpConstant %float 1
%float_0 = OpConstant %float 0
%24 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_1
%v2float = OpTypeVector %float 2
%buf0 = OpTypeStruct %v2float
%_ptr_Uniform_buf0 = OpTypePointer Uniform %buf0
%_ = OpVariable %_ptr_Uniform_buf0 Uniform
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Uniform_float = OpTypePointer Uniform %float
%main = OpFunction %void None %3
%5 = OpLabel
OpBranch %48
%48 = OpLabel
OpLoopMerge %47 %50 None
OpBranch %49
%49 = OpLabel
%13 = OpAccessChain %_ptr_Input_float %gl_FragCoord %uint_0
%14 = OpLoad %float %13
%17 = OpFOrdLessThan %bool %14 %float_10
OpSelectionMerge %19 None
OpBranchConditional %17 %18 %19
%18 = OpLabel
OpStore %_GLF_color %24
OpBranch %47
%19 = OpLabel
%33 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %uint_0
%34 = OpLoad %float %33
%35 = OpConvertFToS %int %34
OpSelectionMerge %37 None
OpSwitch %35 %37 0 %36
%36 = OpLabel
OpBranch %38
%38 = OpLabel
OpLoopMerge %40 %41 None
OpBranch %39
%39 = OpLabel
OpKill
%41 = OpLabel
OpBranch %38
%40 = OpLabel
OpUnreachable
%37 = OpLabel
OpStore %_GLF_color %24
OpBranch %47
%50 = OpLabel
OpBranch %48
%47 = OpLabel
OpReturn
OpFunctionEnd
[test]
uniform ubo 0:0 vec2 0 0.0 1.0
draw rect -1 -1 2 2
probe rgba (0, 0) (1, 0, 0, 1)