Skip to content

Commit 8283290

Browse files
fix: Move jellyfish images to actual files
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
1 parent f46a50d commit 8283290

40 files changed

+1148
-167
lines changed

README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ NOTE: documentation is slightly out of date for the upcoming release of v2. We
9292
* [Supported Math functions](#supported-math-functions)
9393
* [How to check what is supported](#how-to-check-what-is-supported)
9494
* [Typescript Typings](#typescript-typings)
95+
* [Dealing With Transpilation](#dealing-with-transpilation)
9596
* [Full API reference](#full-api-reference)
9697
* [Automatically-built Documentation](#automatically-built-documentation)
9798
* [Contributors](#contributors)
@@ -180,6 +181,7 @@ Settings are an object used to create a `kernel` or `kernelMap`. Example: `gpu.
180181
* `immutable` or `kernel.setImmutable(boolean)`: boolean, default = `false`
181182
* `strictIntegers` or `kernel.setStrictIntegers(boolean)`: boolean, default = `false` - allows undefined argumentTypes and function return values to use strict integer declarations.
182183
* `useLegacyEncoder` or `kernel.setUseLegacyEncoder(boolean)`: boolean, default `false` - more info [here](https://github.com/gpujs/gpu.js/wiki/Encoder-details).
184+
* `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.
183185

184186

185187
## Creating and Running Functions
@@ -858,6 +860,21 @@ To assist with mostly unit tests, but perhaps in scenarios outside of GPU.js, th
858860
## Typescript Typings
859861
Typescript is supported! Typings can be found [here](src/index.d.ts)!
860862

863+
## Dealing With Transpilation
864+
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.
865+
Here is a list of a few things that GPU.js does to fix transpilation:
866+
867+
* When a transpiler such as [Babel](https://babeljs.io/) changes `myCall()` to `(0, _myCall.myCall)`, it is gracefully handled.
868+
* 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.
869+
To aid in the irritation, there is an option to alleviate the irritation.
870+
When `const` and `let` are converted to `var`, and you'r prefer not to see it, use the following:
871+
```js
872+
const kernel = gpu.createKernel(myKernelFunction)
873+
.setWarnVarUsage(false);
874+
// or
875+
const kernel = gpu.createKernel(myKernelFunction, { output: [1], warnVarUsage: false });
876+
```
877+
861878
## Full API Reference
862879

863880
You can find a [complete API reference here](https://doxdox.org/gpujs/gpu.js/).

dist/gpu-browser-core.js

Lines changed: 79 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.0.0-rc.19
8-
* @date Tue Jul 02 2019 12:17:44 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.0.0-rc.20
8+
* @date Fri Jul 05 2019 11:02:54 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -717,7 +717,7 @@ class CPUFunctionNode extends FunctionNode {
717717
}
718718

719719
astVariableDeclaration(varDecNode, retArr) {
720-
if (varDecNode.kind === 'var') {
720+
if (varDecNode.kind === 'var' && this.warnVarUsage) {
721721
this.varWarn();
722722
}
723723
retArr.push(`${varDecNode.kind} `);
@@ -900,9 +900,9 @@ class CPUFunctionNode extends FunctionNode {
900900
if (isInput) {
901901
retArr.push('[(');
902902
this.astGeneric(zProperty, retArr);
903-
retArr.push(`*${ size[1] * size[0]})+(`);
903+
retArr.push(`*${ this.dynamicArguments ? '(outputY * outputX)' : size[1] * size[0] })+(`);
904904
this.astGeneric(yProperty, retArr);
905-
retArr.push(`*${ size[0] })+`);
905+
retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
906906
this.astGeneric(xProperty, retArr);
907907
retArr.push(']');
908908
} else {
@@ -920,7 +920,7 @@ class CPUFunctionNode extends FunctionNode {
920920
if (isInput) {
921921
retArr.push('[(');
922922
this.astGeneric(yProperty, retArr);
923-
retArr.push(`*${ size[0] })+`);
923+
retArr.push(`*${ this.dynamicArguments ? 'outputX' : size[0] })+`);
924924
this.astGeneric(xProperty, retArr);
925925
retArr.push(']');
926926
} else {
@@ -1674,7 +1674,9 @@ class FunctionBuilder {
16741674
functions,
16751675
leadingReturnStatement,
16761676
followingReturnStatement,
1677+
dynamicArguments,
16771678
dynamicOutput,
1679+
warnVarUsage,
16781680
} = kernel;
16791681

16801682
const needsArgumentType = (functionName, index) => {
@@ -1736,7 +1738,8 @@ class FunctionBuilder {
17361738
triggerImplyArgumentType,
17371739
triggerTrackArgumentSynonym,
17381740
lookupArgumentSynonym,
1739-
onFunctionCall
1741+
onFunctionCall,
1742+
warnVarUsage,
17401743
}));
17411744
nestedFunction.traceFunctionAST(ast);
17421745
functionBuilder.addFunctionNode(nestedFunction);
@@ -1764,6 +1767,7 @@ class FunctionBuilder {
17641767
loopMaxIterations,
17651768
output,
17661769
plugins,
1770+
dynamicArguments,
17671771
dynamicOutput,
17681772
}, extraNodeOptions || {});
17691773

@@ -2234,8 +2238,10 @@ class FunctionNode {
22342238
this.leadingReturnStatement = null;
22352239
this.followingReturnStatement = null;
22362240
this.dynamicOutput = null;
2241+
this.dynamicArguments = null;
22372242
this.strictTypingChecking = false;
22382243
this.fixIntegerDivisionAccuracy = null;
2244+
this.warnVarUsage = true;
22392245

22402246
if (settings) {
22412247
for (const p in settings) {
@@ -5465,6 +5471,7 @@ class Kernel {
54655471
this.optimizeFloatMemory = null;
54665472
this.strictIntegers = false;
54675473
this.fixIntegerDivisionAccuracy = null;
5474+
this.warnVarUsage = true;
54685475
}
54695476

54705477
mergeSettings(settings) {
@@ -5660,6 +5667,11 @@ class Kernel {
56605667
return this;
56615668
}
56625669

5670+
setWarnVarUsage(flag) {
5671+
this.warnVarUsage = flag;
5672+
return this;
5673+
}
5674+
56635675
getCanvas() {
56645676
utils.warnDeprecated('method', 'getCanvas');
56655677
return this.canvas;
@@ -6784,7 +6796,7 @@ class WebGLFunctionNode extends FunctionNode {
67846796
}
67856797

67866798
astVariableDeclaration(varDecNode, retArr) {
6787-
if (varDecNode.kind === 'var') {
6799+
if (varDecNode.kind === 'var' && this.warnVarUsage) {
67886800
this.varWarn();
67896801
}
67906802
const declarations = varDecNode.declarations;
@@ -7569,7 +7581,7 @@ module.exports = {
75697581
const { utils } = require('../../../utils');
75707582
const { WebGLKernelValueHTMLImage } = require('./html-image');
75717583

7572-
class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
7584+
class WebGLKernelValueDynamicHTMLImage extends WebGLKernelValueHTMLImage {
75737585
getSource() {
75747586
return utils.linesToString([
75757587
`uniform sampler2D ${this.id}`,
@@ -7589,7 +7601,7 @@ class WebGLKernelValueDynamicInput extends WebGLKernelValueHTMLImage {
75897601
}
75907602

75917603
module.exports = {
7592-
WebGLKernelValueDynamicInput
7604+
WebGLKernelValueDynamicHTMLImage
75937605
};
75947606
},{"../../../utils":89,"./html-image":47}],40:[function(require,module,exports){
75957607
const { utils } = require('../../../utils');
@@ -7630,8 +7642,8 @@ class WebGLKernelValueDynamicNumberTexture extends WebGLKernelValueNumberTexture
76307642
}
76317643

76327644
updateValue(value) {
7633-
this.dimensions = inputTexture.dimensions;
7634-
this.textureSize = inputTexture.size;
7645+
this.dimensions = value.dimensions;
7646+
this.textureSize = value.size;
76357647
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
76367648
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
76377649
super.updateValue(value);
@@ -7684,7 +7696,7 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
76847696
updateValue(value) {
76857697
this.dimensions = value.size;
76867698
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
7687-
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
7699+
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
76887700
this.uploadValue = new Float32Array(this.uploadArrayLength);
76897701
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
76907702
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
@@ -9957,6 +9969,7 @@ void main(void) {
99579969
module.exports = {
99589970
fragmentShader
99599971
};
9972+
99609973
},{}],59:[function(require,module,exports){
99619974
const { WebGLFunctionNode } = require('../web-gl/function-node');
99629975

@@ -10148,9 +10161,9 @@ module.exports = {
1014810161
};
1014910162
},{"./html-image-array":71}],63:[function(require,module,exports){
1015010163
const { utils } = require('../../../utils');
10151-
const { WebGLKernelValueDynamicInput } = require('../../web-gl/kernel-value/dynamic-html-image');
10164+
const { WebGLKernelValueDynamicHTMLImage } = require('../../web-gl/kernel-value/dynamic-html-image');
1015210165

10153-
class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
10166+
class WebGL2KernelValueDynamicHTMLImage extends WebGLKernelValueDynamicHTMLImage {
1015410167
getSource() {
1015510168
return utils.linesToString([
1015610169
`uniform highp sampler2D ${this.id}`,
@@ -10161,7 +10174,7 @@ class WebGL2KernelValueDynamicInput extends WebGLKernelValueDynamicInput {
1016110174
}
1016210175

1016310176
module.exports = {
10164-
WebGL2KernelValueDynamicInput
10177+
WebGL2KernelValueDynamicHTMLImage
1016510178
};
1016610179
},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-html-image":39}],64:[function(require,module,exports){
1016710180
const { utils } = require('../../../utils');
@@ -10199,39 +10212,59 @@ module.exports = {
1019910212
};
1020010213
},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-number-texture":41}],66:[function(require,module,exports){
1020110214
const { utils } = require('../../../utils');
10202-
const { WebGLKernelValueDynamicSingleArray } = require('../../web-gl/kernel-value/dynamic-single-array');
10215+
const { WebGL2KernelValueSingleArray } = require('../../web-gl2/kernel-value/single-array');
1020310216

10204-
class WebGL2KernelValueDynamicSingleArray extends WebGLKernelValueDynamicSingleArray {
10217+
class WebGL2KernelValueDynamicSingleArray extends WebGL2KernelValueSingleArray {
1020510218
getSource() {
1020610219
return utils.linesToString([
1020710220
`uniform highp sampler2D ${this.id}`,
1020810221
`uniform highp ivec2 ${this.sizeId}`,
1020910222
`uniform highp ivec3 ${this.dimensionsId}`,
1021010223
]);
1021110224
}
10225+
10226+
updateValue(value) {
10227+
this.dimensions = utils.getDimensions(value, true);
10228+
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
10229+
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
10230+
this.uploadValue = new Float32Array(this.uploadArrayLength);
10231+
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
10232+
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
10233+
super.updateValue(value);
10234+
}
1021210235
}
1021310236

1021410237
module.exports = {
1021510238
WebGL2KernelValueDynamicSingleArray
1021610239
};
10217-
},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-single-array":42}],67:[function(require,module,exports){
10240+
},{"../../../utils":89,"../../web-gl2/kernel-value/single-array":76}],67:[function(require,module,exports){
1021810241
const { utils } = require('../../../utils');
10219-
const { WebGLKernelValueDynamicSingleInput } = require('../../web-gl/kernel-value/dynamic-single-input');
10242+
const { WebGL2KernelValueSingleInput } = require('../../web-gl2/kernel-value/single-input');
1022010243

10221-
class WebGL2KernelValueDynamicSingleInput extends WebGLKernelValueDynamicSingleInput {
10244+
class WebGL2KernelValueDynamicSingleInput extends WebGL2KernelValueSingleInput {
1022210245
getSource() {
1022310246
return utils.linesToString([
1022410247
`uniform highp sampler2D ${this.id}`,
1022510248
`uniform highp ivec2 ${this.sizeId}`,
1022610249
`uniform highp ivec3 ${this.dimensionsId}`,
1022710250
]);
1022810251
}
10252+
10253+
updateValue(value) {
10254+
this.dimensions = value.size;
10255+
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
10256+
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
10257+
this.uploadValue = new Float32Array(this.uploadArrayLength);
10258+
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
10259+
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
10260+
super.updateValue(value);
10261+
}
1022910262
}
1023010263

1023110264
module.exports = {
1023210265
WebGL2KernelValueDynamicSingleInput
1023310266
};
10234-
},{"../../../utils":89,"../../web-gl/kernel-value/dynamic-single-input":43}],68:[function(require,module,exports){
10267+
},{"../../../utils":89,"../../web-gl2/kernel-value/single-input":77}],68:[function(require,module,exports){
1023510268
const { utils } = require('../../../utils');
1023610269
const { WebGLKernelValueDynamicUnsignedArray } = require('../../web-gl/kernel-value/dynamic-unsigned-array');
1023710270

@@ -10523,6 +10556,7 @@ let isSupported = null;
1052310556
let testCanvas = null;
1052410557
let testContext = null;
1052510558
let testExtensions = null;
10559+
1052610560
let features = null;
1052710561

1052810562
class WebGL2Kernel extends WebGLKernel {
@@ -11338,7 +11372,25 @@ class GPU {
1133811372
gpu: this,
1133911373
validate,
1134011374
onRequestFallback: (args) => {
11341-
const fallbackKernel = new CPUKernel(source, mergedSettings);
11375+
const fallbackKernel = new CPUKernel(source, {
11376+
graphical: kernel.graphical,
11377+
loopMaxIterations: kernel.loopMaxIterations,
11378+
constants: kernel.constants,
11379+
dynamicOutput: kernel.dynamicOutput,
11380+
dynamicArgument: kernel.dynamicArguments,
11381+
output: kernel.output,
11382+
precision: kernel.precision,
11383+
pipeline: kernel.pipeline,
11384+
immutable: kernel.immutable,
11385+
optimizeFloatMemory: kernel.optimizeFloatMemory,
11386+
fixIntegerDivisionAccuracy: kernel.fixIntegerDivisionAccuracy,
11387+
functions: kernel.functions,
11388+
nativeFunctions: kernel.nativeFunctions,
11389+
subKernels: kernel.subKernels,
11390+
strictIntegers: kernel.strictIntegers,
11391+
debug: kernel.debug,
11392+
warnVarUsage: kernel.warnVarUsage,
11393+
});
1134211394
fallbackKernel.build.apply(fallbackKernel, args);
1134311395
const result = fallbackKernel.run.apply(fallbackKernel, args);
1134411396
kernel.replaceKernel(fallbackKernel);
@@ -11361,7 +11413,10 @@ class GPU {
1136111413
}
1136211414
const newKernel = switchableKernels[signature] = new this.Kernel(source, {
1136311415
graphical: kernel.graphical,
11416+
loopMaxIterations: kernel.loopMaxIterations,
1136411417
constants: kernel.constants,
11418+
dynamicOutput: kernel.dynamicOutput,
11419+
dynamicArgument: kernel.dynamicArguments,
1136511420
context: kernel.context,
1136611421
canvas: kernel.canvas,
1136711422
output: kernel.output,
@@ -11377,6 +11432,7 @@ class GPU {
1137711432
debug: kernel.debug,
1137811433
gpu: this,
1137911434
validate,
11435+
warnVarUsage: kernel.warnVarUsage,
1138011436
});
1138111437
newKernel.build.apply(newKernel, args);
1138211438
newKernel.run.apply(newKernel, args);

0 commit comments

Comments
 (0)