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