|
5 | 5 | * GPU Accelerated JavaScript
|
6 | 6 | *
|
7 | 7 | * @version 2.0.0-rc.14
|
8 |
| - * @date Wed May 22 2019 15:57:55 GMT-0400 (Eastern Daylight Time) |
| 8 | + * @date Thu May 23 2019 14:25:29 GMT-0400 (Eastern Daylight Time) |
9 | 9 | *
|
10 | 10 | * @license MIT
|
11 | 11 | * The MIT License
|
@@ -4011,10 +4011,10 @@ class GLKernel extends Kernel {
|
4011 | 4011 | super.setOutput(output);
|
4012 | 4012 | if (this.program) {
|
4013 | 4013 | this.threadDim = [this.output[0], this.output[1] || 1, this.output[2] || 1];
|
4014 |
| - this.texSize = utils.dimToTexSize({ |
4015 |
| - floatTextures: this.optimizeFloatMemory, |
4016 |
| - floatOutput: this.precision === 'single', |
4017 |
| - }, this.threadDim, true); |
| 4014 | + this.texSize = utils.getKernelTextureSize({ |
| 4015 | + optimizeFloatMemory: this.optimizeFloatMemory, |
| 4016 | + precision: this.precision, |
| 4017 | + }, this.output); |
4018 | 4018 | const { context: gl } = this;
|
4019 | 4019 | gl.bindFramebuffer(gl.FRAMEBUFFER, this.framebuffer);
|
4020 | 4020 | this.updateMaxTexSize();
|
@@ -7425,10 +7425,10 @@ class WebGLKernel extends GLKernel {
|
7425 | 7425 |
|
7426 | 7426 | validateSettings() {
|
7427 | 7427 | if (!this.validate) {
|
7428 |
| - this.texSize = utils.dimToTexSize({ |
7429 |
| - floatTextures: this.optimizeFloatMemory, |
7430 |
| - floatOutput: this.precision === 'single', |
7431 |
| - }, this.output, true); |
| 7428 | + this.texSize = utils.getKernelTextureSize({ |
| 7429 | + optimizeFloatMemory: this.optimizeFloatMemory, |
| 7430 | + precision: this.precision, |
| 7431 | + }, this.output); |
7432 | 7432 | return;
|
7433 | 7433 | }
|
7434 | 7434 |
|
@@ -7484,10 +7484,10 @@ class WebGLKernel extends GLKernel {
|
7484 | 7484 | this.precision = 'single';
|
7485 | 7485 | }
|
7486 | 7486 |
|
7487 |
| - this.texSize = utils.dimToTexSize({ |
7488 |
| - floatTextures: this.floatTextures, |
7489 |
| - floatOutput: this.precision === 'single' |
7490 |
| - }, this.output, true); |
| 7487 | + this.texSize = utils.getKernelTextureSize({ |
| 7488 | + optimizeFloatMemory: this.optimizeFloatMemory, |
| 7489 | + precision: this.precision, |
| 7490 | + }, this.output); |
7491 | 7491 | }
|
7492 | 7492 |
|
7493 | 7493 | updateMaxTexSize() {
|
@@ -9316,10 +9316,10 @@ class WebGL2Kernel extends WebGLKernel {
|
9316 | 9316 |
|
9317 | 9317 | validateSettings() {
|
9318 | 9318 | if (!this.validate) {
|
9319 |
| - this.texSize = utils.dimToTexSize({ |
9320 |
| - floatTextures: this.optimizeFloatMemory, |
9321 |
| - floatOutput: this.precision === 'single', |
9322 |
| - }, this.output, true); |
| 9319 | + this.texSize = utils.getKernelTextureSize({ |
| 9320 | + optimizeFloatMemory: this.optimizeFloatMemory, |
| 9321 | + precision: this.precision, |
| 9322 | + }, this.output); |
9323 | 9323 | return;
|
9324 | 9324 | }
|
9325 | 9325 |
|
@@ -9377,14 +9377,10 @@ class WebGL2Kernel extends WebGLKernel {
|
9377 | 9377 | this.precision = 'single';
|
9378 | 9378 | }
|
9379 | 9379 |
|
9380 |
| - this.texSize = utils.dimToTexSize({ |
9381 |
| - floatTextures: !this.optimizeFloatMemory, |
9382 |
| - floatOutput: this.precision === 'single', |
9383 |
| - }, this.output, true); |
9384 |
| - |
9385 |
| - if (this.precision === 'single') { |
9386 |
| - this.context.getExtension('EXT_color_buffer_float'); |
9387 |
| - } |
| 9380 | + this.texSize = utils.getKernelTextureSize({ |
| 9381 | + optimizeFloatMemory: this.optimizeFloatMemory, |
| 9382 | + precision: this.precision, |
| 9383 | + }, this.output); |
9388 | 9384 | }
|
9389 | 9385 |
|
9390 | 9386 | translateSource() {
|
@@ -9487,25 +9483,23 @@ class WebGL2Kernel extends WebGLKernel {
|
9487 | 9483 | case 'Float':
|
9488 | 9484 | case 'Integer':
|
9489 | 9485 | if (this.optimizeFloatMemory) {
|
9490 |
| - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, texSize[0], texSize[1], 0, gl.RGBA, gl.FLOAT, null); |
| 9486 | + gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32F, texSize[0], texSize[1]); |
9491 | 9487 | } else {
|
9492 |
| - gl.texImage2D(gl.TEXTURE_2D, 0, gl.R32F, texSize[0], texSize[1], 0, gl.RED, gl.FLOAT, null); |
| 9488 | + gl.texStorage2D(gl.TEXTURE_2D, 1, gl.R32F, texSize[0], texSize[1]); |
9493 | 9489 | }
|
9494 | 9490 | break;
|
9495 | 9491 | case 'Array(2)':
|
9496 |
| - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RG32F, texSize[0], texSize[1], 0, gl.RG, gl.FLOAT, null); |
9497 |
| - break; |
9498 |
| - case 'Array(3)': |
9499 |
| - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGB32F, texSize[0], texSize[1], 0, gl.RGB, gl.FLOAT, null); |
| 9492 | + gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RG32F, texSize[0], texSize[1]); |
9500 | 9493 | break;
|
| 9494 | + case 'Array(3)': |
9501 | 9495 | case 'Array(4)':
|
9502 |
| - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, texSize[0], texSize[1], 0, gl.RGBA, gl.FLOAT, null); |
| 9496 | + gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32F, texSize[0], texSize[1]); |
9503 | 9497 | break;
|
9504 | 9498 | default:
|
9505 | 9499 | throw new Error('Unhandled return type');
|
9506 | 9500 | }
|
9507 | 9501 | } else {
|
9508 |
| - gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA32F, texSize[0], texSize[1], 0, gl.RGBA, gl.FLOAT, null); |
| 9502 | + gl.texStorage2D(gl.TEXTURE_2D, 1, gl.RGBA32F, texSize[0], texSize[1]); |
9509 | 9503 | }
|
9510 | 9504 | } else {
|
9511 | 9505 | gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, texSize[0], texSize[1], 0, gl.RGBA, gl.UNSIGNED_BYTE, null);
|
@@ -9802,6 +9796,7 @@ class WebGL2Kernel extends WebGLKernel {
|
9802 | 9796 | module.exports = {
|
9803 | 9797 | WebGL2Kernel
|
9804 | 9798 | };
|
| 9799 | + |
9805 | 9800 | },{"../../utils":88,"../function-builder":8,"../web-gl/kernel":55,"./fragment-shader":57,"./function-node":58,"./kernel-value-maps":59,"./vertex-shader":80}],80:[function(require,module,exports){
|
9806 | 9801 | const vertexShader = `#version 300 es
|
9807 | 9802 | precision highp float;
|
@@ -10331,33 +10326,34 @@ function kernelRunShortcut(kernel) {
|
10331 | 10326 | kernel = replacementKernel;
|
10332 | 10327 | };
|
10333 | 10328 |
|
10334 |
| - utils |
10335 |
| - .allPropertiesOf(kernel) |
10336 |
| - .forEach((key) => { |
10337 |
| - if (key[0] === '_' && key[1] === '_') return; |
10338 |
| - if (typeof kernel[key] === 'function') { |
10339 |
| - if (key.substring(0, 3) === 'add' || key.substring(0, 3) === 'set') { |
10340 |
| - shortcut[key] = function() { |
10341 |
| - kernel[key].apply(kernel, arguments); |
10342 |
| - return shortcut; |
10343 |
| - }; |
10344 |
| - } else if (key === 'requestFallback') { |
10345 |
| - const requestFallback = kernel[key].bind(kernel); |
10346 |
| - shortcut[key] = () => { |
10347 |
| - kernel = requestFallback(); |
| 10329 | + const properties = utils.allPropertiesOf(kernel); |
| 10330 | + for (let i = 0; i < properties.length; i++) { |
| 10331 | + const property = properties[i]; |
| 10332 | + if (property[0] === '_' && property[1] === '_') continue; |
| 10333 | + if (typeof kernel[property] === 'function') { |
| 10334 | + if (property.substring(0, 3) === 'add' || property.substring(0, 3) === 'set') { |
| 10335 | + shortcut[property] = function() { |
| 10336 | + kernel[property].apply(kernel, arguments); |
| 10337 | + return shortcut; |
| 10338 | + }; |
| 10339 | + } else { |
| 10340 | + if (property === 'toString') { |
| 10341 | + shortcut.toString = function() { |
| 10342 | + return kernel.toString.apply(kernel, arguments); |
10348 | 10343 | };
|
10349 | 10344 | } else {
|
10350 |
| - shortcut[key] = kernel[key].bind(kernel); |
| 10345 | + shortcut[property] = kernel[property].bind(kernel); |
10351 | 10346 | }
|
10352 |
| - } else { |
10353 |
| - shortcut.__defineGetter__(key, () => { |
10354 |
| - return kernel[key]; |
10355 |
| - }); |
10356 |
| - shortcut.__defineSetter__(key, (value) => { |
10357 |
| - kernel[key] = value; |
10358 |
| - }); |
10359 | 10347 | }
|
10360 |
| - }); |
| 10348 | + } else { |
| 10349 | + shortcut.__defineGetter__(property, () => { |
| 10350 | + return kernel[property]; |
| 10351 | + }); |
| 10352 | + shortcut.__defineSetter__(property, (value) => { |
| 10353 | + kernel[property] = value; |
| 10354 | + }); |
| 10355 | + } |
| 10356 | + } |
10361 | 10357 |
|
10362 | 10358 | shortcut.kernel = kernel;
|
10363 | 10359 |
|
@@ -10556,11 +10552,11 @@ const utils = {
|
10556 | 10552 | },
|
10557 | 10553 |
|
10558 | 10554 |
|
10559 |
| - dimToTexSize(opt, dimensions, output) { |
| 10555 | + getKernelTextureSize(settings, dimensions) { |
10560 | 10556 | let [w, h, d] = dimensions;
|
10561 | 10557 | let texelCount = (w || 1) * (h || 1) * (d || 1);
|
10562 | 10558 |
|
10563 |
| - if (opt.floatTextures && (!output || opt.precision === 'single')) { |
| 10559 | + if (settings.optimizeFloatMemory && settings.precision === 'single') { |
10564 | 10560 | w = texelCount = Math.ceil(texelCount / 4);
|
10565 | 10561 | }
|
10566 | 10562 | if (h > 1 && w * h === texelCount) {
|
|
0 commit comments