Add floatBitsToInt family of ES3 intrinsics to SkSL public ES3.

These now have proper testing and compile-time optimization support.

Change-Id: I7978161ec126e1c3096b9ca9dfbb2be7d8ea02f5
Bug: skia:12202
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/440859
Commit-Queue: John Stiles <johnstiles@google.com>
Commit-Queue: Brian Osman <brianosman@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
John Stiles 2021-08-20 10:10:02 -04:00 committed by SkCQ
parent 55dc5c8325
commit b39236bc0f
20 changed files with 1404 additions and 745 deletions

View File

@ -1 +1,20 @@
uniform float a; void main() { sk_FragColor.x = half(floatBitsToInt(a)); }
uniform float testInput;
uniform float2x2 testMatrix2x2;
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
const float4 constVal = float4(-1, 0, 1, 2);
const int4 expectedA = int4(-0x40800000, 0x00000000, 0x3F800000, 0x40000000);
float4 input = float4(testMatrix2x2) * float4(1, 1, -1, -1);
const int4 expectedB = int4(0x3F800000, 0x40000000, -0x3FC00000, -0x3F800000);
return (floatBitsToInt(constVal.x) == expectedA.x &&
floatBitsToInt(constVal.xy) == expectedA.xy &&
floatBitsToInt(constVal.xyz) == expectedA.xyz &&
floatBitsToInt(constVal.xyzw) == expectedA.xyzw &&
floatBitsToInt(input.x) == expectedB.x &&
floatBitsToInt(input.xy) == expectedB.xy &&
floatBitsToInt(input.xyz) == expectedB.xyz &&
floatBitsToInt(input.xyzw) == expectedB.xyzw) ? colorGreen : colorRed;
}

View File

@ -1 +1,20 @@
uniform float a; void main() { sk_FragColor.x = half(floatBitsToUint(a)); }
uniform float testInput;
uniform float2x2 testMatrix2x2;
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
const float4 constVal = float4(-1, 0, 1, 2);
const uint4 expectedA = uint4(0xBF800000, 0x00000000, 0x3F800000, 0x40000000);
float4 input = float4(testMatrix2x2) * float4(1, 1, -1, -1);
const uint4 expectedB = uint4(0x3F800000, 0x40000000, 0xC0400000, 0xC0800000);
return (floatBitsToUint(constVal.x) == expectedA.x &&
floatBitsToUint(constVal.xy) == expectedA.xy &&
floatBitsToUint(constVal.xyz) == expectedA.xyz &&
floatBitsToUint(constVal.xyzw) == expectedA.xyzw &&
floatBitsToUint(input.x) == expectedB.x &&
floatBitsToUint(input.xy) == expectedB.xy &&
floatBitsToUint(input.xyz) == expectedB.xyz &&
floatBitsToUint(input.xyzw) == expectedB.xyzw) ? colorGreen : colorRed;
}

View File

@ -1 +1,20 @@
uniform int a; void main() { sk_FragColor.x = half(intBitsToFloat(a)); }
uniform float testInput;
uniform float2x2 testMatrix2x2;
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
const float4 constVal = float4(-1, 0, 1, 2);
const int4 expectedA = int4(-0x40800000, 0x00000000, 0x3F800000, 0x40000000);
float4 input = float4(testMatrix2x2) * float4(1, 1, -1, -1);
int4 expectedB = int4(0x3F800000, 0x40000000, -0x3FC00000, -0x3F800000);
return (constVal.x == intBitsToFloat(expectedA.x) &&
constVal.xy == intBitsToFloat(expectedA.xy) &&
constVal.xyz == intBitsToFloat(expectedA.xyz) &&
constVal.xyzw == intBitsToFloat(expectedA.xyzw) &&
input.x == intBitsToFloat(expectedB.x) &&
input.xy == intBitsToFloat(expectedB.xy) &&
input.xyz == intBitsToFloat(expectedB.xyz) &&
input.xyzw == intBitsToFloat(expectedB.xyzw)) ? colorGreen : colorRed;
}

View File

@ -1 +1,20 @@
uniform uint a; void main() { sk_FragColor.x = half(uintBitsToFloat(a)); }
uniform float testInput;
uniform float2x2 testMatrix2x2;
uniform half4 colorGreen, colorRed;
half4 main(float2 coords) {
const float4 constVal = float4(-1, 0, 1, 2);
const uint4 expectedA = uint4(0xBF800000, 0x00000000, 0x3F800000, 0x40000000);
float4 input = float4(testMatrix2x2) * float4(1, 1, -1, -1);
uint4 expectedB = uint4(0x3F800000, 0x40000000, 0xC0400000, 0xC0800000);
return (constVal.x == uintBitsToFloat(expectedA.x) &&
constVal.xy == uintBitsToFloat(expectedA.xy) &&
constVal.xyz == uintBitsToFloat(expectedA.xyz) &&
constVal.xyzw == uintBitsToFloat(expectedA.xyzw) &&
input.x == uintBitsToFloat(expectedB.x) &&
input.xy == uintBitsToFloat(expectedB.xy) &&
input.xyz == uintBitsToFloat(expectedB.xyz) &&
input.xyzw == uintBitsToFloat(expectedB.xyzw)) ? colorGreen : colorRed;
}

File diff suppressed because it is too large Load Diff

View File

