I've built a demo of a single shared Rust codebase that runs on every major GPU platform: CUDA for NVIDIA GPUs SPIR-V for Vulkan-compatible GPUs from AMD, Intel, NVIDIA, and Android devices Metal for Apple devices DirectX 12 for Windows WebGPU for browsers CPU fallback for non-GPU systems The same compute logic runs on all targets, written entirely in regular Rust. No shader or kernel languages are used. The code is available on GitHub. Background GPUs are typically programmed using specialized languages like WGSL, GLSL, MSL, HLSL, Slang, or Triton. These languages are GPU-specific and separate from the host application's language and tooling, increasing complexity and duplicating logic across CPU and GPU code. Some of us in the Rust community are taking a different approach and want to program GPUs by compiling standard Rust code directly to GPU targets. Three main projects make this possible1: Rust GPU: Compiles Rust code to SPIR-V, the binary format used by Vulkan and other modern GPU APIs. This allows GPU code to be written entirely in Rust and used in any Vulkan-compatible workflow. Rust CUDA: Compiles Rust code to NVVM IR, enabling execution on NVIDIA GPUs through the CUDA runtime. Naga: A GPU language translation layer developed by the wgpu team. It provides a common intermediate representation and supports translating between WGSL, SPIR-V, GLSL, MSL, and HLSL. Naga focuses on portability and is used to bridge different graphics backends. Previously, these projects were siloed as they were started by different people at different times with different goals. As a maintainer of Rust GPU and Rust CUDA and a contributor to naga, I have been working to bring them closer together. This demo is the first time all major GPU backends run from a single Rust codebase without a ton of hacks. It's the culmination of hard work from many contributors and shows that cross-platform GPU compute in Rust is now possible. There are still many rough edges and a lot of work to do,...
First seen: 2025-07-26 11:12
Last seen: 2025-07-27 09:23