Skip to content

Commit

Permalink
fix: Move jellyfish images to actual files
Browse files Browse the repository at this point in the history
fix: added `warnVarUsage` and `Dealing With Transpilation`
fix: Test dynamic arguments and provide some fixes for
fix: Dynamic arguments for `CPUFunctionNode`
fix: Dynamic arguments for `WebGLKernelValueDynamicHTMLImage`, `WebGLKernelValueDynamicNumberTexture`, `WebGLKernelValueDynamicSingleInput`, `WebGL2KernelValueDynamicHTMLImage`, `WebGL2KernelValueDynamicNumberTexture`, and `WebGL2KernelValueDynamicSingleInput`
fix: `onRequestFallback` settings in `createKernel` and `createKernel` inclusion of `loopMaxIterations`, `dynamicOutput`, and `dynamicArgument` in settings for when switching kernels
fix: `WebGL2Kernel` and `HeadlessGLKernel` typescript definition extensions
  • Loading branch information
robertleeplummerjr committed Jul 5, 2019
1 parent f46a50d commit 8283290
Show file tree
Hide file tree
Showing 40 changed files with 1,148 additions and 167 deletions.
17 changes: 17 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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/).
Expand Down
102 changes: 79 additions & 23 deletions dist/gpu-browser-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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} `);
Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -1674,7 +1674,9 @@ class FunctionBuilder {
functions,
leadingReturnStatement,
followingReturnStatement,
dynamicArguments,
dynamicOutput,
warnVarUsage,
} = kernel;

const needsArgumentType = (functionName, index) => {
Expand Down Expand Up @@ -1736,7 +1738,8 @@ class FunctionBuilder {
triggerImplyArgumentType,
triggerTrackArgumentSynonym,
lookupArgumentSynonym,
onFunctionCall
onFunctionCall,
warnVarUsage,
}));
nestedFunction.traceFunctionAST(ast);
functionBuilder.addFunctionNode(nestedFunction);
Expand Down Expand Up @@ -1764,6 +1767,7 @@ class FunctionBuilder {
loopMaxIterations,
output,
plugins,
dynamicArguments,
dynamicOutput,
}, extraNodeOptions || {});

Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -5465,6 +5471,7 @@ class Kernel {
this.optimizeFloatMemory = null;
this.strictIntegers = false;
this.fixIntegerDivisionAccuracy = null;
this.warnVarUsage = true;
}

mergeSettings(settings) {
Expand Down Expand Up @@ -5660,6 +5667,11 @@ class Kernel {
return this;
}

setWarnVarUsage(flag) {
this.warnVarUsage = flag;
return this;
}

getCanvas() {
utils.warnDeprecated('method', 'getCanvas');
return this.canvas;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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}`,
Expand All @@ -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');
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -9957,6 +9969,7 @@ void main(void) {
module.exports = {
fragmentShader
};

},{}],59:[function(require,module,exports){
const { WebGLFunctionNode } = require('../web-gl/function-node');

Expand Down Expand Up @@ -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}`,
Expand All @@ -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');
Expand Down Expand Up @@ -10199,39 +10212,59 @@ 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}`,
`uniform highp ivec2 ${this.sizeId}`,
`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}`,
`uniform highp ivec2 ${this.sizeId}`,
`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');

Expand Down Expand Up @@ -10523,6 +10556,7 @@ let isSupported = null;
let testCanvas = null;
let testContext = null;
let testExtensions = null;

let features = null;

class WebGL2Kernel extends WebGLKernel {
Expand Down Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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);
Expand Down
Loading

0 comments on commit 8283290

Please sign in to comment.