expose means of adding glsl functions directly to kernel

This commit is contained in:
Robert Plummer 2017-08-15 15:19:02 -04:00
parent 9f592add1a
commit d5cb8bbd37
16 changed files with 104 additions and 64 deletions

View File

@ -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

View File

@ -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;

View File

@ -63,4 +63,6 @@ module.exports = class CPUFunctionBuilder extends FunctionBuilderBase {
node.isSubKernel = true;
this.addFunctionNode(node);
}
polyfillStandardFunctions() {}
};

View File

@ -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);
}
polyfillStandardFunctions() {
throw new Error('polyfillStandardFunctions not defined on base function builder');
}
};

View File

@ -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;
}
};
//---------------------------------------------------------
//
// 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);
}

View File

@ -1189,4 +1189,8 @@ module.exports = class WebGLKernel extends KernelBase {
toString() {
return kernelString(this);
}
addGLSLFunction(name, source) {
this.functionBuilder.addGLSLFunction(name, source);
}
};

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../bin/gpu.js"></script>
</head>
<body>

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../bin/gpu.js"></script>
</head>
<body>

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../bin/gpu.js"></script>
</head>
<body>

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../bin/gpu.js"></script>
</head>
<body>

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../bin/gpu.js"></script>
</head>
<body>

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../bin/gpu.js"></script>
</head>
<body>

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../bin/gpu.js"></script>
</head>
<body>

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../bin/gpu.js"></script>
</head>
<body>

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../../node_modules/qunitjs/qunit/qunit.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../src/utils.js"></script>
</head>
<body>

View File

@ -6,7 +6,6 @@
<link rel="stylesheet" href="../../lib/qunit-1.20.0.css">
<!-- gpu.js scripts -->
<script src="../../../src/parser.js"></script>
<script src="../../../src/utils.js"></script>
<script src="../../../src/backend/functionNode_webgl.js"></script>
<script src="../../../src/backend/functionNode.js"></script>