1#!amber 2 3# Copyright 2018 Google LLC 4# 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 8# 9# http://www.apache.org/licenses/LICENSE-2.0 10# 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. 16 17# A test for a bug found by GraphicsFuzz. 18 19# A fragment shader that uses an array of matrices and distance. 20# Derived from the following GLSL fragment shader. 21# We check that the top-left pixel is red. The test passes because the 22# first if statement checks if the x coordinate is less than 10 and if so writes 23# red to _GLF_color and then returns. 24 25# #version 310 es 26# 27# precision highp float; 28# precision highp int; 29# 30# layout(location=0) out vec4 _GLF_color; 31# 32# void main() 33# { 34# if (gl_FragCoord.x < 10.0) { 35# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); 36# return; 37# } 38# mat4 m[4] = mat4[](mat4(1.0), mat4(1.0), mat4(1.0), mat4(1.0)); 39# for(int i = 0; i < 4; i ++) { 40# int l = 0; 41# for(int j = 0; j < 4; j ++) { 42# if(l >= 2) { 43# break; 44# } 45# l++; 46# vec2 v = m[j][i].xy; 47# if(distance(vec2(1.0), v) < 1.0) { 48# _GLF_color = vec4(1.0); 49# } 50# } 51# } 52# } 53 54 55SHADER vertex variant_vertex_shader PASSTHROUGH 56 57SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 58; SPIR-V 59; Version: 1.0 60; Generator: Khronos SPIR-V Tools Assembler; 0 61; Bound: 75 62; Schema: 0 63 OpCapability Shader 64 %1 = OpExtInstImport "GLSL.std.450" 65 OpMemoryModel Logical GLSL450 66 OpEntryPoint Fragment %2 "main" %3 %4 67 OpExecutionMode %2 OriginUpperLeft 68 OpSource ESSL 310 69 OpName %2 "main" 70 OpName %3 "gl_FragCoord" 71 OpName %4 "_GLF_color" 72 OpName %5 "m" 73 OpDecorate %3 BuiltIn FragCoord 74 OpDecorate %4 Location 0 75 %6 = OpTypeVoid 76 %7 = OpTypeFunction %6 77 %8 = OpTypeFloat 32 78 %9 = OpTypeVector %8 4 79 %10 = OpTypePointer Input %9 80 %3 = OpVariable %10 Input 81 %11 = OpTypeInt 32 0 82 %12 = OpConstant %11 0 83 %13 = OpTypePointer Input %8 84 %14 = OpConstant %8 10 85 %15 = OpTypeBool 86 %16 = OpTypePointer Output %9 87 %4 = OpVariable %16 Output 88 %17 = OpConstant %8 1 89 %18 = OpConstant %8 0 90 %19 = OpConstantComposite %9 %17 %18 %18 %17 91 %20 = OpTypeMatrix %9 4 92 %21 = OpConstant %11 4 93 %22 = OpTypeArray %20 %21 94 %23 = OpTypePointer Function %22 95 %24 = OpConstantComposite %9 %17 %18 %18 %18 96 %25 = OpConstantComposite %9 %18 %17 %18 %18 97 %26 = OpConstantComposite %9 %18 %18 %17 %18 98 %27 = OpConstantComposite %9 %18 %18 %18 %17 99 %28 = OpConstantComposite %20 %24 %25 %26 %27 100 %29 = OpConstantComposite %22 %28 %28 %28 %28 101 %30 = OpTypeInt 32 1 102 %31 = OpConstant %30 0 103 %32 = OpConstant %30 4 104 %33 = OpConstant %30 2 105 %34 = OpConstant %30 1 106 %35 = OpTypeVector %8 2 107 %36 = OpTypePointer Function %9 108 %37 = OpConstantComposite %35 %17 %17 109 %38 = OpConstantComposite %9 %17 %17 %17 %17 110 %2 = OpFunction %6 None %7 111 %39 = OpLabel 112 %5 = OpVariable %23 Function 113 OpBranch %40 114 %40 = OpLabel 115 OpLoopMerge %41 %42 None 116 OpBranch %43 117 %43 = OpLabel 118 %44 = OpAccessChain %13 %3 %12 119 %45 = OpLoad %8 %44 120 %46 = OpFOrdLessThan %15 %45 %14 121 OpSelectionMerge %47 None 122 OpBranchConditional %46 %48 %47 123 %48 = OpLabel 124 OpStore %4 %19 125 OpBranch %41 126 %47 = OpLabel 127 OpStore %5 %29 128 OpBranch %49 129 %49 = OpLabel 130 %50 = OpPhi %30 %31 %47 %51 %52 131 %53 = OpSLessThan %15 %50 %32 132 OpLoopMerge %54 %52 None 133 OpBranchConditional %53 %55 %54 134 %55 = OpLabel 135 OpBranch %56 136 %56 = OpLabel 137 %57 = OpPhi %30 %31 %55 %58 %59 138 %60 = OpPhi %30 %31 %55 %61 %59 139 %62 = OpSLessThan %15 %60 %32 140 OpLoopMerge %63 %59 None 141 OpBranchConditional %62 %64 %63 142 %64 = OpLabel 143 %65 = OpSGreaterThanEqual %15 %57 %33 144 OpSelectionMerge %66 None 145 OpBranchConditional %65 %67 %66 146 %67 = OpLabel 147 OpBranch %63 148 %66 = OpLabel 149 %58 = OpIAdd %30 %57 %34 150 %68 = OpAccessChain %36 %5 %60 %50 151 %69 = OpLoad %9 %68 152 %70 = OpVectorShuffle %35 %69 %69 0 1 153 %71 = OpExtInst %8 %1 Distance %37 %70 154 %72 = OpFOrdLessThan %15 %71 %17 155 OpSelectionMerge %73 None 156 OpBranchConditional %72 %74 %59 157 %74 = OpLabel 158 OpStore %4 %38 159 OpBranch %59 160 %73 = OpLabel 161 OpBranch %59 162 %59 = OpLabel 163 %61 = OpIAdd %30 %60 %34 164 OpBranch %56 165 %63 = OpLabel 166 OpBranch %52 167 %52 = OpLabel 168 %51 = OpIAdd %30 %50 %34 169 OpBranch %49 170 %54 = OpLabel 171 OpBranch %41 172 %42 = OpLabel 173 OpBranch %40 174 %41 = OpLabel 175 OpReturn 176 OpFunctionEnd 177END 178 179BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 180 181PIPELINE graphics variant_pipeline 182 ATTACH variant_vertex_shader 183 ATTACH variant_fragment_shader 184 FRAMEBUFFER_SIZE 256 256 185 BIND BUFFER variant_framebuffer AS color LOCATION 0 186END 187CLEAR_COLOR variant_pipeline 0 0 0 255 188 189CLEAR variant_pipeline 190RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 191 192EXPECT variant_framebuffer IDX 0 0 SIZE 1 1 EQ_RGBA 255 0 0 255 193