#!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_0 _GLF_uniform_int_values[1] # #define _int_8 _GLF_uniform_int_values[2] # #define _float_0_0 _GLF_uniform_float_values[0] # # precision highp float; # precision highp int; # # // Contents of _GLF_uniform_int_values: [1, 0, 8] # layout(set = 0, binding = 0) uniform buf0 # { # int _GLF_uniform_int_values[3]; # }; # # // Contents of _GLF_uniform_float_values: 0.0 # layout(set = 0, binding = 1) uniform buf1 # { # float _GLF_uniform_float_values[1]; # }; # # layout(location = 0) out vec4 _GLF_color; # # void main() # { # int a = _int_0; # # // Iterates i = 1, 2, 4, 8. # for(int i = 1; i <= 10; i *= 2) # { # for(int j = 0; j < 10; j += i) # { # int b = j + i - 1; # // For the last iteration of the outer loop i = 8 and j iterates values 0 and 8. # // The last assignment to a is 8. # a = j; # # # // The condition of the while loop below can be opened as follows: # // a <= b <= 1 # // j <= j + i - 1 <= 1 # // # // Because j <= 1 the values for j can be 0 and 1. # // Therefore j + i - 1 <= 1 gives us: # // 0 + i - 1 <= 1 # // i <= 2 # // and # // 1 + i - 1 <= 1 # // i <= 1 # // # // i starts at one so the condition is true when i = 1 or 2 and j = 0 or 1. # # // This condition is false during the last iteration of i = 8 and j = 8. # while(a <= b && b <= 1) # { # // Always false. # if(gl_FragCoord.x < _float_0_0) # { # discard; # } # a++; # } # } # } # # // Always true. The last iteration assigned i = 8 but didn't increment it in a while loop. # if(a == _int_8) # { # _GLF_color = vec4(_int_1, _int_0, _int_0, _int_1); # } # else # { # _GLF_color = vec4(_int_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: 109 ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %4 "main" %58 %90 OpExecutionMode %4 OriginUpperLeft OpSource ESSL 320 OpName %4 "main" OpName %8 "a" OpName %12 "buf0" OpMemberName %12 0 "_GLF_uniform_int_values" OpName %14 "" OpName %20 "i" OpName %30 "j" OpName %38 "b" OpName %58 "gl_FragCoord" OpName %65 "buf1" OpMemberName %65 0 "_GLF_uniform_float_values" OpName %67 "" OpName %90 "_GLF_color" OpDecorate %11 ArrayStride 16 OpMemberDecorate %12 0 Offset 0 OpDecorate %12 Block OpDecorate %14 DescriptorSet 0 OpDecorate %14 Binding 0 OpDecorate %58 BuiltIn FragCoord OpDecorate %64 ArrayStride 16 OpMemberDecorate %65 0 Offset 0 OpDecorate %65 Block OpDecorate %67 DescriptorSet 0 OpDecorate %67 Binding 1 OpDecorate %90 Location 0 %2 = OpTypeVoid %3 = OpTypeFunction %2 %6 = OpTypeInt 32 1 %7 = OpTypePointer Function %6 %9 = OpTypeInt 32 0 %10 = OpConstant %9 3 %11 = OpTypeArray %6 %10 %12 = OpTypeStruct %11 %13 = OpTypePointer Uniform %12 %14 = OpVariable %13 Uniform %15 = OpConstant %6 0 %16 = OpConstant %6 1 %17 = OpTypePointer Uniform %6 %27 = OpConstant %6 10 %28 = OpTypeBool %55 = OpTypeFloat 32 %56 = OpTypeVector %55 4 %57 = OpTypePointer Input %56 %58 = OpVariable %57 Input %59 = OpConstant %9 0 %60 = OpTypePointer Input %55 %63 = OpConstant %9 1 %64 = OpTypeArray %55 %63 %65 = OpTypeStruct %64 %66 = OpTypePointer Uniform %65 %67 = OpVariable %66 Uniform %68 = OpTypePointer Uniform %55 %80 = OpConstant %6 2 %89 = OpTypePointer Output %56 %90 = OpVariable %89 Output %4 = OpFunction %2 None %3 %5 = OpLabel %8 = OpVariable %7 Function %20 = OpVariable %7 Function %30 = OpVariable %7 Function %38 = OpVariable %7 Function %18 = OpAccessChain %17 %14 %15 %16 %19 = OpLoad %6 %18 OpStore %8 %19 OpStore %20 %16 OpBranch %21 %21 = OpLabel OpLoopMerge %23 %24 None OpBranch %25 %25 = OpLabel %26 = OpLoad %6 %20 %29 = OpSLessThanEqual %28 %26 %27 OpBranchConditional %29 %22 %23 %22 = OpLabel OpStore %30 %15 OpBranch %31 %31 = OpLabel OpLoopMerge %33 %34 None OpBranch %35 %35 = OpLabel %36 = OpLoad %6 %30 %37 = OpSLessThan %28 %36 %27 OpBranchConditional %37 %32 %33 %32 = OpLabel %39 = OpLoad %6 %30 %40 = OpLoad %6 %20 %41 = OpIAdd %6 %39 %40 %42 = OpISub %6 %41 %16 OpStore %38 %42 %43 = OpLoad %6 %30 OpStore %8 %43 OpBranch %44 %44 = OpLabel OpLoopMerge %46 %47 None OpBranch %48 %48 = OpLabel %49 = OpLoad %6 %8 %50 = OpLoad %6 %38 %51 = OpSLessThanEqual %28 %49 %50 %52 = OpLoad %6 %38 %53 = OpSLessThanEqual %28 %52 %16 %54 = OpLogicalAnd %28 %51 %53 OpBranchConditional %54 %45 %46 %45 = OpLabel %61 = OpAccessChain %60 %58 %59 %62 = OpLoad %55 %61 %69 = OpAccessChain %68 %67 %15 %15 %70 = OpLoad %55 %69 %71 = OpFOrdLessThan %28 %62 %70 OpSelectionMerge %73 None OpBranchConditional %71 %72 %73 %72 = OpLabel OpKill %73 = OpLabel %75 = OpLoad %6 %8 %76 = OpIAdd %6 %75 %16 OpStore %8 %76 OpBranch %47 %47 = OpLabel OpBranch %44 %46 = OpLabel OpBranch %34 %34 = OpLabel %77 = OpLoad %6 %20 %78 = OpLoad %6 %30 %79 = OpIAdd %6 %78 %77 OpStore %30 %79 OpBranch %31 %33 = OpLabel OpBranch %24 %24 = OpLabel %81 = OpLoad %6 %20 %82 = OpIMul %6 %81 %80 OpStore %20 %82 OpBranch %21 %23 = OpLabel %83 = OpLoad %6 %8 %84 = OpAccessChain %17 %14 %15 %80 %85 = OpLoad %6 %84 %86 = OpIEqual %28 %83 %85 OpSelectionMerge %88 None OpBranchConditional %86 %87 %104 %87 = OpLabel %91 = OpAccessChain %17 %14 %15 %15 %92 = OpLoad %6 %91 %93 = OpConvertSToF %55 %92 %94 = OpAccessChain %17 %14 %15 %16 %95 = OpLoad %6 %94 %96 = OpConvertSToF %55 %95 %97 = OpAccessChain %17 %14 %15 %16 %98 = OpLoad %6 %97 %99 = OpConvertSToF %55 %98 %100 = OpAccessChain %17 %14 %15 %15 %101 = OpLoad %6 %100 %102 = OpConvertSToF %55 %101 %103 = OpCompositeConstruct %56 %93 %96 %99 %102 OpStore %90 %103 OpBranch %88 %104 = OpLabel %105 = OpAccessChain %17 %14 %15 %16 %106 = OpLoad %6 %105 %107 = OpConvertSToF %55 %106 %108 = OpCompositeConstruct %56 %107 %107 %107 %107 OpStore %90 %108 OpBranch %88 %88 = OpLabel OpReturn OpFunctionEnd END # uniforms for variant # _GLF_uniform_float_values BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 0.0 END # _GLF_uniform_int_values BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 1 0 8 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__GLF_uniform_float_values 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