-
-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a Rust WASM template #1977
Add a Rust WASM template #1977
Conversation
Only the four functions needed to run the demo are currently bound.
This new allocator should be able to use the full amount of memory without corrupting other data.
More wrappers to come
Still going to redo some of these to add default arguments (using a struct)
- Options structs with impls of Default allow default arguments - Some functions renamed - API is close to the Zig one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the Rust template 👍
This is really a Rust problem IMHO... we're effectively "legacy" hardware, Rust has to deal with us as-is... it doesn't make sense to add complexity for a single compiled language in a single runtime. Rust could add a
So I think we've (@nesbox) been pretty against this in the past - I'd guess because of the complexity and edge cases this introduces. If you're really chomping at the bit AND the change was small and non-invasive (a few lines somewhere) I'd go to bat for you, but I fear it is likely to be neither. How were you planning to solve this?
A fix for this would be a great PR though. |
Yeah, I do see that it's a specific language issue, and Rust is now usable here, so it's not too big an issue if it can't be fixed.
Each of the memory access APIs currently accesses ram by finding a pointer using something like: |
It might be better to track this in the per-runtime configuration, though I'm forgetting how easy that is to access during API calls.
A pointer to where? We're not even in charge of that allocation... WASM allocates it... so it isn't possible to over-allocate... you'd really need to subtract from the pointer (point earlier) to move the MMIO higher, wouldn't you? And if we're not in charge of the allocation - then we can't front pad it with the extra RAM we'd need. Am I missing something? |
For this to work properly you'd need all the RAM shifted all the time, would you not? Just fixing the memory APIs would be only half the problem... pointers to RAM would also need to know about the shift which means that the WASM VM would have to be aware as well, which is a whole other ballpark. |
To
See above,
|
Yes, but then wouldn't that expose internal data structure and require extra bounds checks on the low side? And how does that solve pointers inside the VM runtime, which isn't using the tic_ram pointer at all? |
If you think it's trivial and want to spec it and write it (with no promise it'll be merged) I would happily review and go to bat for you IF I thought it was low enough complexity. @nesbox is the real gatekeeper here though. My worry is that to do it fully correctly it's more complex than you think - but it's possible I'm mistaken. :-) The compiler would need to know about this RAM shift as well, wouldn't it so that any globals it placed in RAM it would know where to find them? |
I still don't see how I'm really exposing anything that didn't already exist. I'm simply decoupling MMIO from the start of RAM so it can be adjusted as seen above. Most API functions read the exact same
I'm not sure there is anything to be solved, other than tweaking the template to use the alternate MMIO addresses. The VM still sees memory as starting at 0, and all pointers should work fine and match up with the
Yeah, but since it's mostly relevant to the Rust template, I'll just tweak its
Quite possible, but I'm happy to give it a shot anyway. |
All right then... :-) Good luck. |
Based on the WASM-4 Rust template, this should allow WASM TIC-80 cartridges to be built using Rust.
It should be pretty much as functional as the Zig template, including safe wrappers for the TIC-80 API, as well as the raw bindings, and raw memory access.
One issue still remains, and while it doesn't prevent the use of this template, it does limit it. TIC-80's memory layout uses address 0, which is basically impossible to access in Rust. Currently, the template defaults to building without any optimisations, which does allow access to the
FRAMEBUFFER
array, but also significantly increases cart size and reduces performance.One possible way I can see to fix this would be to implement an alternate memory layout. It would require an extra pointer or offset so that
memcpy
,memset
,peek
, andpoke
could access the correct region of memory even if the MMIO wasn't at the beginning of memory, but since extra data about the memory needs to be stored to solve #1956, I think this would be okay. I'm happy to implement this, probably along with a fix to #1956, would the extra logic to handle this be acceptable?Anyway, whatever happens with the memory situation, this template should be in a perfectly usable state, even if it doesn't have ideal performance.