blob: edfc42cd257b311ab6d2bf079ae3352c21e75dc8 [file] [log] [blame]
#!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.
# Optimized using spirv-opt with the following arguments:
# '--copy-propagate-arrays'
# '--eliminate-dead-branches'
# '--merge-blocks'
# '--private-to-local'
# '--reduce-load-size'
# '--eliminate-dead-code-aggressive'
# '--ccp'
# '--reduce-load-size'
# '--convert-local-access-chains'
# '--eliminate-dead-branches'
# '--merge-return'
# '--eliminate-local-single-block'
# '--eliminate-dead-code-aggressive'
# '--redundancy-elimination'
# '--eliminate-dead-branches'
# '--merge-return'
# '--eliminate-local-multi-store'
# '--reduce-load-size'
# '--inline-entry-points-exhaustive'
# '--vector-dce'
# '--eliminate-dead-branches'
# '--merge-return'
# '--eliminate-local-multi-store'
# '--eliminate-dead-branches'
# '--merge-blocks'
# '--eliminate-local-single-store'
# spirv-opt commit hash: a0370efd589be33d5d9a85cfde2f85841b3755af
SHADER vertex variant_vertex_shader PASSTHROUGH
# variant_fragment_shader is derived from the following GLSL:
# #version 320 es
# #define _int_0 _GLF_uniform_int_values[0]
# #define _float_1_0 _GLF_uniform_float_values[0]
# #define _float_0_1 _GLF_uniform_float_values[1]
# #define _float_0_0 _GLF_uniform_float_values[2]
#
# precision highp float;
# precision highp int;
#
# // Contents of _GLF_uniform_int_values: 0
# layout(set = 0, binding = 0) uniform buf0
# {
# int _GLF_uniform_int_values[1];
# };
# // Contents of _GLF_uniform_float_values: [1.0, 0.1, 0.0]
# layout(set = 0, binding = 1) uniform buf1
# {
# float _GLF_uniform_float_values[3];
# };
#
# const int _GLF_global_loop_bound = 10;
# int _GLF_global_loop_count = 0;
#
# layout(location = 0) out vec4 _GLF_color;
#
# // This function always returns 1.0 or greater.
# float func(float x)
# {
# float f = _float_1_0;
#
# // Always false.
# if(_float_1_0 < 1.0)
# {
# if(gl_FragCoord.x < _float_0_0)
# {
# return _float_1_0;
# }
# }
#
# while(_GLF_global_loop_count < _GLF_global_loop_bound)
# {
# _GLF_global_loop_count++;
# f += _float_1_0;
#
# // Always true.
# if(gl_FragCoord.x >= 0.0)
# {
# _GLF_color = vec4(_float_1_0);
# }
#
# // Always false.
# if (x < _float_0_0)
# {
# return f;
# }
# }
#
# // Never iterated as the loop bound has already been reached.
# while(_GLF_global_loop_count < _GLF_global_loop_bound)
# {
# _GLF_global_loop_count ++;
# }
#
# return f;
# }
#
# void main()
# {
# _GLF_color = vec4(_int_0);
#
# // Always false.
# if(gl_FragCoord.x < _float_0_1)
# {
# return;
# }
#
# // v0 becomes (0, 0, 0, 0).
# vec4 v0 = _GLF_color;
#
# // Always true.
# if(gl_FragCoord.x >= 0.0)
# {
# _GLF_color = vec4(_float_1_0);
# }
#
# _GLF_color = v0;
#
# // Always false.
# if(gl_FragCoord.y < _float_0_1)
# {
# return;
# }
#
# vec4 v1 = vec4(_float_0_0);
# // v1 becomes (x, 0, 0, x), where x >= 1.0.
# v1.x = v1.w = func(gl_FragCoord.y);
#
# // Always true.
# if(gl_FragCoord.x >= 0.0)
# {
# _GLF_color = vec4(_float_1_0);
# }
#
# // Always false.
# if(gl_FragCoord.x < _float_0_0)
# {
# return;
# }
#
# // Results clamps to (1, 0, 0, 1).
# _GLF_color = v1;
# }
SHADER fragment variant_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 247
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main" %35 %71
OpExecutionMode %4 OriginUpperLeft
OpSource ESSL 320
OpName %4 "main"
OpName %10 "func(f1;"
OpName %9 "x"
OpName %14 "_GLF_global_loop_count"
OpName %16 "f"
OpName %20 "buf1"
OpMemberName %20 0 "_GLF_uniform_float_values"
OpName %22 ""
OpName %35 "gl_FragCoord"
OpName %71 "_GLF_color"
OpName %97 "buf0"
OpMemberName %97 0 "_GLF_uniform_int_values"
OpName %99 ""
OpName %114 "v0"
OpName %133 "v1"
OpName %137 "param"
OpDecorate %19 ArrayStride 16
OpMemberDecorate %20 0 Offset 0
OpDecorate %20 Block
OpDecorate %22 DescriptorSet 0
OpDecorate %22 Binding 1
OpDecorate %35 BuiltIn FragCoord
OpDecorate %71 Location 0
OpDecorate %96 ArrayStride 16
OpMemberDecorate %97 0 Offset 0
OpDecorate %97 Block
OpDecorate %99 DescriptorSet 0
OpDecorate %99 Binding 0
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypePointer Function %6
%8 = OpTypeFunction %6 %7
%12 = OpTypeInt 32 1
%13 = OpTypePointer Private %12
%14 = OpVariable %13 Private
%15 = OpConstant %12 0
%17 = OpTypeInt 32 0
%18 = OpConstant %17 3
%19 = OpTypeArray %6 %18
%20 = OpTypeStruct %19
%21 = OpTypePointer Uniform %20
%22 = OpVariable %21 Uniform
%23 = OpTypePointer Uniform %6
%28 = OpConstant %6 1
%29 = OpTypeBool
%33 = OpTypeVector %6 4
%34 = OpTypePointer Input %33
%35 = OpVariable %34 Input
%36 = OpConstant %17 0
%37 = OpTypePointer Input %6
%40 = OpConstant %12 2
%55 = OpConstant %12 10
%58 = OpConstant %12 1
%66 = OpConstant %6 0
%70 = OpTypePointer Output %33
%71 = OpVariable %70 Output
%95 = OpConstant %17 1
%96 = OpTypeArray %12 %95
%97 = OpTypeStruct %96
%98 = OpTypePointer Uniform %97
%99 = OpVariable %98 Uniform
%100 = OpTypePointer Uniform %12
%113 = OpTypePointer Function %33
%166 = OpConstantFalse %29
%167 = OpTypePointer Function %29
%169 = OpConstantTrue %29
%192 = OpUndef %6
%4 = OpFunction %2 None %3
%5 = OpLabel
%194 = OpVariable %167 Function %166
%195 = OpVariable %7 Function
%196 = OpVariable %7 Function
%197 = OpVariable %7 Function
%114 = OpVariable %113 Function
%133 = OpVariable %113 Function
%137 = OpVariable %7 Function
OpSelectionMerge %164 None
OpSwitch %36 %165
%165 = OpLabel
OpStore %14 %15
%101 = OpAccessChain %100 %99 %15 %15
%102 = OpLoad %12 %101
%103 = OpConvertSToF %6 %102
%104 = OpCompositeConstruct %33 %103 %103 %103 %103
OpStore %71 %104
%105 = OpAccessChain %37 %35 %36
%106 = OpLoad %6 %105
%107 = OpAccessChain %23 %22 %15 %58
%108 = OpLoad %6 %107
%109 = OpFOrdLessThan %29 %106 %108
OpSelectionMerge %111 None
OpBranchConditional %109 %110 %111
%110 = OpLabel
OpBranch %164
%111 = OpLabel
%115 = OpLoad %33 %71
OpStore %114 %115
%118 = OpFOrdGreaterThanEqual %29 %106 %66
OpSelectionMerge %120 None
OpBranchConditional %118 %119 %120
%119 = OpLabel
%121 = OpAccessChain %23 %22 %15 %15
%122 = OpLoad %6 %121
%123 = OpCompositeConstruct %33 %122 %122 %122 %122
OpStore %71 %123
OpBranch %120
%120 = OpLabel
OpStore %71 %115
%125 = OpAccessChain %37 %35 %95
%126 = OpLoad %6 %125
%129 = OpFOrdLessThan %29 %126 %108
OpSelectionMerge %131 None
OpBranchConditional %129 %130 %131
%130 = OpLabel
OpBranch %164
%131 = OpLabel
%134 = OpAccessChain %23 %22 %15 %40
%135 = OpLoad %6 %134
%136 = OpCompositeConstruct %33 %135 %135 %135 %135
OpStore %133 %136
OpStore %137 %126
OpStore %194 %166
OpSelectionMerge %245 None
OpSwitch %36 %199
%199 = OpLabel
%200 = OpAccessChain %23 %22 %15 %15
%201 = OpLoad %6 %200
OpStore %196 %201
%202 = OpFOrdLessThan %29 %201 %28
OpSelectionMerge %211 None
OpBranchConditional %202 %203 %211
%203 = OpLabel
%204 = OpAccessChain %37 %35 %36
%205 = OpLoad %6 %204
%206 = OpAccessChain %23 %22 %15 %40
%207 = OpLoad %6 %206
%208 = OpFOrdLessThan %29 %205 %207
OpSelectionMerge %210 None
OpBranchConditional %208 %209 %210
%209 = OpLabel
OpStore %194 %169
OpStore %195 %201
OpBranch %245
%210 = OpLabel
OpBranch %211
%211 = OpLabel
OpBranch %212
%212 = OpLabel
%213 = OpPhi %6 %201 %211 %219 %232
%214 = OpLoad %12 %14
%215 = OpSLessThan %29 %214 %55
OpLoopMerge %233 %232 None
OpBranchConditional %215 %216 %233
%216 = OpLabel
%217 = OpLoad %12 %14
%218 = OpIAdd %12 %217 %58
OpStore %14 %218
%219 = OpFAdd %6 %213 %201
OpStore %196 %219
%220 = OpAccessChain %37 %35 %36
%221 = OpLoad %6 %220
%222 = OpFOrdGreaterThanEqual %29 %221 %66
OpSelectionMerge %225 None
OpBranchConditional %222 %223 %225
%223 = OpLabel
%224 = OpCompositeConstruct %33 %201 %201 %201 %201
OpStore %71 %224
OpBranch %225
%225 = OpLabel
%227 = OpAccessChain %23 %22 %15 %40
%228 = OpLoad %6 %227
%229 = OpFOrdLessThan %29 %126 %228
OpSelectionMerge %231 None
OpBranchConditional %229 %230 %231
%230 = OpLabel
OpStore %194 %169
OpStore %195 %219
OpBranch %233
%231 = OpLabel
OpBranch %232
%232 = OpLabel
OpBranch %212
%233 = OpLabel
%234 = OpPhi %6 %192 %212 %219 %230
%235 = OpPhi %6 %213 %212 %219 %230
%236 = OpPhi %29 %166 %212 %169 %230
OpSelectionMerge %237 None
OpBranchConditional %236 %245 %237
%237 = OpLabel
OpBranch %238
%238 = OpLabel
%239 = OpLoad %12 %14
%240 = OpSLessThan %29 %239 %55
OpLoopMerge %244 %241 None
OpBranchConditional %240 %241 %244
%241 = OpLabel
%242 = OpLoad %12 %14
%243 = OpIAdd %12 %242 %58
OpStore %14 %243
OpBranch %238
%244 = OpLabel
OpStore %194 %169
OpStore %195 %235
OpBranch %245
%245 = OpLabel
%246 = OpPhi %6 %201 %209 %234 %233 %235 %244
OpStore %197 %246
%161 = OpCompositeInsert %33 %246 %136 3
%163 = OpCompositeInsert %33 %246 %161 0
OpStore %133 %163
OpSelectionMerge %147 None
OpBranchConditional %118 %146 %147
%146 = OpLabel
%148 = OpAccessChain %23 %22 %15 %15
%149 = OpLoad %6 %148
%150 = OpCompositeConstruct %33 %149 %149 %149 %149
OpStore %71 %150
OpBranch %147
%147 = OpLabel
%155 = OpFOrdLessThan %29 %106 %135
OpSelectionMerge %157 None
OpBranchConditional %155 %156 %157
%156 = OpLabel
OpBranch %164
%157 = OpLabel
OpStore %71 %163
OpBranch %164
%164 = OpLabel
OpReturn
OpFunctionEnd
%10 = OpFunction %6 None %8
%9 = OpFunctionParameter %7
%11 = OpLabel
%174 = OpVariable %167 Function %166
%171 = OpVariable %7 Function
%16 = OpVariable %7 Function
OpSelectionMerge %170 None
OpSwitch %36 %173
%173 = OpLabel
%24 = OpAccessChain %23 %22 %15 %15
%25 = OpLoad %6 %24
OpStore %16 %25
%30 = OpFOrdLessThan %29 %25 %28
OpSelectionMerge %32 None
OpBranchConditional %30 %31 %32
%31 = OpLabel
%38 = OpAccessChain %37 %35 %36
%39 = OpLoad %6 %38
%41 = OpAccessChain %23 %22 %15 %40
%42 = OpLoad %6 %41
%43 = OpFOrdLessThan %29 %39 %42
OpSelectionMerge %45 None
OpBranchConditional %43 %44 %45
%44 = OpLabel
OpStore %174 %169
OpStore %171 %25
OpBranch %170
%45 = OpLabel
OpBranch %32
%32 = OpLabel
OpBranch %49
%49 = OpLabel
%179 = OpPhi %6 %25 %32 %63 %52
%54 = OpLoad %12 %14
%56 = OpSLessThan %29 %54 %55
OpLoopMerge %51 %52 None
OpBranchConditional %56 %50 %51
%50 = OpLabel
%57 = OpLoad %12 %14
%59 = OpIAdd %12 %57 %58
OpStore %14 %59
%63 = OpFAdd %6 %179 %25
OpStore %16 %63
%64 = OpAccessChain %37 %35 %36
%65 = OpLoad %6 %64
%67 = OpFOrdGreaterThanEqual %29 %65 %66
OpSelectionMerge %69 None
OpBranchConditional %67 %68 %69
%68 = OpLabel
%74 = OpCompositeConstruct %33 %25 %25 %25 %25
OpStore %71 %74
OpBranch %69
%69 = OpLabel
%75 = OpLoad %6 %9
%76 = OpAccessChain %23 %22 %15 %40
%77 = OpLoad %6 %76
%78 = OpFOrdLessThan %29 %75 %77
OpSelectionMerge %80 None
OpBranchConditional %78 %79 %80
%79 = OpLabel
OpStore %174 %169
OpStore %171 %63
OpBranch %51
%80 = OpLabel
OpBranch %52
%52 = OpLabel
OpBranch %49
%51 = OpLabel
%189 = OpPhi %6 %192 %49 %63 %79
%187 = OpPhi %6 %179 %49 %63 %79
%182 = OpPhi %29 %166 %49 %169 %79
OpSelectionMerge %175 None
OpBranchConditional %182 %170 %175
%175 = OpLabel
OpBranch %83
%83 = OpLabel
%88 = OpLoad %12 %14
%89 = OpSLessThan %29 %88 %55
OpLoopMerge %85 %84 None
OpBranchConditional %89 %84 %85
%84 = OpLabel
%90 = OpLoad %12 %14
%91 = OpIAdd %12 %90 %58
OpStore %14 %91
OpBranch %83
%85 = OpLabel
OpStore %174 %169
OpStore %171 %187
OpBranch %170
%170 = OpLabel
%188 = OpPhi %6 %25 %44 %189 %51 %187 %85
OpReturnValue %188
OpFunctionEnd
END
# uniforms for variant
# _GLF_uniform_float_values
BUFFER variant__GLF_uniform_float_values DATA_TYPE float[] STD140 DATA
1.0 0.1 0.0
END
# _GLF_uniform_int_values
BUFFER variant__GLF_uniform_int_values DATA_TYPE int32[] STD140 DATA
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_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 256 256
EXPECT variant_framebuffer IDX 0 0 SIZE 256 256 EQ_RGBA 255 0 0 255