Implement determinant() in SkSL ES3 public API.

The prototype has been added sksl_public, compile-time optimization is
implemented, and test code has been improved.

Change-Id: I536d6bd7fcae437a03744941b008940bf2a3b1c1
Bug: skia:12202
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/440524
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
Commit-Queue: John Stiles <johnstiles@google.com>
diff --git a/resources/sksl/intrinsics/Determinant.sksl b/resources/sksl/intrinsics/Determinant.sksl
index 5b0f30f..a7d5956 100644
--- a/resources/sksl/intrinsics/Determinant.sksl
+++ b/resources/sksl/intrinsics/Determinant.sksl
@@ -1 +1,9 @@
-half4x4 a; void main() { sk_FragColor.x = determinant(a); }
+uniform float2x2 testMatrix2x2;
+uniform half4 colorGreen, colorRed;
+
+half4 main(float2 coords) {
+    return (determinant(testMatrix2x2) == -2 &&
+            determinant(half3x3(1, 2, 3, 4, 5, 6, 7, 8, 10)) == -3 &&
+            determinant(float4x4(1, 2, 3, 4, 5, 7, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17)) == -16)
+                ? colorGreen : colorRed;
+}
diff --git a/src/sksl/generated/sksl_public.dehydrated.sksl b/src/sksl/generated/sksl_public.dehydrated.sksl
index 70e3941..6589de8 100644
--- a/src/sksl/generated/sksl_public.dehydrated.sksl
+++ b/src/sksl/generated/sksl_public.dehydrated.sksl
@@ -1,4 +1,4 @@
-static uint8_t SKSL_INCLUDE_sksl_public[] = {161,2,
+static uint8_t SKSL_INCLUDE_sksl_public[] = {173,2,
 7,100,101,103,114,101,101,115,
 8,36,103,101,110,84,121,112,101,
 7,114,97,100,105,97,110,115,
@@ -67,6 +67,7 @@
 14,109,97,116,114,105,120,67,111,109,112,77,117,108,116,
 11,36,115,113,117,97,114,101,72,77,97,116,
 1,109,
+11,100,101,116,101,114,109,105,110,97,110,116,
 9,116,114,97,110,115,112,111,115,101,
 8,102,108,111,97,116,51,120,50,
 8,102,108,111,97,116,50,120,51,
@@ -102,7 +103,7 @@
 1,112,
 4,100,70,100,120,
 4,100,70,100,121,
-48,210,1,
+48,215,1,
 52,1,0,
 17,2,0,
 49,2,0,10,0,3,
@@ -1120,7 +1121,7 @@
 29,79,1,
 37,
 16,0,16,0,0,152,1,1,78,1,
-46,70,1,
+46,145,0,
 52,80,1,
 17,150,1,
 46,74,1,3,
@@ -1129,525 +1130,542 @@
 29,82,1,
 37,
 16,0,16,0,0,152,1,1,80,1,
-46,74,1,
+46,153,0,
 46,82,1,
 52,83,1,
 17,150,1,
-49,84,1,162,1,3,
-51,85,1,3,
-46,79,1,
-46,82,1,
-29,86,1,
+46,70,1,3,
+29,84,1,
 37,
-16,0,16,0,0,152,1,1,83,1,
-49,87,1,171,1,
-46,86,1,
+16,0,16,0,0,164,1,1,83,1,
+46,70,1,
+52,85,1,
+17,150,1,
+46,74,1,3,
+51,86,1,2,
+46,84,1,
+29,87,1,
+37,
+16,0,16,0,0,164,1,1,85,1,
+46,74,1,
+46,87,1,
 52,88,1,
 17,150,1,
-49,89,1,180,1,3,
-51,90,1,4,
-46,79,1,
-46,82,1,
-46,86,1,
+49,89,1,174,1,3,
+51,90,1,3,
+46,84,1,
+46,87,1,
 29,91,1,
 37,
-16,0,16,0,0,152,1,1,88,1,
-49,92,1,188,1,
+16,0,16,0,0,164,1,1,88,1,
+49,92,1,183,1,
 46,91,1,
 52,93,1,
 17,150,1,
-49,94,1,196,1,3,
-51,95,1,5,
-46,79,1,
-46,82,1,
-46,86,1,
+49,94,1,192,1,3,
+51,95,1,4,
+46,84,1,
+46,87,1,
 46,91,1,
 29,96,1,
 37,
-16,0,16,0,0,152,1,1,93,1,
-49,97,1,205,1,
+16,0,16,0,0,164,1,1,93,1,
+49,97,1,200,1,
 46,96,1,
 52,98,1,
 17,150,1,
-49,99,1,214,1,3,
-51,100,1,6,
-46,79,1,
-46,82,1,
-46,86,1,
+49,99,1,208,1,3,
+51,100,1,5,
+46,84,1,
+46,87,1,
 46,91,1,
 46,96,1,
 29,101,1,
 37,
-16,0,16,0,0,152,1,1,98,1,
-49,102,1,222,1,
+16,0,16,0,0,164,1,1,98,1,
+49,102,1,217,1,
 46,101,1,
 52,103,1,
 17,150,1,
-46,87,1,3,
-51,104,1,7,
-46,79,1,
-46,82,1,
-46,86,1,
+49,104,1,226,1,3,
+51,105,1,6,
+46,84,1,
+46,87,1,
 46,91,1,
 46,96,1,
 46,101,1,
-29,105,1,
+29,106,1,
 37,
-16,0,16,0,0,152,1,1,103,1,
-46,84,1,
-46,105,1,
-52,106,1,
+16,0,16,0,0,164,1,1,103,1,
+49,107,1,234,1,
+46,106,1,
+52,108,1,
 17,150,1,
 46,92,1,3,
-51,107,1,8,
-46,79,1,
-46,82,1,
-46,86,1,
+51,109,1,7,
+46,84,1,
+46,87,1,
 46,91,1,
 46,96,1,
 46,101,1,
-46,105,1,
-29,108,1,
+46,106,1,
+29,110,1,
 37,
-16,0,16,0,0,152,1,1,106,1,
+16,0,16,0,0,164,1,1,108,1,
 46,89,1,
-46,108,1,
-52,109,1,
+46,110,1,
+52,111,1,
 17,150,1,
-49,110,1,230,1,3,
-51,111,1,9,
-46,79,1,
-46,82,1,
-46,86,1,
+46,97,1,3,
+51,112,1,8,
+46,84,1,
+46,87,1,
 46,91,1,
 46,96,1,
 46,101,1,
-46,105,1,
-46,108,1,
-29,112,1,
+46,106,1,
+46,110,1,
+29,113,1,
 37,
-16,0,16,0,0,152,1,1,109,1,
-49,113,1,239,1,
-46,112,1,
+16,0,16,0,0,164,1,1,111,1,
+46,94,1,
+46,113,1,
 52,114,1,
 17,150,1,
-49,115,1,248,1,3,
-51,116,1,10,
-46,79,1,
-46,82,1,
-46,86,1,
+49,115,1,242,1,3,
+51,116,1,9,
+46,84,1,
+46,87,1,
 46,91,1,
 46,96,1,
 46,101,1,
-46,105,1,
-46,108,1,
-46,112,1,
+46,106,1,
+46,110,1,
+46,113,1,
 29,117,1,
 37,
-16,0,16,0,0,152,1,1,114,1,
-49,118,1,0,2,
+16,0,16,0,0,164,1,1,114,1,
+49,118,1,251,1,
 46,117,1,
 52,119,1,
 17,150,1,
-46,97,1,3,
-51,120,1,11,
-46,79,1,
-46,82,1,
-46,86,1,
+49,120,1,4,2,3,
+51,121,1,10,
+46,84,1,
+46,87,1,
 46,91,1,
 46,96,1,
 46,101,1,
-46,105,1,
-46,108,1,
-46,112,1,
+46,106,1,
+46,110,1,
+46,113,1,
 46,117,1,
-29,121,1,
+29,122,1,
 37,
-16,0,16,0,0,152,1,1,119,1,
-46,94,1,
-46,121,1,
-52,122,1,
+16,0,16,0,0,164,1,1,119,1,
+49,123,1,12,2,
+46,122,1,
+52,124,1,
 17,150,1,
 46,102,1,3,
-51,123,1,12,
-46,79,1,
-46,82,1,
-46,86,1,
+51,125,1,11,
+46,84,1,
+46,87,1,
 46,91,1,
 46,96,1,
 46,101,1,
-46,105,1,
-46,108,1,
-46,112,1,
-46,117,1,
-46,121,1,
-29,124,1,
-37,
-16,0,16,0,0,152,1,1,122,1,
-46,99,1,
-46,124,1,
-52,125,1,
-17,150,1,
-46,113,1,3,
-51,126,1,13,
-46,79,1,
-46,82,1,
-46,86,1,
-46,91,1,
-46,96,1,
-46,101,1,
-46,105,1,
-46,108,1,
-46,112,1,
-46,117,1,
-46,121,1,
-46,124,1,
-29,127,1,
-37,
-16,0,16,0,0,152,1,1,125,1,
+46,106,1,
 46,110,1,
-46,127,1,
-52,128,1,
+46,113,1,
+46,117,1,
+46,122,1,
+29,126,1,
+37,
+16,0,16,0,0,164,1,1,124,1,
+46,99,1,
+46,126,1,
+52,127,1,
+17,150,1,
+46,107,1,3,
+51,128,1,12,
+46,84,1,
+46,87,1,
+46,91,1,
+46,96,1,
+46,101,1,
+46,106,1,
+46,110,1,
+46,113,1,
+46,117,1,
+46,122,1,
+46,126,1,
+29,129,1,
+37,
+16,0,16,0,0,164,1,1,127,1,
+46,104,1,
+46,129,1,
+52,130,1,
 17,150,1,
 46,118,1,3,
-51,129,1,14,
-46,79,1,
-46,82,1,
-46,86,1,
+51,131,1,13,
+46,84,1,
+46,87,1,
 46,91,1,
 46,96,1,
 46,101,1,
-46,105,1,
-46,108,1,
-46,112,1,
+46,106,1,
+46,110,1,
+46,113,1,
 46,117,1,
-46,121,1,
-46,124,1,
-46,127,1,
-29,130,1,
-37,
-16,0,16,0,0,152,1,1,128,1,
-46,115,1,
-46,130,1,
-52,131,1,
-17,150,1,
-46,70,1,3,
+46,122,1,
+46,126,1,
+46,129,1,
 29,132,1,
-17,8,2,1,131,1,
-46,70,1,
+37,
+16,0,16,0,0,164,1,1,130,1,
+46,115,1,
+46,132,1,
 52,133,1,
 17,150,1,
-46,74,1,3,
-51,134,1,2,
+46,123,1,3,
+51,134,1,14,
+46,84,1,
+46,87,1,
+46,91,1,
+46,96,1,
+46,101,1,
+46,106,1,
+46,110,1,
+46,113,1,
+46,117,1,
+46,122,1,
+46,126,1,
+46,129,1,
 46,132,1,
 29,135,1,
-17,8,2,1,133,1,
-46,74,1,
+37,
+16,0,16,0,0,164,1,1,133,1,
+46,120,1,
 46,135,1,
 52,136,1,
-17,55,0,
-49,137,1,16,2,3,
+17,150,1,
+46,70,1,3,
+29,137,1,
+17,20,2,1,136,1,
+46,70,1,
 52,138,1,
-17,67,0,
-46,137,1,3,
-29,139,1,
-17,21,2,2,136,1,138,1,
-49,140,1,30,2,
+17,150,1,
+46,74,1,3,
+51,139,1,2,
+46,137,1,
+29,140,1,
+17,20,2,1,138,1,
+46,74,1,
+46,140,1,
 52,141,1,
 17,55,0,
-49,142,1,36,2,3,
+49,142,1,28,2,3,
 52,143,1,
 17,67,0,
 46,142,1,3,
-51,144,1,2,
-46,139,1,
-29,145,1,
-17,21,2,2,141,1,143,1,
-46,140,1,
-46,145,1,
+29,144,1,
+17,33,2,2,141,1,143,1,
+49,145,1,42,2,
 52,146,1,
 17,55,0,
-49,147,1,42,2,3,
+49,147,1,48,2,3,
 52,148,1,
 17,67,0,
 46,147,1,3,
-51,149,1,3,
-46,139,1,
-46,145,1,
+51,149,1,2,
+46,144,1,
 29,150,1,
-17,21,2,2,146,1,148,1,
-46,140,1,
+17,33,2,2,146,1,148,1,
+46,145,1,
 46,150,1,
 52,151,1,
 17,55,0,
-46,137,1,3,
-52,152,1,
+49,152,1,54,2,3,
+52,153,1,
 17,67,0,
-46,137,1,3,
-29,153,1,
-17,48,2,2,151,1,152,1,
-46,140,1,
-52,154,1,
+46,152,1,3,
+51,154,1,3,
+46,144,1,
+46,150,1,
+29,155,1,
+17,33,2,2,151,1,153,1,
+46,145,1,
+46,155,1,
+52,156,1,
 17,55,0,
 46,142,1,3,
-52,155,1,
+52,157,1,
 17,67,0,
 46,142,1,3,
-51,156,1,2,
-46,153,1,
-29,157,1,
-17,48,2,2,154,1,155,1,
-46,140,1,
-46,157,1,
-52,158,1,
-17,55,0,
-46,147,1,3,
+29,158,1,
+17,60,2,2,156,1,157,1,
+46,145,1,
 52,159,1,
+17,55,0,
+46,147,1,3,
+52,160,1,
 17,67,0,
 46,147,1,3,
-51,160,1,3,
-46,153,1,
-46,157,1,
-29,161,1,
-17,48,2,2,158,1,159,1,
-46,140,1,
-46,161,1,
-52,162,1,
-17,55,0,
-46,137,1,3,
+51,161,1,2,
+46,158,1,
+29,162,1,
+17,60,2,2,159,1,160,1,
+46,145,1,
+46,162,1,
 52,163,1,
+17,55,0,
+46,152,1,3,
+52,164,1,
 17,67,0,
-46,137,1,3,
-29,164,1,
-17,62,2,2,162,1,163,1,
-46,140,1,
-52,165,1,
+46,152,1,3,
+51,165,1,3,
+46,158,1,
+46,162,1,
+29,166,1,
+17,60,2,2,163,1,164,1,
+46,145,1,
+46,166,1,
+52,167,1,
 17,55,0,
 46,142,1,3,
-52,166,1,
+52,168,1,
 17,67,0,
 46,142,1,3,
-51,167,1,2,
-46,164,1,
-29,168,1,
-17,62,2,2,165,1,166,1,
-46,140,1,
-46,168,1,
-52,169,1,
-17,55,0,
-46,147,1,3,
+29,169,1,
+17,74,2,2,167,1,168,1,
+46,145,1,
 52,170,1,
+17,55,0,
+46,147,1,3,
+52,171,1,
 17,67,0,
 46,147,1,3,
-51,171,1,3,
-46,164,1,
-46,168,1,
-29,172,1,
-17,62,2,2,169,1,170,1,
-46,140,1,
-46,172,1,
-52,173,1,
-17,55,0,
-46,137,1,3,
+51,172,1,2,
+46,169,1,
+29,173,1,
+17,74,2,2,170,1,171,1,
+46,145,1,
+46,173,1,
 52,174,1,
+17,55,0,
+46,152,1,3,
+52,175,1,
 17,67,0,
-46,137,1,3,
-29,175,1,
-17,74,2,2,173,1,174,1,
-46,140,1,
-52,176,1,
+46,152,1,3,
+51,176,1,3,
+46,169,1,
+46,173,1,
+29,177,1,
+17,74,2,2,174,1,175,1,
+46,145,1,
+46,177,1,
+52,178,1,
 17,55,0,
 46,142,1,3,
-52,177,1,
+52,179,1,
 17,67,0,
 46,142,1,3,
-51,178,1,2,
-46,175,1,
-29,179,1,
-17,74,2,2,176,1,177,1,
-46,140,1,
-46,179,1,
-52,180,1,
-17,55,0,
-46,147,1,3,
+29,180,1,
+17,86,2,2,178,1,179,1,
+46,145,1,
 52,181,1,
+17,55,0,
+46,147,1,3,
+52,182,1,
 17,67,0,
 46,147,1,3,
-51,182,1,3,
-46,175,1,
-46,179,1,
-29,183,1,
-17,74,2,2,180,1,181,1,
-46,140,1,
-46,183,1,
-52,184,1,
-17,55,0,
-46,137,1,3,
+51,183,1,2,
+46,180,1,
+29,184,1,
+17,86,2,2,181,1,182,1,
+46,145,1,
+46,184,1,
 52,185,1,
+17,55,0,
+46,152,1,3,
+52,186,1,
 17,67,0,
-46,137,1,3,
-29,186,1,
-17,91,2,2,184,1,185,1,
-46,140,1,
-52,187,1,
+46,152,1,3,
+51,187,1,3,
+46,180,1,
+46,184,1,
+29,188,1,
+17,86,2,2,185,1,186,1,
+46,145,1,
+46,188,1,
+52,189,1,
 17,55,0,
 46,142,1,3,
-52,188,1,
+52,190,1,
 17,67,0,
 46,142,1,3,
-51,189,1,2,
-46,186,1,
-29,190,1,
-17,91,2,2,187,1,188,1,
-46,140,1,
-46,190,1,
-52,191,1,
-17,55,0,
-46,147,1,3,
+29,191,1,
+17,103,2,2,189,1,190,1,
+46,145,1,
 52,192,1,
+17,55,0,
+46,147,1,3,
+52,193,1,
 17,67,0,
 46,147,1,3,
-51,193,1,3,
-46,186,1,
-46,190,1,
-29,194,1,
-17,91,2,2,191,1,192,1,
-46,140,1,
-46,194,1,
-52,195,1,
-17,55,0,
-46,140,1,3,
+51,194,1,2,
+46,191,1,
+29,195,1,
+17,103,2,2,192,1,193,1,
+46,145,1,
+46,195,1,
 52,196,1,
-17,67,0,
-46,140,1,3,
-51,197,1,4,
-46,186,1,
-46,190,1,
-46,194,1,
-29,198,1,
-17,91,2,2,195,1,196,1,
-46,140,1,
-46,198,1,
-52,199,1,
 17,55,0,
-46,137,1,3,
+46,152,1,3,
+52,197,1,
+17,67,0,
+46,152,1,3,
+51,198,1,3,
+46,191,1,
+46,195,1,
+29,199,1,
+17,103,2,2,196,1,197,1,
+46,145,1,
+46,199,1,
 52,200,1,
+17,55,0,
+46,145,1,3,
+52,201,1,
 17,67,0,
-46,137,1,3,
-29,201,1,
-17,97,2,2,199,1,200,1,
-46,140,1,
-52,202,1,
+46,145,1,3,
+51,202,1,4,
+46,191,1,
+46,195,1,
+46,199,1,
+29,203,1,
+17,103,2,2,200,1,201,1,
+46,145,1,
+46,203,1,
+52,204,1,
 17,55,0,
 46,142,1,3,
-52,203,1,
+52,205,1,
 17,67,0,
 46,142,1,3,
-51,204,1,2,
-46,201,1,
-29,205,1,
-17,97,2,2,202,1,203,1,
-46,140,1,
-46,205,1,
-52,206,1,
-17,55,0,
-46,147,1,3,
+29,206,1,
+17,109,2,2,204,1,205,1,
+46,145,1,
 52,207,1,
+17,55,0,
+46,147,1,3,
+52,208,1,
 17,67,0,
 46,147,1,3,
-51,208,1,3,
-46,201,1,
-46,205,1,
-29,209,1,
-17,97,2,2,206,1,207,1,
-46,140,1,
-46,209,1,
-52,210,1,
-17,55,0,
-46,140,1,3,
+51,209,1,2,
+46,206,1,
+29,210,1,
+17,109,2,2,207,1,208,1,
+46,145,1,
+46,210,1,
 52,211,1,
+17,55,0,
+46,152,1,3,
+52,212,1,
 17,67,0,
-46,140,1,3,
-51,212,1,4,
-46,201,1,
-46,205,1,
-46,209,1,
-29,213,1,
-17,97,2,2,210,1,211,1,
-46,140,1,
-46,213,1,
-52,214,1,
+46,152,1,3,
+51,213,1,3,
+46,206,1,
+46,210,1,
+29,214,1,
+17,109,2,2,211,1,212,1,
+46,145,1,
+46,214,1,
+52,215,1,
 17,55,0,
-46,140,1,3,
-29,215,1,
-17,106,2,1,214,1,
-49,216,1,110,2,
-52,217,1,
-17,55,0,
-46,140,1,3,
+46,145,1,3,
+52,216,1,
+17,67,0,
+46,145,1,3,
+51,217,1,4,
+46,206,1,
+46,210,1,
+46,214,1,
 29,218,1,
-17,115,2,1,217,1,
-46,216,1,
+17,109,2,2,215,1,216,1,
+46,145,1,
+46,218,1,
 52,219,1,
 17,55,0,
-46,140,1,3,
+46,145,1,3,
 29,220,1,
-17,119,2,1,219,1,
-46,140,1,
-52,221,1,
-17,123,2,
-49,222,1,129,2,3,
+17,118,2,1,219,1,
+49,221,1,122,2,
+52,222,1,
+17,55,0,
+46,145,1,3,
 29,223,1,
-17,135,2,1,221,1,
-46,222,1,
+17,127,2,1,222,1,
+46,221,1,
 52,224,1,
-17,123,2,
-49,225,1,144,2,3,
-51,226,1,2,
-46,223,1,
-29,227,1,
-17,135,2,1,224,1,
-46,225,1,
+17,55,0,
+46,145,1,3,
+29,225,1,
+17,131,2,1,224,1,
+46,145,1,
+52,226,1,
+17,135,2,
+49,227,1,141,2,3,
+29,228,1,
+17,147,2,1,226,1,
 46,227,1,
-52,228,1,
-17,151,2,
+52,229,1,
+17,135,2,
+49,230,1,156,2,3,
+51,231,1,2,
+46,228,1,
+29,232,1,
+17,147,2,1,229,1,
+46,230,1,
+46,232,1,
+52,233,1,
+17,163,2,
 46,2,0,3,
-29,229,1,
-37,
-16,0,16,0,0,153,2,1,228,1,
-46,2,0,
-52,230,1,
-17,151,2,
-46,2,0,3,
-29,231,1,
-37,
-16,0,16,0,0,158,2,1,230,1,
-46,2,0,
-52,232,1,
-17,151,2,
-46,5,0,3,
-51,233,1,2,
-46,229,1,
 29,234,1,
 37,
-16,0,16,0,0,153,2,1,232,1,
-46,5,0,
-46,234,1,
+16,0,16,0,0,165,2,1,233,1,
+46,2,0,
 52,235,1,
-17,151,2,
-46,5,0,3,
-51,236,1,2,
-46,231,1,
-29,237,1,
+17,163,2,
+46,2,0,3,
+29,236,1,
 37,
-16,0,16,0,0,158,2,1,235,1,
+16,0,16,0,0,170,2,1,235,1,
+46,2,0,
+52,237,1,
+17,163,2,
+46,5,0,3,
+51,238,1,2,
+46,234,1,
+29,239,1,
+37,
+16,0,16,0,0,165,2,1,237,1,
 46,5,0,
-46,237,1,57,0,
+46,239,1,
+52,240,1,
+17,163,2,
+46,5,0,3,
+51,241,1,2,
+46,236,1,
+29,242,1,
+37,
+16,0,16,0,0,170,2,1,240,1,
+46,5,0,
+46,242,1,58,0,
 118,0,
 33,0,
 71,0,
-192,1,
-190,1,
+197,1,
+195,1,
 28,0,
 66,0,
 46,0,
@@ -1657,24 +1675,25 @@
 18,0,
 56,0,
 30,1,
-205,1,
-208,1,
+210,1,
+213,1,
 8,0,
+72,1,
 16,1,
 23,1,
-172,1,
+177,1,
 88,0,
 98,0,
 44,1,
 128,0,
 138,0,
-146,1,
-157,1,
-113,1,
+151,1,
+162,1,
+118,1,
 113,0,
 9,1,
-124,1,
-135,1,
+129,1,
+140,1,
 93,0,
 103,0,
 67,1,
@@ -1683,8 +1702,8 @@
 226,0,
 153,0,
 35,1,
-194,1,
-187,1,
+199,1,
+192,1,
 83,0,
 3,0,
 51,1,
@@ -1698,42 +1717,42 @@
 241,0,
 23,0,
 61,0,
-108,1,
-198,1,
+113,1,
+203,1,
 20,
-28,223,1,
+28,228,1,
 2,
 48,0,0,0,0,1,
 40,
 8,
-46,222,1,2,
+46,227,1,2,
 1,
 45,
-55,221,1,0,3,0,1,2,50,
+55,226,1,0,3,0,1,2,50,
 27,
 46,153,0,185,0,2,
 45,
-55,221,1,0,1,3,
+55,226,1,0,1,3,
 25,
 46,153,0,23,183,209,56,
 45,
-55,221,1,0,1,3,1,0,
-28,227,1,
+55,226,1,0,1,3,1,0,
+28,232,1,
 2,
 48,0,0,0,0,1,
 40,
 8,
-46,225,1,2,
+46,230,1,2,
 1,
 45,
-55,224,1,0,3,0,1,2,50,
+55,229,1,0,3,0,1,2,50,
 27,
 46,145,0,177,0,2,
 45,
-55,224,1,0,1,3,
+55,229,1,0,1,3,
 25,
 46,145,0,23,183,209,56,
 45,
-55,224,1,0,1,3,1,0,
+55,229,1,0,1,3,1,0,
 21,};
 static constexpr size_t SKSL_INCLUDE_sksl_public_LENGTH = sizeof(SKSL_INCLUDE_sksl_public);
diff --git a/src/sksl/ir/SkSLFunctionCall.cpp b/src/sksl/ir/SkSLFunctionCall.cpp
index 05062e1..b11dabd 100644
--- a/src/sksl/ir/SkSLFunctionCall.cpp
+++ b/src/sksl/ir/SkSLFunctionCall.cpp
@@ -421,6 +421,13 @@
 }  // namespace
 }  // namespace Intrinsics
 
