| ▲ | modeless 3 hours ago | ||||||||||||||||
Seems like Theseus is not using OffscreenCanvas yet. Should be a good fit for something that runs off the main thread. Graphics can be rendered from a background worker thread directly to the screen without the involvement of the browser main thread at all. https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCa... | |||||||||||||||||
| ▲ | evmar 2 hours ago | parent [-] | ||||||||||||||||
[post author] I looked into this API but wasn't sure how to make good use of it. I may have misunderstood, maybe you could help! The doc you linked has two forms of use, sync and async. For sync: it seems the idea is for the worker to render into an OffscreenCanvas, then postMessage an ImageBitmap created with transferToImageBitmap from worker to main thread for drawing. It seems like it would need to allocate a new bitmap for each frame. Currently Theseus puts the pixel data in shared memory and the main thread copies it out (required to create an ImageData), which at least in principle could reuse the copy buffer (though it currently doesn't), which seems better? https://github.com/evmar/theseus/blob/a5a849dbcf8046a2d1837a... For async: in this the idea is have the worker render into an OffscreenCanvas linked to the on-screen one. But it seems to get an OffscreenCanvas in a worker, the main thread canvas must .transferControlToOffscreen() it to the worker. Under the current synchronization model[1] the only time the worker can receive a message is during startup, because the rest of the time it's deep in its own wasm call stacks. This means that if the worker needs to resize its canvas and then paint to it, it's stuck. [1] I wrote "current" because after writing this post I learned about JSPI which might help with this. | |||||||||||||||||
| |||||||||||||||||