Log Message
Fill out vector types in WSL's standard library https://bugs.webkit.org/show_bug.cgi?id=177063
Reviewed by Filip Pizlo. Now that we have struct types, operator&[], and operator==, fill out a few of the builtin vector types in the standard library. This patch creates three new types: vec2, vec3, and vec4, each of which takes a type argument, so you can say vec4<float>. This patch also adds typedefs of int4, uint4, float4, and double4 (along with their 2- and 3- length siblings). This patch does not include the swizzling operators, so you can't say float4.yzw. * WebGPUShadingLanguageRI/StandardLibrary.js: (operator.T.vec2.T): (bool.operator.T.Equatable): (thread.T.operator.T): (operator.T.vec3.T): (operator.T.vec4.T): * WebGPUShadingLanguageRI/Test.js: (TEST_builtinVectors):
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (222190 => 222191)
--- trunk/Tools/ChangeLog 2017-09-18 23:36:20 UTC (rev 222190)
+++ trunk/Tools/ChangeLog 2017-09-18 23:42:18 UTC (rev 222191)
@@ -1,5 +1,28 @@
2017-09-18 Myles C. Maxfield <[email protected]>
+ Fill out vector types in WSL's standard library
+ https://bugs.webkit.org/show_bug.cgi?id=177063
+
+ Reviewed by Filip Pizlo.
+
+ Now that we have struct types, operator&[], and operator==, fill out a few of the builtin vector types in the
+ standard library. This patch creates three new types: vec2, vec3, and vec4, each of which takes a type
+ argument, so you can say vec4<float>. This patch also adds typedefs of int4, uint4, float4, and double4 (along
+ with their 2- and 3- length siblings).
+
+ This patch does not include the swizzling operators, so you can't say float4.yzw.
+
+ * WebGPUShadingLanguageRI/StandardLibrary.js:
+ (operator.T.vec2.T):
+ (bool.operator.T.Equatable):
+ (thread.T.operator.T):
+ (operator.T.vec3.T):
+ (operator.T.vec4.T):
+ * WebGPUShadingLanguageRI/Test.js:
+ (TEST_builtinVectors):
+
+2017-09-18 Myles C. Maxfield <[email protected]>
+
WSL needs to annotate vertex shaders and fragment shaders
https://bugs.webkit.org/show_bug.cgi?id=177066
Modified: trunk/Tools/WebGPUShadingLanguageRI/StandardLibrary.js (222190 => 222191)
--- trunk/Tools/WebGPUShadingLanguageRI/StandardLibrary.js 2017-09-18 23:36:20 UTC (rev 222190)
+++ trunk/Tools/WebGPUShadingLanguageRI/StandardLibrary.js 2017-09-18 23:42:18 UTC (rev 222191)
@@ -150,6 +150,192 @@
return x != T();
}
+struct vec2<T> {
+ T x;
+ T y;
+}
+
+typedef int2 = vec2<int>;
+typedef uint2 = vec2<uint>;
+typedef float2 = vec2<float>;
+typedef double2 = vec2<double>;
+
+operator<T> vec2<T>(T x, T y)
+{
+ vec2<T> result;
+ result.x = x;
+ result.y = y;
+ return result;
+}
+
+bool operator==<T:Equatable>(vec2<T> a, vec2<T> b)
+{
+ return a.x == b.x && a.y == b.y;
+}
+
+thread T^ operator&[]<T>(thread vec2<T>^ foo, uint index)
+{
+ if (index == 0)
+ return &foo->x;
+ if (index == 1)
+ return &foo->y;
+ return null;
+}
+
+struct vec3<T> {
+ T x;
+ T y;
+ T z;
+}
+
+typedef int3 = vec3<int>;
+typedef uint3 = vec3<uint>;
+typedef float3 = vec3<float>;
+typedef double3 = vec3<double>;
+
+operator<T> vec3<T>(T x, T y, T z)
+{
+ vec3<T> result;
+ result.x = x;
+ result.y = y;
+ result.z = z;
+ return result;
+}
+
+operator<T> vec3<T>(vec2<T> v2, T z)
+{
+ vec3<T> result;
+ result.x = v2.x;
+ result.y = v2.y;
+ result.z = z;
+ return result;
+}
+
+operator<T> vec3<T>(T x, vec2<T> v2)
+{
+ vec3<T> result;
+ result.x = x;
+ result.y = v2.x;
+ result.z = v2.y;
+ return result;
+}
+
+bool operator==<T:Equatable>(vec3<T> a, vec3<T> b)
+{
+ return a.x == b.x && a.y == b.y && a.z == b.z;
+}
+
+thread T^ operator&[]<T>(thread vec3<T>^ foo, uint index)
+{
+ if (index == 0)
+ return &foo->x;
+ if (index == 1)
+ return &foo->y;
+ if (index == 2)
+ return &foo->z;
+ return null;
+}
+
+struct vec4<T> {
+ T x;
+ T y;
+ T z;
+ T w;
+}
+
+typedef int4 = vec4<int>;
+typedef uint4 = vec4<uint>;
+typedef float4 = vec4<float>;
+typedef double4 = vec4<double>;
+
+operator<T> vec4<T>(T x, T y, T z, T w)
+{
+ vec4<T> result;
+ result.x = x;
+ result.y = y;
+ result.z = z;
+ result.w = w;
+ return result;
+}
+
+operator<T> vec4<T>(vec2<T> v2, T z, T w)
+{
+ vec4<T> result;
+ result.x = v2.x;
+ result.y = v2.y;
+ result.z = z;
+ result.w = w;
+ return result;
+}
+
+operator<T> vec4<T>(T x, vec2<T> v2, T w)
+{
+ vec4<T> result;
+ result.x = x;
+ result.y = v2.x;
+ result.z = v2.y;
+ result.w = w;
+ return result;
+}
+
+operator<T> vec4<T>(T x, T y, vec2<T> v2)
+{
+ vec4<T> result;
+ result.x = x;
+ result.y = y;
+ result.z = v2.x;
+ result.w = v2.y;
+ return result;
+}
+
+operator<T> vec4<T>(vec2<T> v2a, vec2<T> v2b)
+{
+ vec4<T> result;
+ result.x = v2a.x;
+ result.y = v2a.y;
+ result.z = v2b.x;
+ result.w = v2b.y;
+ return result;
+}
+
+operator<T> vec4<T>(vec3<T> v3, T w)
+{
+ vec4<T> result;
+ result.x = v3.x;
+ result.y = v3.y;
+ result.z = v3.z;
+ result.w = w;
+ return result;
+}
+
+operator<T> vec4<T>(T x, vec3<T> v3)
+{
+ vec4<T> result;
+ result.x = x;
+ result.y = v3.x;
+ result.z = v3.y;
+ result.w = v3.z;
+ return result;
+}
+
+bool operator==<T:Equatable>(vec4<T> a, vec4<T> b)
+{
+ return a.x == b.x && a.y == b.y && a.z == b.z && a.w == b.w;
+}
+
+thread T^ operator&[]<T>(thread vec4<T>^ foo, uint index)
+{
+ if (index == 0)
+ return &foo->x;
+ if (index == 1)
+ return &foo->y;
+ if (index == 2)
+ return &foo->z;
+ if (index == 3)
+ return &foo->w;
+ return null;
+}
+
native thread T^ operator&[]<T>(thread T[], uint);
native threadgroup T^ operator&[]<T:primitive>(threadgroup T[], uint);
native device T^ operator&[]<T:primitive>(device T[], uint);
Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (222190 => 222191)
--- trunk/Tools/WebGPUShadingLanguageRI/Test.js 2017-09-18 23:36:20 UTC (rev 222190)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js 2017-09-18 23:42:18 UTC (rev 222191)
@@ -3712,6 +3712,188 @@
(e) => e instanceof WTypeError);
}
+function TEST_builtinVectors()
+{
+ let program = doPrep(`
+ int foo()
+ {
+ int2 a = int2(3, 4);
+ return a[0];
+ }
+ int foo2()
+ {
+ int2 a = int2(3, 4);
+ int3 b = int3(a, 5);
+ return b[1];
+ }
+ int foo3()
+ {
+ int3 a = int3(3, 4, 5);
+ int4 b = int4(6, a);
+ return b[1];
+ }
+ int foo4()
+ {
+ int2 a = int2(3, 4);
+ int2 b = int2(5, 6);
+ int4 c = int4(a, b);
+ return c[2];
+ }
+ bool foo5()
+ {
+ int4 a = int4(3, 4, 5, 6);
+ int2 b = int2(4, 5);
+ int4 c = int4(3, b, 6);
+ return a == c;
+ }
+ bool foo6()
+ {
+ int2 a = int2(4, 5);
+ int3 b = int3(3, a);
+ int3 c = int3(3, 4, 6);
+ return b == c;
+ }
+ uint foou()
+ {
+ uint2 a = uint2(3, 4);
+ return a[0];
+ }
+ uint foou2()
+ {
+ uint2 a = uint2(3, 4);
+ uint3 b = uint3(a, 5);
+ return b[1];
+ }
+ uint foou3()
+ {
+ uint3 a = uint3(3, 4, 5);
+ uint4 b = uint4(6, a);
+ return b[1];
+ }
+ uint foou4()
+ {
+ uint2 a = uint2(3, 4);
+ uint2 b = uint2(5, 6);
+ uint4 c = uint4(a, b);
+ return c[2];
+ }
+ bool foou5()
+ {
+ uint4 a = uint4(3, 4, 5, 6);
+ uint2 b = uint2(4, 5);
+ uint4 c = uint4(3, b, 6);
+ return a == c;
+ }
+ bool foou6()
+ {
+ uint2 a = uint2(4, 5);
+ uint3 b = uint3(3, a);
+ uint3 c = uint3(3, 4, 6);
+ return b == c;
+ }
+ float foof()
+ {
+ float2 a = float2(3., 4.);
+ return a[0];
+ }
+ float foof2()
+ {
+ float2 a = float2(3., 4.);
+ float3 b = float3(a, 5.);
+ return b[1];
+ }
+ float foof3()
+ {
+ float3 a = float3(3., 4., 5.);
+ float4 b = float4(6., a);
+ return b[1];
+ }
+ float foof4()
+ {
+ float2 a = float2(3., 4.);
+ float2 b = float2(5., 6.);
+ float4 c = float4(a, b);
+ return c[2];
+ }
+ bool foof5()
+ {
+ float4 a = float4(3., 4., 5., 6.);
+ float2 b = float2(4., 5.);
+ float4 c = float4(3., b, 6.);
+ return a == c;
+ }
+ bool foof6()
+ {
+ float2 a = float2(4., 5.);
+ float3 b = float3(3., a);
+ float3 c = float3(3., 4., 6.);
+ return b == c;
+ }
+ double food()
+ {
+ double2 a = double2(3., 4.);
+ return a[0];
+ }
+ double food2()
+ {
+ double2 a = double2(3., 4.);
+ double3 b = double3(a, 5.);
+ return b[1];
+ }
+ double food3()
+ {
+ double3 a = double3(3., 4., 5.);
+ double4 b = double4(6., a);
+ return b[1];
+ }
+ double food4()
+ {
+ double2 a = double2(3., 4.);
+ double2 b = double2(5., 6.);
+ double4 c = double4(a, b);
+ return c[2];
+ }
+ bool food5()
+ {
+ double4 a = double4(3., 4., 5., 6.);
+ double2 b = double2(4., 5.);
+ double4 c = double4(3., b, 6.);
+ return a == c;
+ }
+ bool food6()
+ {
+ double2 a = double2(4., 5.);
+ double3 b = double3(3., a);
+ double3 c = double3(3., 4., 6.);
+ return b == c;
+ }
+ `);
+ checkInt(program, callFunction(program, "foo", [], []), 3);
+ checkInt(program, callFunction(program, "foo2", [], []), 4);
+ checkInt(program, callFunction(program, "foo3", [], []), 3);
+ checkInt(program, callFunction(program, "foo4", [], []), 5);
+ checkBool(program, callFunction(program, "foo5", [], []), true);
+ checkBool(program, callFunction(program, "foo6", [], []), false);
+ checkUint(program, callFunction(program, "foou", [], []), 3);
+ checkUint(program, callFunction(program, "foou2", [], []), 4);
+ checkUint(program, callFunction(program, "foou3", [], []), 3);
+ checkUint(program, callFunction(program, "foou4", [], []), 5);
+ checkBool(program, callFunction(program, "foou5", [], []), true);
+ checkBool(program, callFunction(program, "foou6", [], []), false);
+ checkFloat(program, callFunction(program, "foof", [], []), 3);
+ checkFloat(program, callFunction(program, "foof2", [], []), 4);
+ checkFloat(program, callFunction(program, "foof3", [], []), 3);
+ checkFloat(program, callFunction(program, "foof4", [], []), 5);
+ checkBool(program, callFunction(program, "foof5", [], []), true);
+ checkBool(program, callFunction(program, "foof6", [], []), false);
+ checkDouble(program, callFunction(program, "food", [], []), 3);
+ checkDouble(program, callFunction(program, "food2", [], []), 4);
+ checkDouble(program, callFunction(program, "food3", [], []), 3);
+ checkDouble(program, callFunction(program, "food4", [], []), 5);
+ checkBool(program, callFunction(program, "food5", [], []), true);
+ checkBool(program, callFunction(program, "food6", [], []), false);
+}
+
let filter = /.*/; // run everything by default
if (this["arguments"]) {
for (let i = 0; i < arguments.length; i++) {
_______________________________________________ webkit-changes mailing list [email protected] https://lists.webkit.org/mailman/listinfo/webkit-changes
