https://developer.mozilla.org/en-US/docs/Web/API/OffscreenCa...
Theseus: Translating Win32 to WASM
11–20 of 31 posts
Re: Theseus: Translating Win32 to WASM
#12The blog post cites the concern that malloc could block, however when Rust's standard library is compiled with support for atomics enabled the Rust allocator's locking implementation busy loops instead of waiting on the main thread.
See the comment in the Rust source here: https://github.com/rust-lang/rust/blob/77a4fb62f70c6ea05e182...
This means that if care is taken to avoid any other code that makes the main thread wait it should be possible to use a single shared binary instead of the more convoluted approach presented in the blog post.
Re: Theseus: Translating Win32 to WASM
#13If you’re poking around WASM consider falling down the Component Model rabbit hole: https://github.com/WebAssembly/component-model/blob/main/des... Threading is actively being worked on right now (to be released in 0.3.x, soon), and some changes just made their way into LLVM as well: https://github.com/llvm/llvm-project/pull/175800
Re: Theseus: Translating Win32 to WASM
#14It's just a matter of time before we'll have a universal executable/binary translator that can run any program from any OS. These are artificial constructs when you think about it.
Re: Theseus: Translating Win32 to WASM
#15This is a big deal when/if it's working, to me at least. Where can I contribute?
Looks like just enough was supported to run minesweeper. Impressive though.
Re: Theseus: Translating Win32 to WASM
#16Interesting project! It's just a matter of time before we'll have a universal executable/binary translator that can run any program from any OS. These are artificial constructs when you think about it.
People have been working on these layers for a long time. It's understood that programs are almost always fundamentally portable and only unable to run due to peculiarities. Smoothing over those differences in format, whether they be at the machine code layer, API layer, whatever, is doable but difficult. Props to qemu, Wine, DXVK, etc.
Re: Theseus: Translating Win32 to WASM
#17I am unfamiliar with this project and only skimmed this post but if this uses Rust for the main binary blob it should be possible to have the main thread blob shared with the other threads even with the blocking. The blog post cites the concern that malloc could block, however when Rust's standard library is compiled with support for atomics enabled the Rust allocator's locking implementation busy loops instead of wa…
Re: Theseus: Translating Win32 to WASM
#18Re: Theseus: Translating Win32 to WASM
#19Seems 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...
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.
Re: Theseus: Translating Win32 to WASM
#20It simulates x86 (win32 and win16) and implements Windows APIs in javascript and renders window frames with DOM and contents with canvas (e.g. GDI translates to browser canvas operations). A lot of programs run already but a lot of APIs are not yet implemented.
I successfullt spent a few days extending it to run a Click & Create based game from my childhood.