@ -351,6 +351,18 @@ static std::unique_ptr<Expression> evaluate_3_way_intrinsic(const Context& conte
arguments[2].get(), returnType, eval);
}
template <typename T1, typename T2>
static double pun_value(double val) {
// Interpret `val` as a value of type T1.
static_assert(sizeof(T1) == sizeof(T2));
T1 inputValue = (T1)val;
// Reinterpret those bits as a value of type T2.
T2 outputValue;
memcpy(&outputValue, &inputValue, sizeof(T2));
// Return the value-of-type-T2 as a double. (Non-finite values will prohibit optimization.)
return (double)outputValue;
}
// Helper functions for optimizing all of our intrinsics.
namespace Intrinsics {
namespace {
@ -419,6 +431,10 @@ double evaluate_cosh(double a, double, double) { return std::cosh(a); }
double evaluate_tanh(double a, double, double) { return std::tanh(a); }
double evaluate_trunc(double a, double, double) { return std::trunc(a); }
double evaluate_round(double a, double, double) { return std::round(a / 2) * 2; }
double evaluate_floatBitsToInt(double a, double, double) { return pun_value<float, int32_t> (a); }
double evaluate_floatBitsToUint(double a, double, double) { return pun_value<float, uint32_t>(a); }
double evaluate_intBitsToFloat(double a, double, double) { return pun_value<int32_t, float>(a); }
double evaluate_uintBitsToFloat(double a, double, double) { return pun_value<uint32_t, float>(a); }
} // namespace
} // namespace Intrinsics
@ -741,6 +757,18 @@ static std::unique_ptr<Expression> optimize_intrinsic_call(const Context& contex
case k_roundEven_IntrinsicKind: // and is allowed to behave identically to `roundEven`.
return evaluate_intrinsic<float>(context, arguments, returnType,
Intrinsics::evaluate_round);
case k_floatBitsToInt_IntrinsicKind:
return evaluate_intrinsic<float>(context, arguments, returnType,
Intrinsics::evaluate_floatBitsToInt);
case k_floatBitsToUint_IntrinsicKind:
return evaluate_intrinsic<float>(context, arguments, returnType,
Intrinsics::evaluate_floatBitsToUint);
case k_intBitsToFloat_IntrinsicKind:
return evaluate_intrinsic<SKSL_INT>(context, arguments, returnType,
Intrinsics::evaluate_intBitsToFloat);
case k_uintBitsToFloat_IntrinsicKind:
return evaluate_intrinsic<SKSL_INT>(context, arguments, returnType,
Intrinsics::evaluate_uintBitsToFloat);
default:
return nullptr;
}

View File

@ -3,7 +3,6 @@
// See "The OpenGL ES Shading Language, Section 8"
// 8.1 : Angle and Trigonometry Functions (Version 1.0)
$genType radians($genType degrees);
$genHType radians($genHType degrees);
$genType degrees($genType radians);
@ -26,7 +25,6 @@ $genType atan($genType y_over_x);
$genHType atan($genHType y_over_x);
// 8.1 : Angle and Trigonometry Functions (Version 3.0)
$es3 $genType sinh($genType x);
$es3 $genHType sinh($genHType x);
$es3 $genType cosh($genType x);
@ -100,6 +98,12 @@ $genType smoothstep(float edge0, float edge1, $genType x);
$genHType smoothstep($genHType edge0, $genHType edge1, $genHType x);
$genHType smoothstep(half edge0, half edge1, $genHType x);
// 8.3 : Common Functions (Version 3.0)
$es3 $genIType floatBitsToInt ($genType value);
$es3 $genUType floatBitsToUint($genType value);
$es3 $genType intBitsToFloat ($genIType value);
$es3 $genType uintBitsToFloat($genUType value);
// 8.4 : Geometric Functions
float length($genType x);
half length($genHType x);

View File

@ -211,6 +211,10 @@ SKSL_TEST(SkSLIntrinsicCeil, "intrinsics/Ceil.sksl")
SKSL_TEST_ES3(SkSLIntrinsicDeterminant, "intrinsics/Determinant.sksl")
SKSL_TEST_ES3(SkSLIntrinsicDFdx, "intrinsics/DFdx.sksl")
SKSL_TEST_ES3(SkSLIntrinsicDFdy, "intrinsics/DFdy.sksl")
SKSL_TEST_ES3(SkSLIntrinsicFloatBitsToInt, "intrinsics/FloatBitsToInt.sksl")
SKSL_TEST_ES3(SkSLIntrinsicFloatBitsToUint, "intrinsics/FloatBitsToUint.sksl")
SKSL_TEST_ES3(SkSLIntrinsicIntBitsToFloat, "intrinsics/IntBitsToFloat.sksl")
SKSL_TEST_ES3(SkSLIntrinsicUintBitsToFloat, "intrinsics/UintBitsToFloat.sksl")
// TODO(johnstiles): test broken on Adreno 6xx + Vulkan
//SKSL_TEST(SkSLIntrinsicClampFloat, "intrinsics/ClampFloat.sksl")
SKSL_TEST(SkSLIntrinsicMaxFloat, "intrinsics/MaxFloat.sksl")

View File

