1#!amber 2 3# Copyright 2020 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 coverage-gap found by GraphicsFuzz. 19 20# Short description: A fragment shader that covers a specific instruction simplification code path 21 22# The test passes because the shader always writes red. 23 24SHADER vertex variant_vertex_shader PASSTHROUGH 25 26# variant_fragment_shader is derived from the following GLSL: 27# #version 310 es 28# precision highp float; 29# precision highp int; 30# 31# layout(set = 0, binding = 0) uniform buf0 32# { 33# int two; 34# }; 35# layout(location = 0) out vec4 _GLF_color; 36# 37# void main() 38# { 39# int i = 0; 40# 41# for(int r = 0; r < two * 4; r += 2) 42# i += ivec4(1, 2, 3, 4)[r / two]; 43# 44# if (i == 10) 45# _GLF_color = vec4(1, 0, 0, 1); 46# else 47# _GLF_color = vec4(0); 48# } 49SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 50; SPIR-V 51; Version: 1.0 52; Generator: Khronos Glslang Reference Front End; 8 53; Bound: 55 54; Schema: 0 55 OpCapability Shader 56 %1 = OpExtInstImport "GLSL.std.450" 57 OpMemoryModel Logical GLSL450 58 OpEntryPoint Fragment %4 "main" %49 59 OpExecutionMode %4 OriginUpperLeft 60 OpSource ESSL 310 61 OpName %4 "main" 62 OpName %8 "i" 63 OpName %10 "r" 64 OpName %17 "buf0" 65 OpMemberName %17 0 "two" 66 OpName %19 "" 67 OpName %49 "_GLF_color" 68 OpMemberDecorate %17 0 Offset 0 69 OpDecorate %17 Block 70 OpDecorate %19 DescriptorSet 0 71 OpDecorate %19 Binding 0 72 OpDecorate %49 Location 0 73 %2 = OpTypeVoid 74 %3 = OpTypeFunction %2 75 %6 = OpTypeInt 32 1 76 %7 = OpTypePointer Function %6 77 %9 = OpConstant %6 0 78 %17 = OpTypeStruct %6 79 %18 = OpTypePointer Uniform %17 80 %19 = OpVariable %18 Uniform 81 %20 = OpTypePointer Uniform %6 82 %23 = OpConstant %6 4 83 %25 = OpTypeBool 84 %27 = OpTypeVector %6 4 85 %28 = OpConstant %6 1 86 %29 = OpConstant %6 2 87 %30 = OpConstant %6 3 88 %31 = OpConstantComposite %27 %28 %29 %30 %23 89 %42 = OpConstant %6 10 90 %46 = OpTypeFloat 32 91 %47 = OpTypeVector %46 4 92 %48 = OpTypePointer Output %47 93 %49 = OpVariable %48 Output 94 %50 = OpConstant %46 1 95 %51 = OpConstant %46 0 96 %52 = OpConstantComposite %47 %50 %51 %51 %50 97 %54 = OpConstantComposite %47 %51 %51 %51 %51 98 %4 = OpFunction %2 None %3 99 %5 = OpLabel 100 %8 = OpVariable %7 Function 101 %10 = OpVariable %7 Function 102 OpStore %8 %9 103 OpStore %10 %9 104 OpBranch %11 105 %11 = OpLabel 106 OpLoopMerge %13 %14 None 107 OpBranch %15 108 %15 = OpLabel 109 %16 = OpLoad %6 %10 110 %21 = OpAccessChain %20 %19 %9 111 %22 = OpLoad %6 %21 112 %24 = OpIMul %6 %22 %23 113 %26 = OpSLessThan %25 %16 %24 114 OpBranchConditional %26 %12 %13 115 %12 = OpLabel 116 %32 = OpLoad %6 %10 117 %33 = OpAccessChain %20 %19 %9 118 %34 = OpLoad %6 %33 119 %35 = OpSDiv %6 %32 %34 120 %36 = OpVectorExtractDynamic %6 %31 %35 121 %37 = OpLoad %6 %8 122 %38 = OpIAdd %6 %37 %36 123 OpStore %8 %38 124 OpBranch %14 125 %14 = OpLabel 126 %39 = OpLoad %6 %10 127 %40 = OpIAdd %6 %39 %29 128 OpStore %10 %40 129 OpBranch %11 130 %13 = OpLabel 131 %41 = OpLoad %6 %8 132 %43 = OpIEqual %25 %41 %42 133 OpSelectionMerge %45 None 134 OpBranchConditional %43 %44 %53 135 %44 = OpLabel 136 OpStore %49 %52 137 OpBranch %45 138 %53 = OpLabel 139 OpStore %49 %54 140 OpBranch %45 141 %45 = OpLabel 142 OpReturn 143 OpFunctionEnd 144END 145 146# uniforms for variant 147 148# two 149BUFFER variant_two DATA_TYPE int32 DATA 150 2 151END 152 153BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM 154 155PIPELINE graphics variant_pipeline 156 ATTACH variant_vertex_shader 157 ATTACH variant_fragment_shader 158 FRAMEBUFFER_SIZE 256 256 159 BIND BUFFER variant_framebuffer AS color LOCATION 0 160 BIND BUFFER variant_two AS uniform DESCRIPTOR_SET 0 BINDING 0 161END 162CLEAR_COLOR variant_pipeline 0 0 0 255 163 164CLEAR variant_pipeline 165RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256 166 167EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255 168