blob: 9b0ac43c0896b61af735e9540c57355cc07f6bfb [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 vector swizzles, struct initializers, and min.
# 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;
#
# struct S {
# vec2 s2;
# };
#
# 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;
# }
# vec4 v4 = vec4(injectionSwitch.y);
# vec2 p = S(v4.xy).s2;
# v4.xy = p;
# v4.xy = (min(vec4(1.0), v4)).xy;
# _GLF_color = vec4(v4.x, 0.0, 0.0, 1.0);
# }
[vertex shader passthrough]
[fragment shader spirv]
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 63
; 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
%uint_1 = OpConstant %uint 1
%_ptr_Uniform_float = OpTypePointer Uniform %float
%49 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%main = OpFunction %void None %3
%5 = OpLabel
OpBranch %60
%60 = OpLabel
OpLoopMerge %59 %62 None
OpBranch %61
%61 = 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 %59
%19 = OpLabel
%36 = OpAccessChain %_ptr_Uniform_float %_ %int_0 %uint_1
%37 = OpLoad %float %36
%38 = OpCompositeConstruct %v4float %37 %37 %37 %37
%48 = OpVectorShuffle %v4float %38 %38 4 5 2 3
%51 = OpExtInst %v4float %1 FMin %49 %48
%57 = OpCompositeExtract %float %51 0
%58 = OpCompositeConstruct %v4float %57 %float_0 %float_0 %float_1
OpStore %_GLF_color %58
OpBranch %59
%62 = OpLabel
OpBranch %60
%59 = 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)