Skip to content

a7u7a/bevy-matrix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

43 Commits
 
 
 
 
 
 
 
 

Repository files navigation

WebGPU + Rust + LED Matrix [WIP]

This repo documents my AI-driven attempts at learning about modern rendering pipelines, Rust and cross-platform game development using the Bevy game engine.

Examples

Each example runs on its own Bevy project:

About

After some time of looking for fun ways to run graphics code in an environment other than the browser, I finally came across Bevy, a Rust based videogame engine which uses Rust's WebGPU API. I really wanted to try it out, as its not only promising for building games but also suitable for building high-performance graphical interfaces.

Hardware:

I ran into a several challenges implementing this. Including:

  • Compilation: The Pi Zero doesn't have enough RAM to run the Rust compiler. A Mac-to-Pi cross-compilation step was needed.
  • Running the game in headless mode. A headless environment means no OS desktop environment -> no window -> no render target.
  • Assuming we could generate and obtain the rendered frame from Bevy: How can we even extract it and paint it to the screen at a decent speed?
  • Tweak the screen configuration to get glitch-free images.
  • Figuring out platform specific dependencies, etc..

The goal was to create a proof-of-concept workflow for developing cross-platform games in resource-constrained systems.

I'm not heavily invested in rust, yet. However, I suspect there is promise in the potential for synergy between rust and webgpu that bevy could unlock.

Build gallery

(Upcoming)

Setup

Running examples on Mac

Navigate to an example folder and run:

cargo run --features window
# or just:
cargo run

Test headless mode locally (simulates Pi environment):

cargo run --no-default-features --features matrix

Development profiles:

# Standard dev build (optimized for iteration speed)
# - Dependencies: opt-level 3 (slow first compile, fast runtime)
cargo run

# Ultra-fast compilation for quick syntax checks
cargo build --profile dev-fast --features window

# Release build (maximum optimization)
cargo build --release

The dev profile balances compile time and runtime performance. First compile is slow (dependencies), but subsequent builds are fast since dependencies are cached.

Running examples on the Raspberry Pi

The cross-compilation setup

On the Mac:

  1. Add the ARM64 Linux target:
rustup target add aarch64-unknown-linux-gnu

Install a cross-linker (via Homebrew):

brew install messense/macos-cross-toolchains/aarch64-unknown-linux-gnu
  1. Cross-compile the matrix library:
git clone https://github.com/hzeller/rpi-rgb-led-matrix.git
cd rpi-rgb-led-matrix

Then, build using the cross-compiler:

make -C lib \
  CC=aarch64-unknown-linux-gnu-gcc \
  CXX=aarch64-unknown-linux-gnu-g++ \
  AR=aarch64-unknown-linux-gnu-ar

Create a directory for cross-compile libraries and copy:

mkdir -p ~/cross-libs/aarch64-linux-gnu
cp lib/librgbmatrix.a ~/cross-libs/aarch64-linux-gnu/

Now we have a basic cross compiling setup for the game.

Cross-compile the game for Pi

On the Mac: Use the deploy script.

$ ./deploy.sh
Building for Raspberry Pi...
Finished `release` profile [optimized] target(s) in 0.32s
Binary size: 66 MB
Copying to Pi...
bevy_screen_3d_demo                                                                                                                                                                                                                                          100%   65MB   4.6MB/s   00:14    
Done! Binary deployed to ayu@pi.local:~/

On the Pi:

sudo ./my_bevy_game

Troubleshooting

Error: "Pi sound module is loaded"

# Edit the config file
sudo nano /boot/firmware/config.txt

# Add this line at the end:
dtparam=audio=off

# Also blacklist the module
echo "blacklist snd_bcm2835" | sudo tee /etc/modprobe.d/blacklist-rgb-matrix.conf

# Reboot
sudo reboot

About

Graphics experiments in WebGPU, Rust and Raspberry Pi

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors