gpujs / gpu.js

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

Textures - read and write #801

Open lukeellison opened 1 year ago

lukeellison commented 1 year ago

A GIF or MEME to give some spice of the internet

What is wrong?

Assignment to a texture fails with error gpu-browser.min.js:28 Uncaught Error: Error compiling fragment shader: ERROR: 0:461: 'assign' : l-value required. This should be possible but may not be implemented and would be useful. Regardless the error is cryptic.

Where does it happen?

In Web2GL supported browser running on a mac.

How do we replicate the issue?

const clearKernel = gpu
  .createKernel(function () {
    return 0;
  })
  .setOutput([3, 3])
  .setPipeline(true)
  .setImmutable(true);

const testKernel = gpu
  .createKernel(function (_tex) {
    const x = this.thread.x;
    _tex[x][x] = 1;
    return 0;
  })
  .setOutput([2]);

const tex = clearKernel();
const result = testKernel(tex);
console.log(tex.toArray());
tex.delete();

How important is this (1-5)?

I would say 2 because it currently doesn't break anything but the error and lack of claims that this is not supported is confusing. If it is supposed to be supported it should be higher.

Expected behavior (i.e. solution)

Should not error and should show:

[[1,0,0],
 [0,1,0],
 [0,0,0]]

Other Comments

Another solution would be to have some way of outputting a copied texture that was a different size to the kernel size? I.e different output size to kernel size.

Thank you for your time looking into this.

regretronics commented 1 year ago

i got the same problem even when the textures are not immutable. that feature would be really useful to me, because i'm doing deeply iterative computations (currently, creating new textures for every iteration, which sometimes causes freezing or unpredictable jittering).

SparkHao commented 8 months ago

The array passed as a parameter cannot be modified internally, I don't know why