@ -1,22 +1,37 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise
OpExecutionMode %main OriginUpperLeft
OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise
OpExecutionMode %_entrypoint_v OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "a"
OpMemberName %_UniformBuffer 0 "testInput"
OpMemberName %_UniformBuffer 1 "testMatrix2x2"
OpMemberName %_UniformBuffer 2 "colorGreen"
OpMemberName %_UniformBuffer 3 "colorRed"
OpName %_entrypoint_v "_entrypoint_v"
OpName %main "main"
OpName %input "input"
OpName %expectedB "expectedB"
OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0
OpDecorate %sk_Clockwise BuiltIn FrontFacing
OpMemberDecorate %_UniformBuffer 0 Offset 0
OpMemberDecorate %_UniformBuffer 1 Offset 16
OpMemberDecorate %_UniformBuffer 1 ColMajor
OpMemberDecorate %_UniformBuffer 1 MatrixStride 16
OpMemberDecorate %_UniformBuffer 2 Offset 48
OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision
OpMemberDecorate %_UniformBuffer 3 Offset 64
OpMemberDecorate %_UniformBuffer 3 RelaxedPrecision
OpDecorate %_UniformBuffer Block
OpDecorate %10 Binding 0
OpDecorate %10 DescriptorSet 0
OpDecorate %22 RelaxedPrecision
OpDecorate %95 RelaxedPrecision
OpDecorate %98 RelaxedPrecision
OpDecorate %99 RelaxedPrecision
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
@ -24,22 +39,117 @@ OpDecorate %22 RelaxedPrecision
%bool = OpTypeBool
%_ptr_Input_bool = OpTypePointer Input %bool
%sk_Clockwise = OpVariable %_ptr_Input_bool Input
%_UniformBuffer = OpTypeStruct %float
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%_UniformBuffer = OpTypeStruct %float %mat2v2float %v4float %v4float
%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
%10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%void = OpTypeVoid
%14 = OpTypeFunction %void
%_ptr_Uniform_float = OpTypePointer Uniform %float
%17 = OpTypeFunction %void
%float_0 = OpConstant %float 0
%20 = OpConstantComposite %v2float %float_0 %float_0
%_ptr_Function_v2float = OpTypePointer Function %v2float
%24 = OpTypeFunction %v4float %_ptr_Function_v2float
%_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_Uniform_mat2v2float = OpTypePointer Uniform %mat2v2float
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Output_float = OpTypePointer Output %float
%main = OpFunction %void None %14
%15 = OpLabel
%17 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%21 = OpLoad %float %17
%16 = OpBitcast %int %21
%22 = OpConvertSToF %float %16
%23 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
OpStore %23 %22
%int_1 = OpConstant %int 1
%float_1 = OpConstant %float 1
%float_n1 = OpConstant %float -1
%41 = OpConstantComposite %v4float %float_1 %float_1 %float_n1 %float_n1
%v4int = OpTypeVector %int 4
%_ptr_Function_v4int = OpTypePointer Function %v4int
%int_1065353216 = OpConstant %int 1065353216
%int_1073741824 = OpConstant %int 1073741824
%int_n1069547520 = OpConstant %int -1069547520
%int_n1065353216 = OpConstant %int -1065353216
%50 = OpConstantComposite %v4int %int_1065353216 %int_1073741824 %int_n1069547520 %int_n1065353216
%false = OpConstantFalse %bool
%v2int = OpTypeVector %int 2
%62 = OpConstantComposite %v2int %int_1065353216 %int_1073741824
%v2bool = OpTypeVector %bool 2
%v3float = OpTypeVector %float 3
%v3int = OpTypeVector %int 3
%74 = OpConstantComposite %v3int %int_1065353216 %int_1073741824 %int_n1069547520
%v3bool = OpTypeVector %bool 3
%v4bool = OpTypeVector %bool 4
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int_2 = OpConstant %int 2
%int_3 = OpConstant %int 3
%_entrypoint_v = OpFunction %void None %17
%18 = OpLabel
%21 = OpVariable %_ptr_Function_v2float Function
OpStore %21 %20
%23 = OpFunctionCall %v4float %main %21
OpStore %sk_FragColor %23
OpReturn
OpFunctionEnd
%main = OpFunction %v4float None %24
%25 = OpFunctionParameter %_ptr_Function_v2float
%26 = OpLabel
%input = OpVariable %_ptr_Function_v4float Function
%expectedB = OpVariable %_ptr_Function_v4int Function
%88 = OpVariable %_ptr_Function_v4float Function
%29 = OpAccessChain %_ptr_Uniform_mat2v2float %10 %int_1
%33 = OpLoad %mat2v2float %29
%34 = OpCompositeExtract %float %33 0 0
%35 = OpCompositeExtract %float %33 0 1
%36 = OpCompositeExtract %float %33 1 0
%37 = OpCompositeExtract %float %33 1 1
%38 = OpCompositeConstruct %v4float %34 %35 %36 %37
%42 = OpFMul %v4float %38 %41
OpStore %input %42
OpStore %expectedB %50
%53 = OpLoad %v4float %input
%54 = OpCompositeExtract %float %53 0
%52 = OpBitcast %int %54
%55 = OpIEqual %bool %52 %int_1065353216
OpSelectionMerge %57 None
OpBranchConditional %55 %56 %57
%56 = OpLabel
%59 = OpLoad %v4float %input
%60 = OpVectorShuffle %v2float %59 %59 0 1
%58 = OpBitcast %v2int %60
%63 = OpIEqual %v2bool %58 %62
%65 = OpAll %bool %63
OpBranch %57
%57 = OpLabel
%66 = OpPhi %bool %false %26 %65 %56
OpSelectionMerge %68 None
OpBranchConditional %66 %67 %68
%67 = OpLabel
%70 = OpLoad %v4float %input
%71 = OpVectorShuffle %v3float %70 %70 0 1 2
%69 = OpBitcast %v3int %71
%75 = OpIEqual %v3bool %69 %74
%77 = OpAll %bool %75
OpBranch %68
%68 = OpLabel
%78 = OpPhi %bool %false %57 %77 %67
OpSelectionMerge %80 None
OpBranchConditional %78 %79 %80
%79 = OpLabel
%82 = OpLoad %v4float %input
%81 = OpBitcast %v4int %82
%83 = OpLoad %v4int %expectedB
%84 = OpIEqual %v4bool %81 %83
%86 = OpAll %bool %84
OpBranch %80
%80 = OpLabel
%87 = OpPhi %bool %false %68 %86 %79
OpSelectionMerge %91 None
OpBranchConditional %87 %89 %90
%89 = OpLabel
%92 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2
%95 = OpLoad %v4float %92
OpStore %88 %95
OpBranch %91
%90 = OpLabel
%96 = OpAccessChain %_ptr_Uniform_v4float %10 %int_3
%98 = OpLoad %v4float %96
OpStore %88 %98
OpBranch %91
%91 = OpLabel
%99 = OpLoad %v4float %88
OpReturnValue %99
OpFunctionEnd

View File

