Add float-packing intrinsics from sksl_gpu to Metal.
It turned out that Metal had equivalent intrinsics/casts all along; we just needed to emit them. Tests will be improved in a followup CL which adds the ES3-compatible packing intrinsics into sksl_public. Change-Id: Iec8a20b9f9fe9b1badea2944eb0b1f0a17c74560 Bug: skia:12351 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/446744 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:
parent
51f9512928
commit
b6981fb6a4
@ -595,7 +595,66 @@ bool MetalCodeGenerator::writeIntrinsicCall(const FunctionCall& c, IntrinsicKind
|
||||
this->write(")");
|
||||
return true;
|
||||
}
|
||||
|
||||
case k_packUnorm2x16_IntrinsicKind: {
|
||||
this->write("pack_float_to_unorm2x16(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write(")");
|
||||
return true;
|
||||
}
|
||||
case k_unpackUnorm2x16_IntrinsicKind: {
|
||||
this->write("unpack_unorm2x16_to_float(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write(")");
|
||||
return true;
|
||||
}
|
||||
case k_packSnorm2x16_IntrinsicKind: {
|
||||
this->write("pack_float_to_snorm2x16(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write(")");
|
||||
return true;
|
||||
}
|
||||
case k_unpackSnorm2x16_IntrinsicKind: {
|
||||
this->write("unpack_snorm2x16_to_float(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write(")");
|
||||
return true;
|
||||
}
|
||||
case k_packUnorm4x8_IntrinsicKind: {
|
||||
this->write("pack_float_to_unorm4x8(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write(")");
|
||||
return true;
|
||||
}
|
||||
case k_unpackUnorm4x8_IntrinsicKind: {
|
||||
this->write("unpack_unorm4x8_to_float(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write(")");
|
||||
return true;
|
||||
}
|
||||
case k_packSnorm4x8_IntrinsicKind: {
|
||||
this->write("pack_float_to_snorm4x8(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write(")");
|
||||
return true;
|
||||
}
|
||||
case k_unpackSnorm4x8_IntrinsicKind: {
|
||||
this->write("unpack_snorm4x8_to_float(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write(")");
|
||||
return true;
|
||||
}
|
||||
case k_packHalf2x16_IntrinsicKind: {
|
||||
this->write("as_type<uint>(half2(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write("))");
|
||||
return true;
|
||||
}
|
||||
case k_unpackHalf2x16_IntrinsicKind: {
|
||||
this->write("float2(as_type<half2>(");
|
||||
this->writeExpression(*arguments[0], Precedence::kSequence);
|
||||
this->write("))");
|
||||
return true;
|
||||
}
|
||||
case k_floatBitsToInt_IntrinsicKind:
|
||||
case k_floatBitsToUint_IntrinsicKind:
|
||||
case k_intBitsToFloat_IntrinsicKind:
|
||||
|
@ -13,10 +13,10 @@ struct Outputs {
|
||||
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(packHalf2x16(_uniforms.a));
|
||||
_out.sk_FragColor.x = float(packUnorm2x16(_uniforms.a));
|
||||
_out.sk_FragColor.x = float(packSnorm2x16(_uniforms.a));
|
||||
_out.sk_FragColor.x = float(packUnorm4x8(_uniforms.b));
|
||||
_out.sk_FragColor.x = float(packSnorm4x8(_uniforms.b));
|
||||
_out.sk_FragColor.x = float(as_type<uint>(half2(_uniforms.a)));
|
||||
_out.sk_FragColor.x = float(pack_float_to_unorm2x16(_uniforms.a));
|
||||
_out.sk_FragColor.x = float(pack_float_to_snorm2x16(_uniforms.a));
|
||||
_out.sk_FragColor.x = float(pack_float_to_unorm4x8(_uniforms.b));
|
||||
_out.sk_FragColor.x = float(pack_float_to_snorm4x8(_uniforms.b));
|
||||
return _out;
|
||||
}
|
||||
|
@ -12,10 +12,10 @@ struct Outputs {
|
||||
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.xy = unpackHalf2x16(_uniforms.a);
|
||||
_out.sk_FragColor.xy = unpackUnorm2x16(_uniforms.a);
|
||||
_out.sk_FragColor.xy = unpackSnorm2x16(_uniforms.a);
|
||||
_out.sk_FragColor = unpackUnorm4x8(_uniforms.a);
|
||||
_out.sk_FragColor = unpackSnorm4x8(_uniforms.a);
|
||||
_out.sk_FragColor.xy = float2(as_type<half2>(_uniforms.a));
|
||||
_out.sk_FragColor.xy = unpack_unorm2x16_to_float(_uniforms.a);
|
||||
_out.sk_FragColor.xy = unpack_snorm2x16_to_float(_uniforms.a);
|
||||
_out.sk_FragColor = unpack_unorm4x8_to_float(_uniforms.a);
|
||||
_out.sk_FragColor = unpack_snorm4x8_to_float(_uniforms.a);
|
||||
return _out;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user