#!amber # Copyright 2021 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_4 _GLF_uniform_int_values[1] # #define _int_35 _GLF_uniform_int_values[2] # #define _int_0 _GLF_uniform_int_values[3] # #define _float_1_0 _GLF_uniform_float_values[0] # #define _float_0_0 _GLF_uniform_float_values[1] # #define _float_2_0 _GLF_uniform_float_values[2] # # precision highp float; # precision highp int; # # // Contents of _GLF_uniform_float_values: [1.0, 0.0, 2.0] # layout(set = 0, binding = 0) uniform buf0 # { # float _GLF_uniform_float_values[3]; # }; # # // Contents of _GLF_uniform_int_values: [1, 4, 35, 0] # layout(set = 0, binding = 1) uniform buf1 # { # int _GLF_uniform_int_values[4]; # }; # # const int _GLF_global_loop_bound = 100; # int _GLF_global_loop_count = 0; # # struct S # { # int data0; # int data1; # }; # # int a = 1; # # S arr[10] = S[10](S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1), S(1, 1)); # # layout(location = 0) out vec4 _GLF_color; # # // Has no effect because the original value is always one. Also this function is never called. # void func0(inout S s) # { # s.data0 = _int_1; # } # # // Always returns vec4(fract(x), 1, 1). # vec3 func1(float x) # { # // Always false because x is the result of a call to sin. # if(x > _float_1_0) # { # return vec3(_int_0); # } # # return vec3(fract(x), _float_1_0, _float_1_0); # } # # vec3 func2() # { # // Always true. # if(gl_FragCoord.x > _float_0_0) # { # // a becomes one. # a = S[10](S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1), S(_int_1, _int_1))[a].data1; # } # # vec3 v0 = vec3(_float_1_0); # for(int i = _int_35; i >= _int_1 && _GLF_global_loop_count < _GLF_global_loop_bound; i--) # { # _GLF_global_loop_count++; # # vec3 v1 = func1(sin(float(i))); # # // Always true. # if(length(v1) >= _float_0_0) # { # v0 = v1; # } # } # # return v0; # } # # void main() # { # a = _int_4; # func2(); # vec3 v = func2(); # # // Always true. # if(gl_FragCoord.x > _float_0_0) # { # // Always false. # if(arr[a].data1 == 0) # { # func0(arr[a]); # return; # } # } # # // Guaranteed to be true because of an identical check in func2. # if(length(v) > _float_0_0) # { # _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: 238 ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %4 "main" %75 %219 OpExecutionMode %4 OriginUpperLeft OpSource ESSL 320 OpName %4 "main" OpName %7 "S" OpMemberName %7 0 "data0" OpMemberName %7 1 "data1" OpName %11 "func0(struct-S-i1-i11;" OpName %10 "s" OpName %18 "func1(f1;" OpName %17 "x" OpName %21 "func2(" OpName %24 "_GLF_global_loop_count" OpName %26 "a" OpName %32 "arr" OpName %37 "buf1" OpMemberName %37 0 "_GLF_uniform_int_values" OpName %39 "" OpName %48 "buf0" OpMemberName %48 0 "_GLF_uniform_float_values" OpName %50 "" OpName %75 "gl_FragCoord" OpName %138 "indexable" OpName %142 "v0" OpName %146 "i" OpName %165 "v1" OpName %169 "param" OpName %187 "v" OpName %203 "param" OpName %219 "_GLF_color" OpDecorate %36 ArrayStride 16 OpMemberDecorate %37 0 Offset 0 OpDecorate %37 Block OpDecorate %39 DescriptorSet 0 OpDecorate %39 Binding 1 OpDecorate %47 ArrayStride 16 OpMemberDecorate %48 0 Offset 0 OpDecorate %48 Block OpDecorate %50 DescriptorSet 0 OpDecorate %50 Binding 0 OpDecorate %75 BuiltIn FragCoord OpDecorate %219 Location 0 %2 = OpTypeVoid %3 = OpTypeFunction %2 %6 = OpTypeInt 32 1 %7 = OpTypeStruct %6 %6 %8 = OpTypePointer Function %7 %9 = OpTypeFunction %2 %8 %13 = OpTypeFloat 32 %14 = OpTypePointer Function %13 %15 = OpTypeVector %13 3 %16 = OpTypeFunction %15 %14 %20 = OpTypeFunction %15 %23 = OpTypePointer Private %6 %24 = OpVariable %23 Private %25 = OpConstant %6 0 %26 = OpVariable %23 Private %27 = OpConstant %6 1 %28 = OpTypeInt 32 0 %29 = OpConstant %28 10 %30 = OpTypeArray %7 %29 %31 = OpTypePointer Private %30 %32 = OpVariable %31 Private %33 = OpConstantComposite %7 %27 %27 %34 = OpConstantComposite %30 %33 %33 %33 %33 %33 %33 %33 %33 %33 %33 %35 = OpConstant %28 4 %36 = OpTypeArray %6 %35 %37 = OpTypeStruct %36 %38 = OpTypePointer Uniform %37 %39 = OpVariable %38 Uniform %40 = OpTypePointer Uniform %6 %43 = OpTypePointer Function %6 %46 = OpConstant %28 3 %47 = OpTypeArray %13 %46 %48 = OpTypeStruct %47 %49 = OpTypePointer Uniform %48 %50 = OpVariable %49 Uniform %51 = OpTypePointer Uniform %13 %54 = OpTypeBool %58 = OpConstant %6 3 %73 = OpTypeVector %13 4 %74 = OpTypePointer Input %73 %75 = OpVariable %74 Input %76 = OpConstant %28 0 %77 = OpTypePointer Input %13 %137 = OpTypePointer Function %30 %141 = OpTypePointer Function %15 %147 = OpConstant %6 2 %160 = OpConstant %6 100 %204 = OpTypePointer Private %7 %218 = OpTypePointer Output %73 %219 = OpVariable %218 Output %4 = OpFunction %2 None %3 %5 = OpLabel %187 = OpVariable %141 Function %203 = OpVariable %8 Function OpStore %24 %25 OpStore %26 %27 OpStore %32 %34 %184 = OpAccessChain %40 %39 %25 %27 %185 = OpLoad %6 %184 OpStore %26 %185 %186 = OpFunctionCall %15 %21 %188 = OpFunctionCall %15 %21 OpStore %187 %188 %189 = OpAccessChain %77 %75 %76 %190 = OpLoad %13 %189 %191 = OpAccessChain %51 %50 %25 %27 %192 = OpLoad %13 %191 %193 = OpFOrdGreaterThan %54 %190 %192 OpSelectionMerge %195 None OpBranchConditional %193 %194 %195 %194 = OpLabel %196 = OpLoad %6 %26 %197 = OpAccessChain %23 %32 %196 %27 %198 = OpLoad %6 %197 %199 = OpIEqual %54 %198 %25 OpSelectionMerge %201 None OpBranchConditional %199 %200 %201 %200 = OpLabel %202 = OpLoad %6 %26 %205 = OpAccessChain %204 %32 %202 %206 = OpLoad %7 %205 OpStore %203 %206 %207 = OpFunctionCall %2 %11 %203 %208 = OpLoad %7 %203 %209 = OpAccessChain %204 %32 %202 OpStore %209 %208 OpReturn %201 = OpLabel OpBranch %195 %195 = OpLabel %211 = OpLoad %15 %187 %212 = OpExtInst %13 %1 Length %211 %213 = OpAccessChain %51 %50 %25 %27 %214 = OpLoad %13 %213 %215 = OpFOrdGreaterThan %54 %212 %214 OpSelectionMerge %217 None OpBranchConditional %215 %216 %233 %216 = OpLabel %220 = OpAccessChain %40 %39 %25 %25 %221 = OpLoad %6 %220 %222 = OpConvertSToF %13 %221 %223 = OpAccessChain %40 %39 %25 %58 %224 = OpLoad %6 %223 %225 = OpConvertSToF %13 %224 %226 = OpAccessChain %40 %39 %25 %58 %227 = OpLoad %6 %226 %228 = OpConvertSToF %13 %227 %229 = OpAccessChain %40 %39 %25 %25 %230 = OpLoad %6 %229 %231 = OpConvertSToF %13 %230 %232 = OpCompositeConstruct %73 %222 %225 %228 %231 OpStore %219 %232 OpBranch %217 %233 = OpLabel %234 = OpAccessChain %40 %39 %25 %58 %235 = OpLoad %6 %234 %236 = OpConvertSToF %13 %235 %237 = OpCompositeConstruct %73 %236 %236 %236 %236 OpStore %219 %237 OpBranch %217 %217 = OpLabel OpReturn OpFunctionEnd %11 = OpFunction %2 None %9 %10 = OpFunctionParameter %8 %12 = OpLabel %41 = OpAccessChain %40 %39 %25 %25 %42 = OpLoad %6 %41 %44 = OpAccessChain %43 %10 %25 OpStore %44 %42 OpReturn OpFunctionEnd %18 = OpFunction %15 None %16 %17 = OpFunctionParameter %14 %19 = OpLabel %45 = OpLoad %13 %17 %52 = OpAccessChain %51 %50 %25 %25 %53 = OpLoad %13 %52 %55 = OpFOrdGreaterThan %54 %45 %53 OpSelectionMerge %57 None OpBranchConditional %55 %56 %57 %56 = OpLabel %59 = OpAccessChain %40 %39 %25 %58 %60 = OpLoad %6 %59 %61 = OpConvertSToF %13 %60 %62 = OpCompositeConstruct %15 %61 %61 %61 OpReturnValue %62 %57 = OpLabel %64 = OpLoad %13 %17 %65 = OpExtInst %13 %1 Fract %64 %66 = OpAccessChain %51 %50 %25 %25 %67 = OpLoad %13 %66 %68 = OpAccessChain %51 %50 %25 %25 %69 = OpLoad %13 %68 %70 = OpCompositeConstruct %15 %65 %67 %69 OpReturnValue %70 OpFunctionEnd %21 = OpFunction %15 None %20 %22 = OpLabel %138 = OpVariable %137 Function %142 = OpVariable %141 Function %146 = OpVariable %43 Function %165 = OpVariable %141 Function %169 = OpVariable %14 Function %78 = OpAccessChain %77 %75 %76 %79 = OpLoad %13 %78 %80 = OpAccessChain %51 %50 %25 %27 %81 = OpLoad %13 %80 %82 = OpFOrdGreaterThan %54 %79 %81 OpSelectionMerge %84 None OpBranchConditional %82 %83 %84 %83 = OpLabel %85 = OpAccessChain %40 %39 %25 %25 %86 = OpLoad %6 %85 %87 = OpAccessChain %40 %39 %25 %25 %88 = OpLoad %6 %87 %89 = OpCompositeConstruct %7 %86 %88 %90 = OpAccessChain %40 %39 %25 %25 %91 = OpLoad %6 %90 %92 = OpAccessChain %40 %39 %25 %25 %93 = OpLoad %6 %92 %94 = OpCompositeConstruct %7 %91 %93 %95 = OpAccessChain %40 %39 %25 %25 %96 = OpLoad %6 %95 %97 = OpAccessChain %40 %39 %25 %25 %98 = OpLoad %6 %97 %99 = OpCompositeConstruct %7 %96 %98 %100 = OpAccessChain %40 %39 %25 %25 %101 = OpLoad %6 %100 %102 = OpAccessChain %40 %39 %25 %25 %103 = OpLoad %6 %102 %104 = OpCompositeConstruct %7 %101 %103 %105 = OpAccessChain %40 %39 %25 %25 %106 = OpLoad %6 %105 %107 = OpAccessChain %40 %39 %25 %25 %108 = OpLoad %6 %107 %109 = OpCompositeConstruct %7 %106 %108 %110 = OpAccessChain %40 %39 %25 %25 %111 = OpLoad %6 %110 %112 = OpAccessChain %40 %39 %25 %25 %113 = OpLoad %6 %112 %114 = OpCompositeConstruct %7 %111 %113 %115 = OpAccessChain %40 %39 %25 %25 %116 = OpLoad %6 %115 %117 = OpAccessChain %40 %39 %25 %25 %118 = OpLoad %6 %117 %119 = OpCompositeConstruct %7 %116 %118 %120 = OpAccessChain %40 %39 %25 %25 %121 = OpLoad %6 %120 %122 = OpAccessChain %40 %39 %25 %25 %123 = OpLoad %6 %122 %124 = OpCompositeConstruct %7 %121 %123 %125 = OpAccessChain %40 %39 %25 %25 %126 = OpLoad %6 %125 %127 = OpAccessChain %40 %39 %25 %25 %128 = OpLoad %6 %127 %129 = OpCompositeConstruct %7 %126 %128 %130 = OpAccessChain %40 %39 %25 %25 %131 = OpLoad %6 %130 %132 = OpAccessChain %40 %39 %25 %25 %133 = OpLoad %6 %132 %134 = OpCompositeConstruct %7 %131 %133 %135 = OpCompositeConstruct %30 %89 %94 %99 %104 %109 %114 %119 %124 %129 %134 %136 = OpLoad %6 %26 OpStore %138 %135 %139 = OpAccessChain %43 %138 %136 %27 %140 = OpLoad %6 %139 OpStore %26 %140 OpBranch %84 %84 = OpLabel %143 = OpAccessChain %51 %50 %25 %25 %144 = OpLoad %13 %143 %145 = OpCompositeConstruct %15 %144 %144 %144 OpStore %142 %145 %148 = OpAccessChain %40 %39 %25 %147 %149 = OpLoad %6 %148 OpStore %146 %149 OpBranch %150 %150 = OpLabel OpLoopMerge %152 %153 None OpBranch %154 %154 = OpLabel %155 = OpLoad %6 %146 %156 = OpAccessChain %40 %39 %25 %25 %157 = OpLoad %6 %156 %158 = OpSGreaterThanEqual %54 %155 %157 %159 = OpLoad %6 %24 %161 = OpSLessThan %54 %159 %160 %162 = OpLogicalAnd %54 %158 %161 OpBranchConditional %162 %151 %152 %151 = OpLabel %163 = OpLoad %6 %24 %164 = OpIAdd %6 %163 %27 OpStore %24 %164 %166 = OpLoad %6 %146 %167 = OpConvertSToF %13 %166 %168 = OpExtInst %13 %1 Sin %167 OpStore %169 %168 %170 = OpFunctionCall %15 %18 %169 OpStore %165 %170 %171 = OpLoad %15 %165 %172 = OpExtInst %13 %1 Length %171 %173 = OpAccessChain %51 %50 %25 %27 %174 = OpLoad %13 %173 %175 = OpFOrdGreaterThanEqual %54 %172 %174 OpSelectionMerge %177 None OpBranchConditional %175 %176 %177 %176 = OpLabel %178 = OpLoad %15 %165 OpStore %142 %178 OpBranch %177 %177 = OpLabel OpBranch %153 %153 = OpLabel %179 = OpLoad %6 %146 %180 = OpISub %6 %179 %27 OpStore %146 %180 OpBranch %150 %152 = OpLabel %181 = OpLoad %15 %142 OpReturnValue %181 OpFunctionEnd END # uniforms for variant # _GLF_uniform_int_values BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 1 4 35 0 END # _GLF_uniform_float_values BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA 1.0 0.0 2.0 END BUFFER variant_framebuffer FORMAT B8G8R8A8_UNORM PIPELINE graphics variant_pipeline ATTACH variant_vertex_shader ATTACH variant_fragment_shader FRAMEBUFFER_SIZE 256 256 BIND BUFFER variant_framebuffer AS color LOCATION 0 BIND BUFFER variant__GLF_uniform_int_values AS uniform DESCRIPTOR_SET 0 BINDING 1 BIND BUFFER variant__GLF_uniform_float_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 256 256 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255