@ -1,6 +1,11 @@
out vec4 sk_FragColor;
uniform float a;
void main() {
sk_FragColor.x = float(floatBitsToInt(a));
uniform float testInput;
uniform mat2 testMatrix2x2;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 input = vec4(testMatrix2x2) * vec4(1.0, 1.0, -1.0, -1.0);
const ivec4 expectedB = ivec4(1065353216, 1073741824, -1069547520, -1065353216);
return ((floatBitsToInt(input.x) == 1065353216 && floatBitsToInt(input.xy) == ivec2(1065353216, 1073741824)) && floatBitsToInt(input.xyz) == ivec3(1065353216, 1073741824, -1069547520)) && floatBitsToInt(input) == expectedB ? colorGreen : colorRed;
}

View File

@ -2,16 +2,25 @@
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
float a;
float testInput;
float2x2 testMatrix2x2;
float4 colorGreen;
float4 colorRed;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
float4 float4_from_float2x2(float2x2 x) {
return float4(x[0].xy, x[1].xy);
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
_out.sk_FragColor.x = float(as_type<int>(_uniforms.a));
float4 input = float4_from_float2x2(_uniforms.testMatrix2x2) * float4(1.0, 1.0, -1.0, -1.0);
const int4 expectedB = int4(1065353216, 1073741824, -1069547520, -1065353216);
_out.sk_FragColor = ((as_type<int>(input.x) == 1065353216 && all(as_type<int2>(input.xy) == int2(1065353216, 1073741824))) && all(as_type<int3>(input.xyz) == int3(1065353216, 1073741824, -1069547520))) && all(as_type<int4>(input) == expectedB) ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}

View File

@ -1,22 +1,37 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise
OpExecutionMode %main OriginUpperLeft
OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise
OpExecutionMode %_entrypoint_v OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "a"
OpMemberName %_UniformBuffer 0 "testInput"
OpMemberName %_UniformBuffer 1 "testMatrix2x2"
OpMemberName %_UniformBuffer 2 "colorGreen"
OpMemberName %_UniformBuffer 3 "colorRed"
OpName %_entrypoint_v "_entrypoint_v"
OpName %main "main"
OpName %input "input"
OpName %expectedB "expectedB"
OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0
OpDecorate %sk_Clockwise BuiltIn FrontFacing
OpMemberDecorate %_UniformBuffer 0 Offset 0
OpMemberDecorate %_UniformBuffer 1 Offset 16
OpMemberDecorate %_UniformBuffer 1 ColMajor
OpMemberDecorate %_UniformBuffer 1 MatrixStride 16
OpMemberDecorate %_UniformBuffer 2 Offset 48
OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision
OpMemberDecorate %_UniformBuffer 3 Offset 64
OpMemberDecorate %_UniformBuffer 3 RelaxedPrecision
OpDecorate %_UniformBuffer Block
OpDecorate %10 Binding 0
OpDecorate %10 DescriptorSet 0
OpDecorate %23 RelaxedPrecision
OpDecorate %96 RelaxedPrecision
OpDecorate %99 RelaxedPrecision
OpDecorate %100 RelaxedPrecision
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
@ -24,23 +39,118 @@ OpDecorate %23 RelaxedPrecision
%bool = OpTypeBool
%_ptr_Input_bool = OpTypePointer Input %bool
%sk_Clockwise = OpVariable %_ptr_Input_bool Input
%_UniformBuffer = OpTypeStruct %float
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%_UniformBuffer = OpTypeStruct %float %mat2v2float %v4float %v4float
%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
%10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%void = OpTypeVoid
%14 = OpTypeFunction %void
%_ptr_Uniform_float = OpTypePointer Uniform %float
%17 = OpTypeFunction %void
%float_0 = OpConstant %float 0
%20 = OpConstantComposite %v2float %float_0 %float_0
%_ptr_Function_v2float = OpTypePointer Function %v2float
%24 = OpTypeFunction %v4float %_ptr_Function_v2float
%_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_Uniform_mat2v2float = OpTypePointer Uniform %mat2v2float
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%int_1 = OpConstant %int 1
%float_1 = OpConstant %float 1
%float_n1 = OpConstant %float -1
%41 = OpConstantComposite %v4float %float_1 %float_1 %float_n1 %float_n1
%uint = OpTypeInt 32 0
%_ptr_Output_float = OpTypePointer Output %float
%main = OpFunction %void None %14
%15 = OpLabel
%17 = OpAccessChain %_ptr_Uniform_float %10 %int_0
%21 = OpLoad %float %17
%16 = OpBitcast %uint %21
%23 = OpConvertUToF %float %16
%24 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
OpStore %24 %23
%v4uint = OpTypeVector %uint 4
%_ptr_Function_v4uint = OpTypePointer Function %v4uint
%uint_1065353216 = OpConstant %uint 1065353216
%uint_1073741824 = OpConstant %uint 1073741824
%uint_3225419776 = OpConstant %uint 3225419776
%uint_3229614080 = OpConstant %uint 3229614080
%51 = OpConstantComposite %v4uint %uint_1065353216 %uint_1073741824 %uint_3225419776 %uint_3229614080
%false = OpConstantFalse %bool
%v2uint = OpTypeVector %uint 2
%63 = OpConstantComposite %v2uint %uint_1065353216 %uint_1073741824
%v2bool = OpTypeVector %bool 2
%v3float = OpTypeVector %float 3
%v3uint = OpTypeVector %uint 3
%75 = OpConstantComposite %v3uint %uint_1065353216 %uint_1073741824 %uint_3225419776
%v3bool = OpTypeVector %bool 3
%v4bool = OpTypeVector %bool 4
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int_2 = OpConstant %int 2
%int_3 = OpConstant %int 3
%_entrypoint_v = OpFunction %void None %17
%18 = OpLabel
%21 = OpVariable %_ptr_Function_v2float Function
OpStore %21 %20
%23 = OpFunctionCall %v4float %main %21
OpStore %sk_FragColor %23
OpReturn
OpFunctionEnd
%main = OpFunction %v4float None %24
%25 = OpFunctionParameter %_ptr_Function_v2float
%26 = OpLabel
%input = OpVariable %_ptr_Function_v4float Function
%expectedB = OpVariable %_ptr_Function_v4uint Function
%89 = OpVariable %_ptr_Function_v4float Function
%29 = OpAccessChain %_ptr_Uniform_mat2v2float %10 %int_1
%33 = OpLoad %mat2v2float %29
%34 = OpCompositeExtract %float %33 0 0
%35 = OpCompositeExtract %float %33 0 1
%36 = OpCompositeExtract %float %33 1 0
%37 = OpCompositeExtract %float %33 1 1
%38 = OpCompositeConstruct %v4float %34 %35 %36 %37
%42 = OpFMul %v4float %38 %41
OpStore %input %42
OpStore %expectedB %51
%54 = OpLoad %v4float %input
%55 = OpCompositeExtract %float %54 0
%53 = OpBitcast %uint %55
%56 = OpIEqual %bool %53 %uint_1065353216
OpSelectionMerge %58 None
OpBranchConditional %56 %57 %58
%57 = OpLabel
%60 = OpLoad %v4float %input
%61 = OpVectorShuffle %v2float %60 %60 0 1
%59 = OpBitcast %v2uint %61
%64 = OpIEqual %v2bool %59 %63
%66 = OpAll %bool %64
OpBranch %58
%58 = OpLabel
%67 = OpPhi %bool %false %26 %66 %57
OpSelectionMerge %69 None
OpBranchConditional %67 %68 %69
%68 = OpLabel
%71 = OpLoad %v4float %input
%72 = OpVectorShuffle %v3float %71 %71 0 1 2
%70 = OpBitcast %v3uint %72
%76 = OpIEqual %v3bool %70 %75
%78 = OpAll %bool %76
OpBranch %69
%69 = OpLabel
%79 = OpPhi %bool %false %58 %78 %68
OpSelectionMerge %81 None
OpBranchConditional %79 %80 %81
%80 = OpLabel
%83 = OpLoad %v4float %input
%82 = OpBitcast %v4uint %83
%84 = OpLoad %v4uint %expectedB
%85 = OpIEqual %v4bool %82 %84
%87 = OpAll %bool %85
OpBranch %81
%81 = OpLabel
%88 = OpPhi %bool %false %69 %87 %80
OpSelectionMerge %92 None
OpBranchConditional %88 %90 %91
%90 = OpLabel
%93 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2
%96 = OpLoad %v4float %93
OpStore %89 %96
OpBranch %92
%91 = OpLabel
%97 = OpAccessChain %_ptr_Uniform_v4float %10 %int_3
%99 = OpLoad %v4float %97
OpStore %89 %99
OpBranch %92
%92 = OpLabel
%100 = OpLoad %v4float %89
OpReturnValue %100
OpFunctionEnd

