diff --git a/bin/gpu-core.js b/bin/gpu-core.js index f5b9ec7e..5168ae0a 100644 --- a/bin/gpu-core.js +++ b/bin/gpu-core.js @@ -5,7 +5,7 @@ * GPU Accelerated JavaScript * * @version 0.0.0 - * @date Fri Aug 11 2017 16:56:00 GMT-0400 (EDT) + * @date Tue Aug 15 2017 15:18:02 GMT-0400 (EDT) * * @license MIT * The MIT License diff --git a/bin/gpu.js b/bin/gpu.js index bdf40cbb..b8f38996 100644 --- a/bin/gpu.js +++ b/bin/gpu.js @@ -5,7 +5,7 @@ * GPU Accelerated JavaScript * * @version 0.0.0 - * @date Fri Aug 11 2017 16:56:01 GMT-0400 (EDT) + * @date Tue Aug 15 2017 15:18:02 GMT-0400 (EDT) * * @license MIT * The MIT License @@ -66,6 +66,9 @@ module.exports = function (_FunctionBuilderBase) { node.isSubKernel = true; this.addFunctionNode(node); } + }, { + key: 'polyfillStandardFunctions', + value: function polyfillStandardFunctions() {} }]); return CPUFunctionBuilder; @@ -403,6 +406,7 @@ module.exports = function () { _classCallCheck(this, FunctionBuilderBase); this.nodeMap = {}; + this.rawFunctions = {}; this.gpu = gpu; this.rootKernel = null; } @@ -448,31 +452,24 @@ module.exports = function () { } } + if (this.rawFunctions[functionName]) { + if (retList.indexOf(functionName) >= 0) { + } else { + retList.push(functionName); + } + } + return retList; } - - - }, { key: 'polyfillStandardFunctions', - - value: function polyfillStandardFunctions() { - this.addFunction('round', _round); - } - }], [{ - key: 'round', - value: function round(a) { - return _round(a); + throw new Error('polyfillStandardFunctions not defined on base function builder'); } }]); return FunctionBuilderBase; }(); - -function _round(a) { - return Math.floor(a + 0.5); -} },{}],7:[function(require,module,exports){ 'use strict'; @@ -1046,7 +1043,6 @@ function _inherits(subClass, superClass) { if (typeof superClass !== "function" var FunctionBuilderBase = require('../function-builder-base'); var WebGLFunctionNode = require('./function-node'); -var utils = require('../../core/utils'); module.exports = function (_FunctionBuilderBase) { _inherits(WebGLFunctionBuilder, _FunctionBuilderBase); @@ -1062,6 +1058,11 @@ module.exports = function (_FunctionBuilderBase) { value: function addFunction(functionName, jsFunction, paramTypes, returnType) { this.addFunctionNode(new WebGLFunctionNode(functionName, jsFunction, paramTypes, returnType).setAddFunction(this.addFunction.bind(this))); } + }, { + key: 'addGLSLFunction', + value: function addGLSLFunction(functionName, glslFunctionString) { + this.rawFunctions[functionName] = glslFunctionString; + } }, { @@ -1083,9 +1084,12 @@ module.exports = function (_FunctionBuilderBase) { value: function getPrototypeStringFromFunctionNames(functionList, opt) { var ret = []; for (var i = 0; i < functionList.length; ++i) { - var node = this.nodeMap[functionList[i]]; + var functionName = functionList[i]; + var node = this.nodeMap[functionName]; if (node) { ret.push(node.getFunctionPrototypeString(opt)); + } else if (this.rawFunctions[functionName]) { + ret.push(this.rawFunctions[functionName]); } } return ret.join('\n'); @@ -1139,11 +1143,30 @@ module.exports = function (_FunctionBuilderBase) { this.addFunctionNode(kernelNode); return kernelNode; } + + + + }, { + key: 'polyfillStandardFunctions', + + + value: function polyfillStandardFunctions() { + this.addFunction('round', _round); + } + }], [{ + key: 'round', + value: function round(a) { + return _round(a); + } }]); return WebGLFunctionBuilder; }(FunctionBuilderBase); -},{"../../core/utils":24,"../function-builder-base":6,"./function-node":12}],12:[function(require,module,exports){ + +function _round(a) { + return Math.floor(a + 0.5); +} +},{"../function-builder-base":6,"./function-node":12}],12:[function(require,module,exports){ 'use strict'; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); @@ -2812,6 +2835,11 @@ module.exports = function (_KernelBase) { value: function toString() { return kernelString(this); } + }, { + key: 'addGLSLFunction', + value: function addGLSLFunction(name, source) { + this.functionBuilder.addGLSLFunction(name, source); + } }]); return WebGLKernel; diff --git a/src/backend/cpu/function-builder.js b/src/backend/cpu/function-builder.js index 8e996ddf..7c407d02 100644 --- a/src/backend/cpu/function-builder.js +++ b/src/backend/cpu/function-builder.js @@ -63,4 +63,6 @@ module.exports = class CPUFunctionBuilder extends FunctionBuilderBase { node.isSubKernel = true; this.addFunctionNode(node); } + + polyfillStandardFunctions() {} }; \ No newline at end of file diff --git a/src/backend/function-builder-base.js b/src/backend/function-builder-base.js index dd427200..21cab8d3 100644 --- a/src/backend/function-builder-base.js +++ b/src/backend/function-builder-base.js @@ -15,6 +15,7 @@ module.exports = class FunctionBuilderBase { */ constructor(gpu) { this.nodeMap = {}; + this.rawFunctions = {}; this.gpu = gpu; this.rootKernel = null; } @@ -91,36 +92,18 @@ module.exports = class FunctionBuilderBase { } } + if (this.rawFunctions[functionName]) { + if (retList.indexOf(functionName) >= 0) { + // Does nothing if already traced + } else { + retList.push(functionName); + } + } + return retList; } - - - - //--------------------------------------------------------- - // - // Polyfill stuff - // - //--------------------------------------------------------- - - // Round function used in polyfill - static round(a) { - return round(a); - } - - /** - * @memberOf FunctionBuilderBase# - * @function - * @name polyfillStandardFunctions - * - * @desc Polyfill in the missing Math functions (round) - * - */ - polyfillStandardFunctions() { - this.addFunction('round', round); - } -}; - -function round(a) { - return Math.floor(a + 0.5); -} \ No newline at end of file + polyfillStandardFunctions() { + throw new Error('polyfillStandardFunctions not defined on base function builder'); + } +}; \ No newline at end of file diff --git a/src/backend/web-gl/function-builder.js b/src/backend/web-gl/function-builder.js index c8f49943..1549582a 100644 --- a/src/backend/web-gl/function-builder.js +++ b/src/backend/web-gl/function-builder.js @@ -2,7 +2,6 @@ const FunctionBuilderBase = require('../function-builder-base'); const WebGLFunctionNode = require('./function-node'); -const utils = require('../../core/utils'); /** * @class WebGLFunctionBuilder @@ -20,6 +19,10 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase { ); } + addGLSLFunction(functionName, glslFunctionString) { + this.rawFunctions[functionName] = glslFunctionString; + } + /** * @memberOf WebGLFunctionBuilder# * @function @@ -59,10 +62,13 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase { getPrototypeStringFromFunctionNames(functionList, opt) { const ret = []; for (let i = 0; i < functionList.length; ++i) { - const node = this.nodeMap[functionList[i]]; + const functionName = functionList[i]; + const node = this.nodeMap[functionName]; if (node) { ret.push(node.getFunctionPrototypeString(opt)); - } + } else if (this.rawFunctions[functionName]) { + ret.push(this.rawFunctions[functionName]); + } } return ret.join('\n'); } @@ -158,4 +164,31 @@ module.exports = class WebGLFunctionBuilder extends FunctionBuilderBase { this.addFunctionNode(kernelNode); return kernelNode; } -}; \ No newline at end of file + + //--------------------------------------------------------- + // + // Polyfill stuff + // + //--------------------------------------------------------- + + // Round function used in polyfill + static round(a) { + return round(a); + } + + /** + * @memberOf FunctionBuilderBase# + * @function + * @name polyfillStandardFunctions + * + * @desc Polyfill in the missing Math functions (round) + * + */ + polyfillStandardFunctions() { + this.addFunction('round', round); + } +}; + +function round(a) { + return Math.floor(a + 0.5); +} \ No newline at end of file diff --git a/src/backend/web-gl/kernel.js b/src/backend/web-gl/kernel.js index 76f04834..ede05a59 100644 --- a/src/backend/web-gl/kernel.js +++ b/src/backend/web-gl/kernel.js @@ -1189,4 +1189,8 @@ module.exports = class WebGLKernel extends KernelBase { toString() { return kernelString(this); } + + addGLSLFunction(name, source) { + this.functionBuilder.addGLSLFunction(name, source); + } }; \ No newline at end of file diff --git a/test/html/features/for-loop.html b/test/html/features/for-loop.html index 338041be..d118a53f 100644 --- a/test/html/features/for-loop.html +++ b/test/html/features/for-loop.html @@ -6,7 +6,6 @@ -
diff --git a/test/html/features/function-return.html b/test/html/features/function-return.html index 02ff1057..de5f7832 100644 --- a/test/html/features/function-return.html +++ b/test/html/features/function-return.html @@ -6,7 +6,6 @@ - diff --git a/test/html/features/if-else.html b/test/html/features/if-else.html index fce10fbd..a1fa711f 100644 --- a/test/html/features/if-else.html +++ b/test/html/features/if-else.html @@ -6,7 +6,6 @@ - diff --git a/test/html/features/mult-ab.html b/test/html/features/mult-ab.html index c06003bc..ded1b7e6 100644 --- a/test/html/features/mult-ab.html +++ b/test/html/features/mult-ab.html @@ -6,7 +6,6 @@ - diff --git a/test/html/features/nested-function.html b/test/html/features/nested-function.html index cb53fec7..5befaedf 100644 --- a/test/html/features/nested-function.html +++ b/test/html/features/nested-function.html @@ -6,7 +6,6 @@ - diff --git a/test/html/features/read-from-texture.html b/test/html/features/read-from-texture.html index 8b1ba0ef..b5716ebc 100644 --- a/test/html/features/read-from-texture.html +++ b/test/html/features/read-from-texture.html @@ -6,7 +6,6 @@ - diff --git a/test/html/features/sum-ab.html b/test/html/features/sum-ab.html index b74daaa7..3dcb7326 100644 --- a/test/html/features/sum-ab.html +++ b/test/html/features/sum-ab.html @@ -6,7 +6,6 @@ - diff --git a/test/html/features/to-string.html b/test/html/features/to-string.html index 8341c0fe..103d6cfa 100644 --- a/test/html/features/to-string.html +++ b/test/html/features/to-string.html @@ -6,7 +6,6 @@ - diff --git a/test/html/internal/function-builder.html b/test/html/internal/function-builder.html index 83e4ae9f..db285464 100644 --- a/test/html/internal/function-builder.html +++ b/test/html/internal/function-builder.html @@ -6,7 +6,6 @@ - diff --git a/test/html/internal/function-node.html b/test/html/internal/function-node.html index 693d9290..8e763e06 100644 --- a/test/html/internal/function-node.html +++ b/test/html/internal/function-node.html @@ -6,7 +6,6 @@ -