Title: [222279] trunk/Tools
Revision
222279
Author
[email protected]
Date
2017-09-20 13:03:22 -0700 (Wed, 20 Sep 2017)

Log Message

[WSL] Restrict vertex and fragment entry points according to WSL.md
https://bugs.webkit.org/show_bug.cgi?id=177253

Reviewed by Filip Pizlo.

Entry points can't have template arguments, and their argument/return types need to be restricted.

* WebGPUShadingLanguageRI/Checker.js:
(Checker):
(Checker.prototype._checkShaderType.NonNumericSearcher):
(Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitArrayRefType):
(Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitPtrType):
(Checker.prototype._checkShaderType):
(Checker.prototype.visitFuncDef):
(Checker.prototype._requireBool):
* WebGPUShadingLanguageRI/Func.js:
(Func.prototype.toDeclString):
* WebGPUShadingLanguageRI/Test.js:
(TEST_shaderTypes):

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (222278 => 222279)


--- trunk/Tools/ChangeLog	2017-09-20 19:38:59 UTC (rev 222278)
+++ trunk/Tools/ChangeLog	2017-09-20 20:03:22 UTC (rev 222279)
@@ -1,3 +1,25 @@
+2017-09-20  Myles C. Maxfield  <[email protected]>
+
+        [WSL] Restrict vertex and fragment entry points according to WSL.md
+        https://bugs.webkit.org/show_bug.cgi?id=177253
+
+        Reviewed by Filip Pizlo.
+
+        Entry points can't have template arguments, and their argument/return types need to be restricted.
+
+        * WebGPUShadingLanguageRI/Checker.js:
+        (Checker):
+        (Checker.prototype._checkShaderType.NonNumericSearcher):
+        (Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitArrayRefType):
+        (Checker.prototype._checkShaderType.NonNumericSearcher.prototype.visitPtrType):
+        (Checker.prototype._checkShaderType):
+        (Checker.prototype.visitFuncDef):
+        (Checker.prototype._requireBool):
+        * WebGPUShadingLanguageRI/Func.js:
+        (Func.prototype.toDeclString):
+        * WebGPUShadingLanguageRI/Test.js:
+        (TEST_shaderTypes):
+
 2017-09-20  Per Arne Vollan  <[email protected]>
 
         [Win] Cygwin 64-bit EWS process cannot find Visual Studio installation.

Modified: trunk/Tools/WebGPUShadingLanguageRI/Checker.js (222278 => 222279)


--- trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-20 19:38:59 UTC (rev 222278)
+++ trunk/Tools/WebGPUShadingLanguageRI/Checker.js	2017-09-20 20:03:22 UTC (rev 222279)
@@ -30,6 +30,8 @@
         super();
         this._program = program;
         this._currentStatement = null;
+        this._vertexEntryPoints = new Set();
+        this._fragmentEntryPoints = new Set();
     }
     
     visitProgram(node)
@@ -53,9 +55,67 @@
                 doStatement(func);
         }
     }
+
+    _checkShaderType(node)
+    {
+        // FIXME: Relax these checks once we have implemented support for textures and samplers.
+        if (node.typeParameters.length != 0)
+            throw new WTypeError("Entry point " + node.name + " must not have type arguments.");
+        class NonNumericSearcher extends Visitor {
+            constructor(name)
+            {
+                super();
+                this._name = name;
+            }
+            visitArrayRefType(node)
+            {
+                throw new WTypeError(this._name + " must transitively only have numeric types.");
+            }
+            visitPtrType(node)
+            {
+                throw new WTypeError(this._name + " must transitively only have numeric types.");
+            }
+        }
+        switch (node.shaderType) {
+        case "vertex":
+            if (this._vertexEntryPoints.has(node.name))
+                throw new WTypeError("Duplicate vertex entry point name " + node.name);
+            this._vertexEntryPoints.add(node.name);
+            if (!(node.returnType.type instanceof StructType))
+                throw new WTypeError("Vertex shader " + node.name + " must return a struct.");
+            for (let parameter of node.parameters) {
+                if (parameter.type.type instanceof StructType)
+                    parameter.type.visit(new NonNumericSearcher(node.name));
+                else if (!(parameter.type.type instanceof ArrayRefType))
+                    throw new WTypeError(node.name + " accepts a parameter " + parameter.name + " which isn't a struct and isn't an ArrayRef.");
+            }
+            node.returnType.type.visit(new NonNumericSearcher);
+            break;
+        case "fragment":
+            if (this._fragmentEntryPoints.has(node.name))
+                throw new WTypeError("Duplicate fragment entry point name " + node.name);
+            this._fragmentEntryPoints.add(node.name);
+            if (!(node.returnType.type instanceof StructType))
+                throw new WTypeError("Fragment shader " + node.name + " must return a struct.");
+            for (let parameter of node.parameters) {
+                if (parameter.name == "stageIn") {
+                    if (!(parameter.type.type instanceof StructType))
+                        throw new WTypeError("Fragment entry points' stageIn parameter (of " + node.name + ") must be a struct type.");
+                    parameter.type.visit(new NonNumericSearcher(node.name));
+                } else {
+                    if (!(parameter.type.type instanceof ArrayRefType))
+                        throw new WTypeError("Fragment entry point's " + parameter.name + " parameter is not an array reference.");
+                }
+            }
+            node.returnType.type.visit(new NonNumericSearcher);
+            break;
+        }
+    }
     
     visitFuncDef(node)
     {
+        if (node.shaderType)
+            this._checkShaderType(node);
         node.body.visit(this);
     }
     