View File

@ -1,6 +1,11 @@
out vec4 sk_FragColor;
uniform float a;
void main() {
sk_FragColor.x = float(floatBitsToUint(a));
uniform float testInput;
uniform mat2 testMatrix2x2;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 input = vec4(testMatrix2x2) * vec4(1.0, 1.0, -1.0, -1.0);
const uvec4 expectedB = uvec4(1065353216u, 1073741824u, 3225419776u, 3229614080u);
return ((floatBitsToUint(input.x) == 1065353216u && floatBitsToUint(input.xy) == uvec2(1065353216u, 1073741824u)) && floatBitsToUint(input.xyz) == uvec3(1065353216u, 1073741824u, 3225419776u)) && floatBitsToUint(input) == expectedB ? colorGreen : colorRed;
}

View File

@ -2,16 +2,25 @@
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
float a;
float testInput;
float2x2 testMatrix2x2;
float4 colorGreen;
float4 colorRed;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
float4 float4_from_float2x2(float2x2 x) {
return float4(x[0].xy, x[1].xy);
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
_out.sk_FragColor.x = float(as_type<uint>(_uniforms.a));
float4 input = float4_from_float2x2(_uniforms.testMatrix2x2) * float4(1.0, 1.0, -1.0, -1.0);
const uint4 expectedB = uint4(1065353216u, 1073741824u, 3225419776u, 3229614080u);
_out.sk_FragColor = ((as_type<uint>(input.x) == 1065353216u && all(as_type<uint2>(input.xy) == uint2(1065353216u, 1073741824u))) && all(as_type<uint3>(input.xyz) == uint3(1065353216u, 1073741824u, 3225419776u))) && all(as_type<uint4>(input) == expectedB) ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}

View File

