Title: [222185] trunk/Tools
Revision
222185
Author
[email protected]
Date
2017-09-18 15:39:30 -0700 (Mon, 18 Sep 2017)

Log Message

WSL needs to annotate vertex shaders and fragment shaders
https://bugs.webkit.org/show_bug.cgi?id=177066

Reviewed by Filip Pizlo.

Metal Shading Language requires annotating vertex and fragment shaders, so this information needs to be in
the source WSL file.

* WebGPUShadingLanguageRI/Func.js:
(Func):
(Func.prototype.get shaderType):
* WebGPUShadingLanguageRI/FuncDef.js:
(FuncDef):
* WebGPUShadingLanguageRI/NativeFunc.js:
(NativeFunc):
* WebGPUShadingLanguageRI/Parse.js:
(parseFuncDecl):
(parseProtocolFuncDecl):
(parseFuncDef):
(parseNativeFunc):
* WebGPUShadingLanguageRI/ResolveOverloadImpl.js:
(resolveOverloadImpl):
* WebGPUShadingLanguageRI/Test.js:

Modified Paths

Diff

Modified: trunk/Tools/ChangeLog (222184 => 222185)


--- trunk/Tools/ChangeLog	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/ChangeLog	2017-09-18 22:39:30 UTC (rev 222185)
@@ -1,3 +1,29 @@
+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
+
+        Reviewed by Filip Pizlo.
+
+        Metal Shading Language requires annotating vertex and fragment shaders, so this information needs to be in
+        the source WSL file.
+
+        * WebGPUShadingLanguageRI/Func.js:
+        (Func):
+        (Func.prototype.get shaderType):
+        * WebGPUShadingLanguageRI/FuncDef.js:
+        (FuncDef):
+        * WebGPUShadingLanguageRI/NativeFunc.js:
+        (NativeFunc):
+        * WebGPUShadingLanguageRI/Parse.js:
+        (parseFuncDecl):
+        (parseProtocolFuncDecl):
+        (parseFuncDef):
+        (parseNativeFunc):
+        * WebGPUShadingLanguageRI/ResolveOverloadImpl.js:
+        (resolveOverloadImpl):
+        * WebGPUShadingLanguageRI/Test.js:
+
 2017-09-18  Filip Pizlo  <[email protected]>
 
         WSL should know that constexpr parameters are not lvalues

Modified: trunk/Tools/WebGPUShadingLanguageRI/Func.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/Func.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/Func.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -25,7 +25,7 @@
 "use strict";
 
 class Func extends Node {
-    constructor(origin, name, returnType, typeParameters, parameters, isCast)
+    constructor(origin, name, returnType, typeParameters, parameters, isCast, shaderType)
     {
         if (!(origin instanceof LexerToken))
             throw new Error("Bad origin: " + origin);
@@ -42,6 +42,7 @@
         this._typeParameters = typeParameters;
         this._parameters = parameters;
         this._isCast = isCast;
+        this._shaderType = shaderType;
     }
     
     get origin() { return this._origin; }
@@ -52,6 +53,7 @@
     get parameters() { return this._parameters; }
     get parameterTypes() { return this.parameters.map(parameter => parameter.type); }
     get isCast() { return this._isCast; }
+    get shaderType() { return this._shaderType; }
     get returnTypeForOverloadResolution() { return this.isCast ? this.returnType : null; }
     
     get kind() { return Func; }

Modified: trunk/Tools/WebGPUShadingLanguageRI/FuncDef.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/FuncDef.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/FuncDef.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -25,9 +25,9 @@
 "use strict";
 
 class FuncDef extends Func {
-    constructor(origin, name, returnType, typeParameters, parameters, body, isCast)
+    constructor(origin, name, returnType, typeParameters, parameters, body, isCast, shaderType)
     {
-        super(origin, name, returnType, typeParameters, parameters, isCast);
+        super(origin, name, returnType, typeParameters, parameters, isCast, shaderType);
         this._body = body;
         this.isRestricted = false;
     }

Modified: trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -112,6 +112,7 @@
                     func.returnType.visit(substitution).visit(instantiateImmediates),
                     func.parameters.map(parameter => parameter.visit(substitution).visit(instantiateImmediates)),
                     func.isCast,
+                    func.shaderType,
                     func.instantiateImplementation(substitution));
             }
         }

