[WHLSL] Add unary plus
authormmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Aug 2019 01:54:20 +0000 (01:54 +0000)
committermmaxfield@apple.com <mmaxfield@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 16 Aug 2019 01:54:20 +0000 (01:54 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200753

Reviewed by Saam Barati.

Source/WebCore:

HLSL has these, so we should too.

Test: webgpu/whlsl/vector-matrix-addition-subtraction.html

* Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt:

LayoutTests:

* webgpu/whlsl/vector-matrix-addition-subtraction-expected.txt: Added.
* webgpu/whlsl/vector-matrix-addition-subtraction.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@248756 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/webgpu/whlsl/vector-matrix-addition-subtraction-expected.txt [new file with mode: 0644]
LayoutTests/webgpu/whlsl/vector-matrix-addition-subtraction.html [new file with mode: 0644]
Source/WebCore/ChangeLog
Source/WebCore/Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt

index 26b922c..9d0cc50 100644 (file)
@@ -1,5 +1,15 @@
 2019-08-15  Myles C. Maxfield  <mmaxfield@apple.com>
 
+        [WHLSL] Add unary plus
+        https://bugs.webkit.org/show_bug.cgi?id=200753
+
+        Reviewed by Saam Barati.
+
+        * webgpu/whlsl/vector-matrix-addition-subtraction-expected.txt: Added.
+        * webgpu/whlsl/vector-matrix-addition-subtraction.html: Added.
+
+2019-08-15  Myles C. Maxfield  <mmaxfield@apple.com>
+
         [WHLSL] Matrices should have constructors that take a flattened list of scalars
         https://bugs.webkit.org/show_bug.cgi?id=200804
 
diff --git a/LayoutTests/webgpu/whlsl/vector-matrix-addition-subtraction-expected.txt b/LayoutTests/webgpu/whlsl/vector-matrix-addition-subtraction-expected.txt
new file mode 100644 (file)
index 0000000..5160452
--- /dev/null
@@ -0,0 +1,6 @@
+
+PASS vectorAddition 
+PASS vectorSubtraction 
+PASS matrixAddition 
+PASS matrixSubtraction 
+
diff --git a/LayoutTests/webgpu/whlsl/vector-matrix-addition-subtraction.html b/LayoutTests/webgpu/whlsl/vector-matrix-addition-subtraction.html
new file mode 100644 (file)
index 0000000..b58d742
--- /dev/null
@@ -0,0 +1,208 @@
+<!DOCTYPE html>
+<html>
+<meta charset=utf-8>
+<meta name="timeout" content="long">
+<title>Test prefix/postfix.</title>
+<script src="js/test-harness.js"></script>
+<script src="../js/webgpu-functions.js"></script>
+<script src="../../resources/testharness.js"></script>
+<script src="../../resources/testharnessreport.js"></script>
+<script>
+const whlslTests = {};
+const epsilon = 0.0001;
+
+whlslTests.vectorAddition = async () => {
+    let program = `
+        float a()
+        {
+            float2 v = float2(3, 4);
+            float2 u = v + 7;
+            return u.x;
+        }
+        float b()
+        {
+            float2 v = float2(3, 4);
+            float2 u = v + 7;
+            return u.y;
+        }
+        float c()
+        {
+            float2 v = float2(3, 4);
+            float2 u = 7 + v;
+            return u.x;
+        }
+        float d()
+        {
+            float2 v = float2(3, 4);
+            float2 u = 7 + v;
+            return u.y;
+        }
+        float e()
+        {
+            float2 v = float2(3, 4);
+            float2 u = +v;
+            return u.x;
+        }
+        float f()
+        {
+            float2 v = float2(3, 4);
+            float2 u = +v;
+            return u.y;
+        }
+    `;
+
+    assert_approx_equals(await callFloatFunction(program,  "a", []), 10, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "b", []), 11, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "c", []), 10, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "d", []), 11, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "e", []), 3, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "f", []), 4, epsilon);
+};
+
+whlslTests.vectorSubtraction = async () => {
+    let program = `
+        float a()
+        {
+            float2 v = float2(3, 4);
+            float2 u = v - 7;
+            return u.x;
+        }
+        float b()
+        {
+            float2 v = float2(3, 4);
+            float2 u = v - 7;
+            return u.y;
+        }
+        float c()
+        {
+            float2 v = float2(3, 4);
+            float2 u = 7 - v;
+            return u.x;
+        }
+        float d()
+        {
+            float2 v = float2(3, 4);
+            float2 u = 7 - v;
+            return u.y;
+        }
+        float e()
+        {
+            float2 v = float2(3, 4);
+            float2 u = -v;
+            return u.x;
+        }
+        float f()
+        {
+            float2 v = float2(3, 4);
+            float2 u = -v;
+            return u.y;
+        }
+    `;
+
+    assert_approx_equals(await callFloatFunction(program,  "a", []), -4, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "b", []), -3, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "c", []), 4, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "d", []), 3, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "e", []), -3, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "f", []), -4, epsilon);
+};
+
+whlslTests.matrixAddition = async () => {
+    let program = `
+        float a()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = m + 7;
+            return n[0][0];
+        }
+        float b()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = m + 7;
+            return n[0][1];
+        }
+        float c()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = 7 + m;
+            return n[0][0];
+        }
+        float d()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = 7 + m;
+            return n[0][1];
+        }
+        float e()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = +m;
+            return n[0][0];
+        }
+        float f()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = +m;
+            return n[0][1];
+        }
+    `;
+
+    assert_approx_equals(await callFloatFunction(program,  "a", []), 10, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "b", []), 11, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "c", []), 10, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "d", []), 11, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "e", []), 3, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "f", []), 4, epsilon);
+};
+
+whlslTests.matrixSubtraction = async () => {
+    let program = `
+        float a()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = m - 7;
+            return n[0][0];
+        }
+        float b()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = m - 7;
+            return n[0][1];
+        }
+        float c()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = 7 - m;
+            return n[0][0];
+        }
+        float d()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = 7 - m;
+            return n[0][1];
+        }
+        float e()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = -m;
+            return n[0][0];
+        }
+        float f()
+        {
+            float2x2 m = float2x2(float2(3, 4), float2(5, 6));
+            float2x2 n = -m;
+            return n[0][1];
+        }
+    `;
+
+    assert_approx_equals(await callFloatFunction(program,  "a", []), -4, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "b", []), -3, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "c", []), 4, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "d", []), 3, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "e", []), -3, epsilon);
+    assert_approx_equals(await callFloatFunction(program,  "f", []), -4, epsilon);
+};
+
+runTests(whlslTests);
+</script>
+</html>
index db25b9b..c151f53 100644 (file)
@@ -1,5 +1,18 @@
 2019-08-15  Myles C. Maxfield  <mmaxfield@apple.com>
 
