Skip to content

Commit 4d2f27e

Browse files
fix: gpujs#590 add Kernel.onActivate
- which is called after gpu.js switches kernels based off need fix: Consistent error message for values that are not defined fix: Add recompiled kernels to gpu.js kernels property and test fix: Move texture deleting to within the GLKernel Texture implementation fix: Add Texture.clear as an abstract method on the base Texture fix: Bump and build
1 parent 7e62639 commit 4d2f27e

16 files changed

+310
-92
lines changed

dist/gpu-browser-core.js

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.9.2
8-
* @date Mon Mar 30 2020 08:17:24 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.9.3
8+
* @date Wed Apr 01 2020 07:53:27 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -2952,11 +2952,7 @@ class FunctionNode {
29522952
if (this.isAstVariable(ast)) {
29532953
const signature = this.getVariableSignature(ast);
29542954
if (signature === 'value') {
2955-
const type = this.getVariableType(ast);
2956-
if (!type) {
2957-
throw this.astErrorOutput(`Unable to find identifier valueType`, ast);
2958-
}
2959-
return type;
2955+
return this.getCheckVariableType(ast);
29602956
}
29612957
}
29622958
const origin = this.findIdentifierOrigin(ast);
@@ -2982,13 +2978,13 @@ class FunctionNode {
29822978
const variableSignature = this.getVariableSignature(ast);
29832979
switch (variableSignature) {
29842980
case 'value[]':
2985-
return this.getLookupType(this.getVariableType(ast.object));
2981+
return this.getLookupType(this.getCheckVariableType(ast.object));
29862982
case 'value[][]':
2987-
return this.getLookupType(this.getVariableType(ast.object.object));
2983+
return this.getLookupType(this.getCheckVariableType(ast.object.object));
29882984
case 'value[][][]':
2989-
return this.getLookupType(this.getVariableType(ast.object.object.object));
2985+
return this.getLookupType(this.getCheckVariableType(ast.object.object.object));
29902986
case 'value[][][][]':
2991-
return this.getLookupType(this.getVariableType(ast.object.object.object.object));
2987+
return this.getLookupType(this.getCheckVariableType(ast.object.object.object.object));
29922988
case 'value.thread.value':
29932989
case 'this.thread.value':
29942990
return 'Integer';
@@ -3005,9 +3001,7 @@ class FunctionNode {
30053001
case 'this.constants.value[][][][]':
30063002
return this.getLookupType(this.getConstantType(ast.object.object.object.object.property.name));
30073003
case 'fn()[]':
3008-
return this.getLookupType(this.getType(ast.object));
30093004
case 'fn()[][]':
3010-
return this.getLookupType(this.getType(ast.object));
30113005
case 'fn()[][][]':
30123006
return this.getLookupType(this.getType(ast.object));
30133007
case 'value.value':
@@ -3016,13 +3010,10 @@ class FunctionNode {
30163010
}
30173011
switch (ast.property.name) {
30183012
case 'r':
3019-
return this.getLookupType(this.getVariableType(ast.object));
30203013
case 'g':
3021-
return this.getLookupType(this.getVariableType(ast.object));
30223014
case 'b':
3023-
return this.getLookupType(this.getVariableType(ast.object));
30243015
case 'a':
3025-
return this.getLookupType(this.getVariableType(ast.object));
3016+
return this.getLookupType(this.getCheckVariableType(ast.object));
30263017
}
30273018
case '[][]':
30283019
return 'Number';
@@ -3048,6 +3039,14 @@ class FunctionNode {
30483039
}
30493040
}
30503041

3042+
getCheckVariableType(ast) {
3043+
const type = this.getVariableType(ast);
3044+
if (!type) {
3045+
throw this.astErrorOutput(`${ast.type} is not defined`, ast);
3046+
}
3047+
return type;
3048+
}
3049+
30513050
inferArgumentTypesIfNeeded(functionName, args) {
30523051
for (let i = 0; i < args.length; i++) {
30533052
if (!this.needsArgumentType(functionName, i)) continue;
@@ -5456,6 +5455,17 @@ class GLKernel extends Kernel {
54565455
}
54575456
}
54585457

5458+
onActivate(previousKernel) {
5459+
this._textureSwitched = true;
5460+
this.texture = previousKernel.texture;
5461+
if (this.mappedTextures) {
5462+
for (let i = 0; i < this.mappedTextures.length; i++) {
5463+
this._mappedTextureSwitched[i] = true;
5464+
}
5465+
this.mappedTextures = previousKernel.mappedTextures;
5466+
}
5467+
}
5468+
54595469
initCanvas() {}
54605470
}
54615471

@@ -5784,7 +5794,13 @@ class GLTexture extends Texture {
57845794
}
57855795

57865796
delete() {
5787-
super.delete();
5797+
if (this._deleted) return;
5798+
this._deleted = true;
5799+
if (this.texture._refs) {
5800+
this.texture._refs--;
5801+
if (this.texture._refs) return;
5802+
}
5803+
this.context.deleteTexture(this.texture);
57885804
if (this.texture._refs === 0 && this._framebuffer) {
57895805
this.context.deleteFramebuffer(this._framebuffer);
57905806
this._framebuffer = null;
@@ -6722,6 +6738,8 @@ class Kernel {
67226738
returnType: settings.returnType || null,
67236739
};
67246740
}
6741+
6742+
onActivate(previousKernel) {}
67256743
}
67266744

67276745
function splitArgumentTypes(argumentTypesObject) {
@@ -13504,9 +13522,10 @@ class GPU {
1350413522
throw new Error('source parameter not a function');
1350513523
}
1350613524

13525+
const kernels = this.kernels;
1350713526
if (this.mode === 'dev') {
1350813527
const devKernel = gpuMock(source, upgradeDeprecatedCreateKernelSettings(settings));
13509-
this.kernels.push(devKernel);
13528+
kernels.push(devKernel);
1351013529
return devKernel;
1351113530
}
1351213531

@@ -13568,6 +13587,7 @@ class GPU {
1356813587
const signature = Constructor.getSignature(_kernel, argumentTypes);
1356913588
const existingKernel = switchableKernels[signature];
1357013589
if (existingKernel) {
13590+
existingKernel.onActivate(_kernel);
1357113591
return existingKernel;
1357213592
}
1357313593

@@ -13607,6 +13627,7 @@ class GPU {
1360713627
});
1360813628
newKernel.build.apply(newKernel, args);
1360913629
kernelRun.replaceKernel(newKernel);
13630+
kernels.push(newKernel);
1361013631
return newKernel;
1361113632
}
1361213633
const mergedSettings = Object.assign({
@@ -13634,7 +13655,7 @@ class GPU {
1363413655
this.context = kernel.context;
1363513656
}
1363613657

13637-
this.kernels.push(kernel);
13658+
kernels.push(kernel);
1363813659

1363913660
return kernelRun;
1364013661
}
@@ -14077,13 +14098,11 @@ class Texture {
1407714098
}
1407814099

1407914100
delete() {
14080-
if (this._deleted) return;
14081-
this._deleted = true;
14082-
if (this.texture._refs) {
14083-
this.texture._refs--;
14084-
if (this.texture._refs) return;
14085-
}
14086-
return this.context.deleteTexture(this.texture);
14101+
throw new Error(`Not implemented on ${this.constructor.name}`);
14102+
}
14103+
14104+
clear() {
14105+
throw new Error(`Not implemented on ${this.constructor.name}`);
1408714106
}
1408814107
}
1408914108

dist/gpu-browser-core.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/gpu-browser.js

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.9.2
8-
* @date Mon Mar 30 2020 08:17:24 GMT-0400 (Eastern Daylight Time)
7+
* @version 2.9.3
8+
* @date Wed Apr 01 2020 07:53:27 GMT-0400 (Eastern Daylight Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -7405,11 +7405,7 @@ class FunctionNode {
74057405
if (this.isAstVariable(ast)) {
74067406
const signature = this.getVariableSignature(ast);
74077407
if (signature === 'value') {
7408-
const type = this.getVariableType(ast);
7409-
if (!type) {
7410-
throw this.astErrorOutput(`Unable to find identifier valueType`, ast);
7411-
}
7412-
return type;
7408+
return this.getCheckVariableType(ast);
74137409
}
74147410
}
74157411
const origin = this.findIdentifierOrigin(ast);
@@ -7435,13 +7431,13 @@ class FunctionNode {
74357431
const variableSignature = this.getVariableSignature(ast);
74367432
switch (variableSignature) {
74377433
case 'value[]':
7438-
return this.getLookupType(this.getVariableType(ast.object));
7434+
return this.getLookupType(this.getCheckVariableType(ast.object));
74397435
case 'value[][]':
7440-
return this.getLookupType(this.getVariableType(ast.object.object));
7436+
return this.getLookupType(this.getCheckVariableType(ast.object.object));
74417437
case 'value[][][]':
7442-
return this.getLookupType(this.getVariableType(ast.object.object.object));
7438+
return this.getLookupType(this.getCheckVariableType(ast.object.object.object));
74437439
case 'value[][][][]':
7444-
return this.getLookupType(this.getVariableType(ast.object.object.object.object));
7440+
return this.getLookupType(this.getCheckVariableType(ast.object.object.object.object));
74457441
case 'value.thread.value':
74467442
case 'this.thread.value':
74477443
return 'Integer';
@@ -7458,9 +7454,7 @@ class FunctionNode {
74587454
case 'this.constants.value[][][][]':
74597455
return this.getLookupType(this.getConstantType(ast.object.object.object.object.property.name));
74607456
case 'fn()[]':
7461-
return this.getLookupType(this.getType(ast.object));
74627457
case 'fn()[][]':
7463-
return this.getLookupType(this.getType(ast.object));
74647458
case 'fn()[][][]':
74657459
return this.getLookupType(this.getType(ast.object));
74667460
case 'value.value':
@@ -7469,13 +7463,10 @@ class FunctionNode {
74697463
}
74707464
switch (ast.property.name) {
74717465
case 'r':
7472-
return this.getLookupType(this.getVariableType(ast.object));
74737466
case 'g':
7474-
return this.getLookupType(this.getVariableType(ast.object));
74757467
case 'b':
7476-
return this.getLookupType(this.getVariableType(ast.object));
74777468
case 'a':
7478-
return this.getLookupType(this.getVariableType(ast.object));
7469+
return this.getLookupType(this.getCheckVariableType(ast.object));
74797470
}
74807471
case '[][]':
74817472
return 'Number';
@@ -7501,6 +7492,14 @@ class FunctionNode {
75017492
}
75027493
}
75037494

7495+
getCheckVariableType(ast) {
7496+
const type = this.getVariableType(ast);
7497+
if (!type) {
7498+
throw this.astErrorOutput(`${ast.type} is not defined`, ast);
7499+
}
7500+
return type;
7501+
}
7502+
75047503
inferArgumentTypesIfNeeded(functionName, args) {
75057504
for (let i = 0; i < args.length; i++) {
75067505
if (!this.needsArgumentType(functionName, i)) continue;
@@ -9909,6 +9908,17 @@ class GLKernel extends Kernel {
99099908
}
99109909
}
99119910

9911+
onActivate(previousKernel) {
9912+
this._textureSwitched = true;
9913+
this.texture = previousKernel.texture;
9914+
if (this.mappedTextures) {
9915+
for (let i = 0; i < this.mappedTextures.length; i++) {
9916+
this._mappedTextureSwitched[i] = true;
9917+
}
9918+
this.mappedTextures = previousKernel.mappedTextures;
9919+
}
9920+
}
9921+
99129922
initCanvas() {}
99139923
}
99149924

@@ -10237,7 +10247,13 @@ class GLTexture extends Texture {
1023710247
}
1023810248

1023910249
delete() {
10240-
super.delete();
10250+
if (this._deleted) return;
10251+
this._deleted = true;
10252+
if (this.texture._refs) {
10253+
this.texture._refs--;
10254+
if (this.texture._refs) return;
10255+
}
10256+
this.context.deleteTexture(this.texture);
1024110257
if (this.texture._refs === 0 && this._framebuffer) {
1024210258
this.context.deleteFramebuffer(this._framebuffer);
1024310259
this._framebuffer = null;
@@ -11175,6 +11191,8 @@ class Kernel {
1117511191
returnType: settings.returnType || null,
1117611192
};
1117711193
}
11194+
11195+
onActivate(previousKernel) {}
1117811196
}
1117911197

1118011198
function splitArgumentTypes(argumentTypesObject) {
@@ -17957,9 +17975,10 @@ class GPU {
1795717975
throw new Error('source parameter not a function');
1795817976
}
1795917977

17978+
const kernels = this.kernels;
1796017979
if (this.mode === 'dev') {
1796117980
const devKernel = gpuMock(source, upgradeDeprecatedCreateKernelSettings(settings));
17962-
this.kernels.push(devKernel);
17981+
kernels.push(devKernel);
1796317982
return devKernel;
1796417983
}
1796517984

@@ -18021,6 +18040,7 @@ class GPU {
1802118040
const signature = Constructor.getSignature(_kernel, argumentTypes);
1802218041
const existingKernel = switchableKernels[signature];
1802318042
if (existingKernel) {
18043+
existingKernel.onActivate(_kernel);
1802418044
return existingKernel;
1802518045
}
1802618046

@@ -18060,6 +18080,7 @@ class GPU {
1806018080
});
1806118081
newKernel.build.apply(newKernel, args);
1806218082
kernelRun.replaceKernel(newKernel);
18083+
kernels.push(newKernel);
1806318084
return newKernel;
1806418085
}
1806518086
const mergedSettings = Object.assign({
@@ -18087,7 +18108,7 @@ class GPU {
1808718108
this.context = kernel.context;
1808818109
}
1808918110

18090-
this.kernels.push(kernel);
18111+
kernels.push(kernel);
1809118112

1809218113
return kernelRun;
1809318114
}
@@ -18530,13 +18551,11 @@ class Texture {
1853018551
}
1853118552

1853218553
delete() {
18533-
if (this._deleted) return;
18534-
this._deleted = true;
18535-
if (this.texture._refs) {
18536-
this.texture._refs--;
18537-
if (this.texture._refs) return;
18538-
}
18539-
return this.context.deleteTexture(this.texture);
18554+
throw new Error(`Not implemented on ${this.constructor.name}`);
18555+
}
18556+
18557+
clear() {
18558+
throw new Error(`Not implemented on ${this.constructor.name}`);
1854018559
}
1854118560
}
1854218561

dist/gpu-browser.min.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "gpu.js",
3-
"version": "2.9.2",
3+
"version": "2.9.3",
44
"description": "GPU Accelerated JavaScript",
55
"engines": {
66
"node": ">=8.0.0"
@@ -44,8 +44,8 @@
4444
"vinyl-source-stream": "^2.0.0"
4545
},
4646
"scripts": {
47-
"test": "qunit",
48-
"coverage": "c8 qunit",
47+
"test": "qunit test/issues test/internal test/features",
48+
"coverage": "c8 qunit test/issues test/internal test/features",
4949
"setup": "npm i -g gulp-cli",
5050
"make": "gulp make",
5151
"build": "gulp build",

0 commit comments

Comments
 (0)