godot-proposals
godot-proposals copied to clipboard
Build a tiny RISC virtual machine which can interpret and execute GDExtensions
Describe the project you are working on
V-Sekai is a self-hostable MIT open source software stack built with Godot Engine 4. This project aims to provide a robust and flexible platform for game development.
Describe the problem or limitation you are having in your project
The main challenge we're facing is the inefficiency of compiling gdextension for multiple platform variants. Running a custom engine isn't feasible due to lack of adoption. We want more efficient and flexible ways to handle gdextension binaries. Additionally, we're interested in exploring the possibility of players distributing riscv binaries as user-generated scripts inside of godot scenes. As part of our future work, we plan to convert gdscript bytecode via string templating the bytecode as c and compile it with the TCC c compiler.
Describe the feature / enhancement and how it helps to overcome the problem or limitation
To address these issues, we propose building a tiny RISC virtual machine capable of interpreting and executing GDExtensions. The entire gdextension API would be wrapped and compiled as RISCV binaries. These binaries would function like shared libraries via librisc emulation, either as an interpreter or a register machine. An interpreter would allow us to maintain the fast developer iteration times that Godot Engine is known for, while an ahead-of-time compiled riscv binary would offer greater efficiency. We have already implemented instruction count limits.
Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams
Our approach involves using libriscv's vmcall to call into the riscv gdextension binary and exchange data. Here are some resources that will aid in this process:
- libriscv VM Call Documentation - Detailed documentation on making function calls into the VM guest.
- tcc
- Godot Orchestrator
- @shakesoda has provided an implementation of riscv processors in Godot Engine via zig language as a reference.
If this enhancement will not be used often, can it be worked around with a few lines of script?
The alternative to using compiled code is slower gdscript or utilizing the godot orchestrator. However, these options may not provide the same level of efficiency and flexibility that our proposed solution offers.
Is there a reason why this should be core and not an add-on in the asset library?
While this could potentially be developed as an addon, we are currently tracking the proposal in godot-proposals for better visibility and collaboration. More information can be found at godot-riscv.