@@ -408,7 +468,7 @@
         if (!type)
             throw new Error("_expression_ has no type, but should be bool: " + _expression_);
         if (!type.equals(this._program.intrinsics.bool))
-            throw new WError("_expression_ isn't a bool: " + _expression_);
+            throw new WTypeError("_expression_ isn't a bool: " + _expression_);
     }
 
     visitLogicalNot(node)

Modified: trunk/Tools/WebGPUShadingLanguageRI/Func.js (222278 => 222279)


--- trunk/Tools/WebGPUShadingLanguageRI/Func.js	2017-09-20 19:38:59 UTC (rev 222278)
+++ trunk/Tools/WebGPUShadingLanguageRI/Func.js	2017-09-20 20:03:22 UTC (rev 222279)
@@ -60,7 +60,13 @@
     
     toDeclString()
     {
-        return (this.isCast ? "operator " + this.returnType : this.returnType + " " + this.name) + "<" + this.typeParameters + ">(" + this.parameters + ")";
+        let type = "";
+        if (this.shaderType)
+            type = this.shaderType + " ";
+        let returnAndName = this.returnType + " " + this.name;
+        if (this.isCast)
+            returnAndName = "operator " + this.returnType;
+        return type + returnAndName + "<" + this.typeParameters + ">(" + this.parameters + ")";
     }
     
     toString()

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (222278 => 222279)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-20 19:38:59 UTC (rev 222278)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-20 20:03:22 UTC (rev 222279)
@@ -3709,15 +3709,131 @@
 {
     checkFail(
         () => doPrep(`
-            vertex float4 bar()
+            struct Foo {
+                float4 x;
+            }
+            vertex Foo bar()
             {
-                return float4();
+                Foo result;
+                result.x = float4();
+                return result;
             }
-            float4 foo() {
+            Foo foo() {
                 return bar();
             }
         `),
         (e) => e instanceof WTypeError);
+    checkFail(
+        () => doPrep(`
+            vertex float bar()
+            {
+                return 4.;
+            }
+        `),
+        (e) => e instanceof WTypeError);
+    checkFail(
+        () => doPrep(`
+            struct Foo {
+                float4 x;
+            }
+            vertex Foo bar(device Foo^ x)
+            {
+                return Foo();
+            }
+        `),
+        (e) => e instanceof WTypeError);
+    checkFail(
+        () => doPrep(`
+            struct Boo {
+                float4 x;
+            }
+            struct Foo {
+                float4 x;
+                device Boo^ y;
+            }
+            vertex Foo bar()
+            {
+                return Foo();
+            }
+        `),
+        (e) => e instanceof WTypeError);
+    checkFail(
+        () => doPrep(`
+            struct Foo {
+                float4 x;
+            }
+            struct Boo {
+                device Foo^ y;
+            }
+            vertex Foo bar(Boo b)
+            {
+                return Foo();
+            }
+        `),
+        (e) => e instanceof WTypeError);
+    checkFail(
+        () => doPrep(`
+            struct Foo {
+                float4 x;
+            }
+            vertex Foo bar(device Foo^ x)
+            {
+                return Foo();
+            }
+        `),
+        (e) => e instanceof WTypeError);
+    checkFail(
+        () => doPrep(`
+            struct Foo {
+                float4 x;
+            }
+            fragment Foo bar(Foo foo)
+            {
+                return Foo();
+            }
+        `),
+        (e) => e instanceof WTypeError);
+    checkFail(
+        () => doPrep(`
+            struct Foo {
+                float4 x;
+            }
+            fragment Foo bar(device Foo^ stageIn)
+            {
+                return Foo();
+            }
+        `),
+        (e) => e instanceof WTypeError);
+    checkFail(
+        () => doPrep(`
+            struct Boo {
+                float4 x;
+            }
+            struct Foo {
+                float4 x;
+                device Boo^ y;
+            }
+            fragment Boo bar(Foo stageIn)
+            {
+                return boo();
+            }
+        `),
+        (e) => e instanceof WTypeError);
+    checkFail(
+        () => doPrep(`
+            struct Boo {
+                float4 x;
+            }
+            struct Foo {
+                float4 x;
+                device Boo^ y;
+            }
+            fragment Foo bar(Boo stageIn)
+            {
+                return Foo();
+            }
+        `),
+        (e) => e instanceof WTypeError);
 }
 
 function TEST_builtinVectors()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to