+static void extract_matrix(const Expression* expr, float mat[16]) {
+    size_t numSlots = expr->type().slotCount();
+    for (size_t index = 0; index < numSlots; ++index) {
+        mat[index] = expr->getConstantSubexpression(index)->as<FloatLiteral>().value();
+    }
+}
+
 static std::unique_ptr<Expression> optimize_intrinsic_call(const Context& context,
                                                            IntrinsicKind intrinsic,
                                                            const ExpressionArray& arguments,
@@ -631,6 +638,27 @@
             return ConstructorCompound::Make(context, matrix->fOffset, returnType,
                                              std::move(array));
         }
+        case k_determinant_IntrinsicKind: {
+            matrix = ConstantFolder::GetConstantValueForVariable(*arguments[0]);
+            float m[16];
+            extract_matrix(matrix, m);
+            float determinant;
+            switch (matrix->type().slotCount()) {
+                case 4:
+                    determinant = SkInvert2x2Matrix(m, /*outMatrix=*/nullptr);
+                    break;
+                case 9:
+                    determinant = SkInvert3x3Matrix(m, /*outMatrix=*/nullptr);
+                    break;
+                case 16:
+                    determinant = SkInvert4x4Matrix(m, /*outMatrix=*/nullptr);
+                    break;
+                default:
+                    SkDEBUGFAILF("unsupported type %s", matrix->type().description().c_str());
+                    return nullptr;
+            }
+            return FloatLiteral::Make(matrix->fOffset, determinant, &returnType);
+        }
         case k_inverse_IntrinsicKind: {
             matrix = ConstantFolder::GetConstantValueForVariable(*arguments[0]);
             switch (arguments[0]->type().slotCount()) {
diff --git a/src/sksl/sksl_public.sksl b/src/sksl/sksl_public.sksl
index ea70cd5..77f539a 100644
--- a/src/sksl/sksl_public.sksl
+++ b/src/sksl/sksl_public.sksl
@@ -121,6 +121,8 @@
 // 8.5 : Matrix Functions
 $squareMat  matrixCompMult($squareMat  x, $squareMat  y);
 $squareHMat matrixCompMult($squareHMat x, $squareHMat y);
+$es3 float  determinant($squareMat m);
+$es3 half   determinant($squareHMat m);
 $es3 $squareMat  transpose($squareMat  m);
 $es3 $squareHMat transpose($squareHMat m);
 $es3 float2x3    transpose(float3x2 m);
diff --git a/tests/SkSLTest.cpp b/tests/SkSLTest.cpp
index cbea336..71ce98f 100644
--- a/tests/SkSLTest.cpp
+++ b/tests/SkSLTest.cpp
@@ -208,6 +208,7 @@
 
 SKSL_TEST(SkSLIntrinsicAbsFloat,               "intrinsics/AbsFloat.sksl")
 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")
 // TODO(johnstiles): test broken on Adreno 6xx + Vulkan
diff --git a/tests/sksl/intrinsics/Determinant.asm.frag b/tests/sksl/intrinsics/Determinant.asm.frag
index f42f055..1a77b57 100644
--- a/tests/sksl/intrinsics/Determinant.asm.frag
+++ b/tests/sksl/intrinsics/Determinant.asm.frag
@@ -1,19 +1,33 @@
 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 %a "a"
+OpName %_UniformBuffer "_UniformBuffer"
+OpMemberName %_UniformBuffer 0 "testMatrix2x2"
+OpMemberName %_UniformBuffer 1 "colorGreen"
+OpMemberName %_UniformBuffer 2 "colorRed"
+OpName %_entrypoint_v "_entrypoint_v"
 OpName %main "main"
 OpDecorate %sk_FragColor RelaxedPrecision
 OpDecorate %sk_FragColor Location 0
 OpDecorate %sk_FragColor Index 0
 OpDecorate %sk_Clockwise BuiltIn FrontFacing
-OpDecorate %a RelaxedPrecision
-OpDecorate %16 RelaxedPrecision
-OpDecorate %17 RelaxedPrecision
+OpMemberDecorate %_UniformBuffer 0 Offset 0
+OpMemberDecorate %_UniformBuffer 0 ColMajor
+OpMemberDecorate %_UniformBuffer 0 MatrixStride 16
+OpMemberDecorate %_UniformBuffer 1 Offset 32
+OpMemberDecorate %_UniformBuffer 1 RelaxedPrecision
+OpMemberDecorate %_UniformBuffer 2 Offset 48
+OpMemberDecorate %_UniformBuffer 2 RelaxedPrecision
+OpDecorate %_UniformBuffer Block
+OpDecorate %10 Binding 0
+OpDecorate %10 DescriptorSet 0
+OpDecorate %43 RelaxedPrecision
+OpDecorate %46 RelaxedPrecision
+OpDecorate %47 RelaxedPrecision
 %float = OpTypeFloat 32
 %v4float = OpTypeVector %float 4
 %_ptr_Output_v4float = OpTypePointer Output %v4float
@@ -21,19 +35,54 @@
 %bool = OpTypeBool
 %_ptr_Input_bool = OpTypePointer Input %bool
 %sk_Clockwise = OpVariable %_ptr_Input_bool Input
-%mat4v4float = OpTypeMatrix %v4float 4
-%_ptr_Private_mat4v4float = OpTypePointer Private %mat4v4float
-%a = OpVariable %_ptr_Private_mat4v4float Private
+%v2float = OpTypeVector %float 2
+%mat2v2float = OpTypeMatrix %v2float 2
+%_UniformBuffer = OpTypeStruct %mat2v2float %v4float %v4float
+%_ptr_Uniform__UniformBuffer = OpTypePointer Uniform %_UniformBuffer
+%10 = OpVariable %_ptr_Uniform__UniformBuffer Uniform
 %void = OpTypeVoid
-%14 = OpTypeFunction %void
-%_ptr_Output_float = OpTypePointer Output %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_Uniform_mat2v2float = OpTypePointer Uniform %mat2v2float
 %int = OpTypeInt 32 1
 %int_0 = OpConstant %int 0
-%main = OpFunction %void None %14
-%15 = OpLabel
-%17 = OpLoad %mat4v4float %a
-%16 = OpExtInst %float %1 Determinant %17
-%18 = OpAccessChain %_ptr_Output_float %sk_FragColor %int_0
-OpStore %18 %16
+%float_n2 = OpConstant %float -2
+%_ptr_Function_v4float = OpTypePointer Function %v4float
+%_ptr_Uniform_v4float = OpTypePointer Uniform %v4float
+%int_1 = OpConstant %int 1
+%int_2 = OpConstant %int 2
+%_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
+%35 = OpVariable %_ptr_Function_v4float Function
+%28 = OpAccessChain %_ptr_Uniform_mat2v2float %10 %int_0
+%32 = OpLoad %mat2v2float %28
+%27 = OpExtInst %float %1 Determinant %32
+%34 = OpFOrdEqual %bool %27 %float_n2
+OpSelectionMerge %39 None
+OpBranchConditional %34 %37 %38
+%37 = OpLabel
+%40 = OpAccessChain %_ptr_Uniform_v4float %10 %int_1
+%43 = OpLoad %v4float %40
+OpStore %35 %43
+OpBranch %39
+%38 = OpLabel
+%44 = OpAccessChain %_ptr_Uniform_v4float %10 %int_2
+%46 = OpLoad %v4float %44
+OpStore %35 %46
+OpBranch %39
+%39 = OpLabel
+%47 = OpLoad %v4float %35
+OpReturnValue %47
+OpFunctionEnd
diff --git a/tests/sksl/intrinsics/Determinant.glsl b/tests/sksl/intrinsics/Determinant.glsl
index 4de54eb..d904d6d 100644
--- a/tests/sksl/intrinsics/Determinant.glsl
+++ b/tests/sksl/intrinsics/Determinant.glsl
@@ -1,6 +1,8 @@
 
-mat4 _determinant4(mat4 m) {    float a00 = m[0][0], a01 = m[0][1], a02 = m[0][2], a03 = m[0][3];    float a10 = m[1][0], a11 = m[1][1], a12 = m[1][2], a13 = m[1][3];    float a20 = m[2][0], a21 = m[2][1], a22 = m[2][2], a23 = m[2][3];    float a30 = m[3][0], a31 = m[3][1], a32 = m[3][2], a33 = m[3][3];    float b00 = a00 * a11 - a01 * a10;    float b01 = a00 * a12 - a02 * a10;    float b02 = a00 * a13 - a03 * a10;    float b03 = a01 * a12 - a02 * a11;    float b04 = a01 * a13 - a03 * a11;    float b05 = a02 * a13 - a03 * a12;    float b06 = a20 * a31 - a21 * a30;    float b07 = a20 * a32 - a22 * a30;    float b08 = a20 * a33 - a23 * a30;    float b09 = a21 * a32 - a22 * a31;    float b10 = a21 * a33 - a23 * a31;    float b11 = a22 * a33 - a23 * a32;    return b00 * b11 - b01 * b10 + b02 * b09 + b03 * b08 - b04 * b07 + b05 * b06;}out vec4 sk_FragColor;
-mat4 a;
-void main() {
-    sk_FragColor.x = _determinant4(a);
+float _determinant2(mat2 m) {    return m[0][0] * m[1][1] - m[0][1] * m[1][0];}out vec4 sk_FragColor;
+uniform mat2 testMatrix2x2;
+uniform vec4 colorGreen;
+uniform vec4 colorRed;
+vec4 main() {
+    return _determinant2(testMatrix2x2) == -2.0 ? colorGreen : colorRed;
 }
diff --git a/tests/sksl/intrinsics/Determinant.metal b/tests/sksl/intrinsics/Determinant.metal
index 3d6df3b..0d795a4 100644
--- a/tests/sksl/intrinsics/Determinant.metal
+++ b/tests/sksl/intrinsics/Determinant.metal
@@ -1,19 +1,19 @@
 #include <metal_stdlib>
 #include <simd/simd.h>
 using namespace metal;
+struct Uniforms {
+    float2x2 testMatrix2x2;
+    float4 colorGreen;
+    float4 colorRed;
+};
 struct Inputs {
 };
 struct Outputs {
     float4 sk_FragColor [[color(0)]];
 };
-struct Globals {
-    float4x4 a;
-};
-fragment Outputs fragmentMain(Inputs _in [[stage_in]], bool _frontFacing [[front_facing]], float4 _fragCoord [[position]]) {
-    Globals _globals{{}};
-    (void)_globals;
+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 = determinant(_globals.a);
+    _out.sk_FragColor = determinant(_uniforms.testMatrix2x2) == -2.0 ? _uniforms.colorGreen : _uniforms.colorRed;
     return _out;
 }