Add unit test for array narrowing conversions.
Change-Id: Ibadda2a10e19984c7a0efb66fd3187f280666445
Bug: skia:12248
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/436996
Commit-Queue: John Stiles <johnstiles@google.com>
Auto-Submit: John Stiles <johnstiles@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
diff --git a/gn/sksl_tests.gni b/gn/sksl_tests.gni
index 2425c2d..5098b2b 100644
--- a/gn/sksl_tests.gni
+++ b/gn/sksl_tests.gni
@@ -518,6 +518,7 @@
sksl_rte_tests = [
"/sksl/runtime/AllowNarrowingConversions.rts",
"/sksl/runtime/ArrayIndexing.rts",
+ "/sksl/runtime/ArrayNarrowingConversions.rts",
"/sksl/runtime/Blend.rtb",
"/sksl/runtime/ConstPreservation.rts",
"/sksl/runtime/ConversionConstructors.rts",
diff --git a/resources/sksl/runtime/ArrayNarrowingConversions.rts b/resources/sksl/runtime/ArrayNarrowingConversions.rts
new file mode 100644
index 0000000..e6608b2
--- /dev/null
+++ b/resources/sksl/runtime/ArrayNarrowingConversions.rts
@@ -0,0 +1,19 @@
+/*#pragma settings NoES2Restrictions*/
+
+uniform half4 colorGreen, colorRed;
+
+half4 main(float2 coords) {
+ highp int i2[2] = int [2](1, 2);
+ mediump int s2[2] = int [2](1, 2);
+ highp float f2[2] = float [2](1, 2);
+ mediump float h2[2] = float [2](1, 2);
+
+ const highp int ci2[2] = int [2](1, 2);
+ const mediump int cs2[2] = int [2](1, 2);
+ const highp float cf2[2] = float [2](1, 2);
+ const mediump float ch2[2] = float [2](1, 2);
+
+ return (i2 == s2 && f2 == h2 && ci2 == cs2 && cf2 == ch2 && i2 == cs2 && h2 == cf2)
+ ? colorGreen
+ : colorRed;
+}
diff --git a/src/sksl/SkSLMain.cpp b/src/sksl/SkSLMain.cpp
index e8ba2c4..0b495ee 100644
--- a/src/sksl/SkSLMain.cpp
+++ b/src/sksl/SkSLMain.cpp
@@ -214,6 +214,9 @@
if (settingsText.consumeSuffix(" ForceHighPrecision")) {
settings->fForceHighPrecision = true;
}
+ if (settingsText.consumeSuffix(" NoES2Restrictions")) {
+ settings->fEnforceES2Restrictions = false;
+ }
if (settingsText.consumeSuffix(" NoInline")) {
settings->fInlineThreshold = 0;
}
diff --git a/tests/SkSLTest.cpp b/tests/SkSLTest.cpp
index c48315a..134c52e 100644
--- a/tests/SkSLTest.cpp
+++ b/tests/SkSLTest.cpp
@@ -221,6 +221,8 @@
SKSL_TEST(SkSLIntrinsicSignFloat, "intrinsics/SignFloat.sksl")
SKSL_TEST(SkSLIntrinsicStep, "intrinsics/Step.sksl")
+SKSL_TEST_ES3(SkSLArrayNarrowingConversions, "runtime/ArrayNarrowingConversions.rts")
+
SKSL_TEST_ES3(SkSLArrayComparison, "shared/ArrayComparison.sksl")
SKSL_TEST_ES3(SkSLArrayConstructors, "shared/ArrayConstructors.sksl")
SKSL_TEST(SkSLArrayTypes, "shared/ArrayTypes.sksl")
@@ -298,8 +300,6 @@
SKSL_TEST(SkSLMatrixFoldingES3, "folding/MatrixFoldingES3.sksl")
-SKSL_TEST(SkSLEnumsCanBeInlinedSafely, "inliner/EnumsCanBeInlinedSafely.sksl")
-
SKSL_TEST(SkSLIntrinsicAbsInt, "intrinsics/AbsInt.sksl")
SKSL_TEST(SkSLIntrinsicClampInt, "intrinsics/ClampInt.sksl")
SKSL_TEST(SkSLIntrinsicMaxInt, "intrinsics/MaxInt.sksl")
diff --git a/tests/sksl/runtime/ArrayNarrowingConversions.skvm b/tests/sksl/runtime/ArrayNarrowingConversions.skvm
new file mode 100644
index 0000000..8f00020
--- /dev/null
+++ b/tests/sksl/runtime/ArrayNarrowingConversions.skvm
@@ -0,0 +1,10 @@
+4 registers, 8 instructions:
+0 r0 = uniform32 ptr0 4
+1 r1 = uniform32 ptr0 8
+2 r2 = uniform32 ptr0 C
+3 r3 = uniform32 ptr0 10
+loop:
+4 store32 ptr1 r0
+5 store32 ptr2 r1
+6 store32 ptr3 r2
+7 store32 ptr4 r3
diff --git a/tests/sksl/runtime/ArrayNarrowingConversions.stage b/tests/sksl/runtime/ArrayNarrowingConversions.stage
new file mode 100644
index 0000000..fea6ac1
--- /dev/null
+++ b/tests/sksl/runtime/ArrayNarrowingConversions.stage
@@ -0,0 +1,14 @@
+uniform half4 colorGreen;
+uniform half4 colorRed;
+half4 main(float2 coords)
+{
+ int i2[2] = int[2](1, 2);
+ short s2[2] = short[2](1, 2);
+ float f2[2] = float[2](1.0, 2.0);
+ half h2[2] = half[2](1.0, 2.0);
+ ;
+ ;
+ const float cf2[2] = float[2](1.0, 2.0);
+ ;
+ return half4(((i2 == s2 && f2 == h2) && i2 == int[2](1, 2)) && h2 == cf2 ? colorGreen : colorRed);
+}