blob: 58e415945dec384253eef8911327fe0703f02968 [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 an array of matrices and distance.
# 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;
#
# void main()
# {
# if (gl_FragCoord.x < 10.0) {
# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0);
# return;
# }
# mat4 m[4] = mat4[](mat4(1.0), mat4(1.0), mat4(1.0), mat4(1.0));
# for(int i = 0; i < 4; i ++) {
# int l = 0;
# for(int j = 0; j < 4; j ++) {
# if(l >= 2) {
# break;
# }
# l++;
# vec2 v = m[j][i].xy;
# if(distance(vec2(1.0), v) < 1.0) {
# _GLF_color = vec4(1.0);
# }
# }
# }
# }
[vertex shader passthrough]
[fragment shader spirv]
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 7
; Bound: 98
; 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 %m "m"
OpDecorate %gl_FragCoord BuiltIn FragCoord
OpDecorate %_GLF_color Location 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
%mat4v4float = OpTypeMatrix %v4float 4
%uint_4 = OpConstant %uint 4
%_arr_mat4v4float_uint_4 = OpTypeArray %mat4v4float %uint_4
%_ptr_Function__arr_mat4v4float_uint_4 = OpTypePointer Function %_arr_mat4v4float_uint_4
%31 = OpConstantComposite %v4float %float_1 %float_0 %float_0 %float_0
%32 = OpConstantComposite %v4float %float_0 %float_1 %float_0 %float_0
%33 = OpConstantComposite %v4float %float_0 %float_0 %float_1 %float_0
%34 = OpConstantComposite %v4float %float_0 %float_0 %float_0 %float_1
%35 = OpConstantComposite %mat4v4float %31 %32 %33 %34
%36 = OpConstantComposite %_arr_mat4v4float_uint_4 %35 %35 %35 %35
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%int_4 = OpConstant %int 4
%int_2 = OpConstant %int 2
%int_1 = OpConstant %int 1
%v2float = OpTypeVector %float 2
%_ptr_Function_v4float = OpTypePointer Function %v4float
%76 = OpConstantComposite %v2float %float_1 %float_1
%82 = OpConstantComposite %v4float %float_1 %float_1 %float_1 %float_1
%main = OpFunction %void None %3
%5 = OpLabel
%m = OpVariable %_ptr_Function__arr_mat4v4float_uint_4 Function
OpBranch %88
%88 = OpLabel
OpLoopMerge %87 %90 None
OpBranch %89
%89 = 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 %87
%19 = OpLabel
OpStore %m %36
OpBranch %41
%41 = OpLabel
%95 = OpPhi %int %int_0 %19 %86 %53
%48 = OpSLessThan %bool %95 %int_4
OpLoopMerge %43 %53 None
OpBranchConditional %48 %42 %43
%42 = OpLabel
OpBranch %51
%51 = OpLabel
%97 = OpPhi %int %int_0 %42 %66 %81
%96 = OpPhi %int %int_0 %42 %84 %81
%57 = OpSLessThan %bool %96 %int_4
OpLoopMerge %53 %81 None
OpBranchConditional %57 %52 %53
%52 = OpLabel
%60 = OpSGreaterThanEqual %bool %97 %int_2
OpSelectionMerge %62 None
OpBranchConditional %60 %61 %62
%61 = OpLabel
OpBranch %53
%62 = OpLabel
%66 = OpIAdd %int %97 %int_1
%73 = OpAccessChain %_ptr_Function_v4float %m %96 %95
%74 = OpLoad %v4float %73
%75 = OpVectorShuffle %v2float %74 %74 0 1
%78 = OpExtInst %float %1 Distance %76 %75
%79 = OpFOrdLessThan %bool %78 %float_1
OpSelectionMerge %81 None
OpBranchConditional %79 %80 %81
%80 = OpLabel
OpStore %_GLF_color %82
OpBranch %81
%81 = OpLabel
%84 = OpIAdd %int %96 %int_1
OpBranch %51
%53 = OpLabel
%86 = OpIAdd %int %95 %int_1
OpBranch %41
%43 = OpLabel
OpBranch %87
%90 = OpLabel
OpBranch %88
%87 = OpLabel
OpReturn
OpFunctionEnd
[test]
draw rect -1 -1 2 2
probe rgba (0, 0) (1, 0, 0, 1)