Fix matrixCompMult halfNxM implementation and add unit tests.

The existing code didn't work properly with half types since the $mat
type encompassed both halfNxM and floatNxM. This was fixed by splitting
the half types out of $mat into a separate $matH generic.

Unit tests now compile properly for GLSL, but generate errors in SPIR-V
and generate Metal code which attempts to call a non-existent intrinsic.

Change-Id: I2fff10f0dd7f00534bf6b1d5b13354543694194e
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/342926
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
This commit is contained in:
John Stiles 2020-12-10 12:54:31 -05:00
parent fb018a8d80
commit d06d4a983f
9 changed files with 2755 additions and 2689 deletions

View File

@ -244,6 +244,7 @@ sksl_shared_tests = [
"$_tests/sksl/intrinsics/LessThanEqual.sksl",
"$_tests/sksl/intrinsics/Log.sksl",
"$_tests/sksl/intrinsics/Log2.sksl",
"$_tests/sksl/intrinsics/MatrixCompMult.sksl",
"$_tests/sksl/intrinsics/Max.sksl",
"$_tests/sksl/intrinsics/Min.sksl",
"$_tests/sksl/intrinsics/Mix.sksl",

View File

@ -119,7 +119,7 @@ Compiler::Compiler(const ShaderCapsClass* caps, Flags flags)
TYPE(Half4x2), TYPE(Half4x3), TYPE(Half4x4),
TYPE(GenType), TYPE(GenHType), TYPE(GenIType), TYPE(GenUType), TYPE(GenBType),
TYPE(Mat), TYPE(Vec),
TYPE(Mat), TYPE(MatH), TYPE(Vec),
TYPE(GVec), TYPE(GVec2), TYPE(GVec3), TYPE(GVec4),
TYPE(HVec), TYPE(IVec), TYPE(UVec), TYPE(SVec), TYPE(USVec),
TYPE(ByteVec), TYPE(UByteVec), TYPE(BVec),

View File

@ -153,15 +153,16 @@ public:
fUInt3_Type.get(), fUInt4_Type.get() }))
, fGenBType_Type(new Type("$genBType", { fBool_Type.get(), fBool2_Type.get(),
fBool3_Type.get(), fBool4_Type.get() }))
, fMat_Type(new Type("$mat", { fFloat2x2_Type.get(), fFloat2x3_Type.get(),
fFloat2x4_Type.get(), fFloat3x2_Type.get(),
fFloat3x3_Type.get(), fFloat3x4_Type.get(),
fFloat4x2_Type.get(), fFloat4x3_Type.get(),
fFloat4x4_Type.get(), fHalf2x2_Type.get(),
fHalf2x3_Type.get(), fHalf2x4_Type.get(),
fHalf3x2_Type.get(), fHalf3x3_Type.get(),
fHalf3x4_Type.get(), fHalf4x2_Type.get(),
fHalf4x3_Type.get(), fHalf4x4_Type.get() }))
, fMat_Type(new Type("$mat", { fFloat2x2_Type.get(), fFloat2x3_Type.get(),
fFloat2x4_Type.get(), fFloat3x2_Type.get(),
fFloat3x3_Type.get(), fFloat3x4_Type.get(),
fFloat4x2_Type.get(), fFloat4x3_Type.get(),
fFloat4x4_Type.get() }))
, fMatH_Type(new Type("$matH", { fHalf2x2_Type.get(), fHalf2x3_Type.get(),
fHalf2x4_Type.get(), fHalf3x2_Type.get(),
fHalf3x3_Type.get(), fHalf3x4_Type.get(),
fHalf4x2_Type.get(), fHalf4x3_Type.get(),
fHalf4x4_Type.get() }))
, fVec_Type(new Type("$vec", { fInvalid_Type.get(), fFloat2_Type.get(),
fFloat3_Type.get(), fFloat4_Type.get() }))
, fGVec_Type(new Type("$gvec"))
@ -322,6 +323,7 @@ public:
const std::unique_ptr<Type> fGenBType_Type;
const std::unique_ptr<Type> fMat_Type;
const std::unique_ptr<Type> fMatH_Type;
const std::unique_ptr<Type> fVec_Type;

File diff suppressed because it is too large Load Diff

View File

@ -143,6 +143,7 @@ $genHType reflect($genHType I, $genHType N);
$genType refract($genType I, $genType N, float eta);
$genHType refract($genHType I, $genHType N, float eta);
$mat matrixCompMult($mat x, $mat y);
$matH matrixCompMult($matH x, $matH y);
float2x2 outerProduct(float2 c, float2 r);
float3x3 outerProduct(float3 c, float3 r);
float4x3 outerProduct(float4 c, float4 r);

View File

@ -0,0 +1,6 @@
half3x3 a, b;
float4x4 c, d;
void main() {
sk_FragColor.xyz = matrixCompMult(a, b)[0];
sk_FragColor = half4(matrixCompMult(c, d)[0]);
}

View File

@ -0,0 +1,5 @@
### Compilation failed:
error: 4: unsupported intrinsic '$matH matrixCompMult($matH, $matH)'
error: 5: unsupported intrinsic '$mat matrixCompMult($mat, $mat)'
2 errors

View File

@ -0,0 +1,10 @@
out vec4 sk_FragColor;
mat3 a;
mat3 b;
mat4 c;
mat4 d;
void main() {
sk_FragColor.xyz = matrixCompMult(a, b)[0];
sk_FragColor = matrixCompMult(c, d)[0];
}

View File

@ -0,0 +1,28 @@
#include <metal_stdlib>
#include <simd/simd.h>
using namespace metal;
struct Inputs {
};
struct Outputs {
float4 sk_FragColor [[color(0)]];
};
struct Globals {
float3x3 a;
float3x3 b;
float4x4 c;
float4x4 d;
};
fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
Globals globalStruct{{}, {}, {}, {}};
thread Globals* _globals = &globalStruct;
(void)_globals;
Outputs _outputStruct;
thread Outputs* _out = &_outputStruct;
_out->sk_FragColor.xyz = matrixCompMult(_globals->a, _globals->b)[0];
_out->sk_FragColor = matrixCompMult(_globals->c, _globals->d)[0];
return *_out;
}