gpujs / gpu.js

GPU Accelerated JavaScript
https://gpu.rocks
MIT License
15.1k stars 652 forks source link

Multi-Dimensional arrays as kernel arguments not working #679

Closed andrewbrg closed 3 years ago

andrewbrg commented 3 years ago

What is wrong?

If you declare a kernel and pass a 2D array as an argument then try to reference elements from that argument, it would be expected that the referenced variable would be an array, however it seems that the argument for some reason is being passed as a 1D array insead with the content of this array being a concatenation of all the elements of the 2d array.

As an example:

let kernel = gpu.makeKernel(function (x) {
    return x[0]; // Expected output [1,1,1] Actual output 1
    return x[2]; // Expected output [3,3,3] Actual output 1
    return x[3]; // Expected output [4,4,4] Actual output 2
}).setPipeline(true).setOutput([10, 10]);

kernel([[1, 1, 1], [2, 2, 2], [3, 3, 3], [4, 4, 4]]);

In the documentation is says that it is possible to pass an 'Array of Arrays' https://github.com/gpujs/gpu.js#accepting-input

However what seems to be happening is that the 'Array of Arrays' is getting transformed into a single array containing all the elements of all the child arrays instead which is strange to me :/ Maybe i'm not doing something properly I don't know.

How important is this (1-5)?

To me it's a 5

Expected behavior (i.e. solution)

I would expect that the structure of the argument passed to the kernel remains the same, i.e. a 2D array is passed and a 2D array is loaded into the kernel.