Skip to content

Commit

Permalink
Merge pull request gpujs#458 from Drenata/fix-return-nd-array
Browse files Browse the repository at this point in the history
Fix return of >=2d arrays from GPU
  • Loading branch information
robertleeplummerjr authored Apr 29, 2019
2 parents 47bae6b + ce6fb28 commit d6757ab
Show file tree
Hide file tree
Showing 6 changed files with 173 additions and 101 deletions.
36 changes: 21 additions & 15 deletions bin/gpu-browser-core.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* GPU Accelerated JavaScript
*
* @version 2.0.0-rc.13
* @date Mon Apr 29 2019 08:45:13 GMT-0400 (Eastern Daylight Time)
* @date Mon Apr 29 2019 20:46:46 GMT+0200 (CEST)
*
* @license MIT
* The MIT License
Expand Down Expand Up @@ -3466,9 +3466,10 @@ class GLKernel extends Kernel {
const XResultsMax = xMax * 4;
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = y * XResultsMax;
let i = 0;
for (let x = 0; x < XResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x, x + 2);
xResults[i++] = pixels.subarray(x + offset, x + offset + 2);
}
yResults[y] = xResults;
}
Expand All @@ -3483,9 +3484,10 @@ class GLKernel extends Kernel {
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = (z * xResultsMax * yMax) + (y * xResultsMax);
let i = 0;
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x, x + 2);
xResults[i++] = pixels.subarray(x + offset, x + offset + 2);
}
yResults[y] = xResults;
}
Expand All @@ -3507,13 +3509,14 @@ class GLKernel extends Kernel {
render2DArray3() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax] = this.output;
const xMaxResults = xMax * 4;
const xResultsMax = xMax * 4;
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = y * xResultsMax;
let i = 0;
for (let x = 0; x < xMaxResults; x += 4) {
xResults[i++] = pixels.subarray(x, x + 3);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 3);
}
yResults[y] = xResults;
}
Expand All @@ -3522,15 +3525,16 @@ class GLKernel extends Kernel {
render3DArray3() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax, zMax] = this.output;
const xMaxResults = xMax * 4;
const xResultsMax = xMax * 4;
const zResults = new Array(zMax);
for (let z = 0; z < zMax; z++) {
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = (z * xResultsMax * yMax) + (y * xResultsMax);
let i = 0;
for (let x = 0; x < xMaxResults; x += 4) {
xResults[i++] = pixels.subarray(x, x + 3);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 3);
}
yResults[y] = xResults;
}
Expand All @@ -3552,13 +3556,14 @@ class GLKernel extends Kernel {
render2DArray4() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax] = this.output;
const xMaxResult = xMax * 4;
const xResultsMax = xMax * 4;
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = y * xResultsMax;
let i = 0;
for (let x = 0; x < xMaxResult; x += 4) {
xResults[i++] = pixels.subarray(x, x + 4);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 4);
}
yResults[y] = xResults;
}
Expand All @@ -3567,15 +3572,16 @@ class GLKernel extends Kernel {
render3DArray4() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax, zMax] = this.output;
const xResultsMap = xMax * 4;
const xResultsMax = xMax * 4;
const zResults = new Array(zMax);
for (let z = 0; z < zMax; z++) {
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = (z * xResultsMax * yMax) + (y * xResultsMax);
let i = 0;
for (let x = 0; x < xResultsMap; x += 4) {
xResults[i++] = pixels.subarray(x, x + 4);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 4);
}
yResults[y] = xResults;
}
Expand Down
38 changes: 22 additions & 16 deletions bin/gpu-browser-core.min.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* GPU Accelerated JavaScript
*
* @version 2.0.0-rc.13
* @date Mon Apr 29 2019 08:45:16 GMT-0400 (Eastern Daylight Time)
* @date Mon Apr 29 2019 20:46:48 GMT+0200 (CEST)
*
* @license MIT
* The MIT License
Expand All @@ -18,7 +18,7 @@
* GPU Accelerated JavaScript
*
* @version 2.0.0-rc.13
* @date Mon Apr 29 2019 08:45:13 GMT-0400 (Eastern Daylight Time)
* @date Mon Apr 29 2019 20:46:46 GMT+0200 (CEST)
*
* @license MIT
* The MIT License
Expand Down Expand Up @@ -3479,9 +3479,10 @@ class GLKernel extends Kernel {
const XResultsMax = xMax * 4;
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = y * XResultsMax;
let i = 0;
for (let x = 0; x < XResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x, x + 2);
xResults[i++] = pixels.subarray(x + offset, x + offset + 2);
}
yResults[y] = xResults;
}
Expand All @@ -3496,9 +3497,10 @@ class GLKernel extends Kernel {
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = (z * xResultsMax * yMax) + (y * xResultsMax);
let i = 0;
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x, x + 2);
xResults[i++] = pixels.subarray(x + offset, x + offset + 2);
}
yResults[y] = xResults;
}
Expand All @@ -3520,13 +3522,14 @@ class GLKernel extends Kernel {
render2DArray3() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax] = this.output;
const xMaxResults = xMax * 4;
const xResultsMax = xMax * 4;
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = y * xResultsMax;
let i = 0;
for (let x = 0; x < xMaxResults; x += 4) {
xResults[i++] = pixels.subarray(x, x + 3);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 3);
}
yResults[y] = xResults;
}
Expand All @@ -3535,15 +3538,16 @@ class GLKernel extends Kernel {
render3DArray3() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax, zMax] = this.output;
const xMaxResults = xMax * 4;
const xResultsMax = xMax * 4;
const zResults = new Array(zMax);
for (let z = 0; z < zMax; z++) {
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = (z * xResultsMax * yMax) + (y * xResultsMax);
let i = 0;
for (let x = 0; x < xMaxResults; x += 4) {
xResults[i++] = pixels.subarray(x, x + 3);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 3);
}
yResults[y] = xResults;
}
Expand All @@ -3565,13 +3569,14 @@ class GLKernel extends Kernel {
render2DArray4() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax] = this.output;
const xMaxResult = xMax * 4;
const xResultsMax = xMax * 4;
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = y * xResultsMax;
let i = 0;
for (let x = 0; x < xMaxResult; x += 4) {
xResults[i++] = pixels.subarray(x, x + 4);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 4);
}
yResults[y] = xResults;
}
Expand All @@ -3580,15 +3585,16 @@ class GLKernel extends Kernel {
render3DArray4() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax, zMax] = this.output;
const xResultsMap = xMax * 4;
const xResultsMax = xMax * 4;
const zResults = new Array(zMax);
for (let z = 0; z < zMax; z++) {
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = (z * xResultsMax * yMax) + (y * xResultsMax);
let i = 0;
for (let x = 0; x < xResultsMap; x += 4) {
xResults[i++] = pixels.subarray(x, x + 4);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 4);
}
yResults[y] = xResults;
}
Expand Down
36 changes: 21 additions & 15 deletions bin/gpu-browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* GPU Accelerated JavaScript
*
* @version 2.0.0-rc.13
* @date Mon Apr 29 2019 08:45:14 GMT-0400 (Eastern Daylight Time)
* @date Mon Apr 29 2019 20:46:46 GMT+0200 (CEST)
*
* @license MIT
* The MIT License
Expand Down Expand Up @@ -8230,9 +8230,10 @@ class GLKernel extends Kernel {
const XResultsMax = xMax * 4;
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = y * XResultsMax;
let i = 0;
for (let x = 0; x < XResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x, x + 2);
xResults[i++] = pixels.subarray(x + offset, x + offset + 2);
}
yResults[y] = xResults;
}
Expand All @@ -8247,9 +8248,10 @@ class GLKernel extends Kernel {
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = (z * xResultsMax * yMax) + (y * xResultsMax);
let i = 0;
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x, x + 2);
xResults[i++] = pixels.subarray(x + offset, x + offset + 2);
}
yResults[y] = xResults;
}
Expand All @@ -8271,13 +8273,14 @@ class GLKernel extends Kernel {
render2DArray3() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax] = this.output;
const xMaxResults = xMax * 4;
const xResultsMax = xMax * 4;
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = y * xResultsMax;
let i = 0;
for (let x = 0; x < xMaxResults; x += 4) {
xResults[i++] = pixels.subarray(x, x + 3);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 3);
}
yResults[y] = xResults;
}
Expand All @@ -8286,15 +8289,16 @@ class GLKernel extends Kernel {
render3DArray3() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax, zMax] = this.output;
const xMaxResults = xMax * 4;
const xResultsMax = xMax * 4;
const zResults = new Array(zMax);
for (let z = 0; z < zMax; z++) {
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = (z * xResultsMax * yMax) + (y * xResultsMax);
let i = 0;
for (let x = 0; x < xMaxResults; x += 4) {
xResults[i++] = pixels.subarray(x, x + 3);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 3);
}
yResults[y] = xResults;
}
Expand All @@ -8316,13 +8320,14 @@ class GLKernel extends Kernel {
render2DArray4() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax] = this.output;
const xMaxResult = xMax * 4;
const xResultsMax = xMax * 4;
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = y * xResultsMax;
let i = 0;
for (let x = 0; x < xMaxResult; x += 4) {
xResults[i++] = pixels.subarray(x, x + 4);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 4);
}
yResults[y] = xResults;
}
Expand All @@ -8331,15 +8336,16 @@ class GLKernel extends Kernel {
render3DArray4() {
const pixels = this.readFloatPixelsToFloat32Array();
const [xMax, yMax, zMax] = this.output;
const xResultsMap = xMax * 4;
const xResultsMax = xMax * 4;
const zResults = new Array(zMax);
for (let z = 0; z < zMax; z++) {
const yResults = new Array(yMax);
for (let y = 0; y < yMax; y++) {
const xResults = new Array(xMax);
const offset = (z * xResultsMax * yMax) + (y * xResultsMax);
let i = 0;
for (let x = 0; x < xResultsMap; x += 4) {
xResults[i++] = pixels.subarray(x, x + 4);
for (let x = 0; x < xResultsMax; x += 4) {
xResults[i++] = pixels.subarray(x + offset, x + offset + 4);
}
yResults[y] = xResults;
}
Expand Down
Loading

0 comments on commit d6757ab

Please sign in to comment.