Modified: trunk/Tools/WebGPUShadingLanguageRI/NativeFunc.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/NativeFunc.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/NativeFunc.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -25,9 +25,9 @@
 "use strict";
 
 class NativeFunc extends Func {
-    constructor(origin, name, returnType, typeParameters, parameters, isCast)
+    constructor(origin, name, returnType, typeParameters, parameters, isCast, shaderType)
     {
-        super(origin, name, returnType, typeParameters, parameters, isCast);
+        super(origin, name, returnType, typeParameters, parameters, isCast, shaderType);
         this.isRestricted = false;
         this.implementation = null;
         this.instantiateImplementation = (substitution) => {};

Modified: trunk/Tools/WebGPUShadingLanguageRI/NativeFuncInstance.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/NativeFuncInstance.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/NativeFuncInstance.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -25,9 +25,9 @@
 "use strict";
 
 class NativeFuncInstance extends Func {
-    constructor(func, returnType, parameters, isCast, implementationData)
+    constructor(func, returnType, parameters, isCast, shaderType, implementationData)
     {
-        super(func.origin, func.name, returnType, [], parameters, isCast);
+        super(func.origin, func.name, returnType, [], parameters, isCast, shaderType);
         this._func = func;
         this._implementationData = implementationData;
     }

Modified: trunk/Tools/WebGPUShadingLanguageRI/Parse.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/Parse.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/Parse.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -816,6 +816,7 @@
         let name;
         let typeParameters;
         let isCast;
+        let shaderType;
         let operatorToken = tryConsume("operator");
         if (operatorToken) {
             origin = operatorToken;
@@ -824,20 +825,25 @@
             name = "operator cast";
             isCast = true;
         } else {
+            shaderType = tryConsume("vertex", "fragment");
             returnType = parseType();
-            origin = returnType.origin;
+            if (shaderType) {
+                origin = shaderType;
+                shaderType = shaderType.text;
+            } else
+                origin = returnType.origin;
             name = parseFuncName();
             typeParameters = parseTypeParameters();
             isCast = false;
         }
         let parameters = parseParameters();
-        return new Func(origin, name, returnType, typeParameters, parameters, isCast);
+        return new Func(origin, name, returnType, typeParameters, parameters, isCast, shaderType);
     }
 
     function parseProtocolFuncDecl()
     {
         let func = parseFuncDecl();
-        return new ProtocolFuncDecl(func.origin, func.name, func.returnType, func.typeParameters, func.parameters, func.isCast);
+        return new ProtocolFuncDecl(func.origin, func.name, func.returnType, func.typeParameters, func.parameters, func.isCast, func.shaderType);
     }
     
     function parseFuncDef()
@@ -844,7 +850,7 @@
     {
         let func = parseFuncDecl();
         let body = parseBlock();
-        return new FuncDef(func.origin, func.name, func.returnType, func.typeParameters, func.parameters, body, func.isCast);
+        return new FuncDef(func.origin, func.name, func.returnType, func.typeParameters, func.parameters, body, func.isCast, func.shaderType);
     }
     
     function parseProtocolDecl()
@@ -891,7 +897,7 @@
     {
         let func = parseFuncDecl();
         consume(";");
-        return new NativeFunc(func.origin, func.name, func.returnType, func.typeParameters, func.parameters, func.isCast);
+        return new NativeFunc(func.origin, func.name, func.returnType, func.typeParameters, func.parameters, func.isCast, func.shaderType);
     }
     
     function parseNative()

Modified: trunk/Tools/WebGPUShadingLanguageRI/ResolveOverloadImpl.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/ResolveOverloadImpl.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/ResolveOverloadImpl.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -32,6 +32,10 @@
     let failures = [];
     let successes = [];
     for (let func of functions) {
+        if (func.shaderType) {
+            failures.push(new OverloadResolutionFailure(func, "Function is a " + func.shaderType + " shader, so it cannot be called from within an existing shader."))
+            continue;
+        }
         let overload = inferTypesForCall(func, typeArguments, argumentTypes, returnType);
         if (overload.failure)
             failures.push(overload.failure);

Modified: trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -73,7 +73,8 @@
             node.returnType.visit(this),
             node.typeParameters.map(parameter => parameter.visit(this)),
             node.parameters.map(parameter => parameter.visit(this)),
-            node.isCast);
+            node.isCast,
+            node.shaderType);
         result.protocolDecl = node.protocolDecl;
         result.possibleOverloads = node.possibleOverloads;
         return result;

Modified: trunk/Tools/WebGPUShadingLanguageRI/SynthesizeStructAccessors.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/SynthesizeStructAccessors.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/SynthesizeStructAccessors.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -98,6 +98,7 @@
             }
             
             let isCast = false;
+            let shaderType;
             let typeParameters;
             let nativeFunc;
 
@@ -105,7 +106,7 @@
             typeParameters = createTypeParameters();
             nativeFunc = new NativeFunc(
                 field.origin, "operator." + field.name, createFieldType(), typeParameters,
-                [new FuncParameter(field.origin, null, createTypeRef())], isCast);
+                [new FuncParameter(field.origin, null, createTypeRef())], isCast, shaderType);
             setupImplementationData(nativeFunc, ([base], offset, structSize, fieldSize) => {
                 let result = new EPtr(new EBuffer(fieldSize), 0);
                 result.copyFrom(base.plus(offset), fieldSize);
@@ -121,7 +122,7 @@
                     new FuncParameter(field.origin, null, createTypeRef()),
                     new FuncParameter(field.origin, null, createFieldType())
                 ],
-                isCast);
+                isCast, shaderType);
             setupImplementationData(nativeFunc, ([base, value], offset, structSize, fieldSize) => {
                 let result = new EPtr(new EBuffer(structSize), 0);
                 result.copyFrom(base, structSize);
@@ -142,7 +143,7 @@
                             field.origin, null,
                             new PtrType(field.origin, addressSpace, createTypeRef()))
                     ],
-                    isCast);
+                    isCast, shaderType);
                 setupImplementationData(nativeFunc, ([base], offset, structSize, fieldSize) => {
                     base = base.loadValue();
                     if (!base)

Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (222184 => 222185)


--- trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-18 22:36:28 UTC (rev 222184)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js	2017-09-18 22:39:30 UTC (rev 222185)
@@ -3697,6 +3697,21 @@
     checkInt(program, callFunction(program, "foo", [], []), 0);
 }
 
+function TEST_shaderTypes()
+{
+    checkFail(
+        () => doPrep(`
+            vertex float4 bar()
+            {
+                return float4();
+            }
+            float4 foo() {
+                return bar();
+            }
+        `),
+        (e) => e instanceof WTypeError);
+}
+
 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

Reply via email to