gpujs / gpu.js

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

Pipelining example code throws "OffscreenCanvas is not defined" #745

Open Garfield100 opened 2 years ago

Garfield100 commented 2 years ago

A GIF or MEME to give some spice of the internet

What is wrong?

The pipelining example code doesn't work, it throws an OffscreenCanvas is not defined error.

Where does it happen?

In gpu.js when running the pipelining example code.

How do we replicate the issue?

Run the following code (slightly modified from the pipeline example in the readme):

const { GPU } = require('gpu.js');
const gpu = new GPU();

const kernel1 = gpu.createKernel(function () {
    return this.thread.x;
})
    .setPipeline(true)
    .setOutput([100]);

const kernel2 = gpu.createKernel(function (v) {
    return v[this.thread.x];
})
    .setOutput([100]);

const result1 = kernel1();
// Result: Texture
console.log(result1.toArray());
// Result: Float32Array[0, 1, 2, 3, ... 99]

const result2 = kernel2(result1);
// Result should be: Float32Array[0, 1, 2, 3, ... 99]
console.log(result2);

How important is this (1-5)?

From what I understand, getting this to work would massively reduce overhead. I'm not sure if this is a bug or if the example code has some mistake I don't see. I would rate it a 3 since it's an important feature that I (and probably other newcomers) can't use.

Expected behavior (i.e. solution)

The [0, 1, 2, 3, ... 99] array should simply be printed twice in the example. I'm afraid I don't know the solution ;-;

ctralie commented 2 years ago

I had the same issue, but it seemed to work fine in the most recent maintenance release on Jan 19, 2021 https://github.com/gpujs/gpu.js/releases

Garfield100 commented 2 years ago

Thank you, that release works! Weird since the release on the npm repo doesn't. It seems that the newer versions broke this.