Diff
Modified: trunk/Tools/ChangeLog (234174 => 234175)
--- trunk/Tools/ChangeLog 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/ChangeLog 2018-07-24 23:08:26 UTC (rev 234175)
@@ -1,3 +1,78 @@
+2018-07-24 Thomas Denney <[email protected]>
+ Minor changes to the WHLSL interpreter to support the new compiler
+ https://bugs.webkit.org/show_bug.cgi?id=187728
+
+ Reviewed by Myles C. Maxfield.
+
+ This bug contains small changes that are make minor changes to the
+ behaviour of the existing interpreter (the tests are unaffected and all
+ still pass).
+
+ * WebGPUShadingLanguageRI/EnumType.js:
+ (EnumType.prototype.get isEnum): Property added to EnumType and Type
+ * WebGPUShadingLanguageRI/Evaluator.js: Correct typo
+ * WebGPUShadingLanguageRI/Func.js:
+ (Func.prototype.get isEntryPoint): Add boolean property
+ * WebGPUShadingLanguageRI/FuncInstantiator.js:
+ (FuncInstantiator.prototype.get instances): Public accessor for existing
+ private field
+ * WebGPUShadingLanguageRI/FunctionLikeBlock.js: Refactored the class so
+ that it directly wraps a Func instance (therefore the only interface
+ change is to the constructor and the addition of the func accessor).
+ This change allows the de-inlining of functions.
+ (FunctionLikeBlock):
+ (FunctionLikeBlock.prototype.get func):
+ (FunctionLikeBlock.prototype.get returnType):
+ (FunctionLikeBlock.prototype.get parameters):
+ (FunctionLikeBlock.prototype.get body):
+ * WebGPUShadingLanguageRI/Inliner.js: Use the new FunctionLikeBlock
+ constructor
+ (Inliner.prototype.visitCallExpression):
+ (Inliner):
+ * WebGPUShadingLanguageRI/Intrinsics.js: Migrate the swizzle operators
+ to native functions (with additional support in StandardLibrary.js).
+ This reduces first-time compile-time from around 4s to around 0.1s.
+ (Intrinsics):
+ * WebGPUShadingLanguageRI/Lexer.js: Ensure that the parsing of multiline
+ comments completes correctly
+ (Lexer.prototype.next):
+ (Lexer):
+ * WebGPUShadingLanguageRI/MakeArrayRefExpression.js: Addition of type
+ property, which is based on the type of the lValue and the semantics of
+ the language (the @ operator yields an array reference with the thread
+ scope).
+ (MakeArrayRefExpression):
+ (MakeArrayRefExpression.prototype.get type):
+ * WebGPUShadingLanguageRI/NativeFunc.js: Add setter/getter for
+ implementationData to support swizzle operator change
+ (NativeFunc.prototype.get implementationData):
+ (NativeFunc.prototype.set implementationData):
+ * WebGPUShadingLanguageRI/Rewriter.js: Use new FunctionLikeBlock
+ constructor
+ (Rewriter.prototype.visitFunctionLikeBlock):
+ * WebGPUShadingLanguageRI/StandardLibrary.js:
+ (_generateSwizzle): Deleted.
+ * WebGPUShadingLanguageRI/SwizzleOp.js: Introduces a new class for
+ carrying metadata about swizzle operators so that they are implemented
+ as native functions rather than generated at compile time.
+ (SwizzleOp):
+ (SwizzleOp.prototype.get outSize):
+ (SwizzleOp.prototype.get components):
+ (SwizzleOp.prototype.get inSize):
+ (SwizzleOp.prototype.toString):
+ (SwizzleOp.allSwizzleOperators.):
+ (SwizzleOp.allSwizzleOperators):
+ * WebGPUShadingLanguageRI/StandardLibrary.js: + (SwizzleOp):
+ (SwizzleOp.prototype.get outSize):
+ (SwizzleOp.prototype.get components):
+ (SwizzleOp.prototype.get inSize):
+ (SwizzleOp.prototype.toString):
+ (generateSwizzles):
+ (_generateSwizzle): Deleted.
+ * WebGPUShadingLanguageRI/Type.js: Addition of isEnum property, as
+ above.
+ (Type.prototype.get isEnum):
+
2018-07-24 Ryan Haddad <[email protected]>
Unreviewed, rolling out r234121.
Modified: trunk/Tools/WebGPUShadingLanguageRI/EnumType.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/EnumType.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/EnumType.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -45,6 +45,7 @@
get origin() { return this._origin; }
get name() { return this._name; }
get baseType() { return this._baseType; }
+ get isEnum() { return true; }
get memberNames() { return this._members.keys(); }
memberByName(name) { return this._members.get(name); }
Modified: trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/Evaluator.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -33,7 +33,7 @@
}
// You must snapshot if you use a value in rvalue context. For example, a call _expression_ will
- // snapshot all of its arguments immedaitely upon executing them. In general, it should not be
+ // snapshot all of its arguments immediately upon executing them. In general, it should not be
// possible for a pointer returned from a visit method in rvalue context to live across any effects.
_snapshot(type, dstPtr, srcPtr)
{
Modified: trunk/Tools/WebGPUShadingLanguageRI/Func.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/Func.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/Func.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -54,6 +54,7 @@
get parameterTypes() { return this.parameters.map(parameter => parameter.type); }
get isCast() { return this._isCast; }
get shaderType() { return this._shaderType; }
+ get isEntryPoint() { return this.shaderType != null; }
get returnTypeForOverloadResolution() { return this.isCast ? this.returnType : null; }
get kind() { return Func; }
Modified: trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/FuncInstantiator.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -31,6 +31,8 @@
this._instances = new Map();
}
+ get instances() { return this._instances; }
+
// Returns a Func object that uniquely identifies a particular system of type arguments. You must
// intantiate things with concrete types, because this code casually assumes this. Note that this
// will return a different func from `func` no matter what. This ensures that we can use the
Modified: trunk/Tools/WebGPUShadingLanguageRI/FunctionLikeBlock.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/FunctionLikeBlock.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/FunctionLikeBlock.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -25,21 +25,20 @@
"use strict";
class FunctionLikeBlock extends Value {
- constructor(origin, returnType, argumentList, parameters, body)
+ constructor(origin, func, argumentList)
{
super();
this._origin = origin;
- this._returnType = returnType;
+ this._func = func;
this._argumentList = argumentList;
- this._parameters = parameters;
- this._body = body;
}
get origin() { return this._origin; }
- get returnType() { return this._returnType; }
+ get func() { return this._func; }
+ get returnType() { return this.func._returnType; }
get argumentList() { return this._argumentList; }
- get parameters() { return this._parameters; }
- get body() { return this._body; }
+ get parameters() { return this.func._parameters; }
+ get body() { return this.func._body; }
toString()
{
Modified: trunk/Tools/WebGPUShadingLanguageRI/Inliner.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/Inliner.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/Inliner.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -42,8 +42,7 @@
if (func.isNative)
throw new Error("Unexpected native func: " + func);
_inlineFunction(this._program, func, this._visiting);
- let resultingBlock = new FunctionLikeBlock(
- result.origin, func.returnType, result.argumentList, func.parameters, func.body);
+ let resultingBlock = new FunctionLikeBlock(result.origin, func, result.argumentList);
resultingBlock.returnEPtr = result.resultEPtr;
return resultingBlock;
});
Modified: trunk/Tools/WebGPUShadingLanguageRI/Intrinsics.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/Intrinsics.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/Intrinsics.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -30,7 +30,7 @@
this._map = new Map();
// NOTE: Intrinsic resolution happens before type name resolution, so the strings we use here
- // to catch the intrinsics must be based on the type names that StandardLibraryPrologue.js uses.
+ // to catch the intrinsics must be based on the type names that StandardLibrary.js uses.
// For example, if a native function is declared using "int" rather than "int32", then we must
// use "int" here, since we don't yet know that they are the same type.
@@ -654,6 +654,23 @@
};
});
}
+
+ for (let swizzle of SwizzleOp.allSwizzleOperators()) {
+ this._map.set(swizzle.toString(),
+ func => {
+ func.implementation = ([vec], node) => {
+ const outputBuffer = new EBuffer(swizzle.outSize);
+ const readIndices = { 'x': 0, 'y': 1, 'z': 2, 'w': 3 };
+ for (let i = 0; i < swizzle.outSize; i++)
+ outputBuffer.set(i, vec.get(readIndices[swizzle.components[i]]));
+
+
+ return new EPtr(outputBuffer, 0);
+ },
+ func.implementationData = swizzle;
+ });
+ console.log(swizzle.toString());
+ }
}
add(thing)
Modified: trunk/Tools/WebGPUShadingLanguageRI/Lexer.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/Lexer.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/Lexer.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -103,7 +103,7 @@
let endIndex = relevantText.search(/\*\//);
if (endIndex < 0)
this.fail("Unterminated comment");
- this._index += endIndex;
+ this._index += endIndex + 2;
continue;
}
if (/^\/\/.*/.test(relevantText)) {
Modified: trunk/Tools/WebGPUShadingLanguageRI/MakeArrayRefExpression.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/MakeArrayRefExpression.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/MakeArrayRefExpression.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -29,10 +29,14 @@
{
super(origin);
this._lValue = lValue;
+ if (this.lValue.variable && this.lValue.variable.type && this.lValue.variable.type.isArray && this.lValue.variable.type.elementType) {
+ this._type = new ArrayRefType(origin, "thread", this.lValue.variable.type.elementType);
+ }
}
-
+
+ get type() { return this._type; }
get lValue() { return this._lValue; }
-
+
toString()
{
return "@" + (this.numElements ? "<<" + this.numElements + ">>" : "") + "(" + this.lValue + ")";
Modified: trunk/Tools/WebGPUShadingLanguageRI/NativeFunc.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/NativeFunc.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/NativeFunc.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -30,13 +30,17 @@
super(origin, name, returnType, typeParameters, parameters, isCast, shaderType);
this.isRestricted = false;
this.implementation = null;
+ this._implementationData = null;
this.instantiateImplementation = (substitution) => {};
this.visitImplementationData = (implementationData, visitor) => null;
this.didLayoutStructsInImplementationData = implementationData => null;
}
-
+
get isNative() { return true; }
+ get implementationData() { return this._implementationData; }
+ set implementationData(newImplData) { this._implementationData = newImplData; }
+
toDeclString()
{
return "native " + super.toDeclString();
Modified: trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/Rewriter.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -351,10 +351,9 @@
{
let result = new FunctionLikeBlock(
node.origin,
- Node.visit(node.returnType, this),
- node.argumentList.map(argument => argument.visit(this)),
- node.parameters.map(parameter => parameter.visit(this)),
- node.body.visit(this));
+ node.func.visit(this),
+ node.argumentList.map(arg => arg.visit(this))
+ );
result.returnEPtr = node.returnEPtr;
return result;
}
Modified: trunk/Tools/WebGPUShadingLanguageRI/SPIRV.html (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/SPIRV.html 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/SPIRV.html 2018-07-24 23:08:26 UTC (rev 234175)
@@ -17,6 +17,7 @@
<script src=""
<script src=""
<script src=""
+ <script src=""
<script src=""
<script src=""
Modified: trunk/Tools/WebGPUShadingLanguageRI/StandardLibrary.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/StandardLibrary.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/StandardLibrary.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -406,35 +406,6 @@
}
}
-// There are 481 swizzle operators. Let's not list them explicitly.
-function _generateSwizzle(maxDepth, maxItems, array)
-{
- if (!array)
- array = [];
- if (array.length == maxDepth) {
- let result = `vec${array.length}<T> operator.${array.join("")}<T>(vec${maxItems}<T> v)
-{
- vec${array.length}<T> result;
-`;
- for (let i = 0; i < array.length; ++i) {
- result += ` result.${intToString(i)} = v.${array[i]};
-`;
- }
- result += ` return result;
-}
-`;
- return result;
- }
- let result = "";
- for (let i = 0; i < maxItems; ++i) {
- array.push(intToString(i));
- result += _generateSwizzle(maxDepth, maxItems, array);
- array.pop();
- }
- return result;
-}
-
-for (let maxDepth = 2; maxDepth <= 4; maxDepth++) {
- for (let maxItems = 2; maxItems <= 4; maxItems++)
- standardLibrary += _generateSwizzle(maxDepth, maxItems);
-}
+// There are 481 swizzle operators, so we compile them as native functions
+standardLibrary += SwizzleOp.allSwizzleOperators().join(";\n") + ";";
+console.log(standardLibrary);
\ No newline at end of file
Added: trunk/Tools/WebGPUShadingLanguageRI/SwizzleOp.js (0 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/SwizzleOp.js (rev 0)
+++ trunk/Tools/WebGPUShadingLanguageRI/SwizzleOp.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -0,0 +1,73 @@
+/*
+ * Copyright (C) 2017 Apple Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE INC. ``AS IS'' AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL APPLE INC. OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
+ * OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+"use strict";
+
+class SwizzleOp {
+ constructor(outSize, components, inSize)
+ {
+ this._outSize = outSize;
+ this._components = components.slice(); // Shallow clone
+ this._inSize = inSize;
+ }
+
+ get outSize() { return this._outSize; }
+ get components() { return this._components; }
+ get inSize() { return this._inSize; }
+
+ toString()
+ {
+ return `native vec${this.outSize}<T> operator.${this.components.join("")}<T>(vec${this.inSize}<T> v)`;
+ }
+
+ static allSwizzleOperators()
+ {
+ if (!SwizzleOp._allSwizzleOperators) {
+ SwizzleOp._allSwizzleOperators = [];
+
+ function _generateSwizzle(maxDepth, maxItems, array) {
+ if (!array)
+ array = [];
+ if (array.length == maxDepth) {
+ SwizzleOp._allSwizzleOperators.push(new SwizzleOp(array.length, array, maxItems));
+ return;
+ }
+ for (let i = 0; i < maxItems; ++i) {
+ array.push(intToString(i));
+ _generateSwizzle(maxDepth, maxItems, array);
+ array.pop();
+ }
+ };
+
+ for (let maxDepth = 2; maxDepth <= 4; maxDepth++) {
+ for (let maxItems = 2; maxItems <= 4; maxItems++)
+ _generateSwizzle(maxDepth, maxItems);
+ }
+ }
+ return SwizzleOp._allSwizzleOperators;
+ }
+}
+
+// Initialise the static member (JS doesn't allow static fields declared in the class)
+SwizzleOp._allSwizzleOperators = null;
\ No newline at end of file
Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.html (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/Test.html 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.html 2018-07-24 23:08:26 UTC (rev 234175)
@@ -11,6 +11,7 @@
<script src=""
<script src=""
<script src=""
+<script src=""
<script src=""
<script src=""
Modified: trunk/Tools/WebGPUShadingLanguageRI/Test.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/Test.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/Test.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -194,6 +194,23 @@
}
});
+tests.commentParsing = function() {
+ let program = doPrep(`
+ /* this comment
+ runs over multiple lines */
+ bool foo() { return true; }
+ `);
+ checkBool(program, callFunction(program, "foo", [], []), true);
+
+ checkFail(
+ () => doPrep(`
+ /* this comment
+ runs over multiple lines
+ bool foo() { return true; }
+ `),
+ (e) => e instanceof WSyntaxError);
+}
+
tests.literalBool = function() {
let program = doPrep("bool foo() { return true; }");
checkBool(program, callFunction(program, "foo", [], []), true);
Modified: trunk/Tools/WebGPUShadingLanguageRI/Type.js (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/Type.js 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/Type.js 2018-07-24 23:08:26 UTC (rev 234175)
@@ -34,6 +34,7 @@
get isNumber() { return false; }
get isInt() { return false; }
get isFloating() { return false; }
+ get isEnum() { return false; }
get isPrimitive() { return false; }
inherits(protocol)
Modified: trunk/Tools/WebGPUShadingLanguageRI/index.html (234174 => 234175)
--- trunk/Tools/WebGPUShadingLanguageRI/index.html 2018-07-24 22:20:05 UTC (rev 234174)
+++ trunk/Tools/WebGPUShadingLanguageRI/index.html 2018-07-24 23:08:26 UTC (rev 234175)
@@ -11,6 +11,7 @@
<script src=""
<script src=""
<script src=""
+<script src=""
<script src=""
<script src=""