blob: 88c6e0350e0cfcde55c208d91ea600e0ea9b0a57 [file] [log] [blame]
#!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 bug found by GraphicsFuzz.
# Short description: A fragment shader with conditional and simple loop
# The test passes because both shaders render the same image.
SHADER vertex reference_vertex_shader PASSTHROUGH
# reference_fragment_shader is derived from the following GLSL:
# #version 320 es
# precision highp float;
#
# precision highp int;
#
# layout(location = 0) out vec4 _GLF_color;
#
# layout(set = 0, binding = 0) uniform buf0
# {
# vec2 resolution;
# };
# float compute_value(float limit, float thirty_two)
# {
# float result = -0.5;
# for (int i = 1; i < 800; i++)
# {
# if ((i % 32) == 0)
# {
# result += 0.4;
# }
# else
# {
# if (mod(float(i), round(thirty_two)) <= 0.01)
# {
# result += 100.0;
# }
# }
# if (float(i) >= limit)
# {
# return result;
# }
# }
# return result;
# }
# void main()
# {
# vec3 c = vec3(7.0, 8.0, 9.0);
# float thirty_two = round(resolution.x / 8.0);
# c.x = compute_value(gl_FragCoord.x, thirty_two);
# c.y = compute_value(gl_FragCoord.y, thirty_two);
# c.z = c.x + c.y;
# for (int i = 0; i < 3; i++)
# {
# if (c[i] >= 1.0)
# {
# c[i] = c[i] * c[i];
# }
# }
# _GLF_color = vec4(normalize(abs(c)), 1.0);
# }
SHADER fragment reference_fragment_shader SPIRV-ASM TARGET_ENV spv1.0
; SPIR-V
; Version: 1.0
; Generator: Khronos Glslang Reference Front End; 10
; Bound: 145
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main" %85 %137
OpExecutionMode %4 OriginUpperLeft
OpSource ESSL 320
OpName %4 "main"
OpName %11 "compute_value(f1;f1;"
OpName %9 "limit"
OpName %10 "thirty_two"
OpName %13 "result"
OpName %17 "i"
OpName %66 "c"
OpName %71 "thirty_two"
OpName %73 "buf0"
OpMemberName %73 0 "resolution"
OpName %75 ""
OpName %85 "gl_FragCoord"
OpName %86 "param"
OpName %90 "param"
OpName %94 "param"
OpName %98 "param"
OpName %109 "i"
OpName %137 "_GLF_color"
OpMemberDecorate %73 0 Offset 0
OpDecorate %73 Block
OpDecorate %75 DescriptorSet 0
OpDecorate %75 Binding 0
OpDecorate %85 BuiltIn FragCoord
OpDecorate %137 Location 0
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypePointer Function %6
%8 = OpTypeFunction %6 %7 %7
%14 = OpConstant %6 -0.5
%15 = OpTypeInt 32 1
%16 = OpTypePointer Function %15
%18 = OpConstant %15 1
%25 = OpConstant %15 800
%26 = OpTypeBool
%29 = OpConstant %15 32
%31 = OpConstant %15 0
%35 = OpConstant %6 0.400000006
%44 = OpConstant %6 0.00999999978
%48 = OpConstant %6 100
%64 = OpTypeVector %6 3
%65 = OpTypePointer Function %64
%67 = OpConstant %6 7
%68 = OpConstant %6 8
%69 = OpConstant %6 9
%70 = OpConstantComposite %64 %67 %68 %69
%72 = OpTypeVector %6 2
%73 = OpTypeStruct %72
%74 = OpTypePointer Uniform %73
%75 = OpVariable %74 Uniform
%76 = OpTypeInt 32 0
%77 = OpConstant %76 0
%78 = OpTypePointer Uniform %6
%83 = OpTypeVector %6 4
%84 = OpTypePointer Input %83
%85 = OpVariable %84 Input
%87 = OpTypePointer Input %6
%95 = OpConstant %76 1
%107 = OpConstant %76 2
%116 = OpConstant %15 3
%121 = OpConstant %6 1
%136 = OpTypePointer Output %83
%137 = OpVariable %136 Output
%4 = OpFunction %2 None %3
%5 = OpLabel
%66 = OpVariable %65 Function
%71 = OpVariable %7 Function
%86 = OpVariable %7 Function
%90 = OpVariable %7 Function
%94 = OpVariable %7 Function
%98 = OpVariable %7 Function
%109 = OpVariable %16 Function
OpStore %66 %70
%79 = OpAccessChain %78 %75 %31 %77
%80 = OpLoad %6 %79
%81 = OpFDiv %6 %80 %68
%82 = OpExtInst %6 %1 Round %81
OpStore %71 %82
%88 = OpAccessChain %87 %85 %77
%89 = OpLoad %6 %88
OpStore %86 %89
%91 = OpLoad %6 %71
OpStore %90 %91
%92 = OpFunctionCall %6 %11 %86 %90
%93 = OpAccessChain %7 %66 %77
OpStore %93 %92
%96 = OpAccessChain %87 %85 %95
%97 = OpLoad %6 %96
OpStore %94 %97
%99 = OpLoad %6 %71
OpStore %98 %99
%100 = OpFunctionCall %6 %11 %94 %98
%101 = OpAccessChain %7 %66 %95
OpStore %101 %100
%102 = OpAccessChain %7 %66 %77
%103 = OpLoad %6 %102
%104 = OpAccessChain %7 %66 %95
%105 = OpLoad %6 %104
%106 = OpFAdd %6 %103 %105
%108 = OpAccessChain %7 %66 %107
OpStore %108 %106
OpStore %109 %31
OpBranch %110
%110 = OpLabel
OpLoopMerge %112 %113 None
OpBranch %114
%114 = OpLabel
%115 = OpLoad %15 %109
%117 = OpSLessThan %26 %115 %116
OpBranchConditional %117 %111 %112
%111 = OpLabel
%118 = OpLoad %15 %109
%119 = OpAccessChain %7 %66 %118
%120 = OpLoad %6 %119
%122 = OpFOrdGreaterThanEqual %26 %120 %121
OpSelectionMerge %124 None
OpBranchConditional %122 %123 %124
%123 = OpLabel
%125 = OpLoad %15 %109
%126 = OpLoad %15 %109
%127 = OpAccessChain %7 %66 %126
%128 = OpLoad %6 %127
%129 = OpLoad %15 %109
%130 = OpAccessChain %7 %66 %129
%131 = OpLoad %6 %130
%132 = OpFMul %6 %128 %131
%133 = OpAccessChain %7 %66 %125
OpStore %133 %132
OpBranch %124
%124 = OpLabel
OpBranch %113
%113 = OpLabel
%134 = OpLoad %15 %109
%135 = OpIAdd %15 %134 %18
OpStore %109 %135
OpBranch %110
%112 = OpLabel
%138 = OpLoad %64 %66
%139 = OpExtInst %64 %1 FAbs %138
%140 = OpExtInst %64 %1 Normalize %139
%141 = OpCompositeExtract %6 %140 0
%142 = OpCompositeExtract %6 %140 1
%143 = OpCompositeExtract %6 %140 2
%144 = OpCompositeConstruct %83 %141 %142 %143 %121
OpStore %137 %144
OpReturn
OpFunctionEnd
%11 = OpFunction %6 None %8
%9 = OpFunctionParameter %7
%10 = OpFunctionParameter %7
%12 = OpLabel
%13 = OpVariable %7 Function
%17 = OpVariable %16 Function
OpStore %13 %14
OpStore %17 %18
OpBranch %19
%19 = OpLabel
OpLoopMerge %21 %22 None
OpBranch %23
%23 = OpLabel
%24 = OpLoad %15 %17
%27 = OpSLessThan %26 %24 %25
OpBranchConditional %27 %20 %21
%20 = OpLabel
%28 = OpLoad %15 %17
%30 = OpSMod %15 %28 %29
%32 = OpIEqual %26 %30 %31
OpSelectionMerge %34 None
OpBranchConditional %32 %33 %38
%33 = OpLabel
%36 = OpLoad %6 %13
%37 = OpFAdd %6 %36 %35
OpStore %13 %37
OpBranch %34
%38 = OpLabel
%39 = OpLoad %15 %17
%40 = OpConvertSToF %6 %39
%41 = OpLoad %6 %10
%42 = OpExtInst %6 %1 Round %41
%43 = OpFMod %6 %40 %42
%45 = OpFOrdLessThanEqual %26 %43 %44
OpSelectionMerge %47 None
OpBranchConditional %45 %46 %47
%46 = OpLabel
%49 = OpLoad %6 %13
%50 = OpFAdd %6 %49 %48
OpStore %13 %50
OpBranch %47
%47 = OpLabel
OpBranch %34
%34 = OpLabel
%51 = OpLoad %15 %17
%52 = OpConvertSToF %6 %51
%53 = OpLoad %6 %9
%54 = OpFOrdGreaterThanEqual %26 %52 %53
OpSelectionMerge %56 None
OpBranchConditional %54 %55 %56
%55 = OpLabel
%57 = OpLoad %6 %13
OpReturnValue %57
%56 = OpLabel
OpBranch %22
%22 = OpLabel
%59 = OpLoad %15 %17
%60 = OpIAdd %15 %59 %18
OpStore %17 %60
OpBranch %19
%21 = OpLabel
%61 = OpLoad %6 %13
OpReturnValue %61
OpFunctionEnd
END
# uniforms for reference
# resolution
BUFFER reference_resolution DATA_TYPE vec2<float> DATA
256.0 256.0
END
BUFFER reference_framebuffer FORMAT B8G8R8A8_UNORM
PIPELINE graphics reference_pipeline
ATTACH reference_vertex_shader
ATTACH reference_fragment_shader
FRAMEBUFFER_SIZE 256 256
BIND BUFFER reference_framebuffer AS color LOCATION 0
BIND BUFFER reference_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
END
CLEAR_COLOR reference_pipeline 0 0 0 255
CLEAR reference_pipeline
RUN reference_pipeline DRAW_RECT POS 0 0 SIZE 256 256
SHADER vertex variant_vertex_shader PASSTHROUGH
# variant_fragment_shader is derived from the following GLSL:
# #version 320 es
# precision highp float;
#
# precision highp int;
#
# layout(location = 0) out vec4 _GLF_color;
#
# layout(set = 0, binding = 0) uniform buf0
# {
# vec2 resolution;
# };
#
# layout(set = 0, binding = 1) uniform buf1
# {
# vec2 injectionSwitch; //x == 1.0, y == 0.0
# };
# float compute_value(float limit, float thirty_two)
# {
# float result = -0.5;
# for (int i = 1; i < 800; i++)
# {
# if ((i % 32) == 0)
# {
# result += 0.4;
# }
# else
# {
# if (mod(float(i), round(thirty_two)) <= 0.01)
# {
# result += 100.0;
# }
# }
# if (float(i) >= limit)
# {
# return result;
# }
# }
# return result;
# }
# void main()
# {
# vec3 c = vec3(7.0, 8.0, 9.0);
# float thirty_two = round(resolution.x / 8.0);
# c.x = compute_value(gl_FragCoord.x, thirty_two);
# c.y = compute_value(gl_FragCoord.y, thirty_two);
# // Always true and result should be the same as in reference shader.
# c.z = c.x + (true ? c : c * injectionSwitch.x).y;
# for (int i = 0; i < 3; i++)
# {
# if (c[i] >= 1.0)
# {
# c[i] = c[i] * c[i];
# }
# float j = 0.0;
# // Always true, iterates once before break.
# while (injectionSwitch.x > injectionSwitch.y)
# {
# if (j >= injectionSwitch.x)
# {
# break;
# }
# j++;
# }
# }
# _GLF_color = vec4(normalize(abs(c)), 1.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: 179
; Schema: 0
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %4 "main" %85 %171
OpExecutionMode %4 OriginUpperLeft
OpSource ESSL 320
OpName %4 "main"
OpName %11 "compute_value(f1;f1;"
OpName %9 "limit"
OpName %10 "thirty_two"
OpName %13 "result"
OpName %17 "i"
OpName %66 "c"
OpName %71 "thirty_two"
OpName %73 "buf0"
OpMemberName %73 0 "resolution"
OpName %75 ""
OpName %85 "gl_FragCoord"
OpName %86 "param"
OpName %90 "param"
OpName %94 "param"
OpName %98 "param"
OpName %111 "buf1"
OpMemberName %111 0 "injectionSwitch"
OpName %113 ""
OpName %122 "i"
OpName %147 "j"
OpName %171 "_GLF_color"
OpMemberDecorate %73 0 Offset 0
OpDecorate %73 Block
OpDecorate %75 DescriptorSet 0
OpDecorate %75 Binding 0
OpDecorate %85 BuiltIn FragCoord
OpMemberDecorate %111 0 Offset 0
OpDecorate %111 Block
OpDecorate %113 DescriptorSet 0
OpDecorate %113 Binding 1
OpDecorate %171 Location 0
%2 = OpTypeVoid
%3 = OpTypeFunction %2
%6 = OpTypeFloat 32
%7 = OpTypePointer Function %6
%8 = OpTypeFunction %6 %7 %7
%14 = OpConstant %6 -0.5
%15 = OpTypeInt 32 1
%16 = OpTypePointer Function %15
%18 = OpConstant %15 1
%25 = OpConstant %15 800
%26 = OpTypeBool
%29 = OpConstant %15 32
%31 = OpConstant %15 0
%35 = OpConstant %6 0.400000006
%44 = OpConstant %6 0.00999999978
%48 = OpConstant %6 100
%64 = OpTypeVector %6 3
%65 = OpTypePointer Function %64
%67 = OpConstant %6 7
%68 = OpConstant %6 8
%69 = OpConstant %6 9
%70 = OpConstantComposite %64 %67 %68 %69
%72 = OpTypeVector %6 2
%73 = OpTypeStruct %72
%74 = OpTypePointer Uniform %73
%75 = OpVariable %74 Uniform
%76 = OpTypeInt 32 0
%77 = OpConstant %76 0
%78 = OpTypePointer Uniform %6
%83 = OpTypeVector %6 4
%84 = OpTypePointer Input %83
%85 = OpVariable %84 Input
%87 = OpTypePointer Input %6
%95 = OpConstant %76 1
%104 = OpConstantTrue %26
%111 = OpTypeStruct %72
%112 = OpTypePointer Uniform %111
%113 = OpVariable %112 Uniform
%120 = OpConstant %76 2
%129 = OpConstant %15 3
%134 = OpConstant %6 1
%148 = OpConstant %6 0
%170 = OpTypePointer Output %83
%171 = OpVariable %170 Output
%4 = OpFunction %2 None %3
%5 = OpLabel
%66 = OpVariable %65 Function
%71 = OpVariable %7 Function
%86 = OpVariable %7 Function
%90 = OpVariable %7 Function
%94 = OpVariable %7 Function
%98 = OpVariable %7 Function
%105 = OpVariable %65 Function
%122 = OpVariable %16 Function
%147 = OpVariable %7 Function
OpStore %66 %70
%79 = OpAccessChain %78 %75 %31 %77
%80 = OpLoad %6 %79
%81 = OpFDiv %6 %80 %68
%82 = OpExtInst %6 %1 Round %81
OpStore %71 %82
%88 = OpAccessChain %87 %85 %77
%89 = OpLoad %6 %88
OpStore %86 %89
%91 = OpLoad %6 %71
OpStore %90 %91
%92 = OpFunctionCall %6 %11 %86 %90
%93 = OpAccessChain %7 %66 %77
OpStore %93 %92
%96 = OpAccessChain %87 %85 %95
%97 = OpLoad %6 %96
OpStore %94 %97
%99 = OpLoad %6 %71
OpStore %98 %99
%100 = OpFunctionCall %6 %11 %94 %98
%101 = OpAccessChain %7 %66 %95
OpStore %101 %100
%102 = OpAccessChain %7 %66 %77
%103 = OpLoad %6 %102
OpSelectionMerge %107 None
OpBranchConditional %104 %106 %109
%106 = OpLabel
%108 = OpLoad %64 %66
OpStore %105 %108
OpBranch %107
%109 = OpLabel
%110 = OpLoad %64 %66
%114 = OpAccessChain %78 %113 %31 %77
%115 = OpLoad %6 %114
%116 = OpVectorTimesScalar %64 %110 %115
OpStore %105 %116
OpBranch %107
%107 = OpLabel
%117 = OpAccessChain %7 %105 %95
%118 = OpLoad %6 %117
%119 = OpFAdd %6 %103 %118
%121 = OpAccessChain %7 %66 %120
OpStore %121 %119
OpStore %122 %31
OpBranch %123
%123 = OpLabel
OpLoopMerge %125 %126 None
OpBranch %127
%127 = OpLabel
%128 = OpLoad %15 %122
%130 = OpSLessThan %26 %128 %129
OpBranchConditional %130 %124 %125
%124 = OpLabel
%131 = OpLoad %15 %122
%132 = OpAccessChain %7 %66 %131
%133 = OpLoad %6 %132
%135 = OpFOrdGreaterThanEqual %26 %133 %134
OpSelectionMerge %137 None
OpBranchConditional %135 %136 %137
%136 = OpLabel
%138 = OpLoad %15 %122
%139 = OpLoad %15 %122
%140 = OpAccessChain %7 %66 %139
%141 = OpLoad %6 %140
%142 = OpLoad %15 %122
%143 = OpAccessChain %7 %66 %142
%144 = OpLoad %6 %143
%145 = OpFMul %6 %141 %144
%146 = OpAccessChain %7 %66 %138
OpStore %146 %145
OpBranch %137
%137 = OpLabel
OpStore %147 %148
OpBranch %149
%149 = OpLabel
OpLoopMerge %151 %152 None
OpBranch %153
%153 = OpLabel
%154 = OpAccessChain %78 %113 %31 %77
%155 = OpLoad %6 %154
%156 = OpAccessChain %78 %113 %31 %95
%157 = OpLoad %6 %156
%158 = OpFOrdGreaterThan %26 %155 %157
OpBranchConditional %158 %150 %151
%150 = OpLabel
%159 = OpLoad %6 %147
%160 = OpAccessChain %78 %113 %31 %77
%161 = OpLoad %6 %160
%162 = OpFOrdGreaterThanEqual %26 %159 %161
OpSelectionMerge %164 None
OpBranchConditional %162 %163 %164
%163 = OpLabel
OpBranch %151
%164 = OpLabel
%166 = OpLoad %6 %147
%167 = OpFAdd %6 %166 %134
OpStore %147 %167
OpBranch %152
%152 = OpLabel
OpBranch %149
%151 = OpLabel
OpBranch %126
%126 = OpLabel
%168 = OpLoad %15 %122
%169 = OpIAdd %15 %168 %18
OpStore %122 %169
OpBranch %123
%125 = OpLabel
%172 = OpLoad %64 %66
%173 = OpExtInst %64 %1 FAbs %172
%174 = OpExtInst %64 %1 Normalize %173
%175 = OpCompositeExtract %6 %174 0
%176 = OpCompositeExtract %6 %174 1
%177 = OpCompositeExtract %6 %174 2
%178 = OpCompositeConstruct %83 %175 %176 %177 %134
OpStore %171 %178
OpReturn
OpFunctionEnd
%11 = OpFunction %6 None %8
%9 = OpFunctionParameter %7
%10 = OpFunctionParameter %7
%12 = OpLabel
%13 = OpVariable %7 Function
%17 = OpVariable %16 Function
OpStore %13 %14
OpStore %17 %18
OpBranch %19
%19 = OpLabel
OpLoopMerge %21 %22 None
OpBranch %23
%23 = OpLabel
%24 = OpLoad %15 %17
%27 = OpSLessThan %26 %24 %25
OpBranchConditional %27 %20 %21
%20 = OpLabel
%28 = OpLoad %15 %17
%30 = OpSMod %15 %28 %29
%32 = OpIEqual %26 %30 %31
OpSelectionMerge %34 None
OpBranchConditional %32 %33 %38
%33 = OpLabel
%36 = OpLoad %6 %13
%37 = OpFAdd %6 %36 %35
OpStore %13 %37
OpBranch %34
%38 = OpLabel
%39 = OpLoad %15 %17
%40 = OpConvertSToF %6 %39
%41 = OpLoad %6 %10
%42 = OpExtInst %6 %1 Round %41
%43 = OpFMod %6 %40 %42
%45 = OpFOrdLessThanEqual %26 %43 %44
OpSelectionMerge %47 None
OpBranchConditional %45 %46 %47
%46 = OpLabel
%49 = OpLoad %6 %13
%50 = OpFAdd %6 %49 %48
OpStore %13 %50
OpBranch %47
%47 = OpLabel
OpBranch %34
%34 = OpLabel
%51 = OpLoad %15 %17
%52 = OpConvertSToF %6 %51
%53 = OpLoad %6 %9
%54 = OpFOrdGreaterThanEqual %26 %52 %53
OpSelectionMerge %56 None
OpBranchConditional %54 %55 %56
%55 = OpLabel
%57 = OpLoad %6 %13
OpReturnValue %57
%56 = OpLabel
OpBranch %22
%22 = OpLabel
%59 = OpLoad %15 %17
%60 = OpIAdd %15 %59 %18
OpStore %17 %60
OpBranch %19
%21 = OpLabel
%61 = OpLoad %6 %13
OpReturnValue %61
OpFunctionEnd
END
# uniforms for variant
# resolution
BUFFER variant_resolution DATA_TYPE vec2<float> DATA
256.0 256.0
END
# injectionSwitch
BUFFER variant_injectionSwitch DATA_TYPE vec2<float> DATA
1.0 0.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_resolution AS uniform DESCRIPTOR_SET 0 BINDING 0
BIND BUFFER variant_injectionSwitch AS uniform DESCRIPTOR_SET 0 BINDING 1
END
CLEAR_COLOR variant_pipeline 0 0 0 255
CLEAR variant_pipeline
RUN variant_pipeline DRAW_RECT POS 0 0 SIZE 256 256
EXPECT reference_framebuffer EQ_HISTOGRAM_EMD_BUFFER variant_framebuffer TOLERANCE 0.005