diff --git a/README.md b/README.md
index 41fc0dad..a78e9d1e 100644
--- a/README.md
+++ b/README.md
@@ -92,6 +92,7 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
* [Supported Math functions](#supported-math-functions)
* [How to check what is supported](#how-to-check-what-is-supported)
* [Typescript Typings](#typescript-typings)
+* [Dealing With Transpilation](#dealing-with-transpilation)
* [Full API reference](#full-api-reference)
* [Automatically-built Documentation](#automatically-built-documentation)
* [Contributors](#contributors)
@@ -180,6 +181,7 @@ Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.
* `immutable` or `kernel.setImmutable(boolean)`: boolean, default = `false`
* `strictIntegers` or `kernel.setStrictIntegers(boolean)`: boolean, default = `false` - allows undefined argumentTypes and function return values to use strict integer declarations.
* `useLegacyEncoder` or `kernel.setUseLegacyEncoder(boolean)`: boolean, default `false` - more info [here](https://github.com/gpujs/gpu.js/wiki/Encoder-details).
+* `warnVarUsage` or `kernel.setWarnVarUsage(boolean)`: turn off var usage warnings, they can be irritating, and in transpiled environments, there is nothing we can do about it.
## Creating and Running Functions
@@ -858,6 +860,21 @@ To assist with mostly unit tests, but perhaps in scenarios outside of GPU.js, th
## Typescript Typings
Typescript is supported! Typings can be found [here](src/index.d.ts)!
+## Dealing With Transpilation
+Transpilation doesn't do the best job of keeping code beautiful. To aid in this endeavor GPU.js can handle some scenarios to still aid you harnessing the GPU in less than ideal circumstances.
+Here is a list of a few things that GPU.js does to fix transpilation:
+
+* When a transpiler such as [Babel](https://babeljs.io/) changes `myCall()` to `(0, _myCall.myCall)`, it is gracefully handled.
+* Using `var` will have a lot of warnings by default, this can be irritating because sometimes there is nothing we can do about this in transpiled environment.
+ To aid in the irritation, there is an option to alleviate the irritation.
+ When `const` and `let` are converted to `var`, and you'r prefer not to see it, use the following:
+ ```js
+ const kernel = gpu.createKernel(myKernelFunction)
+ .setWarnVarUsage(false);
+ // or
+ const kernel = gpu.createKernel(myKernelFunction, { output: [1], warnVarUsage: false });
+ ```
+
## Full API Reference
You can find a [complete API reference here](https://doxdox.org/gpujs/gpu.js/).
diff --git a/dist/gpu-browser-core.js b/dist/gpu-browser-core.js
index 68169b21..ac0539c7 100644
--- a/dist/gpu-browser-core.js
+++ b/dist/gpu-browser-core.js
@@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
- * @version 2.0.0-rc.19
- * @date Tue Jul 02 2019 12:17:44 GMT-0400 (Eastern Daylight Time)
+ * @version 2.0.0-rc.20
+ * @date Fri Jul 05 2019 11:02:54 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
@@ -717,7 +717,7 @@ class CPUFunctionNode extends FunctionNode {
}
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
retArr.push(`${varDecNode.kind} `);
@@ -900,9 +900,9 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(zProperty, retArr);
- retArr.push(`*${ size[1] * size[0]})+(`);
+ retArr.push(`*${ this.dynamicArguments ? '(outputY * outputX)' : size[1] * size[0] })+(`);
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
@@ -920,7 +920,7 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
@@ -1674,7 +1674,9 @@ class FunctionBuilder {
functions,
leadingReturnStatement,
followingReturnStatement,
+ dynamicArguments,
dynamicOutput,
+ warnVarUsage,
} = kernel;
const needsArgumentType = (functionName, index) => {
@@ -1736,7 +1738,8 @@ class FunctionBuilder {
triggerImplyArgumentType,
triggerTrackArgumentSynonym,
lookupArgumentSynonym,
- onFunctionCall
+ onFunctionCall,
+ warnVarUsage,
}));
nestedFunction.traceFunctionAST(ast);
functionBuilder.addFunctionNode(nestedFunction);
@@ -1764,6 +1767,7 @@ class FunctionBuilder {
loopMaxIterations,
output,
plugins,
+ dynamicArguments,
dynamicOutput,
}, extraNodeOptions || {});
@@ -2234,8 +2238,10 @@ class FunctionNode {
this.leadingReturnStatement = null;
this.followingReturnStatement = null;
this.dynamicOutput = null;
+ this.dynamicArguments = null;
this.strictTypingChecking = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
if (settings) {
for (const p in settings) {
@@ -5465,6 +5471,7 @@ class Kernel {
this.optimizeFloatMemory = null;
this.strictIntegers = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
}
mergeSettings(settings) {
@@ -5660,6 +5667,11 @@ class Kernel {
return this;
}
+ setWarnVarUsage(flag) {
+ this.warnVarUsage = flag;
+ return this;
+ }
+
getCanvas() {
utils.warnDeprecated('method', 'getCanvas');
return this.canvas;
@@ -6784,7 +6796,7 @@ class WebGLFunctionNode extends FunctionNode {
}
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
const declarations = varDecNode.declarations;
@@ -7569,7 +7581,7 @@ module.exports = {
const { utils } = require('../../../utils');
const { WebGLKernelValueHTMLImage } = require('./html-image');
-class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
+class WebGLKernelValueDynamicHTMLImage extends WebGLKernelValueHTMLImage {
getSource() {
return utils.linesToString([
`uniform sampler2D ${this.id}`,
@@ -7589,7 +7601,7 @@ class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
}
module.exports = {
- WebGLKernelValueDynamicInput
+ WebGLKernelValueDynamicHTMLImage
};
},{"../../../utils":89,"./html-image":47}],40:[function(require,module,exports){
const { utils } = require('../../../utils');
@@ -7630,8 +7642,8 @@ class WebGLKernelValueDynamicNumberTexture extends WebGLKernelValueNumberTexture
}
updateValue(value) {
- this.dimensions = inputTexture.dimensions;
- this.textureSize = inputTexture.size;
+ this.dimensions = value.dimensions;
+ this.textureSize = value.size;
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
super.updateValue(value);
@@ -7684,7 +7696,7 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
updateValue(value) {
this.dimensions = value.size;
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
- this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.uploadValue = new Float32Array(this.uploadArrayLength);
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
@@ -9957,6 +9969,7 @@ void main(void) {
module.exports = {
fragmentShader
};
+
},{}],59:[function(require,module,exports){
const { WebGLFunctionNode } = require('../web-gl/function-node');
@@ -10148,9 +10161,9 @@ module.exports = {
};
},{"./html-image-array":71}],63:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicInput } = require('../../web-gl/kernel-value/dynamic-html-image');
+const { WebGLKernelValueDynamicHTMLImage } = require('../../web-gl/kernel-value/dynamic-html-image');
-class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
+class WebGL2KernelValueDynamicHTMLImage extends WebGLKernelValueDynamicHTMLImage {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -10161,7 +10174,7 @@ class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
}
module.exports = {
- WebGL2KernelValueDynamicInput
+ WebGL2KernelValueDynamicHTMLImage
};
},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-html-image":39}],64:[function(require,module,exports){
const { utils } = require('../../../utils');
@@ -10199,9 +10212,9 @@ module.exports = {
};
},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-number-texture":41}],66:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleArray } = require('../../web-gl/kernel-value/dynamic-single-array');
+const { WebGL2KernelValueSingleArray } = require('../../web-gl2/kernel-value/single-array');
-class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleArray {
+class WebGL2KernelValueDynamicSingleArray extends WebGL2KernelValueSingleArray {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -10209,16 +10222,26 @@ class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleA
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = utils.getDimensions(value, true);
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
WebGL2KernelValueDynamicSingleArray
};
-},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-single-array":42}],67:[function(require,module,exports){
+},{"../../../utils":89,"../../web-gl2/kernel-value/single-array":76}],67:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleInput } = require('../../web-gl/kernel-value/dynamic-single-input');
+const { WebGL2KernelValueSingleInput } = require('../../web-gl2/kernel-value/single-input');
-class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleInput {
+class WebGL2KernelValueDynamicSingleInput extends WebGL2KernelValueSingleInput {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -10226,12 +10249,22 @@ class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleI
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = value.size;
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
WebGL2KernelValueDynamicSingleInput
};
-},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-single-input":43}],68:[function(require,module,exports){
+},{"../../../utils":89,"../../web-gl2/kernel-value/single-input":77}],68:[function(require,module,exports){
const { utils } = require('../../../utils');
const { WebGLKernelValueDynamicUnsignedArray } = require('../../web-gl/kernel-value/dynamic-unsigned-array');
@@ -10523,6 +10556,7 @@ let isSupported = null;
let testCanvas = null;
let testContext = null;
let testExtensions = null;
+
let features = null;
class WebGL2Kernel extends WebGLKernel {
@@ -11338,7 +11372,25 @@ class GPU {
gpu: this,
validate,
onRequestFallback: (args) => {
- const fallbackKernel = new CPUKernel(source, mergedSettings);
+ const fallbackKernel = new CPUKernel(source, {
+ graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
+ constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
+ output: kernel.output,
+ precision: kernel.precision,
+ pipeline: kernel.pipeline,
+ immutable: kernel.immutable,
+ optimizeFloatMemory: kernel.optimizeFloatMemory,
+ fixIntegerDivisionAccuracy: kernel.fixIntegerDivisionAccuracy,
+ functions: kernel.functions,
+ nativeFunctions: kernel.nativeFunctions,
+ subKernels: kernel.subKernels,
+ strictIntegers: kernel.strictIntegers,
+ debug: kernel.debug,
+ warnVarUsage: kernel.warnVarUsage,
+ });
fallbackKernel.build.apply(fallbackKernel, args);
const result = fallbackKernel.run.apply(fallbackKernel, args);
kernel.replaceKernel(fallbackKernel);
@@ -11361,7 +11413,10 @@ class GPU {
}
const newKernel = switchableKernels[signature] = new this.Kernel(source, {
graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
context: kernel.context,
canvas: kernel.canvas,
output: kernel.output,
@@ -11377,6 +11432,7 @@ class GPU {
debug: kernel.debug,
gpu: this,
validate,
+ warnVarUsage: kernel.warnVarUsage,
});
newKernel.build.apply(newKernel, args);
newKernel.run.apply(newKernel, args);
diff --git a/dist/gpu-browser-core.min.js b/dist/gpu-browser-core.min.js
index c47575fc..9d40381f 100644
--- a/dist/gpu-browser-core.min.js
+++ b/dist/gpu-browser-core.min.js
@@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
- * @version 2.0.0-rc.19
- * @date Tue Jul 02 2019 12:17:46 GMT-0400 (Eastern Daylight Time)
+ * @version 2.0.0-rc.20
+ * @date Fri Jul 05 2019 11:02:56 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
@@ -17,8 +17,8 @@
*
* GPU Accelerated JavaScript
*
- * @version 2.0.0-rc.19
- * @date Tue Jul 02 2019 12:17:44 GMT-0400 (Eastern Daylight Time)
+ * @version 2.0.0-rc.20
+ * @date Fri Jul 05 2019 11:02:54 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
@@ -730,7 +730,7 @@ class CPUFunctionNode extends FunctionNode {
}
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
retArr.push(`${varDecNode.kind} `);
@@ -913,9 +913,9 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(zProperty, retArr);
- retArr.push(`*${ size[1] * size[0]})+(`);
+ retArr.push(`*${ this.dynamicArguments ? '(outputY * outputX)' : size[1] * size[0] })+(`);
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
@@ -933,7 +933,7 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
@@ -1687,7 +1687,9 @@ class FunctionBuilder {
functions,
leadingReturnStatement,
followingReturnStatement,
+ dynamicArguments,
dynamicOutput,
+ warnVarUsage,
} = kernel;
const needsArgumentType = (functionName, index) => {
@@ -1749,7 +1751,8 @@ class FunctionBuilder {
triggerImplyArgumentType,
triggerTrackArgumentSynonym,
lookupArgumentSynonym,
- onFunctionCall
+ onFunctionCall,
+ warnVarUsage,
}));
nestedFunction.traceFunctionAST(ast);
functionBuilder.addFunctionNode(nestedFunction);
@@ -1777,6 +1780,7 @@ class FunctionBuilder {
loopMaxIterations,
output,
plugins,
+ dynamicArguments,
dynamicOutput,
}, extraNodeOptions || {});
@@ -2247,8 +2251,10 @@ class FunctionNode {
this.leadingReturnStatement = null;
this.followingReturnStatement = null;
this.dynamicOutput = null;
+ this.dynamicArguments = null;
this.strictTypingChecking = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
if (settings) {
for (const p in settings) {
@@ -5478,6 +5484,7 @@ class Kernel {
this.optimizeFloatMemory = null;
this.strictIntegers = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
}
mergeSettings(settings) {
@@ -5673,6 +5680,11 @@ class Kernel {
return this;
}
+ setWarnVarUsage(flag) {
+ this.warnVarUsage = flag;
+ return this;
+ }
+
getCanvas() {
utils.warnDeprecated('method', 'getCanvas');
return this.canvas;
@@ -6797,7 +6809,7 @@ class WebGLFunctionNode extends FunctionNode {
}
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
const declarations = varDecNode.declarations;
@@ -7582,7 +7594,7 @@ module.exports = {
const { utils } = require('../../../utils');
const { WebGLKernelValueHTMLImage } = require('./html-image');
-class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
+class WebGLKernelValueDynamicHTMLImage extends WebGLKernelValueHTMLImage {
getSource() {
return utils.linesToString([
`uniform sampler2D ${this.id}`,
@@ -7602,7 +7614,7 @@ class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
}
module.exports = {
- WebGLKernelValueDynamicInput
+ WebGLKernelValueDynamicHTMLImage
};
},{"../../../utils":89,"./html-image":47}],40:[function(require,module,exports){
const { utils } = require('../../../utils');
@@ -7643,8 +7655,8 @@ class WebGLKernelValueDynamicNumberTexture extends WebGLKernelValueNumberTexture
}
updateValue(value) {
- this.dimensions = inputTexture.dimensions;
- this.textureSize = inputTexture.size;
+ this.dimensions = value.dimensions;
+ this.textureSize = value.size;
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
super.updateValue(value);
@@ -7697,7 +7709,7 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
updateValue(value) {
this.dimensions = value.size;
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
- this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.uploadValue = new Float32Array(this.uploadArrayLength);
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
@@ -9970,6 +9982,7 @@ void main(void) {
module.exports = {
fragmentShader
};
+
},{}],59:[function(require,module,exports){
const { WebGLFunctionNode } = require('../web-gl/function-node');
@@ -10161,9 +10174,9 @@ module.exports = {
};
},{"./html-image-array":71}],63:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicInput } = require('../../web-gl/kernel-value/dynamic-html-image');
+const { WebGLKernelValueDynamicHTMLImage } = require('../../web-gl/kernel-value/dynamic-html-image');
-class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
+class WebGL2KernelValueDynamicHTMLImage extends WebGLKernelValueDynamicHTMLImage {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -10174,7 +10187,7 @@ class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
}
module.exports = {
- WebGL2KernelValueDynamicInput
+ WebGL2KernelValueDynamicHTMLImage
};
},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-html-image":39}],64:[function(require,module,exports){
const { utils } = require('../../../utils');
@@ -10212,9 +10225,9 @@ module.exports = {
};
},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-number-texture":41}],66:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleArray } = require('../../web-gl/kernel-value/dynamic-single-array');
+const { WebGL2KernelValueSingleArray } = require('../../web-gl2/kernel-value/single-array');
-class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleArray {
+class WebGL2KernelValueDynamicSingleArray extends WebGL2KernelValueSingleArray {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -10222,16 +10235,26 @@ class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleA
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = utils.getDimensions(value, true);
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
WebGL2KernelValueDynamicSingleArray
};
-},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-single-array":42}],67:[function(require,module,exports){
+},{"../../../utils":89,"../../web-gl2/kernel-value/single-array":76}],67:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleInput } = require('../../web-gl/kernel-value/dynamic-single-input');
+const { WebGL2KernelValueSingleInput } = require('../../web-gl2/kernel-value/single-input');
-class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleInput {
+class WebGL2KernelValueDynamicSingleInput extends WebGL2KernelValueSingleInput {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -10239,12 +10262,22 @@ class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleI
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = value.size;
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
WebGL2KernelValueDynamicSingleInput
};
-},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-single-input":43}],68:[function(require,module,exports){
+},{"../../../utils":89,"../../web-gl2/kernel-value/single-input":77}],68:[function(require,module,exports){
const { utils } = require('../../../utils');
const { WebGLKernelValueDynamicUnsignedArray } = require('../../web-gl/kernel-value/dynamic-unsigned-array');
@@ -10536,6 +10569,7 @@ let isSupported = null;
let testCanvas = null;
let testContext = null;
let testExtensions = null;
+
let features = null;
class WebGL2Kernel extends WebGLKernel {
@@ -11351,7 +11385,25 @@ class GPU {
gpu: this,
validate,
onRequestFallback: (args) => {
- const fallbackKernel = new CPUKernel(source, mergedSettings);
+ const fallbackKernel = new CPUKernel(source, {
+ graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
+ constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
+ output: kernel.output,
+ precision: kernel.precision,
+ pipeline: kernel.pipeline,
+ immutable: kernel.immutable,
+ optimizeFloatMemory: kernel.optimizeFloatMemory,
+ fixIntegerDivisionAccuracy: kernel.fixIntegerDivisionAccuracy,
+ functions: kernel.functions,
+ nativeFunctions: kernel.nativeFunctions,
+ subKernels: kernel.subKernels,
+ strictIntegers: kernel.strictIntegers,
+ debug: kernel.debug,
+ warnVarUsage: kernel.warnVarUsage,
+ });
fallbackKernel.build.apply(fallbackKernel, args);
const result = fallbackKernel.run.apply(fallbackKernel, args);
kernel.replaceKernel(fallbackKernel);
@@ -11374,7 +11426,10 @@ class GPU {
}
const newKernel = switchableKernels[signature] = new this.Kernel(source, {
graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
context: kernel.context,
canvas: kernel.canvas,
output: kernel.output,
@@ -11390,6 +11445,7 @@ class GPU {
debug: kernel.debug,
gpu: this,
validate,
+ warnVarUsage: kernel.warnVarUsage,
});
newKernel.build.apply(newKernel, args);
newKernel.run.apply(newKernel, args);
diff --git a/dist/gpu-browser.js b/dist/gpu-browser.js
index bf890b6f..6e21a38d 100644
--- a/dist/gpu-browser.js
+++ b/dist/gpu-browser.js
@@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
- * @version 2.0.0-rc.19
- * @date Tue Jul 02 2019 12:17:44 GMT-0400 (Eastern Daylight Time)
+ * @version 2.0.0-rc.20
+ * @date Fri Jul 05 2019 11:02:54 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
@@ -5481,7 +5481,7 @@ class CPUFunctionNode extends FunctionNode {
}
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
retArr.push(`${varDecNode.kind} `);
@@ -5664,9 +5664,9 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(zProperty, retArr);
- retArr.push(`*${ size[1] * size[0]})+(`);
+ retArr.push(`*${ this.dynamicArguments ? '(outputY * outputX)' : size[1] * size[0] })+(`);
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
@@ -5684,7 +5684,7 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
@@ -6438,7 +6438,9 @@ class FunctionBuilder {
functions,
leadingReturnStatement,
followingReturnStatement,
+ dynamicArguments,
dynamicOutput,
+ warnVarUsage,
} = kernel;
const needsArgumentType = (functionName, index) => {
@@ -6500,7 +6502,8 @@ class FunctionBuilder {
triggerImplyArgumentType,
triggerTrackArgumentSynonym,
lookupArgumentSynonym,
- onFunctionCall
+ onFunctionCall,
+ warnVarUsage,
}));
nestedFunction.traceFunctionAST(ast);
functionBuilder.addFunctionNode(nestedFunction);
@@ -6528,6 +6531,7 @@ class FunctionBuilder {
loopMaxIterations,
output,
plugins,
+ dynamicArguments,
dynamicOutput,
}, extraNodeOptions || {});
@@ -6998,8 +7002,10 @@ class FunctionNode {
this.leadingReturnStatement = null;
this.followingReturnStatement = null;
this.dynamicOutput = null;
+ this.dynamicArguments = null;
this.strictTypingChecking = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
if (settings) {
for (const p in settings) {
@@ -10229,6 +10235,7 @@ class Kernel {
this.optimizeFloatMemory = null;
this.strictIntegers = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
}
mergeSettings(settings) {
@@ -10424,6 +10431,11 @@ class Kernel {
return this;
}
+ setWarnVarUsage(flag) {
+ this.warnVarUsage = flag;
+ return this;
+ }
+
getCanvas() {
utils.warnDeprecated('method', 'getCanvas');
return this.canvas;
@@ -11548,7 +11560,7 @@ class WebGLFunctionNode extends FunctionNode {
}
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
const declarations = varDecNode.declarations;
@@ -12333,7 +12345,7 @@ module.exports = {
const { utils } = require('../../../utils');
const { WebGLKernelValueHTMLImage } = require('./html-image');
-class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
+class WebGLKernelValueDynamicHTMLImage extends WebGLKernelValueHTMLImage {
getSource() {
return utils.linesToString([
`uniform sampler2D ${this.id}`,
@@ -12353,7 +12365,7 @@ class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
}
module.exports = {
- WebGLKernelValueDynamicInput
+ WebGLKernelValueDynamicHTMLImage
};
},{"../../../utils":90,"./html-image":48}],41:[function(require,module,exports){
const { utils } = require('../../../utils');
@@ -12394,8 +12406,8 @@ class WebGLKernelValueDynamicNumberTexture extends WebGLKernelValueNumberTexture
}
updateValue(value) {
- this.dimensions = inputTexture.dimensions;
- this.textureSize = inputTexture.size;
+ this.dimensions = value.dimensions;
+ this.textureSize = value.size;
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
super.updateValue(value);
@@ -12448,7 +12460,7 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
updateValue(value) {
this.dimensions = value.size;
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
- this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.uploadValue = new Float32Array(this.uploadArrayLength);
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
@@ -14721,6 +14733,7 @@ void main(void) {
module.exports = {
fragmentShader
};
+
},{}],60:[function(require,module,exports){
const { WebGLFunctionNode } = require('../web-gl/function-node');
@@ -14912,9 +14925,9 @@ module.exports = {
};
},{"./html-image-array":72}],64:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicInput } = require('../../web-gl/kernel-value/dynamic-html-image');
+const { WebGLKernelValueDynamicHTMLImage } = require('../../web-gl/kernel-value/dynamic-html-image');
-class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
+class WebGL2KernelValueDynamicHTMLImage extends WebGLKernelValueDynamicHTMLImage {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -14925,7 +14938,7 @@ class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
}
module.exports = {
- WebGL2KernelValueDynamicInput
+ WebGL2KernelValueDynamicHTMLImage
};
},{"../../../utils":90,"../../web-gl/kernel-value/dynamic-html-image":40}],65:[function(require,module,exports){
const { utils } = require('../../../utils');
@@ -14963,9 +14976,9 @@ module.exports = {
};
},{"../../../utils":90,"../../web-gl/kernel-value/dynamic-number-texture":42}],67:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleArray } = require('../../web-gl/kernel-value/dynamic-single-array');
+const { WebGL2KernelValueSingleArray } = require('../../web-gl2/kernel-value/single-array');
-class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleArray {
+class WebGL2KernelValueDynamicSingleArray extends WebGL2KernelValueSingleArray {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -14973,16 +14986,26 @@ class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleA
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = utils.getDimensions(value, true);
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
WebGL2KernelValueDynamicSingleArray
};
-},{"../../../utils":90,"../../web-gl/kernel-value/dynamic-single-array":43}],68:[function(require,module,exports){
+},{"../../../utils":90,"../../web-gl2/kernel-value/single-array":77}],68:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleInput } = require('../../web-gl/kernel-value/dynamic-single-input');
+const { WebGL2KernelValueSingleInput } = require('../../web-gl2/kernel-value/single-input');
-class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleInput {
+class WebGL2KernelValueDynamicSingleInput extends WebGL2KernelValueSingleInput {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -14990,12 +15013,22 @@ class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleI
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = value.size;
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
WebGL2KernelValueDynamicSingleInput
};
-},{"../../../utils":90,"../../web-gl/kernel-value/dynamic-single-input":44}],69:[function(require,module,exports){
+},{"../../../utils":90,"../../web-gl2/kernel-value/single-input":78}],69:[function(require,module,exports){
const { utils } = require('../../../utils');
const { WebGLKernelValueDynamicUnsignedArray } = require('../../web-gl/kernel-value/dynamic-unsigned-array');
@@ -15287,6 +15320,7 @@ let isSupported = null;
let testCanvas = null;
let testContext = null;
let testExtensions = null;
+
let features = null;
class WebGL2Kernel extends WebGLKernel {
@@ -16102,7 +16136,25 @@ class GPU {
gpu: this,
validate,
onRequestFallback: (args) => {
- const fallbackKernel = new CPUKernel(source, mergedSettings);
+ const fallbackKernel = new CPUKernel(source, {
+ graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
+ constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
+ output: kernel.output,
+ precision: kernel.precision,
+ pipeline: kernel.pipeline,
+ immutable: kernel.immutable,
+ optimizeFloatMemory: kernel.optimizeFloatMemory,
+ fixIntegerDivisionAccuracy: kernel.fixIntegerDivisionAccuracy,
+ functions: kernel.functions,
+ nativeFunctions: kernel.nativeFunctions,
+ subKernels: kernel.subKernels,
+ strictIntegers: kernel.strictIntegers,
+ debug: kernel.debug,
+ warnVarUsage: kernel.warnVarUsage,
+ });
fallbackKernel.build.apply(fallbackKernel, args);
const result = fallbackKernel.run.apply(fallbackKernel, args);
kernel.replaceKernel(fallbackKernel);
@@ -16125,7 +16177,10 @@ class GPU {
}
const newKernel = switchableKernels[signature] = new this.Kernel(source, {
graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
context: kernel.context,
canvas: kernel.canvas,
output: kernel.output,
@@ -16141,6 +16196,7 @@ class GPU {
debug: kernel.debug,
gpu: this,
validate,
+ warnVarUsage: kernel.warnVarUsage,
});
newKernel.build.apply(newKernel, args);
newKernel.run.apply(newKernel, args);
diff --git a/dist/gpu-browser.min.js b/dist/gpu-browser.min.js
index 0ecb60ba..d7f9e6a9 100644
--- a/dist/gpu-browser.min.js
+++ b/dist/gpu-browser.min.js
@@ -4,8 +4,8 @@
*
* GPU Accelerated JavaScript
*
- * @version 2.0.0-rc.19
- * @date Tue Jul 02 2019 12:17:46 GMT-0400 (Eastern Daylight Time)
+ * @version 2.0.0-rc.20
+ * @date Fri Jul 05 2019 11:02:56 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
@@ -17,8 +17,8 @@
*
* GPU Accelerated JavaScript
*
- * @version 2.0.0-rc.19
- * @date Tue Jul 02 2019 12:17:44 GMT-0400 (Eastern Daylight Time)
+ * @version 2.0.0-rc.20
+ * @date Fri Jul 05 2019 11:02:54 GMT-0400 (Eastern Daylight Time)
*
* @license MIT
* The MIT License
@@ -5494,7 +5494,7 @@ class CPUFunctionNode extends FunctionNode {
}
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
retArr.push(`${varDecNode.kind} `);
@@ -5677,9 +5677,9 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(zProperty, retArr);
- retArr.push(`*${ size[1] * size[0]})+(`);
+ retArr.push(`*${ this.dynamicArguments ? '(outputY * outputX)' : size[1] * size[0] })+(`);
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
@@ -5697,7 +5697,7 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
@@ -6451,7 +6451,9 @@ class FunctionBuilder {
functions,
leadingReturnStatement,
followingReturnStatement,
+ dynamicArguments,
dynamicOutput,
+ warnVarUsage,
} = kernel;
const needsArgumentType = (functionName, index) => {
@@ -6513,7 +6515,8 @@ class FunctionBuilder {
triggerImplyArgumentType,
triggerTrackArgumentSynonym,
lookupArgumentSynonym,
- onFunctionCall
+ onFunctionCall,
+ warnVarUsage,
}));
nestedFunction.traceFunctionAST(ast);
functionBuilder.addFunctionNode(nestedFunction);
@@ -6541,6 +6544,7 @@ class FunctionBuilder {
loopMaxIterations,
output,
plugins,
+ dynamicArguments,
dynamicOutput,
}, extraNodeOptions || {});
@@ -7011,8 +7015,10 @@ class FunctionNode {
this.leadingReturnStatement = null;
this.followingReturnStatement = null;
this.dynamicOutput = null;
+ this.dynamicArguments = null;
this.strictTypingChecking = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
if (settings) {
for (const p in settings) {
@@ -10242,6 +10248,7 @@ class Kernel {
this.optimizeFloatMemory = null;
this.strictIntegers = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
}
mergeSettings(settings) {
@@ -10437,6 +10444,11 @@ class Kernel {
return this;
}
+ setWarnVarUsage(flag) {
+ this.warnVarUsage = flag;
+ return this;
+ }
+
getCanvas() {
utils.warnDeprecated('method', 'getCanvas');
return this.canvas;
@@ -11561,7 +11573,7 @@ class WebGLFunctionNode extends FunctionNode {
}
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
const declarations = varDecNode.declarations;
@@ -12346,7 +12358,7 @@ module.exports = {
const { utils } = require('../../../utils');
const { WebGLKernelValueHTMLImage } = require('./html-image');
-class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
+class WebGLKernelValueDynamicHTMLImage extends WebGLKernelValueHTMLImage {
getSource() {
return utils.linesToString([
`uniform sampler2D ${this.id}`,
@@ -12366,7 +12378,7 @@ class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
}
module.exports = {
- WebGLKernelValueDynamicInput
+ WebGLKernelValueDynamicHTMLImage
};
},{"../../../utils":90,"./html-image":48}],41:[function(require,module,exports){
const { utils } = require('../../../utils');
@@ -12407,8 +12419,8 @@ class WebGLKernelValueDynamicNumberTexture extends WebGLKernelValueNumberTexture
}
updateValue(value) {
- this.dimensions = inputTexture.dimensions;
- this.textureSize = inputTexture.size;
+ this.dimensions = value.dimensions;
+ this.textureSize = value.size;
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
super.updateValue(value);
@@ -12461,7 +12473,7 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
updateValue(value) {
this.dimensions = value.size;
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
- this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.uploadValue = new Float32Array(this.uploadArrayLength);
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
@@ -14734,6 +14746,7 @@ void main(void) {
module.exports = {
fragmentShader
};
+
},{}],60:[function(require,module,exports){
const { WebGLFunctionNode } = require('../web-gl/function-node');
@@ -14925,9 +14938,9 @@ module.exports = {
};
},{"./html-image-array":72}],64:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicInput } = require('../../web-gl/kernel-value/dynamic-html-image');
+const { WebGLKernelValueDynamicHTMLImage } = require('../../web-gl/kernel-value/dynamic-html-image');
-class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
+class WebGL2KernelValueDynamicHTMLImage extends WebGLKernelValueDynamicHTMLImage {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -14938,7 +14951,7 @@ class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
}
module.exports = {
- WebGL2KernelValueDynamicInput
+ WebGL2KernelValueDynamicHTMLImage
};
},{"../../../utils":90,"../../web-gl/kernel-value/dynamic-html-image":40}],65:[function(require,module,exports){
const { utils } = require('../../../utils');
@@ -14976,9 +14989,9 @@ module.exports = {
};
},{"../../../utils":90,"../../web-gl/kernel-value/dynamic-number-texture":42}],67:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleArray } = require('../../web-gl/kernel-value/dynamic-single-array');
+const { WebGL2KernelValueSingleArray } = require('../../web-gl2/kernel-value/single-array');
-class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleArray {
+class WebGL2KernelValueDynamicSingleArray extends WebGL2KernelValueSingleArray {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -14986,16 +14999,26 @@ class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleA
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = utils.getDimensions(value, true);
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
WebGL2KernelValueDynamicSingleArray
};
-},{"../../../utils":90,"../../web-gl/kernel-value/dynamic-single-array":43}],68:[function(require,module,exports){
+},{"../../../utils":90,"../../web-gl2/kernel-value/single-array":77}],68:[function(require,module,exports){
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleInput } = require('../../web-gl/kernel-value/dynamic-single-input');
+const { WebGL2KernelValueSingleInput } = require('../../web-gl2/kernel-value/single-input');
-class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleInput {
+class WebGL2KernelValueDynamicSingleInput extends WebGL2KernelValueSingleInput {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -15003,12 +15026,22 @@ class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleI
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = value.size;
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
WebGL2KernelValueDynamicSingleInput
};
-},{"../../../utils":90,"../../web-gl/kernel-value/dynamic-single-input":44}],69:[function(require,module,exports){
+},{"../../../utils":90,"../../web-gl2/kernel-value/single-input":78}],69:[function(require,module,exports){
const { utils } = require('../../../utils');
const { WebGLKernelValueDynamicUnsignedArray } = require('../../web-gl/kernel-value/dynamic-unsigned-array');
@@ -15300,6 +15333,7 @@ let isSupported = null;
let testCanvas = null;
let testContext = null;
let testExtensions = null;
+
let features = null;
class WebGL2Kernel extends WebGLKernel {
@@ -16115,7 +16149,25 @@ class GPU {
gpu: this,
validate,
onRequestFallback: (args) => {
- const fallbackKernel = new CPUKernel(source, mergedSettings);
+ const fallbackKernel = new CPUKernel(source, {
+ graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
+ constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
+ output: kernel.output,
+ precision: kernel.precision,
+ pipeline: kernel.pipeline,
+ immutable: kernel.immutable,
+ optimizeFloatMemory: kernel.optimizeFloatMemory,
+ fixIntegerDivisionAccuracy: kernel.fixIntegerDivisionAccuracy,
+ functions: kernel.functions,
+ nativeFunctions: kernel.nativeFunctions,
+ subKernels: kernel.subKernels,
+ strictIntegers: kernel.strictIntegers,
+ debug: kernel.debug,
+ warnVarUsage: kernel.warnVarUsage,
+ });
fallbackKernel.build.apply(fallbackKernel, args);
const result = fallbackKernel.run.apply(fallbackKernel, args);
kernel.replaceKernel(fallbackKernel);
@@ -16138,7 +16190,10 @@ class GPU {
}
const newKernel = switchableKernels[signature] = new this.Kernel(source, {
graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
context: kernel.context,
canvas: kernel.canvas,
output: kernel.output,
@@ -16154,6 +16209,7 @@ class GPU {
debug: kernel.debug,
gpu: this,
validate,
+ warnVarUsage: kernel.warnVarUsage,
});
newKernel.build.apply(newKernel, args);
newKernel.run.apply(newKernel, args);
diff --git a/package.json b/package.json
index 882866dc..fd4d20e8 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "gpu.js",
- "version": "2.0.0-rc.19",
+ "version": "2.0.0-rc.20",
"description": "GPU Accelerated JavaScript",
"engines": {
"node": ">=10.0.0"
diff --git a/src/backend/cpu/function-node.js b/src/backend/cpu/function-node.js
index 72db578d..0f3c8acb 100644
--- a/src/backend/cpu/function-node.js
+++ b/src/backend/cpu/function-node.js
@@ -325,7 +325,7 @@ class CPUFunctionNode extends FunctionNode {
* @returns {Array} the append retArr
*/
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
retArr.push(`${varDecNode.kind} `);
@@ -529,9 +529,9 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(zProperty, retArr);
- retArr.push(`*${ size[1] * size[0]})+(`);
+ retArr.push(`*${ this.dynamicArguments ? '(outputY * outputX)' : size[1] * size[0] })+(`);
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
@@ -549,7 +549,7 @@ class CPUFunctionNode extends FunctionNode {
if (isInput) {
retArr.push('[(');
this.astGeneric(yProperty, retArr);
- retArr.push(`*${ size[0] })+`);
+ retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
this.astGeneric(xProperty, retArr);
retArr.push(']');
} else {
diff --git a/src/backend/function-builder.js b/src/backend/function-builder.js
index 088cd04d..598f6916 100644
--- a/src/backend/function-builder.js
+++ b/src/backend/function-builder.js
@@ -6,7 +6,7 @@
class FunctionBuilder {
/**
*
- * @param {typeof Kernel} kernel
+ * @param {Kernel} kernel
* @param {FunctionNode} FunctionNode
* @param {object} [extraNodeOptions]
* @returns {FunctionBuilder}
@@ -34,7 +34,9 @@ class FunctionBuilder {
functions,
leadingReturnStatement,
followingReturnStatement,
+ dynamicArguments,
dynamicOutput,
+ warnVarUsage,
} = kernel;
const needsArgumentType = (functionName, index) => {
@@ -96,7 +98,8 @@ class FunctionBuilder {
triggerImplyArgumentType,
triggerTrackArgumentSynonym,
lookupArgumentSynonym,
- onFunctionCall
+ onFunctionCall,
+ warnVarUsage,
}));
nestedFunction.traceFunctionAST(ast);
functionBuilder.addFunctionNode(nestedFunction);
@@ -124,6 +127,7 @@ class FunctionBuilder {
loopMaxIterations,
output,
plugins,
+ dynamicArguments,
dynamicOutput,
}, extraNodeOptions || {});
diff --git a/src/backend/function-node.js b/src/backend/function-node.js
index c800b39e..a9816366 100644
--- a/src/backend/function-node.js
+++ b/src/backend/function-node.js
@@ -59,8 +59,10 @@ class FunctionNode {
this.leadingReturnStatement = null;
this.followingReturnStatement = null;
this.dynamicOutput = null;
+ this.dynamicArguments = null;
this.strictTypingChecking = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
if (settings) {
for (const p in settings) {
diff --git a/src/backend/kernel.js b/src/backend/kernel.js
index 3a218217..094529e5 100644
--- a/src/backend/kernel.js
+++ b/src/backend/kernel.js
@@ -16,6 +16,10 @@ class Kernel {
throw new Error(`"isContextMatch" not implemented on ${ this.name }`);
}
+ /**
+ * @type {IKernelFeatures}
+ * Used internally to populate the kernel.feature, which is a getter for the output of this value
+ */
static getFeatures() {
throw new Error(`"getFeatures" not implemented on ${ this.name }`);
}
@@ -181,6 +185,7 @@ class Kernel {
this.optimizeFloatMemory = null;
this.strictIntegers = false;
this.fixIntegerDivisionAccuracy = null;
+ this.warnVarUsage = true;
}
mergeSettings(settings) {
@@ -486,6 +491,16 @@ class Kernel {
return this;
}
+ /**
+ *
+ * @param {Boolean} flag
+ * @return {Kernel}
+ */
+ setWarnVarUsage(flag) {
+ this.warnVarUsage = flag;
+ return this;
+ }
+
/**
* @deprecated
* @returns {Object}
diff --git a/src/backend/web-gl/function-node.js b/src/backend/web-gl/function-node.js
index 44105ba8..4551076d 100644
--- a/src/backend/web-gl/function-node.js
+++ b/src/backend/web-gl/function-node.js
@@ -767,7 +767,7 @@ class WebGLFunctionNode extends FunctionNode {
* @returns {Array} the append retArr
*/
astVariableDeclaration(varDecNode, retArr) {
- if (varDecNode.kind === 'var') {
+ if (varDecNode.kind === 'var' && this.warnVarUsage) {
this.varWarn();
}
const declarations = varDecNode.declarations;
diff --git a/src/backend/web-gl/kernel-value/dynamic-html-image.js b/src/backend/web-gl/kernel-value/dynamic-html-image.js
index 34f7925e..e5653205 100644
--- a/src/backend/web-gl/kernel-value/dynamic-html-image.js
+++ b/src/backend/web-gl/kernel-value/dynamic-html-image.js
@@ -1,7 +1,7 @@
const { utils } = require('../../../utils');
const { WebGLKernelValueHTMLImage } = require('./html-image');
-class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
+class WebGLKernelValueDynamicHTMLImage extends WebGLKernelValueHTMLImage {
getSource() {
return utils.linesToString([
`uniform sampler2D ${this.id}`,
@@ -21,5 +21,5 @@ class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
}
module.exports = {
- WebGLKernelValueDynamicInput
+ WebGLKernelValueDynamicHTMLImage
};
\ No newline at end of file
diff --git a/src/backend/web-gl/kernel-value/dynamic-number-texture.js b/src/backend/web-gl/kernel-value/dynamic-number-texture.js
index a2d33556..246c47cc 100644
--- a/src/backend/web-gl/kernel-value/dynamic-number-texture.js
+++ b/src/backend/web-gl/kernel-value/dynamic-number-texture.js
@@ -11,8 +11,8 @@ class WebGLKernelValueDynamicNumberTexture extends WebGLKernelValueNumberTexture
}
updateValue(value) {
- this.dimensions = inputTexture.dimensions;
- this.textureSize = inputTexture.size;
+ this.dimensions = value.dimensions;
+ this.textureSize = value.size;
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
super.updateValue(value);
diff --git a/src/backend/web-gl/kernel-value/dynamic-single-input.js b/src/backend/web-gl/kernel-value/dynamic-single-input.js
index fefcd7c7..1db18f17 100644
--- a/src/backend/web-gl/kernel-value/dynamic-single-input.js
+++ b/src/backend/web-gl/kernel-value/dynamic-single-input.js
@@ -13,7 +13,7 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
updateValue(value) {
this.dimensions = value.size;
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
- this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.uploadValue = new Float32Array(this.uploadArrayLength);
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
diff --git a/src/backend/web-gl2/kernel-value/dynamic-html-image.js b/src/backend/web-gl2/kernel-value/dynamic-html-image.js
index dbcceaac..da5e6eed 100644
--- a/src/backend/web-gl2/kernel-value/dynamic-html-image.js
+++ b/src/backend/web-gl2/kernel-value/dynamic-html-image.js
@@ -1,7 +1,7 @@
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicInput } = require('../../web-gl/kernel-value/dynamic-html-image');
+const { WebGLKernelValueDynamicHTMLImage } = require('../../web-gl/kernel-value/dynamic-html-image');
-class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
+class WebGL2KernelValueDynamicHTMLImage extends WebGLKernelValueDynamicHTMLImage {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -12,5 +12,5 @@ class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
}
module.exports = {
- WebGL2KernelValueDynamicInput
+ WebGL2KernelValueDynamicHTMLImage
};
\ No newline at end of file
diff --git a/src/backend/web-gl2/kernel-value/dynamic-single-array.js b/src/backend/web-gl2/kernel-value/dynamic-single-array.js
index a5d25b78..30ef8afe 100644
--- a/src/backend/web-gl2/kernel-value/dynamic-single-array.js
+++ b/src/backend/web-gl2/kernel-value/dynamic-single-array.js
@@ -1,7 +1,7 @@
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleArray } = require('../../web-gl/kernel-value/dynamic-single-array');
+const { WebGL2KernelValueSingleArray } = require('../../web-gl2/kernel-value/single-array');
-class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleArray {
+class WebGL2KernelValueDynamicSingleArray extends WebGL2KernelValueSingleArray {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -9,6 +9,16 @@ class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleA
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = utils.getDimensions(value, true);
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
diff --git a/src/backend/web-gl2/kernel-value/dynamic-single-input.js b/src/backend/web-gl2/kernel-value/dynamic-single-input.js
index 9c6d616e..5826d04d 100644
--- a/src/backend/web-gl2/kernel-value/dynamic-single-input.js
+++ b/src/backend/web-gl2/kernel-value/dynamic-single-input.js
@@ -1,7 +1,7 @@
const { utils } = require('../../../utils');
-const { WebGLKernelValueDynamicSingleInput } = require('../../web-gl/kernel-value/dynamic-single-input');
+const { WebGL2KernelValueSingleInput } = require('../../web-gl2/kernel-value/single-input');
-class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleInput {
+class WebGL2KernelValueDynamicSingleInput extends WebGL2KernelValueSingleInput {
getSource() {
return utils.linesToString([
`uniform highp sampler2D ${this.id}`,
@@ -9,6 +9,16 @@ class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleI
`uniform highp ivec3 ${this.dimensionsId}`,
]);
}
+
+ updateValue(value) {
+ this.dimensions = value.size;
+ this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
+ this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
+ this.uploadValue = new Float32Array(this.uploadArrayLength);
+ this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
+ this.kernel.setUniform2iv(this.sizeId, this.textureSize);
+ super.updateValue(value);
+ }
}
module.exports = {
diff --git a/src/backend/web-gl2/kernel.js b/src/backend/web-gl2/kernel.js
index c9419c3f..cd466994 100644
--- a/src/backend/web-gl2/kernel.js
+++ b/src/backend/web-gl2/kernel.js
@@ -10,14 +10,10 @@ let isSupported = null;
let testCanvas = null;
let testContext = null;
let testExtensions = null;
+
/**
*
- * @type {{
- * isFloatRead: Boolean,
- * isIntegerDivisionAccurate: Boolean,
- * kernelMap: Boolean,
- * isTextureFloat: Boolean,
- * }|null}
+ * @type {IKernelFeatures}
*/
let features = null;
diff --git a/src/gpu.js b/src/gpu.js
index 3bf4aab7..f9150a09 100644
--- a/src/gpu.js
+++ b/src/gpu.js
@@ -223,7 +223,25 @@ class GPU {
gpu: this,
validate,
onRequestFallback: (args) => {
- const fallbackKernel = new CPUKernel(source, mergedSettings);
+ const fallbackKernel = new CPUKernel(source, {
+ graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
+ constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
+ output: kernel.output,
+ precision: kernel.precision,
+ pipeline: kernel.pipeline,
+ immutable: kernel.immutable,
+ optimizeFloatMemory: kernel.optimizeFloatMemory,
+ fixIntegerDivisionAccuracy: kernel.fixIntegerDivisionAccuracy,
+ functions: kernel.functions,
+ nativeFunctions: kernel.nativeFunctions,
+ subKernels: kernel.subKernels,
+ strictIntegers: kernel.strictIntegers,
+ debug: kernel.debug,
+ warnVarUsage: kernel.warnVarUsage,
+ });
fallbackKernel.build.apply(fallbackKernel, args);
const result = fallbackKernel.run.apply(fallbackKernel, args);
kernel.replaceKernel(fallbackKernel);
@@ -246,7 +264,10 @@ class GPU {
}
const newKernel = switchableKernels[signature] = new this.Kernel(source, {
graphical: kernel.graphical,
+ loopMaxIterations: kernel.loopMaxIterations,
constants: kernel.constants,
+ dynamicOutput: kernel.dynamicOutput,
+ dynamicArgument: kernel.dynamicArguments,
context: kernel.context,
canvas: kernel.canvas,
output: kernel.output,
@@ -262,6 +283,7 @@ class GPU {
debug: kernel.debug,
gpu: this,
validate,
+ warnVarUsage: kernel.warnVarUsage,
});
newKernel.build.apply(newKernel, args);
newKernel.run.apply(newKernel, args);
diff --git a/src/index.d.ts b/src/index.d.ts
index 61bd43b7..ef62b30f 100644
--- a/src/index.d.ts
+++ b/src/index.d.ts
@@ -83,6 +83,7 @@ export abstract class Kernel {
static nativeFunctionReturnType(source: string): string;
static destroyContext(context: any): void;
static features: IKernelFeatures;
+ static getFeatures(): IKernelFeatures;
source: string | object;
Kernel: Kernel;
output: number[];
@@ -169,6 +170,7 @@ export abstract class Kernel {
): string;
toJSON(): object;
setOutput(flag: number[]): this;
+ setWarnVarUsage(flag: boolean): this;
setOptimizeFloatMemory(flag: boolean): this;
setArgumentTypes(flag: any): this;
setDebug(flag: boolean): this;
@@ -197,10 +199,10 @@ export class GLKernel extends Kernel {
export class WebGLKernel extends GLKernel {
}
-export class WebGL2Kernel extends GLKernel {
+export class WebGL2Kernel extends WebGLKernel {
}
-export class HeadlessGLKernel extends GLKernel {
+export class HeadlessGLKernel extends WebGLKernel {
}
diff --git a/test/all.html b/test/all.html
index f0505aab..55f4c454 100644
--- a/test/all.html
+++ b/test/all.html
@@ -159,6 +159,7 @@
+
@@ -273,5 +274,6 @@
+