Skip to content

Commit 5605504

Browse files
fix: Upgrade gpu-mock.js to latest 100% code coverage tested
fix: Added tests for building kernels with "dev" mode feat: Added a `.toArray()` method on `Input`, for usage with "dev" mode fix: `Input.size` to reflect exactly what was sent in, rather than make up dimensions that aren't there fix: `KernelArgument.dimensions` to fill in missing dimensions from size fix: Only safe declarations when using a literal
1 parent 8283290 commit 5605504

17 files changed

+1311
-261
lines changed

dist/gpu-browser-core.js

Lines changed: 269 additions & 58 deletions
Large diffs are not rendered by default.

dist/gpu-browser-core.min.js

Lines changed: 271 additions & 60 deletions
Large diffs are not rendered by default.

dist/gpu-browser.js

Lines changed: 269 additions & 58 deletions
Large diffs are not rendered by default.

dist/gpu-browser.min.js

Lines changed: 271 additions & 60 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
{
22
"name": "gpu.js",
3-
"version": "2.0.0-rc.20",
3+
"version": "2.0.0-rc.21",
44
"description": "GPU Accelerated JavaScript",
55
"engines": {
66
"node": ">=10.0.0"
77
},
88
"main": "./src/index.js",
99
"files": [
10-
"src", "dist"
10+
"src",
11+
"dist"
1112
],
1213
"unpkg": "./dist/gpu-browser.min.js",
1314
"jsdelivr": "./dist/gpu-browser.min.js",
@@ -19,7 +20,7 @@
1920
"acorn": "^5.1.1",
2021
"gl": "^4.3.3",
2122
"gl-wiretap": "^0.6.0",
22-
"gpu-mock.js": "^1.0.1"
23+
"gpu-mock.js": "^1.1.0"
2324
},
2425
"devDependencies": {
2526
"benchmark": "^2.1.4",

src/backend/web-gl/function-node.js

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -593,11 +593,19 @@ class WebGLFunctionNode extends FunctionNode {
593593
if (forNode.init) {
594594
this.pushState('in-for-loop-init');
595595
this.astGeneric(forNode.init, initArr);
596-
for (let i = 0; i < initArr.length; i++) {
597-
if (initArr[i].includes && initArr[i].includes(',')) {
596+
const { declarations } = forNode.init;
597+
for (let i = 0; i < declarations.length; i++) {
598+
if (declarations[i].init && declarations[i].init.type !== 'Literal') {
598599
isSafe = false;
599600
}
600601
}
602+
if (isSafe) {
603+
for (let i = 0; i < initArr.length; i++) {
604+
if (initArr[i].includes && initArr[i].includes(',')) {
605+
isSafe = false;
606+
}
607+
}
608+
}
601609
this.popState('in-for-loop-init');
602610
} else {
603611
isSafe = false;

src/backend/web-gl/kernel-value/dynamic-single-input.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
1111
}
1212

1313
updateValue(value) {
14-
this.dimensions = value.size;
14+
let [w, h, d] = value.size;
15+
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
1516
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
1617
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
1718
this.uploadValue = new Float32Array(this.uploadArrayLength);

src/backend/web-gl/kernel-value/dynamic-unsigned-input.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ class WebGLKernelValueDynamicUnsignedInput extends WebGLKernelValueUnsignedInput
1111
}
1212

1313
updateValue(value) {
14-
this.dimensions = value.size;
14+
let [w, h, d] = value.size;
15+
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
1516
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
1617
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
1718
const Type = this.getTransferArrayType(value.value);

src/backend/web-gl/kernel-value/single-input.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class WebGLKernelValueSingleInput extends WebGLKernelValue {
66
super(value, settings);
77
this.requestTexture();
88
this.bitRatio = 4;
9-
this.dimensions = value.size;
9+
let [w, h, d] = value.size;
10+
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
1011
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
1112
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
1213
this.uploadValue = new Float32Array(this.uploadArrayLength);

src/backend/web-gl/kernel-value/unsigned-input.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ class WebGLKernelValueUnsignedInput extends WebGLKernelValue {
66
super(value, settings);
77
this.requestTexture();
88
this.bitRatio = this.getBitRatio(value);
9-
this.dimensions = value.size;
9+
const [w, h, d] = value.size;
10+
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
1011
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
1112
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
1213
this.TranserArrayType = this.getTransferArrayType(value.value);

0 commit comments

Comments
 (0)