#!amber # Copyright 2020 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: Covers target lowering and compare combining 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 310 es # #define _int_1 _GLF_uniform_int_values[0] # #define _int_3 _GLF_uniform_int_values[1] # #define _int_0 _GLF_uniform_int_values[2] # #define _int_2 _GLF_uniform_int_values[3] # #define _int_5 _GLF_uniform_int_values[4] # # precision highp float; # # precision highp int; # # // Contents of _GLF_uniform_int_values: [1, 3, 0, 2, 5] # layout(set = 0, binding = 0) uniform buf0 # { # int _GLF_uniform_int_values[5]; # }; # layout(location = 0) out vec4 _GLF_color; # # // Contents of v1: [0.0, 1.0] # layout(set = 0, binding = 1) uniform buf1 # { # vec2 v1; # }; # # struct S { # int data; # }; # # void func(inout S s) # { # // Always false. # while (v1.x > v1.y) # { # return; # } # s.data = _int_1; # } # void main() # { # S arr[3]; # for (int i = _int_0; i < _int_3; i++) # { # arr[i].data = i; # } # for (int i = _int_0; i < _int_3; i++) # { # // Always false. # if (v1.x > v1.y) # { # break; # } # # // True for i = 1, 2 # if (arr[i].data == _int_1) # { # arr[clamp(i, 0, 3)].data = _int_2; # func(arr[2]); # } # else # { # for (int j = _int_0; j < _int_3; j++) # { # // Always false. # if (arr[j].data > _int_5) # { # discard; # } # } # } # } # if (arr[_int_0].data == _int_0 && arr[_int_1].data == _int_2 && # arr[_int_2].data == _int_1) # { # _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; 8 ; Bound: 185 ; Schema: 0 OpCapability Shader %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 OpEntryPoint Fragment %4 "main" %166 OpExecutionMode %4 OriginUpperLeft OpSource ESSL 310 OpName %4 "main" OpName %7 "S" OpMemberName %7 0 "data" OpName %11 "func(struct-S-i11;" OpName %10 "s" OpName %20 "buf1" OpMemberName %20 0 "v1" OpName %22 "" OpName %37 "buf0" OpMemberName %37 0 "_GLF_uniform_int_values" OpName %39 "" OpName %45 "i" OpName %62 "arr" OpName %68 "i" OpName %102 "param" OpName %109 "j" OpName %166 "_GLF_color" OpMemberDecorate %20 0 Offset 0 OpDecorate %20 Block OpDecorate %22 DescriptorSet 0 OpDecorate %22 Binding 1 OpDecorate %36 ArrayStride 16 OpMemberDecorate %37 0 Offset 0 OpDecorate %37 Block OpDecorate %39 DescriptorSet 0 OpDecorate %39 Binding 0 OpDecorate %166 Location 0 %2 = OpTypeVoid %3 = OpTypeFunction %2 %6 = OpTypeInt 32 1 %7 = OpTypeStruct %6 %8 = OpTypePointer Function %7 %9 = OpTypeFunction %2 %8 %18 = OpTypeFloat 32 %19 = OpTypeVector %18 2 %20 = OpTypeStruct %19 %21 = OpTypePointer Uniform %20 %22 = OpVariable %21 Uniform %23 = OpConstant %6 0 %24 = OpTypeInt 32 0 %25 = OpConstant %24 0 %26 = OpTypePointer Uniform %18 %29 = OpConstant %24 1 %32 = OpTypeBool %35 = OpConstant %24 5 %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 %6 2 %55 = OpConstant %6 1 %59 = OpConstant %24 3 %60 = OpTypeArray %7 %59 %61 = OpTypePointer Function %60 %97 = OpConstant %6 3 %124 = OpConstant %6 4 %164 = OpTypeVector %18 4 %165 = OpTypePointer Output %164 %166 = OpVariable %165 Output %4 = OpFunction %2 None %3 %5 = OpLabel %45 = OpVariable %43 Function %62 = OpVariable %61 Function %68 = OpVariable %43 Function %102 = OpVariable %8 Function %109 = OpVariable %43 Function %47 = OpAccessChain %40 %39 %23 %46 %48 = OpLoad %6 %47 OpStore %45 %48 OpBranch %49 %49 = OpLabel OpLoopMerge %51 %52 None OpBranch %53 %53 = OpLabel %54 = OpLoad %6 %45 %56 = OpAccessChain %40 %39 %23 %55 %57 = OpLoad %6 %56 %58 = OpSLessThan %32 %54 %57 OpBranchConditional %58 %50 %51 %50 = OpLabel %63 = OpLoad %6 %45 %64 = OpLoad %6 %45 %65 = OpAccessChain %43 %62 %63 %23 OpStore %65 %64 OpBranch %52 %52 = OpLabel %66 = OpLoad %6 %45 %67 = OpIAdd %6 %66 %55 OpStore %45 %67 OpBranch %49 %51 = OpLabel %69 = OpAccessChain %40 %39 %23 %46 %70 = OpLoad %6 %69 OpStore %68 %70 OpBranch %71 %71 = OpLabel OpLoopMerge %73 %74 None OpBranch %75 %75 = OpLabel %76 = OpLoad %6 %68 %77 = OpAccessChain %40 %39 %23 %55 %78 = OpLoad %6 %77 %79 = OpSLessThan %32 %76 %78 OpBranchConditional %79 %72 %73 %72 = OpLabel %80 = OpAccessChain %26 %22 %23 %25 %81 = OpLoad %18 %80 %82 = OpAccessChain %26 %22 %23 %29 %83 = OpLoad %18 %82 %84 = OpFOrdGreaterThan %32 %81 %83 OpSelectionMerge %86 None OpBranchConditional %84 %85 %86 %85 = OpLabel OpBranch %73 %86 = OpLabel %88 = OpLoad %6 %68 %89 = OpAccessChain %43 %62 %88 %23 %90 = OpLoad %6 %89 %91 = OpAccessChain %40 %39 %23 %23 %92 = OpLoad %6 %91 %93 = OpIEqual %32 %90 %92 OpSelectionMerge %95 None OpBranchConditional %93 %94 %108 %94 = OpLabel %96 = OpLoad %6 %68 %98 = OpExtInst %6 %1 SClamp %96 %23 %97 %99 = OpAccessChain %40 %39 %23 %97 %100 = OpLoad %6 %99 %101 = OpAccessChain %43 %62 %98 %23 OpStore %101 %100 %103 = OpAccessChain %8 %62 %46 %104 = OpLoad %7 %103 OpStore %102 %104 %105 = OpFunctionCall %2 %11 %102 %106 = OpLoad %7 %102 %107 = OpAccessChain %8 %62 %46 OpStore %107 %106 OpBranch %95 %108 = OpLabel %110 = OpAccessChain %40 %39 %23 %46 %111 = OpLoad %6 %110 OpStore %109 %111 OpBranch %112 %112 = OpLabel OpLoopMerge %114 %115 None OpBranch %116 %116 = OpLabel %117 = OpLoad %6 %109 %118 = OpAccessChain %40 %39 %23 %55 %119 = OpLoad %6 %118 %120 = OpSLessThan %32 %117 %119 OpBranchConditional %120 %113 %114 %113 = OpLabel %121 = OpLoad %6 %109 %122 = OpAccessChain %43 %62 %121 %23 %123 = OpLoad %6 %122 %125 = OpAccessChain %40 %39 %23 %124 %126 = OpLoad %6 %125 %127 = OpSGreaterThan %32 %123 %126 OpSelectionMerge %129 None OpBranchConditional %127 %128 %129 %128 = OpLabel OpKill %129 = OpLabel OpBranch %115 %115 = OpLabel %131 = OpLoad %6 %109 %132 = OpIAdd %6 %131 %55 OpStore %109 %132 OpBranch %112 %114 = OpLabel OpBranch %95 %95 = OpLabel OpBranch %74 %74 = OpLabel %133 = OpLoad %6 %68 %134 = OpIAdd %6 %133 %55 OpStore %68 %134 OpBranch %71 %73 = OpLabel %135 = OpAccessChain %40 %39 %23 %46 %136 = OpLoad %6 %135 %137 = OpAccessChain %43 %62 %136 %23 %138 = OpLoad %6 %137 %139 = OpAccessChain %40 %39 %23 %46 %140 = OpLoad %6 %139 %141 = OpIEqual %32 %138 %140 OpSelectionMerge %143 None OpBranchConditional %141 %142 %143 %142 = OpLabel %144 = OpAccessChain %40 %39 %23 %23 %145 = OpLoad %6 %144 %146 = OpAccessChain %43 %62 %145 %23 %147 = OpLoad %6 %146 %148 = OpAccessChain %40 %39 %23 %97 %149 = OpLoad %6 %148 %150 = OpIEqual %32 %147 %149 OpBranch %143 %143 = OpLabel %151 = OpPhi %32 %141 %73 %150 %142 OpSelectionMerge %153 None OpBranchConditional %151 %152 %153 %152 = OpLabel %154 = OpAccessChain %40 %39 %23 %97 %155 = OpLoad %6 %154 %156 = OpAccessChain %43 %62 %155 %23 %157 = OpLoad %6 %156 %158 = OpAccessChain %40 %39 %23 %23 %159 = OpLoad %6 %158 %160 = OpIEqual %32 %157 %159 OpBranch %153 %153 = OpLabel %161 = OpPhi %32 %151 %143 %160 %152 OpSelectionMerge %163 None OpBranchConditional %161 %162 %180 %162 = OpLabel %167 = OpAccessChain %40 %39 %23 %23 %168 = OpLoad %6 %167 %169 = OpConvertSToF %18 %168 %170 = OpAccessChain %40 %39 %23 %46 %171 = OpLoad %6 %170 %172 = OpConvertSToF %18 %171 %173 = OpAccessChain %40 %39 %23 %46 %174 = OpLoad %6 %173 %175 = OpConvertSToF %18 %174 %176 = OpAccessChain %40 %39 %23 %23 %177 = OpLoad %6 %176 %178 = OpConvertSToF %18 %177 %179 = OpCompositeConstruct %164 %169 %172 %175 %178 OpStore %166 %179 OpBranch %163 %180 = OpLabel %181 = OpAccessChain %40 %39 %23 %46 %182 = OpLoad %6 %181 %183 = OpConvertSToF %18 %182 %184 = OpCompositeConstruct %164 %183 %183 %183 %183 OpStore %166 %184 OpBranch %163 %163 = OpLabel OpReturn OpFunctionEnd %11 = OpFunction %2 None %9 %10 = OpFunctionParameter %8 %12 = OpLabel OpBranch %13 %13 = OpLabel OpLoopMerge %15 %16 None OpBranch %17 %17 = OpLabel %27 = OpAccessChain %26 %22 %23 %25 %28 = OpLoad %18 %27 %30 = OpAccessChain %26 %22 %23 %29 %31 = OpLoad %18 %30 %33 = OpFOrdGreaterThan %32 %28 %31 OpBranchConditional %33 %14 %15 %14 = OpLabel OpReturn %16 = OpLabel OpBranch %13 %15 = OpLabel %41 = OpAccessChain %40 %39 %23 %23 %42 = OpLoad %6 %41 %44 = OpAccessChain %43 %10 %23 OpStore %44 %42 OpReturn OpFunctionEnd END # uniforms for variant # v1 BUFFER variant_v1 DATA_TYPE vec2 STD140 DATA 0.0 1.0 END # _GLF_uniform_int_values BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA 1 3 0 2 5 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_v1 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 256 256 EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255