Skip to content

Commit

Permalink
fix: #552 remove incorrect texture size checks
Browse files Browse the repository at this point in the history
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
  • Loading branch information
robertleeplummerjr committed Jan 8, 2020
1 parent bdcdf8c commit cd0b417
Show file tree
Hide file tree
Showing 46 changed files with 150 additions and 122 deletions.
52 changes: 30 additions & 22 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.4.7
* @date Mon Jan 06 2020 13:35:02 GMT-0500 (Eastern Standard Time)
* @version 2.4.8
* @date Wed Jan 08 2020 07:08:29 GMT-0500 (Eastern Standard Time)
*
* @license MIT
* The MIT License
Expand Down Expand Up @@ -4387,13 +4387,17 @@ function getToArrayString(kernelResult, textureName) {
if (property === 'context') {
return null;
}
if (property === '_framebuffer') {
return '_framebuffer';
}
if (kernelResult.hasOwnProperty(property)) {
return JSON.stringify(kernelResult[property]);
}
throw new Error(`unhandled thisLookup ${ property }`);
}
});
return `() => {
let _framebuffer;
${flattenedFunctions}
return toArray();
}`;
Expand Down Expand Up @@ -5526,18 +5530,20 @@ class GLTextureFloat extends GLTexture {
this.type = 'ArrayTexture(1)';
}
renderRawOutput() {
const { context: gl } = this;
const framebuffer = gl.createFramebuffer();
gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
const { context: gl, size } = this;
if (!this._framebuffer) {
this._framebuffer = gl.createFramebuffer();
}
gl.bindFramebuffer(gl.FRAMEBUFFER, this._framebuffer);
gl.framebufferTexture2D(
gl.FRAMEBUFFER,
gl.COLOR_ATTACHMENT0,
gl.TEXTURE_2D,
this.texture,
0
);
const result = new Float32Array(this.size[0] * this.size[1] * 4);
gl.readPixels(0, 0, this.size[0], this.size[1], gl.RGBA, gl.FLOAT, result);
const result = new Float32Array(size[0] * size[1] * 4);
gl.readPixels(0, 0, size[0], size[1], gl.RGBA, gl.FLOAT, result);
return result;
}
renderValues() {
Expand Down Expand Up @@ -8467,9 +8473,11 @@ class WebGLKernelArray extends WebGLKernelValue {
const { maxTextureSize } = this.kernel.constructor.features;
if (width > maxTextureSize || height > maxTextureSize) {
if (width > height) {
throw new Error(`Argument width of ${width} larger than maximum size of ${maxTextureSize} for your GPU`);
throw new Error(`Argument texture width of ${width} larger than maximum size of ${maxTextureSize} for your GPU`);
} else if (width < height) {
throw new Error(`Argument texture height of ${height} larger than maximum size of ${maxTextureSize} for your GPU`);
} else {
throw new Error(`Argument height of ${height} larger than maximum size of ${maxTextureSize} for your GPU`);
throw new Error(`Argument texture height and width of ${height} larger than maximum size of ${maxTextureSize} for your GPU`);
}
}
}
Expand Down Expand Up @@ -8666,7 +8674,7 @@ class WebGLKernelValueDynamicSingleArray extends WebGLKernelValueSingleArray {
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.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.uploadValue = new Float32Array(this.uploadArrayLength);
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
Expand Down Expand Up @@ -8767,7 +8775,7 @@ class WebGLKernelValueDynamicSingleInput extends WebGLKernelValueSingleInput {
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.uploadValue = new Float32Array(this.uploadArrayLength);
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
Expand Down Expand Up @@ -8795,7 +8803,7 @@ class WebGLKernelValueDynamicUnsignedArray extends WebGLKernelValueUnsignedArray
this.dimensions = utils.getDimensions(value, true);
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
this.checkSize(this.textureSize[0] * (4 / this.bitRatio), this.textureSize[1] * (4 / this.bitRatio));
this.checkSize(this.textureSize[0], this.textureSize[1]);
const Type = this.getTransferArrayType(value);
this.preUploadValue = new Type(this.uploadArrayLength);
this.uploadValue = new Uint8Array(this.preUploadValue.buffer);
Expand Down Expand Up @@ -8826,7 +8834,7 @@ class WebGLKernelValueDynamicUnsignedInput extends WebGLKernelValueUnsignedInput
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
this.checkSize(this.textureSize[0] * (4 / this.bitRatio), this.textureSize[1] * (4 / this.bitRatio));
this.checkSize(this.textureSize[0], this.textureSize[1]);
const Type = this.getTransferArrayType(value.value);
this.preUploadValue = new Type(this.uploadArrayLength);
this.uploadValue = new Uint8Array(this.preUploadValue.buffer);
Expand Down Expand Up @@ -9125,7 +9133,7 @@ class WebGLKernelValueSingleArray extends WebGLKernelArray {
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.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.uploadValue = new Float32Array(this.uploadArrayLength);
}

Expand Down Expand Up @@ -9178,7 +9186,7 @@ class WebGLKernelValueSingleArray1DI extends WebGLKernelArray {
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(valueDimensions, this.bitRatio);
this.dimensions = new Int32Array([valueDimensions[1], 1, 1]);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.uploadValue = new Float32Array(this.uploadArrayLength);
}

Expand Down Expand Up @@ -9261,7 +9269,7 @@ class WebGLKernelValueSingleArray2DI extends WebGLKernelArray {
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(valueDimensions, this.bitRatio);
this.dimensions = new Int32Array([valueDimensions[1], valueDimensions[2], 1]);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.uploadValue = new Float32Array(this.uploadArrayLength);
}

Expand Down Expand Up @@ -9344,7 +9352,7 @@ class WebGLKernelValueSingleArray3DI extends WebGLKernelArray {
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(valueDimensions, this.bitRatio);
this.dimensions = new Int32Array([valueDimensions[1], valueDimensions[2], valueDimensions[3]]);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.uploadValue = new Float32Array(this.uploadArrayLength);
}

Expand Down Expand Up @@ -9423,7 +9431,7 @@ class WebGLKernelValueSingleInput extends WebGLKernelArray {
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.uploadValue = new Float32Array(this.uploadArrayLength);
}

Expand Down Expand Up @@ -9471,7 +9479,7 @@ class WebGLKernelValueUnsignedArray extends WebGLKernelArray {
this.dimensions = utils.getDimensions(value, true);
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
this.checkSize(this.textureSize[0] * (4 / this.bitRatio), this.textureSize[1] * (4 / this.bitRatio));
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.TranserArrayType = this.getTransferArrayType(value);
this.preUploadValue = new this.TranserArrayType(this.uploadArrayLength);
this.uploadValue = new Uint8Array(this.preUploadValue.buffer);
Expand Down Expand Up @@ -9523,7 +9531,7 @@ class WebGLKernelValueUnsignedInput extends WebGLKernelArray {
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
this.textureSize = utils.getMemoryOptimizedPackedTextureSize(this.dimensions, this.bitRatio);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * (4 / this.bitRatio);
this.checkSize(this.textureSize[0] * (4 / this.bitRatio), this.textureSize[1] * (4 / this.bitRatio));
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.TranserArrayType = this.getTransferArrayType(value.value);
this.preUploadValue = new this.TranserArrayType(this.uploadArrayLength);
this.uploadValue = new Uint8Array(this.preUploadValue.buffer);
Expand Down Expand Up @@ -11693,7 +11701,7 @@ class WebGL2KernelValueDynamicSingleArray extends WebGL2KernelValueSingleArray {
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.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.uploadValue = new Float32Array(this.uploadArrayLength);
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
Expand Down Expand Up @@ -11798,7 +11806,7 @@ class WebGL2KernelValueDynamicSingleInput extends WebGL2KernelValueSingleInput {
this.dimensions = new Int32Array([w || 1, h || 1, d || 1]);
this.textureSize = utils.getMemoryOptimizedFloatTextureSize(this.dimensions, this.bitRatio);
this.uploadArrayLength = this.textureSize[0] * this.textureSize[1] * this.bitRatio;
this.checkSize(this.textureSize[0] * this.bitRatio, this.textureSize[1] * this.bitRatio);
this.checkSize(this.textureSize[0], this.textureSize[1]);
this.uploadValue = new Float32Array(this.uploadArrayLength);
this.kernel.setUniform3iv(this.dimensionsId, this.dimensions);
this.kernel.setUniform2iv(this.sizeId, this.textureSize);
Expand Down
6 changes: 3 additions & 3 deletions dist/gpu-browser-core.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit cd0b417

Please sign in to comment.