Skip to content

Commit cd0b417

Browse files
fix: #552 remove incorrect texture size checks
fix: texture.renderRawOutput to use existing framebuffer, or make it so it can be deleted fix: glKernelString to handle the framebuffer from texture.renderRawOutput fix: WebGLKernelArray.checkSize so display error for all three scenarios 1. width too big 2. height too big 3. width and height too big
1 parent bdcdf8c commit cd0b417

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+150
-122
lines changed

dist/gpu-browser-core.js

Lines changed: 30 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
*
55
* GPU Accelerated JavaScript
66
*
7-
* @version 2.4.7
8-
* @date Mon Jan 06 2020 13:35:02 GMT-0500 (Eastern Standard Time)
7+
* @version 2.4.8
8+
* @date Wed Jan 08 2020 07:08:29 GMT-0500 (Eastern Standard Time)
99
*
1010
* @license MIT
1111
* The MIT License
@@ -4387,13 +4387,17 @@ function getToArrayString(kernelResult, textureName) {
43874387
if (property === 'context') {
43884388
return null;
43894389
}
4390+
if (property === '_framebuffer') {
4391+
return '_framebuffer';
4392+
}
43904393
if (kernelResult.hasOwnProperty(property)) {
43914394
return JSON.stringify(kernelResult[property]);
43924395
}
43934396
throw new Error(`unhandled thisLookup ${ property }`);
43944397
}
43954398
});
43964399
return `() => {
4400+
let _framebuffer;
43974401
${flattenedFunctions}
43984402
return toArray();
43994403
}`;
@@ -5526,18 +5530,20 @@ class GLTextureFloat extends GLTexture {
55265530
this.type = 'ArrayTexture(1)';
55275531
}
55285532
renderRawOutput() {
5529-
const { context: gl } = this;
5530-
const framebuffer = gl.createFramebuffer();
5531-
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
5533+
const { context: gl, size } = this;
5534+
if (!this._framebuffer) {
5535+
this._framebuffer = gl.createFramebuffer();
5536+
}
5537+
gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);
55325538
gl.framebufferTexture2D(
55335539
gl.FRAMEBUFFER,
55345540
gl.COLOR_ATTACHMENT0,
55355541
gl.TEXTURE_2D,
55365542
this.texture,
55375543
0
55385544
);
5539-
const result = new Float32Array(this.size[0] * this.size[1] * 4);
5540-
gl.readPixels(0, 0, this.size[0], this.size[1], gl.RGBA, gl.FLOAT, result);
5545+
const result = new Float32Array(size[0] * size[1] * 4);
5546+
gl.readPixels(0, 0, size[0], size[1], gl.RGBA, gl.FLOAT, result);
55415547
return result;
55425548
}
55435549
renderValues() {
@@ -8467,9 +8473,11 @@ class WebGLKernelArray extends WebGLKernelValue {
84678473
const { maxTextureSize } = this.kernel.constructor.features;
84688474
if (width > maxTextureSize || height > maxTextureSize) {
84698475
if (width > height) {
8470-
throw new Error(`Argument width of ${width} larger than maximum size of ${maxTextureSize} for your GPU`);
8476+
throw new Error(`Argument texture width of ${width} larger than maximum size of ${maxTextureSize} for your GPU`);
8477+
} else if (width < height) {
8478+
throw new Error(`Argument texture height of ${height} larger than maximum size of ${maxTextureSize} for your GPU`);
84718479
} else {
8472-
throw new Error(`Argument height of ${height} larger than maximum size of ${maxTextureSize} for your GPU`);
8480+
throw new Error(`Argument texture height and width of ${height} larger than maximum size of ${maxTextureSize} for your GPU`);
84738481
}
84748482
}
84758483
}
@@ -8666,7 +8674,7 @@ class WebGLKernelValueDynamicSingleArray extends WebGLKernelValueSingleArray {
86668674
this.dimensions = utils.getDimensions(value, true);
86678675
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
86688676
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
8669-
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
8677+
this.checkSize(this.textureSize[0], this.textureSize[1]);
86708678
this.uploadValue = new Float32Array(this.uploadArrayLength);
86718679
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
86728680
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
@@ -8767,7 +8775,7 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
87678775
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
87688776
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
87698777
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
8770-
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
8778+
this.checkSize(this.textureSize[0], this.textureSize[1]);
87718779
this.uploadValue = new Float32Array(this.uploadArrayLength);
87728780
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
87738781
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
@@ -8795,7 +8803,7 @@ class WebGLKernelValueDynamicUnsignedArray extends WebGLKernelValueUnsignedArray
87958803
this.dimensions = utils.getDimensions(value, true);
87968804
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
87978805
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
8798-
this.checkSize(this.textureSize[0] * (4 / this.bitRatio), this.textureSize[1] * (4 / this.bitRatio));
8806+
this.checkSize(this.textureSize[0], this.textureSize[1]);
87998807
const Type = this.getTransferArrayType(value);
88008808
this.preUploadValue = new Type(this.uploadArrayLength);
88018809
this.uploadValue = new Uint8Array(this.preUploadValue.buffer);
@@ -8826,7 +8834,7 @@ class WebGLKernelValueDynamicUnsignedInput extends WebGLKernelValueUnsignedInput
88268834
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
88278835
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
88288836
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
8829-
this.checkSize(this.textureSize[0] * (4 / this.bitRatio), this.textureSize[1] * (4 / this.bitRatio));
8837+
this.checkSize(this.textureSize[0], this.textureSize[1]);
88308838
const Type = this.getTransferArrayType(value.value);
88318839
this.preUploadValue = new Type(this.uploadArrayLength);
88328840
this.uploadValue = new Uint8Array(this.preUploadValue.buffer);
@@ -9125,7 +9133,7 @@ class WebGLKernelValueSingleArray extends WebGLKernelArray {
91259133
this.dimensions = utils.getDimensions(value, true);
91269134
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
91279135
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
9128-
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
9136+
this.checkSize(this.textureSize[0], this.textureSize[1]);
91299137
this.uploadValue = new Float32Array(this.uploadArrayLength);
91309138
}
91319139

@@ -9178,7 +9186,7 @@ class WebGLKernelValueSingleArray1DI extends WebGLKernelArray {
91789186
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(valueDimensions, this.bitRatio);
91799187
this.dimensions = new Int32Array([valueDimensions[1], 1, 1]);
91809188
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
9181-
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
9189+
this.checkSize(this.textureSize[0], this.textureSize[1]);
91829190
this.uploadValue = new Float32Array(this.uploadArrayLength);
91839191
}
91849192

@@ -9261,7 +9269,7 @@ class WebGLKernelValueSingleArray2DI extends WebGLKernelArray {
92619269
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(valueDimensions, this.bitRatio);
92629270
this.dimensions = new Int32Array([valueDimensions[1], valueDimensions[2], 1]);
92639271
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
9264-
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
9272+
this.checkSize(this.textureSize[0], this.textureSize[1]);
92659273
this.uploadValue = new Float32Array(this.uploadArrayLength);
92669274
}
92679275

@@ -9344,7 +9352,7 @@ class WebGLKernelValueSingleArray3DI extends WebGLKernelArray {
93449352
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(valueDimensions, this.bitRatio);
93459353
this.dimensions = new Int32Array([valueDimensions[1], valueDimensions[2], valueDimensions[3]]);
93469354
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
9347-
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
9355+
this.checkSize(this.textureSize[0], this.textureSize[1]);
93489356
this.uploadValue = new Float32Array(this.uploadArrayLength);
93499357
}
93509358

@@ -9423,7 +9431,7 @@ class WebGLKernelValueSingleInput extends WebGLKernelArray {
94239431
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
94249432
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
94259433
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
9426-
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
9434+
this.checkSize(this.textureSize[0], this.textureSize[1]);
94279435
this.uploadValue = new Float32Array(this.uploadArrayLength);
94289436
}
94299437

@@ -9471,7 +9479,7 @@ class WebGLKernelValueUnsignedArray extends WebGLKernelArray {
94719479
this.dimensions = utils.getDimensions(value, true);
94729480
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
94739481
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
9474-
this.checkSize(this.textureSize[0] * (4 / this.bitRatio), this.textureSize[1] * (4 / this.bitRatio));
9482+
this.checkSize(this.textureSize[0], this.textureSize[1]);
94759483
this.TranserArrayType = this.getTransferArrayType(value);
94769484
this.preUploadValue = new this.TranserArrayType(this.uploadArrayLength);
94779485
this.uploadValue = new Uint8Array(this.preUploadValue.buffer);
@@ -9523,7 +9531,7 @@ class WebGLKernelValueUnsignedInput extends WebGLKernelArray {
95239531
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
95249532
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
95259533
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
9526-
this.checkSize(this.textureSize[0] * (4 / this.bitRatio), this.textureSize[1] * (4 / this.bitRatio));
9534+
this.checkSize(this.textureSize[0], this.textureSize[1]);
95279535
this.TranserArrayType = this.getTransferArrayType(value.value);
95289536
this.preUploadValue = new this.TranserArrayType(this.uploadArrayLength);
95299537
this.uploadValue = new Uint8Array(this.preUploadValue.buffer);
@@ -11693,7 +11701,7 @@ class WebGL2KernelValueDynamicSingleArray extends WebGL2KernelValueSingleArray {
1169311701
this.dimensions = utils.getDimensions(value, true);
1169411702
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
1169511703
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
11696-
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
11704+
this.checkSize(this.textureSize[0], this.textureSize[1]);
1169711705
this.uploadValue = new Float32Array(this.uploadArrayLength);
1169811706
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
1169911707
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
@@ -11798,7 +11806,7 @@ class WebGL2KernelValueDynamicSingleInput extends WebGL2KernelValueSingleInput {
1179811806
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
1179911807
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
1180011808
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
11801-
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
11809+
this.checkSize(this.textureSize[0], this.textureSize[1]);
1180211810
this.uploadValue = new Float32Array(this.uploadArrayLength);
1180311811
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
1180411812
this.kernel.setUniform2iv(this.sizeId, this.textureSize);

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.

0 commit comments

Comments
 (0)