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: Fragment shader using (int, mat2) struct 21 22# The test passes because the struct instance is created and used in a way that guarantees writing red to the output buffer 23 24# Optimized using spirv-opt with the following arguments: 25# '--eliminate-local-single-block' 26# '--eliminate-dead-branches' 27# '--vector-dce' 28# '--simplify-instructions' 29# '--reduce-load-size' 30# '--eliminate-local-multi-store' 31# '--private-to-local' 32# '--eliminate-dead-branches' 33# '--eliminate-dead-branches' 34# '--merge-return' 35# '--ccp' 36# '--reduce-load-size' 37# '--eliminate-local-single-block' 38# '--scalar-replacement=100' 39# '--combine-access-chains' 40# '--if-conversion' 41# '--ccp' 42# '--eliminate-dead-branches' 43# '--vector-dce' 44# '--eliminate-dead-branches' 45# '--merge-return' 46# '--eliminate-local-single-block' 47# '--inline-entry-points-exhaustive' 48# '--eliminate-dead-inserts' 49# '--eliminate-local-multi-store' 50# '--convert-local-access-chains' 51# '--eliminate-dead-branches' 52# '--vector-dce' 53# '--eliminate-dead-inserts' 54# '--private-to-local' 55# '--eliminate-local-multi-store' 56# spirv-opt commit hash: f1e5cd73f658abcc23ee96d78f2dc27c4b7028c1 57 58 59 60SHADER vertex variant_vertex_shader PASSTHROUGH 61 62# variant_fragment_shader is derived from the following GLSL: 63# #version 310 es 64# precision highp float; 65# 66# struct S { 67# int f1; 68# mat2 f2; 69# } ; 70# 71# layout(location = 0) out vec4 _GLF_color; 72# 73# void main() 74# { 75# S myS = S(1, transpose(gl_FragCoord.x < 0.0 ? mat2(1.0, 2.0, 3.0, 4.0) : mat2(0.5, -0.5, -0.5, 0.5))); 76# _GLF_color = vec4(float(myS.f1), myS.f2[0][0] + myS.f2[1][0], myS.f2[0][1] + myS.f2[1][1], float(myS.f1)); 77# } 78SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 79; SPIR-V 80; Version: 1.0 81; Generator: Khronos Glslang Reference Front End; 8 82; Bound: 81 83; Schema: 0 84 OpCapability Shader 85 %1 = OpExtInstImport "GLSL.std.450" 86 OpMemoryModel Logical GLSL450 87 OpEntryPoint Fragment %4 "main" %16 %46 88 OpExecutionMode %4 OriginUpperLeft 89 OpSource ESSL 310 90 OpName %4 "main" 91 OpName %10 "S" 92 OpMemberName %10 0 "f1" 93 OpMemberName %10 1 "f2" 94 OpName %16 "gl_FragCoord" 95 OpName %46 "_GLF_color" 96 OpMemberDecorate %10 0 RelaxedPrecision 97 OpDecorate %16 BuiltIn FragCoord 98 OpDecorate %46 Location 0 99 OpDecorate %69 RelaxedPrecision 100 %2 = OpTypeVoid 101 %3 = OpTypeFunction %2 102 %6 = OpTypeInt 32 1 103 %7 = OpTypeFloat 32 104 %8 = OpTypeVector %7 2 105 %9 = OpTypeMatrix %8 2 106 %10 = OpTypeStruct %6 %9 107 %11 = OpTypePointer Function %10 108 %13 = OpConstant %6 1 109 %14 = OpTypeVector %7 4 110 %15 = OpTypePointer Input %14 111 %16 = OpVariable %15 Input 112 %17 = OpTypeInt 32 0 113 %18 = OpConstant %17 0 114 %19 = OpTypePointer Input %7 115 %22 = OpConstant %7 0 116 %23 = OpTypeBool 117 %25 = OpTypePointer Function %9 118 %29 = OpConstant %7 1 119 %30 = OpConstant %7 2 120 %31 = OpConstantComposite %8 %29 %30 121 %32 = OpConstant %7 3 122 %33 = OpConstant %7 4 123 %34 = OpConstantComposite %8 %32 %33 124 %35 = OpConstantComposite %9 %31 %34 125 %37 = OpConstant %7 0.5 126 %38 = OpConstant %7 -0.5 127 %39 = OpConstantComposite %8 %37 %38 128 %40 = OpConstantComposite %8 %38 %37 129 %41 = OpConstantComposite %9 %39 %40 130 %45 = OpTypePointer Output %14 131 %46 = OpVariable %45 Output 132 %47 = OpConstant %6 0 133 %48 = OpTypePointer Function %6 134 %52 = OpTypePointer Function %7 135 %58 = OpConstant %17 1 136 %4 = OpFunction %2 None %3 137 %5 = OpLabel 138 %70 = OpVariable %25 Function 139 %69 = OpVariable %48 Function 140 %26 = OpVariable %25 Function 141 %20 = OpAccessChain %19 %16 %18 142 %21 = OpLoad %7 %20 143 %24 = OpFOrdLessThan %23 %21 %22 144 OpSelectionMerge %28 None 145 OpBranchConditional %24 %27 %36 146 %27 = OpLabel 147 OpStore %26 %35 148 OpBranch %28 149 %36 = OpLabel 150 OpStore %26 %41 151 OpBranch %28 152 %28 = OpLabel 153 %68 = OpPhi %9 %35 %27 %41 %36 154 %43 = OpTranspose %9 %68 155 %44 = OpCompositeConstruct %10 %13 %43 156 %71 = OpCompositeExtract %6 %44 0 157 OpStore %69 %71 158 %72 = OpCompositeExtract %9 %44 1 159 OpStore %70 %72 160 %51 = OpConvertSToF %7 %71 161 %73 = OpAccessChain %52 %70 %47 %18 162 %77 = OpLoad %9 %70 163 %54 = OpCompositeExtract %7 %77 0 0 164 %74 = OpAccessChain %52 %70 %13 %18 165 %78 = OpLoad %9 %70 166 %56 = OpCompositeExtract %7 %78 1 0 167 %57 = OpFAdd %7 %54 %56 168 %75 = OpAccessChain %52 %70 %47 %58 169 %79 = OpLoad %9 %70 170 %60 = OpCompositeExtract %7 %79 0 1 171 %76 = OpAccessChain %52 %70 %13 %58 172 %80 = OpLoad %9 %70 173 %62 = OpCompositeExtract %7 %80 1 1 174 %63 = OpFAdd %7 %60 %62 175 %66 = OpConvertSToF %7 %71 176 %67 = OpCompositeConstruct %14 %51 %57 %63 %66 177 OpStore %46 %67 178 OpReturn 179 OpFunctionEnd 180END 181 182 183BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 184 185PIPELINE graphics variant_pipeline 186 ATTACH variant_vertex_shader 187 ATTACH variant_fragment_shader 188 FRAMEBUFFER_SIZE 256 256 189 BIND BUFFER variant_framebuffer AS color LOCATION 0 190END 191CLEAR_COLOR variant_pipeline 0 0 0 255 192 193CLEAR variant_pipeline 194RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 195 196EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 197