#!amber # Copyright 2022 Google LLC # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. # A test for a coverage-gap found by the GraphicsFuzz project. # Short description: A fragment shader that covers specific LLVM code paths # The test passes because the shader always writes red. SHADER vertex variant_vertex_shader PASSTHROUGH # variant_fragment_shader is derived from the following GLSL: # #version 320 es # #define _int_1 _GLF_uniform_int_values[0] # #define _int_3 _GLF_uniform_int_values[1] # # precision highp float; # precision highp int; # # // Contents of _GLF_uniform_int_values: [1, 3] # layout(set = 0, binding = 0) uniform buf0 # { # int _GLF_uniform_int_values[2]; # }; # # // Contents of zero: 0 # layout(set = 0, binding = 1) uniform buf1 # { # int zero; # }; # # layout(location = 0) out vec4 _GLF_color; # # void main() # { # int a = zero; # int b = _int_1; # # // Iterated once. # do # { # // Always false. # if(b > _int_3) # { # break; # } # # # int arr[10] = int[10](_int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1, _int_1); # # // Makes indices 0..4 undefined as the first iteration reads outside the array # // and other iterations copy that value. # for(int i = 0; i < 5; i++) # { # arr[i] += arr[i - 1]; # } # # b++; # // Use an array element that still contains a defined value (one). # a += arr[5]; # } # while(a != _int_1); # # if (b == 2) # _GLF_color = vec4(1, 0, 0, 1); # else # _GLF_color = vec4(0); # } SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0 ; SPIR-V ; Version: 1.0 ; Generator: Khronos Glslang Reference Front End; 10 ; Bound: 107 ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %4 "main" %101 OpExecutionMode %4 OriginUpperLeft OpSource ESSL 320 OpName %4 "main" OpName %8 "a" OpName %9 "buf1" OpMemberName %9 0 "zero" OpName %11 "" OpName %16 "b" OpName %20 "buf0" OpMemberName %20 0 "_GLF_uniform_int_values" OpName %22 "" OpName %41 "arr" OpName %63 "i" OpName %101 "_GLF_color" OpMemberDecorate %9 0 Offset 0 OpDecorate %9 Block OpDecorate %11 DescriptorSet 0 OpDecorate %11 Binding 1 OpDecorate %19 ArrayStride 16 OpMemberDecorate %20 0 Offset 0 OpDecorate %20 Block OpDecorate %22 DescriptorSet 0 OpDecorate %22 Binding 0 OpDecorate %101 Location 0 %2 = OpTypeVoid %3 = OpTypeFunction %2 %6 = OpTypeInt 32 1 %7 = OpTypePointer Function %6 %9 = OpTypeStruct %6 %10 = OpTypePointer Uniform %9 %11 = OpVariable %10 Uniform %12 = OpConstant %6 0 %13 = OpTypePointer Uniform %6 %17 = OpTypeInt 32 0 %18 = OpConstant %17 2 %19 = OpTypeArray %6 %18 %20 = OpTypeStruct %19 %21 = OpTypePointer Uniform %20 %22 = OpVariable %21 Uniform %30 = OpConstant %6 1 %33 = OpTypeBool %38 = OpConstant %17 10 %39 = OpTypeArray %6 %38 %40 = OpTypePointer Function %39 %70 = OpConstant %6 5 %94 = OpConstant %6 2 %98 = OpTypeFloat 32 %99 = OpTypeVector %98 4 %100 = OpTypePointer Output %99 %101 = OpVariable %100 Output %102 = OpConstant %98 1 %103 = OpConstant %98 0 %104 = OpConstantComposite %99 %102 %103 %103 %102 %106 = OpConstantComposite %99 %103 %103 %103 %103 %4 = OpFunction %2 None %3 %5 = OpLabel %8 = OpVariable %7 Function %16 = OpVariable %7 Function %41 = OpVariable %40 Function %63 = OpVariable %7 Function %14 = OpAccessChain %13 %11 %12 %15 = OpLoad %6 %14 OpStore %8 %15 %23 = OpAccessChain %13 %22 %12 %12 %24 = OpLoad %6 %23 OpStore %16 %24 OpBranch %25 %25 = OpLabel OpLoopMerge %27 %28 None OpBranch %26 %26 = OpLabel %29 = OpLoad %6 %16 %31 = OpAccessChain %13 %22 %12 %30 %32 = OpLoad %6 %31 %34 = OpSGreaterThan %33 %29 %32 OpSelectionMerge %36 None OpBranchConditional %34 %35 %36 %35 = OpLabel OpBranch %27 %36 = OpLabel %42 = OpAccessChain %13 %22 %12 %12 %43 = OpLoad %6 %42 %44 = OpAccessChain %13 %22 %12 %12 %45 = OpLoad %6 %44 %46 = OpAccessChain %13 %22 %12 %12 %47 = OpLoad %6 %46 %48 = OpAccessChain %13 %22 %12 %12 %49 = OpLoad %6 %48 %50 = OpAccessChain %13 %22 %12 %12 %51 = OpLoad %6 %50 %52 = OpAccessChain %13 %22 %12 %12 %53 = OpLoad %6 %52 %54 = OpAccessChain %13 %22 %12 %12 %55 = OpLoad %6 %54 %56 = OpAccessChain %13 %22 %12 %12 %57 = OpLoad %6 %56 %58 = OpAccessChain %13 %22 %12 %12 %59 = OpLoad %6 %58 %60 = OpAccessChain %13 %22 %12 %12 %61 = OpLoad %6 %60 %62 = OpCompositeConstruct %39 %43 %45 %47 %49 %51 %53 %55 %57 %59 %61 OpStore %41 %62 OpStore %63 %12 OpBranch %64 %64 = OpLabel OpLoopMerge %66 %67 None OpBranch %68 %68 = OpLabel %69 = OpLoad %6 %63 %71 = OpSLessThan %33 %69 %70 OpBranchConditional %71 %65 %66 %65 = OpLabel %72 = OpLoad %6 %63 %73 = OpLoad %6 %63 %74 = OpISub %6 %73 %30 %75 = OpAccessChain %7 %41 %74 %76 = OpLoad %6 %75 %77 = OpAccessChain %7 %41 %72 %78 = OpLoad %6 %77 %79 = OpIAdd %6 %78 %76 %80 = OpAccessChain %7 %41 %72 OpStore %80 %79 OpBranch %67 %67 = OpLabel %81 = OpLoad %6 %63 %82 = OpIAdd %6 %81 %30 OpStore %63 %82 OpBranch %64 %66 = OpLabel %83 = OpLoad %6 %16 %84 = OpIAdd %6 %83 %30 OpStore %16 %84 %85 = OpAccessChain %7 %41 %70 %86 = OpLoad %6 %85 %87 = OpLoad %6 %8 %88 = OpIAdd %6 %87 %86 OpStore %8 %88 OpBranch %28 %28 = OpLabel %89 = OpLoad %6 %8 %90 = OpAccessChain %13 %22 %12 %12 %91 = OpLoad %6 %90 %92 = OpINotEqual %33 %89 %91 OpBranchConditional %92 %25 %27 %27 = OpLabel %93 = OpLoad %6 %16 %95 = OpIEqual %33 %93 %94 OpSelectionMerge %97 None OpBranchConditional %95 %96 %105 %96 = OpLabel OpStore %101 %104 OpBranch %97 %105 = OpLabel OpStore %101 %106 OpBranch %97 %97 = OpLabel OpReturn OpFunctionEnd END # uniforms for variant # zero BUFFER variant_zero DATA_TYPE int32 STD140 DATA 0 END # _GLF_uniform_int_values BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 1 3 END BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM PIPELINE graphics variant_pipeline ATTACH variant_vertex_shader ATTACH variant_fragment_shader FRAMEBUFFER_SIZE 32 32 BIND BUFFER variant_framebuffer AS color LOCATION 0 BIND BUFFER variant_zero AS uniform DESCRIPTOR_SET 0 BINDING 1 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 0 END CLEAR_COLOR variant_pipeline 0 0 0 255 CLEAR variant_pipeline RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 32 32 EXPECT variant_framebuffer IDX 0 0 SIZE 32 32 EQ_RGBA 255 0 0 255