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: A fragment shader with return before writing wrong color 21 22# The test passes because the shader always writes color red. 23# Main writes red and returns. Code after writing red is never executed. 24 25# Optimized using spirv-opt with the following arguments: 26# '--private-to-local' 27# '--eliminate-local-multi-store' 28# '--redundancy-elimination' 29# '--eliminate-dead-code-aggressive' 30# '--simplify-instructions' 31# '--eliminate-dead-branches' 32# '--merge-blocks' 33# '--reduce-load-size' 34# '--combine-access-chains' 35# '--combine-access-chains' 36# '--eliminate-dead-branches' 37# '--ccp' 38# '--redundancy-elimination' 39# '--simplify-instructions' 40# '--vector-dce' 41# '--ccp' 42# '--private-to-local' 43# '--eliminate-dead-inserts' 44# spirv-opt commit hash: ad7f2c5c4c7f51360e9e079109a9217aa5ba5cc0 45 46 47 48SHADER vertex variant_vertex_shader PASSTHROUGH 49 50# variant_fragment_shader is derived from the following GLSL: 51# #version 310 es 52# precision highp float; 53# 54# precision highp int; 55# 56# struct _GLF_struct_0 57# { 58# int msb9; 59# }; 60# 61# layout(location = 0) out vec4 _GLF_color; 62# 63# void main() 64# { 65# _GLF_struct_0 _GLF_struct_replacement_0; 66# 67# do 68# { 69# for (int j = 0; 1 < findLSB(1024); 1) 70# { 71# _GLF_color = vec4(1.0, 0.0, 0.0, 1.0); // Write color red 72# return; // We always return here. The code below is never executed. 73# } 74# } while (_GLF_struct_replacement_0.msb9 > 1); 75# _GLF_color = vec4(1.0, 1.0, _GLF_struct_replacement_0.msb9, 1.0); 76# } 77SHADER fragment variant_fragment_shader SPIRV-ASM 78; SPIR-V 79; Version: 1.0 80; Generator: Khronos Glslang Reference Front End; 7 81; Bound: 43 82; Schema: 0 83 OpCapability Shader 84 %1 = OpExtInstImport "GLSL.std.450" 85 OpMemoryModel Logical GLSL450 86 OpEntryPoint Fragment %4 "main" %27 87 OpExecutionMode %4 OriginUpperLeft 88 OpSource ESSL 310 89 OpName %4 "main" 90 OpName %27 "_GLF_color" 91 OpName %32 "_GLF_struct_0" 92 OpMemberName %32 0 "msb9" 93 OpName %34 "_GLF_struct_replacement_0" 94 OpDecorate %21 RelaxedPrecision 95 OpDecorate %27 Location 0 96 %2 = OpTypeVoid 97 %3 = OpTypeFunction %2 98 %10 = OpTypeInt 32 1 99 %11 = OpTypePointer Function %10 100 %13 = OpConstant %10 0 101 %19 = OpConstant %10 1 102 %20 = OpConstant %10 1024 103 %22 = OpTypeBool 104 %24 = OpTypeFloat 32 105 %25 = OpTypeVector %24 4 106 %26 = OpTypePointer Output %25 107 %27 = OpVariable %26 Output 108 %28 = OpConstant %24 1 109 %29 = OpConstant %24 0 110 %30 = OpConstantComposite %25 %28 %29 %29 %28 111 %32 = OpTypeStruct %10 112 %33 = OpTypePointer Function %32 113 %4 = OpFunction %2 None %3 114 %5 = OpLabel 115 %34 = OpVariable %33 Function 116 OpBranch %6 117 %6 = OpLabel 118 OpLoopMerge %8 %16 None 119 OpBranch %14 120 %14 = OpLabel 121 %21 = OpExtInst %10 %1 FindILsb %20 122 %23 = OpSLessThan %22 %19 %21 123 OpLoopMerge %42 %17 None 124 OpBranchConditional %23 %15 %42 125 %15 = OpLabel 126 OpStore %27 %30 127 OpReturn 128 %17 = OpLabel 129 OpBranch %14 130 %42 = OpLabel 131 OpBranch %16 132 %16 = OpLabel 133 %35 = OpAccessChain %11 %34 %13 134 %36 = OpLoad %10 %35 135 %37 = OpSGreaterThan %22 %36 %19 136 OpBranchConditional %37 %6 %8 137 %8 = OpLabel 138 %39 = OpLoad %10 %35 139 %40 = OpConvertSToF %24 %39 140 %41 = OpCompositeConstruct %25 %28 %28 %40 %28 141 OpStore %27 %41 142 OpReturn 143 OpFunctionEnd 144END 145 146# uniforms for variant 147 148 149BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 150 151PIPELINE graphics variant_pipeline 152 ATTACH variant_vertex_shader 153 ATTACH variant_fragment_shader 154 FRAMEBUFFER_SIZE 256 256 155 BIND BUFFER variant_framebuffer AS color LOCATION 0 156END 157CLEAR_COLOR variant_pipeline 0 0 0 255 158 159CLEAR variant_pipeline 160RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 161 162EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 163