@ -1,21 +1,37 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise
OpExecutionMode %main OriginUpperLeft
OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise
OpExecutionMode %_entrypoint_v OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "a"
OpMemberName %_UniformBuffer 0 "testInput"
OpMemberName %_UniformBuffer 1 "testMatrix2x2"
OpMemberName %_UniformBuffer 2 "colorGreen"
OpMemberName %_UniformBuffer 3 "colorRed"
OpName %_entrypoint_v "_entrypoint_v"
OpName %main "main"
OpName %input "input"
OpName %expectedB "expectedB"
OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0
OpDecorate %sk_Clockwise BuiltIn FrontFacing
OpMemberDecorate %_UniformBuffer 0 Offset 0
OpMemberDecorate %_UniformBuffer 1 Offset 16
OpMemberDecorate %_UniformBuffer 1 ColMajor
OpMemberDecorate %_UniformBuffer 1 MatrixStride 16
OpMemberDecorate %_UniformBuffer 2 Offset 48
OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision
OpMemberDecorate %_UniformBuffer 3 Offset 64
OpMemberDecorate %_UniformBuffer 3 RelaxedPrecision
OpDecorate %_UniformBuffer Block
OpDecorate %10 Binding 0
OpDecorate %10 DescriptorSet 0
OpDecorate %99 RelaxedPrecision
OpDecorate %102 RelaxedPrecision
OpDecorate %103 RelaxedPrecision
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
@ -23,21 +39,121 @@ OpDecorate %10 DescriptorSet 0
%bool = OpTypeBool
%_ptr_Input_bool = OpTypePointer Input %bool
%sk_Clockwise = OpVariable %_ptr_Input_bool Input
%int = OpTypeInt 32 1
%_UniformBuffer = OpTypeStruct %int
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%_UniformBuffer = OpTypeStruct %float %mat2v2float %v4float %v4float
%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
%10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%void = OpTypeVoid
%15 = OpTypeFunction %void
%_ptr_Uniform_int = OpTypePointer Uniform %int
%int_0 = OpConstant %int 0
%_ptr_Output_float = OpTypePointer Output %float
%main = OpFunction %void None %15
%16 = OpLabel
%18 = OpAccessChain %_ptr_Uniform_int %10 %int_0
%21 = OpLoad %int %18
%17 = OpBitcast %float %21
%22 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
OpStore %22 %17
%17 = OpTypeFunction %void
%float_0 = OpConstant %float 0
%20 = OpConstantComposite %v2float %float_0 %float_0
%_ptr_Function_v2float = OpTypePointer Function %v2float
%24 = OpTypeFunction %v4float %_ptr_Function_v2float
%_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_Uniform_mat2v2float = OpTypePointer Uniform %mat2v2float
%int = OpTypeInt 32 1
%int_1 = OpConstant %int 1
%float_1 = OpConstant %float 1
%float_n1 = OpConstant %float -1
%41 = OpConstantComposite %v4float %float_1 %float_1 %float_n1 %float_n1
%v4int = OpTypeVector %int 4
%_ptr_Function_v4int = OpTypePointer Function %v4int
%int_1065353216 = OpConstant %int 1065353216
%int_1073741824 = OpConstant %int 1073741824
%int_n1069547520 = OpConstant %int -1069547520
%int_n1065353216 = OpConstant %int -1065353216
%50 = OpConstantComposite %v4int %int_1065353216 %int_1073741824 %int_n1069547520 %int_n1065353216
%false = OpConstantFalse %bool
%v2int = OpTypeVector %int 2
%v2bool = OpTypeVector %bool 2
%v3float = OpTypeVector %float 3
%v3int = OpTypeVector %int 3
%v3bool = OpTypeVector %bool 3
%v4bool = OpTypeVector %bool 4
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int_2 = OpConstant %int 2
%int_3 = OpConstant %int 3
%_entrypoint_v = OpFunction %void None %17
%18 = OpLabel
%21 = OpVariable %_ptr_Function_v2float Function
OpStore %21 %20
%23 = OpFunctionCall %v4float %main %21
OpStore %sk_FragColor %23
OpReturn
OpFunctionEnd
%main = OpFunction %v4float None %24
%25 = OpFunctionParameter %_ptr_Function_v2float
%26 = OpLabel
%input = OpVariable %_ptr_Function_v4float Function
%expectedB = OpVariable %_ptr_Function_v4int Function
%92 = OpVariable %_ptr_Function_v4float Function
%29 = OpAccessChain %_ptr_Uniform_mat2v2float %10 %int_1
%33 = OpLoad %mat2v2float %29
%34 = OpCompositeExtract %float %33 0 0
%35 = OpCompositeExtract %float %33 0 1
%36 = OpCompositeExtract %float %33 1 0
%37 = OpCompositeExtract %float %33 1 1
%38 = OpCompositeConstruct %v4float %34 %35 %36 %37
%42 = OpFMul %v4float %38 %41
OpStore %input %42
OpStore %expectedB %50
%52 = OpLoad %v4float %input
%53 = OpCompositeExtract %float %52 0
%55 = OpLoad %v4int %expectedB
%56 = OpCompositeExtract %int %55 0
%54 = OpBitcast %float %56
%57 = OpFOrdEqual %bool %53 %54
OpSelectionMerge %59 None
OpBranchConditional %57 %58 %59
%58 = OpLabel
%60 = OpLoad %v4float %input
%61 = OpVectorShuffle %v2float %60 %60 0 1
%63 = OpLoad %v4int %expectedB
%64 = OpVectorShuffle %v2int %63 %63 0 1
%62 = OpBitcast %v2float %64
%66 = OpFOrdEqual %v2bool %61 %62
%68 = OpAll %bool %66
OpBranch %59
%59 = OpLabel
%69 = OpPhi %bool %false %26 %68 %58
OpSelectionMerge %71 None
OpBranchConditional %69 %70 %71
%70 = OpLabel
%72 = OpLoad %v4float %input
%73 = OpVectorShuffle %v3float %72 %72 0 1 2
%76 = OpLoad %v4int %expectedB
%77 = OpVectorShuffle %v3int %76 %76 0 1 2
%75 = OpBitcast %v3float %77
%79 = OpFOrdEqual %v3bool %73 %75
%81 = OpAll %bool %79
OpBranch %71
%71 = OpLabel
%82 = OpPhi %bool %false %59 %81 %70
OpSelectionMerge %84 None
OpBranchConditional %82 %83 %84
%83 = OpLabel
%85 = OpLoad %v4float %input
%87 = OpLoad %v4int %expectedB
%86 = OpBitcast %v4float %87
%88 = OpFOrdEqual %v4bool %85 %86
%90 = OpAll %bool %88
OpBranch %84
%84 = OpLabel
%91 = OpPhi %bool %false %71 %90 %83
OpSelectionMerge %95 None
OpBranchConditional %91 %93 %94
%93 = OpLabel
%96 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2
%99 = OpLoad %v4float %96
OpStore %92 %99
OpBranch %95
%94 = OpLabel
%100 = OpAccessChain %_ptr_Uniform_v4float %10 %int_3
%102 = OpLoad %v4float %100
OpStore %92 %102
OpBranch %95
%95 = OpLabel
%103 = OpLoad %v4float %92
OpReturnValue %103
OpFunctionEnd

