Use swizzles in Metal matrix helper functions.
Not a big deal necessarily, but considering using this logic in GLSL as well, and I'm less confident that your average GLSL ES driver will optimize away the separate array loads. Change-Id: I6a9f0d18c0fac138f64ad6426670f615e17f3492 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/449099 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
faf8d57fba
commit
4f1593eaee
@ -947,13 +947,14 @@ void MetalCodeGenerator::assembleMatrixFromExpressions(const AnyConstructor& cto
|
||||
int argPosition = 0;
|
||||
auto args = ctor.argumentSpan();
|
||||
|
||||
static constexpr char kSwizzle[] = "xyzw";
|
||||
const char* separator = "";
|
||||
for (int c = 0; c < columns; ++c) {
|
||||
fExtraFunctions.printf("%s%s%d(", separator, matrixType.c_str(), rows);
|
||||
separator = "), ";
|
||||
|
||||
const char* columnSeparator = "";
|
||||
for (int r = 0; r < rows; ++r) {
|
||||
for (int r = 0; r < rows;) {
|
||||
fExtraFunctions.writeText(columnSeparator);
|
||||
columnSeparator = ", ";
|
||||
|
||||
@ -962,16 +963,26 @@ void MetalCodeGenerator::assembleMatrixFromExpressions(const AnyConstructor& cto
|
||||
switch (argType.typeKind()) {
|
||||
case Type::TypeKind::kScalar: {
|
||||
fExtraFunctions.printf("x%zu", argIndex);
|
||||
++r;
|
||||
++argPosition;
|
||||
break;
|
||||
}
|
||||
case Type::TypeKind::kVector: {
|
||||
fExtraFunctions.printf("x%zu[%d]", argIndex, argPosition);
|
||||
fExtraFunctions.printf("x%zu.", argIndex);
|
||||
do {
|
||||
fExtraFunctions.write8(kSwizzle[argPosition]);
|
||||
++r;
|
||||
++argPosition;
|
||||
} while (r < rows && argPosition < argType.columns());
|
||||
break;
|
||||
}
|
||||
case Type::TypeKind::kMatrix: {
|
||||
fExtraFunctions.printf("x%zu[%d][%d]", argIndex,
|
||||
argPosition / argType.rows(),
|
||||
argPosition % argType.rows());
|
||||
fExtraFunctions.printf("x%zu[%d].", argIndex, argPosition / argType.rows());
|
||||
do {
|
||||
fExtraFunctions.write8(kSwizzle[argPosition]);
|
||||
++r;
|
||||
++argPosition;
|
||||
} while (r < rows && (argPosition % argType.rows()) != 0);
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
@ -981,7 +992,6 @@ void MetalCodeGenerator::assembleMatrixFromExpressions(const AnyConstructor& cto
|
||||
}
|
||||
}
|
||||
|
||||
++argPosition;
|
||||
if (argPosition >= argType.columns() * argType.rows()) {
|
||||
++argIndex;
|
||||
argPosition = 0;
|
||||
|
@ -28,7 +28,7 @@ matrix<float, C, R> matrixCompMult(matrix<float, C, R> a, const matrix<float, C,
|
||||
return a;
|
||||
}
|
||||
float4x2 float4x2_from_float4_float4(float4 x0, float4 x1) {
|
||||
return float4x2(float2(x0[0], x0[1]), float2(x0[2], x0[3]), float2(x1[0], x1[1]), float2(x1[2], x1[3]));
|
||||
return float4x2(float2(x0.xy), float2(x0.zw), float2(x1.xy), float2(x1.zw));
|
||||
}
|
||||
thread bool operator==(const float2x4 left, const float2x4 right) {
|
||||
return all(left[0] == right[0]) &&
|
||||
|
@ -32,7 +32,7 @@ thread bool operator!=(const float2x2 left, const float2x2 right) {
|
||||
return !(left == right);
|
||||
}
|
||||
float2x2 float2x2_from_float3_float(float3 x0, float x1) {
|
||||
return float2x2(float2(x0[0], x0[1]), float2(x0[2], x1));
|
||||
return float2x2(float2(x0.xy), float2(x0.z, x1));
|
||||
}
|
||||
thread bool operator==(const float3x3 left, const float3x3 right) {
|
||||
return all(left[0] == right[0]) &&
|
||||
@ -43,7 +43,7 @@ thread bool operator!=(const float3x3 left, const float3x3 right) {
|
||||
return !(left == right);
|
||||
}
|
||||
float3x3 float3x3_from_float2_float2_float4_float(float2 x0, float2 x1, float4 x2, float x3) {
|
||||
return float3x3(float3(x0[0], x0[1], x1[0]), float3(x1[1], x2[0], x2[1]), float3(x2[2], x2[3], x3));
|
||||
return float3x3(float3(x0.xy, x1.x), float3(x1.y, x2.xy), float3(x2.zw, x3));
|
||||
}
|
||||
thread bool operator==(const float4x4 left, const float4x4 right) {
|
||||
return all(left[0] == right[0]) &&
|
||||
@ -55,7 +55,7 @@ thread bool operator!=(const float4x4 left, const float4x4 right) {
|
||||
return !(left == right);
|
||||
}
|
||||
float4x4 float4x4_from_float2_float4_float3_float2_float4_float(float2 x0, float4 x1, float3 x2, float2 x3, float4 x4, float x5) {
|
||||
return float4x4(float4(x0[0], x0[1], x1[0], x1[1]), float4(x1[2], x1[3], x2[0], x2[1]), float4(x2[2], x3[0], x3[1], x4[0]), float4(x4[1], x4[2], x4[3], x5));
|
||||
return float4x4(float4(x0.xy, x1.xy), float4(x1.zw, x2.xy), float4(x2.z, x3.xy, x4.x), float4(x4.yzw, x5));
|
||||
}
|
||||
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
||||
Outputs _out;
|
||||
|
@ -38,7 +38,7 @@ thread bool operator!=(const float2x3 left, const float2x3 right) {
|
||||
return !(left == right);
|
||||
}
|
||||
float2x3 float2x3_from_float4_float2(float4 x0, float2 x1) {
|
||||
return float2x3(float3(x0[0], x0[1], x0[2]), float3(x0[3], x1[0], x1[1]));
|
||||
return float2x3(float3(x0.xyz), float3(x0.w, x1.xy));
|
||||
}
|
||||
thread bool operator==(const float2x4 left, const float2x4 right) {
|
||||
return all(left[0] == right[0]) &&
|
||||
@ -48,7 +48,7 @@ thread bool operator!=(const float2x4 left, const float2x4 right) {
|
||||
return !(left == right);
|
||||
}
|
||||
float2x4 float2x4_from_float3_float4_float(float3 x0, float4 x1, float x2) {
|
||||
return float2x4(float4(x0[0], x0[1], x0[2], x1[0]), float4(x1[1], x1[2], x1[3], x2));
|
||||
return float2x4(float4(x0.xyz, x1.x), float4(x1.yzw, x2));
|
||||
}
|
||||
thread bool operator==(const float3x3 left, const float3x3 right) {
|
||||
return all(left[0] == right[0]) &&
|
||||
@ -59,7 +59,7 @@ thread bool operator!=(const float3x3 left, const float3x3 right) {
|
||||
return !(left == right);
|
||||
}
|
||||
float3x3 float3x3_from_float2_float2_float4_float(float2 x0, float2 x1, float4 x2, float x3) {
|
||||
return float3x3(float3(x0[0], x0[1], x1[0]), float3(x1[1], x2[0], x2[1]), float3(x2[2], x2[3], x3));
|
||||
return float3x3(float3(x0.xy, x1.x), float3(x1.y, x2.xy), float3(x2.zw, x3));
|
||||
}
|
||||
thread bool operator==(const float4x2 left, const float4x2 right) {
|
||||
return all(left[0] == right[0]) &&
|
||||
@ -71,7 +71,7 @@ thread bool operator!=(const float4x2 left, const float4x2 right) {
|
||||
return !(left == right);
|
||||
}
|
||||
float4x2 float4x2_from_float3_float4_float(float3 x0, float4 x1, float x2) {
|
||||
return float4x2(float2(x0[0], x0[1]), float2(x0[2], x1[0]), float2(x1[1], x1[2]), float2(x1[3], x2));
|
||||
return float4x2(float2(x0.xy), float2(x0.z, x1.x), float2(x1.yz), float2(x1.w, x2));
|
||||
}
|
||||
thread bool operator==(const float4x3 left, const float4x3 right) {
|
||||
return all(left[0] == right[0]) &&
|
||||
@ -83,7 +83,7 @@ thread bool operator!=(const float4x3 left, const float4x3 right) {
|
||||
return !(left == right);
|
||||
}
|
||||
float4x3 float4x3_from_float_float4_float4_float3(float x0, float4 x1, float4 x2, float3 x3) {
|
||||
return float4x3(float3(x0, x1[0], x1[1]), float3(x1[2], x1[3], x2[0]), float3(x2[1], x2[2], x2[3]), float3(x3[0], x3[1], x3[2]));
|
||||
return float4x3(float3(x0, x1.xy), float3(x1.zw, x2.x), float3(x2.yzw), float3(x3.xyz));
|
||||
}
|
||||
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
||||
Outputs _out;
|
||||
|
@ -22,7 +22,7 @@ thread bool operator!=(const float2x2 left, const float2x2 right) {
|
||||
return !(left == right);
|
||||
}
|
||||
float2x2 float2x2_from_float4(float4 x0) {
|
||||
return float2x2(float2(x0[0], x0[1]), float2(x0[2], x0[3]));
|
||||
return float2x2(float2(x0.xy), float2(x0.zw));
|
||||
}
|
||||
fragment Outputs fragmentMain(Inputs _in [[stage_in]], constant Uniforms& _uniforms [[buffer(0)]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
|
||||
Outputs _out;
|
||||
|
Loading…
Reference in New Issue
Block a user