+        [WHLSL] Add unary plus
+        https://bugs.webkit.org/show_bug.cgi?id=200753
+
+        Reviewed by Saam Barati.
+
+        HLSL has these, so we should too.
+
+        Test: webgpu/whlsl/vector-matrix-addition-subtraction.html
+
+        * Modules/webgpu/WHLSL/WHLSLStandardLibrary.txt:
+
+2019-08-15  Myles C. Maxfield  <mmaxfield@apple.com>
+
         [WHLSL] Matrices should have constructors that take a flattened list of scalars
         https://bugs.webkit.org/show_bug.cgi?id=200804
 
index 609b5f2..d37a546 100644 (file)
@@ -32994,6 +32994,24 @@ native float4x3 operator+(float4x3, float);
 native float4x4 operator+(float4x4, float4x4);
 native float4x4 operator+(float, float4x4);
 native float4x4 operator+(float4x4, float);
+native uint2 operator+(uint2);
+native uint3 operator+(uint3);
+native uint4 operator+(uint4);
+native int2 operator+(int2);
+native int3 operator+(int3);
+native int4 operator+(int4);
+native float2 operator+(float2);
+native float3 operator+(float3);
+native float4 operator+(float4);
+native float2x2 operator+(float2x2);
+native float2x3 operator+(float2x3);
+native float2x4 operator+(float2x4);
+native float3x2 operator+(float3x2);
+native float3x3 operator+(float3x3);
+native float3x4 operator+(float3x4);
+native float4x2 operator+(float4x2);
+native float4x3 operator+(float4x3);
+native float4x4 operator+(float4x4);
 
 /* Functions named operator.zxx */
 bool3 operator.zxx(bool3 v) {