View File

@ -1,6 +1,11 @@
out vec4 sk_FragColor;
uniform int a;
void main() {
sk_FragColor.x = intBitsToFloat(a);
uniform float testInput;
uniform mat2 testMatrix2x2;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 input = vec4(testMatrix2x2) * vec4(1.0, 1.0, -1.0, -1.0);
ivec4 expectedB = ivec4(1065353216, 1073741824, -1069547520, -1065353216);
return ((input.x == intBitsToFloat(expectedB.x) && input.xy == intBitsToFloat(expectedB.xy)) && input.xyz == intBitsToFloat(expectedB.xyz)) && input == intBitsToFloat(expectedB) ? colorGreen : colorRed;
}

View File

@ -2,16 +2,25 @@
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
int a;
float testInput;
float2x2 testMatrix2x2;
float4 colorGreen;
float4 colorRed;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
float4 float4_from_float2x2(float2x2 x) {
return float4(x[0].xy, x[1].xy);
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
_out.sk_FragColor.x = as_type<float>(_uniforms.a);
float4 input = float4_from_float2x2(_uniforms.testMatrix2x2) * float4(1.0, 1.0, -1.0, -1.0);
int4 expectedB = int4(1065353216, 1073741824, -1069547520, -1065353216);
_out.sk_FragColor = ((input.x == as_type<float>(expectedB.x) && all(input.xy == as_type<float2>(expectedB.xy))) && all(input.xyz == as_type<float3>(expectedB.xyz))) && all(input == as_type<float4>(expectedB)) ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}

View File

@ -1,21 +1,37 @@
OpCapability Shader
%1 = OpExtInstImport "GLSL.std.450"
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main" %sk_FragColor %sk_Clockwise
OpExecutionMode %main OriginUpperLeft
OpEntryPoint Fragment %_entrypoint_v "_entrypoint" %sk_FragColor %sk_Clockwise
OpExecutionMode %_entrypoint_v OriginUpperLeft
OpName %sk_FragColor "sk_FragColor"
OpName %sk_Clockwise "sk_Clockwise"
OpName %_UniformBuffer "_UniformBuffer"
OpMemberName %_UniformBuffer 0 "a"
OpMemberName %_UniformBuffer 0 "testInput"
OpMemberName %_UniformBuffer 1 "testMatrix2x2"
OpMemberName %_UniformBuffer 2 "colorGreen"
OpMemberName %_UniformBuffer 3 "colorRed"
OpName %_entrypoint_v "_entrypoint_v"
OpName %main "main"
OpName %input "input"
OpName %expectedB "expectedB"
OpDecorate %sk_FragColor RelaxedPrecision
OpDecorate %sk_FragColor Location 0
OpDecorate %sk_FragColor Index 0
OpDecorate %sk_Clockwise BuiltIn FrontFacing
OpMemberDecorate %_UniformBuffer 0 Offset 0
OpMemberDecorate %_UniformBuffer 1 Offset 16
OpMemberDecorate %_UniformBuffer 1 ColMajor
OpMemberDecorate %_UniformBuffer 1 MatrixStride 16
OpMemberDecorate %_UniformBuffer 2 Offset 48
OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision
OpMemberDecorate %_UniformBuffer 3 Offset 64
OpMemberDecorate %_UniformBuffer 3 RelaxedPrecision
OpDecorate %_UniformBuffer Block
OpDecorate %10 Binding 0
OpDecorate %10 DescriptorSet 0
OpDecorate %100 RelaxedPrecision
OpDecorate %103 RelaxedPrecision
OpDecorate %104 RelaxedPrecision
%float = OpTypeFloat 32
%v4float = OpTypeVector %float 4
%_ptr_Output_v4float = OpTypePointer Output %v4float
@ -23,22 +39,122 @@ OpDecorate %10 DescriptorSet 0
%bool = OpTypeBool
%_ptr_Input_bool = OpTypePointer Input %bool
%sk_Clockwise = OpVariable %_ptr_Input_bool Input
%uint = OpTypeInt 32 0
%_UniformBuffer = OpTypeStruct %uint
%v2float = OpTypeVector %float 2
%mat2v2float = OpTypeMatrix %v2float 2
%_UniformBuffer = OpTypeStruct %float %mat2v2float %v4float %v4float
%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
%10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
%void = OpTypeVoid
%15 = OpTypeFunction %void
%_ptr_Uniform_uint = OpTypePointer Uniform %uint
%17 = OpTypeFunction %void
%float_0 = OpConstant %float 0
%20 = OpConstantComposite %v2float %float_0 %float_0
%_ptr_Function_v2float = OpTypePointer Function %v2float
%24 = OpTypeFunction %v4float %_ptr_Function_v2float
%_ptr_Function_v4float = OpTypePointer Function %v4float
%_ptr_Uniform_mat2v2float = OpTypePointer Uniform %mat2v2float
%int = OpTypeInt 32 1
%int_0 = OpConstant %int 0
%_ptr_Output_float = OpTypePointer Output %float
%main = OpFunction %void None %15
%16 = OpLabel
%18 = OpAccessChain %_ptr_Uniform_uint %10 %int_0
%22 = OpLoad %uint %18
%17 = OpBitcast %float %22
%23 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
OpStore %23 %17
%int_1 = OpConstant %int 1
%float_1 = OpConstant %float 1
%float_n1 = OpConstant %float -1
%41 = OpConstantComposite %v4float %float_1 %float_1 %float_n1 %float_n1
%uint = OpTypeInt 32 0
%v4uint = OpTypeVector %uint 4
%_ptr_Function_v4uint = OpTypePointer Function %v4uint
%uint_1065353216 = OpConstant %uint 1065353216
%uint_1073741824 = OpConstant %uint 1073741824
%uint_3225419776 = OpConstant %uint 3225419776
%uint_3229614080 = OpConstant %uint 3229614080
%51 = OpConstantComposite %v4uint %uint_1065353216 %uint_1073741824 %uint_3225419776 %uint_3229614080
%false = OpConstantFalse %bool
%v2uint = OpTypeVector %uint 2
%v2bool = OpTypeVector %bool 2
%v3float = OpTypeVector %float 3
%v3uint = OpTypeVector %uint 3
%v3bool = OpTypeVector %bool 3
%v4bool = OpTypeVector %bool 4
%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
%int_2 = OpConstant %int 2
%int_3 = OpConstant %int 3
%_entrypoint_v = OpFunction %void None %17
%18 = OpLabel
%21 = OpVariable %_ptr_Function_v2float Function
OpStore %21 %20
%23 = OpFunctionCall %v4float %main %21
OpStore %sk_FragColor %23
OpReturn
OpFunctionEnd
%main = OpFunction %v4float None %24
%25 = OpFunctionParameter %_ptr_Function_v2float
%26 = OpLabel
%input = OpVariable %_ptr_Function_v4float Function
%expectedB = OpVariable %_ptr_Function_v4uint Function
%93 = OpVariable %_ptr_Function_v4float Function
%29 = OpAccessChain %_ptr_Uniform_mat2v2float %10 %int_1
%33 = OpLoad %mat2v2float %29
%34 = OpCompositeExtract %float %33 0 0
%35 = OpCompositeExtract %float %33 0 1
%36 = OpCompositeExtract %float %33 1 0
%37 = OpCompositeExtract %float %33 1 1
%38 = OpCompositeConstruct %v4float %34 %35 %36 %37
%42 = OpFMul %v4float %38 %41
OpStore %input %42
OpStore %expectedB %51
%53 = OpLoad %v4float %input
%54 = OpCompositeExtract %float %53 0
%56 = OpLoad %v4uint %expectedB
%57 = OpCompositeExtract %uint %56 0
%55 = OpBitcast %float %57
%58 = OpFOrdEqual %bool %54 %55
OpSelectionMerge %60 None
OpBranchConditional %58 %59 %60
%59 = OpLabel
%61 = OpLoad %v4float %input
%62 = OpVectorShuffle %v2float %61 %61 0 1
%64 = OpLoad %v4uint %expectedB
%65 = OpVectorShuffle %v2uint %64 %64 0 1
%63 = OpBitcast %v2float %65
%67 = OpFOrdEqual %v2bool %62 %63
%69 = OpAll %bool %67
OpBranch %60
%60 = OpLabel
%70 = OpPhi %bool %false %26 %69 %59
OpSelectionMerge %72 None
OpBranchConditional %70 %71 %72
%71 = OpLabel
%73 = OpLoad %v4float %input
%74 = OpVectorShuffle %v3float %73 %73 0 1 2
%77 = OpLoad %v4uint %expectedB
%78 = OpVectorShuffle %v3uint %77 %77 0 1 2
%76 = OpBitcast %v3float %78
%80 = OpFOrdEqual %v3bool %74 %76
%82 = OpAll %bool %80
OpBranch %72
%72 = OpLabel
%83 = OpPhi %bool %false %60 %82 %71
OpSelectionMerge %85 None
OpBranchConditional %83 %84 %85
%84 = OpLabel
%86 = OpLoad %v4float %input
%88 = OpLoad %v4uint %expectedB
%87 = OpBitcast %v4float %88
%89 = OpFOrdEqual %v4bool %86 %87
%91 = OpAll %bool %89
OpBranch %85
%85 = OpLabel
%92 = OpPhi %bool %false %72 %91 %84
OpSelectionMerge %96 None
OpBranchConditional %92 %94 %95
%94 = OpLabel
%97 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2
%100 = OpLoad %v4float %97
OpStore %93 %100
OpBranch %96
%95 = OpLabel
%101 = OpAccessChain %_ptr_Uniform_v4float %10 %int_3
%103 = OpLoad %v4float %101
OpStore %93 %103
OpBranch %96
%96 = OpLabel
%104 = OpLoad %v4float %93
OpReturnValue %104
OpFunctionEnd

