1#!amber 2 3# Copyright 2019 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 18# A test for a bug found by GraphicsFuzz. 19 20# Short description: Shader with matrix multiplication in loop 21 22# The test passes because 'm1' is the identity matrix, so that 'm2' is also the identity matrix, meaning that 'v' gets set to '(1.0, 0.0)'. As a result, the colour that is written is guaranteed to be red 23 24# Optimized using spirv-opt with the following arguments: 25# '--simplify-instructions' 26# '--combine-access-chains' 27# '--eliminate-dead-branches' 28# '--merge-return' 29# '--combine-access-chains' 30# '--eliminate-dead-code-aggressive' 31# '--reduce-load-size' 32# '--eliminate-local-single-block' 33# '--private-to-local' 34# '--inline-entry-points-exhaustive' 35# '--copy-propagate-arrays' 36# '--eliminate-local-multi-store' 37# '--scalar-replacement=100' 38# '--eliminate-dead-branches' 39# '--eliminate-local-single-store' 40# spirv-opt commit hash: f1e5cd73f658abcc23ee96d78f2dc27c4b7028c1 41 42 43 44SHADER vertex variant_vertex_shader PASSTHROUGH 45 46# variant_fragment_shader is derived from the following GLSL: 47# #version 310 es 48# precision highp float; 49# 50# precision highp int; 51# 52# layout(location = 0) out vec4 _GLF_color; 53# 54# void main(void) 55# { 56# vec2 v; 57# mat2 m1 = mat2(1.0, 0.0, 0.0, 1.0); 58# for( 59# int i = 0; 60# i < 1; 61# i++ 62# ) 63# { 64# do 65# { 66# mat2 m2; 67# m2 = m1 * m1; 68# v = m2 * vec2(1.0, 0.0); 69# } 70# while(false); 71# } 72# _GLF_color = vec4(v, 0.0, 1.0); 73# } 74SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 75; SPIR-V 76; Version: 1.0 77; Generator: Khronos Glslang Reference Front End; 8 78; Bound: 56 79; Schema: 0 80 OpCapability Shader 81 %1 = OpExtInstImport "GLSL.std.450" 82 OpMemoryModel Logical GLSL450 83 OpEntryPoint Fragment %4 "main" %46 84 OpExecutionMode %4 OriginUpperLeft 85 OpSource ESSL 310 86 OpName %4 "main" 87 OpName %10 "m1" 88 OpName %18 "i" 89 OpName %33 "m2" 90 OpName %38 "v" 91 OpName %46 "_GLF_color" 92 OpDecorate %46 Location 0 93 %2 = OpTypeVoid 94 %3 = OpTypeFunction %2 95 %6 = OpTypeFloat 32 96 %7 = OpTypeVector %6 2 97 %8 = OpTypeMatrix %7 2 98 %9 = OpTypePointer Function %8 99 %11 = OpConstant %6 1 100 %12 = OpConstant %6 0 101 %13 = OpConstantComposite %7 %11 %12 102 %14 = OpConstantComposite %7 %12 %11 103 %15 = OpConstantComposite %8 %13 %14 104 %16 = OpTypeInt 32 1 105 %17 = OpTypePointer Function %16 106 %19 = OpConstant %16 0 107 %26 = OpConstant %16 1 108 %27 = OpTypeBool 109 %37 = OpTypePointer Function %7 110 %41 = OpConstantFalse %27 111 %44 = OpTypeVector %6 4 112 %45 = OpTypePointer Output %44 113 %46 = OpVariable %45 Output 114 %53 = OpUndef %7 115 %4 = OpFunction %2 None %3 116 %5 = OpLabel 117 %10 = OpVariable %9 Function 118 %18 = OpVariable %17 Function 119 %33 = OpVariable %9 Function 120 %38 = OpVariable %37 Function 121 OpStore %10 %15 122 OpStore %18 %19 123 OpBranch %20 124 %20 = OpLabel 125 %55 = OpPhi %8 %15 %5 %55 %23 126 %52 = OpPhi %7 %53 %5 %40 %23 127 %51 = OpPhi %16 %19 %5 %43 %23 128 OpLoopMerge %22 %23 None 129 OpBranch %24 130 %24 = OpLabel 131 %28 = OpSLessThan %27 %51 %26 132 OpBranchConditional %28 %21 %22 133 %21 = OpLabel 134 OpBranch %29 135 %29 = OpLabel 136 OpLoopMerge %31 %32 None 137 OpBranch %30 138 %30 = OpLabel 139 %36 = OpMatrixTimesMatrix %8 %55 %55 140 OpStore %33 %36 141 %40 = OpMatrixTimesVector %7 %36 %13 142 OpStore %38 %40 143 OpBranch %32 144 %32 = OpLabel 145 OpBranchConditional %41 %29 %31 146 %31 = OpLabel 147 OpBranch %23 148 %23 = OpLabel 149 %43 = OpIAdd %16 %51 %26 150 OpStore %18 %43 151 OpBranch %20 152 %22 = OpLabel 153 %48 = OpCompositeExtract %6 %52 0 154 %49 = OpCompositeExtract %6 %52 1 155 %50 = OpCompositeConstruct %44 %48 %49 %12 %11 156 OpStore %46 %50 157 OpReturn 158 OpFunctionEnd 159END 160 161 162BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 163 164PIPELINE graphics variant_pipeline 165 ATTACH variant_vertex_shader 166 ATTACH variant_fragment_shader 167 FRAMEBUFFER_SIZE 256 256 168 BIND BUFFER variant_framebuffer AS color LOCATION 0 169END 170CLEAR_COLOR variant_pipeline 0 0 0 255 171 172CLEAR variant_pipeline 173RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 174 175EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 176