Add demo using bevy
Bevy is adding no_std support so it will be possible to use a subset of it on the PS1. Once it supports platforms that lack CAS and other atomic operations it'd be nice to add a demo using bevy to this repo.
This should be possible to play with now using Bevy/main.
nice, thanks for the heads up. I don't have time to test it out for a good while but if anyone is using it and puts together some demo PRs are welcome.
Did some experimentation with this, there's definitely work to be done, but unfortunately I think there's an LLVM bug that will prevent Bevy from working for now. First off, there's a patch to foldhash I've developed to give it portable-atomic support:
[patch.crates-io.foldhash]
git = "https://github.com/bushrat011899/foldhash"
branch = "portable_atomic"
This allows the following crates to compile in a test project:
bevy_ptrbevy_platformbevy_utilsbevy_mathbevy_color
Unfortunately, bevy_tasks and bevy_reflect throw an LLVM error:
rustc-LLVM ERROR: Cannot select: 0x1ee0b4c1ef8: ch = MipsISD::Sync 0x1ee0bfb15c0, Constant:i32<0>, C:\Users\Zac.rustup\toolchains\nightly-2024-12-21-x86_64-pc-windows-msvc\lib\rustlib\src\rust\library\core\src\sync\atomic.rs:3693:23 0x1ee0b4c45c8: i32 = Constant<0> In function: _ZN4core4sync6atomic5fence17h2f4ec7e180987d61E
That particular part of the core crate relates to core::sync::atomic::fence:
pub fn fence(order: Ordering) {
// SAFETY: using an atomic fence is safe.
unsafe {
match order {
Acquire => intrinsics::atomic_fence_acquire(),
Release => intrinsics::atomic_fence_release(),
AcqRel => intrinsics::atomic_fence_acqrel(),
SeqCst => intrinsics::atomic_fence_seqcst(),
Relaxed => panic!("there is no such thing as a relaxed fence"),
}
}
}
I believe this is related to llvm-project/#61166, but I'm not sure. Definitely something to do with incomplete atomic support. I did try following these instructions for patching and building rustc to add atomic support to the PSX target, which might resolve the LLVM error, but I'm not certain. I had issues getting cargo to work with the custom rustc toolchain (probably an API mismatch as I'd have a version of cargo too new for that specific custom rustc).
I've uploaded my experimentation here. If you compile as-is it'll work, and with the fail feature enabled it will...fail. fail just enables the bevy_tasks dependency which throws the LLVM error in question. If you have any insights please let me know! I'd love to try and get this working even if I do have to upstream some more patches to crates like foldhash.
Ahh I see, it's #6, I should've looked first! I'm not sure where fences are being used internally to cause the miscompilation, I'll see if I can find it, but I don't have high hopes.
This may or may not be relevant (I'll try to check out your bevy expts anyway), but I'm currently trying to debug why there's a psx-sdk-rs issue on VBlank (wait never completes) when initialising controllers and using the CD-ROM. I can get controllers working on their own, and CD reading on its own, but having more than one peripheral / interrupt mask set seems to be causing issues.
I hadn't noticed #6 , but it sounds like it might help explain what I am seeing, at least its another avenue to investigate, so thanks!
Woo, #41 is now enough for Bevy to work on the PS1! Still needs the patched LLVM, but I've updated the instructions to nightly-2025-05-23.