View File

@ -1,6 +1,11 @@
out vec4 sk_FragColor;
uniform uint a;
void main() {
sk_FragColor.x = uintBitsToFloat(a);
uniform float testInput;
uniform mat2 testMatrix2x2;
uniform vec4 colorGreen;
uniform vec4 colorRed;
vec4 main() {
vec4 input = vec4(testMatrix2x2) * vec4(1.0, 1.0, -1.0, -1.0);
uvec4 expectedB = uvec4(1065353216u, 1073741824u, 3225419776u, 3229614080u);
return ((input.x == uintBitsToFloat(expectedB.x) && input.xy == uintBitsToFloat(expectedB.xy)) && input.xyz == uintBitsToFloat(expectedB.xyz)) && input == uintBitsToFloat(expectedB) ? colorGreen : colorRed;
}

View File

@ -2,16 +2,25 @@
#include <simd/simd.h>
using namespace metal;
struct Uniforms {
uint a;
float testInput;
float2x2 testMatrix2x2;
float4 colorGreen;
float4 colorRed;
};
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
float4 float4_from_float2x2(float2x2 x) {
return float4(x[0].xy, x[1].xy);
}
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Outputs _out;
(void)_out;
_out.sk_FragColor.x = as_type<float>(_uniforms.a);
float4 input = float4_from_float2x2(_uniforms.testMatrix2x2) * float4(1.0, 1.0, -1.0, -1.0);
uint4 expectedB = uint4(1065353216u, 1073741824u, 3225419776u, 3229614080u);
_out.sk_FragColor = ((input.x == as_type<float>(expectedB.x) && all(input.xy == as_type<float2>(expectedB.xy))) && all(input.xyz == as_type<float3>(expectedB.xyz))) && all(input == as_type<float4>(expectedB)) ? _uniforms.colorGreen : _uniforms.colorRed;
return _out;
}