Rust GPU (Rust → SPIR-V)
A rustc codegen backend, rustc_codegen_spirv, that compiles ordinary no_std Rust crates to Vulkan-flavoured SPIR-V, paired with spirv-std, a GPU standard library built on the same glam vector crate the CPU side uses. It is the most mature single-source shading effort in a general-purpose systems language, and the closest analogue in shape to sparkles:shaders.
| Field | Value |
|---|---|
| Language | Rust (edition 2024), compiled by a pinned nightly rustc (nightly-2026-08-15, rustc 1.99.0) — rust-toolchain.toml |
| License | MIT OR Apache-2.0 (dual) — Cargo.toml |
| Repository | Rust-GPU/rust-gpu (pinned at 57d0794, 2026-10-16) |
| Documentation | Rust-GPU dev guide · API docs · docs/src/ in-tree |
| Category | Single-source peer: a host language's compiler grows a GPU backend |
| Latest version | 0.11.0, 2026-10-13 (CHANGELOG.md) |
| Targets | SPIR-V: spirv-unknown-spv1.x, -vulkan1.x, -opengl4.x (target.rs); WGSL via an in-process naga pass (spirv-unknown-naga-wgsl, naga_transpile.rs) |
| Stages | Every SPIR-V ExecutionModel (vertex, fragment, compute, geometry, tessellation, mesh/task, ray tracing) named in snake_case — attributes.md |
| History | First commit 2020-07-24 (Embark Studios); community-owned under the Rust-GPU organisation since 2024-08-12 (transition post) |
| Sibling | Rust-CUDA: rustc → NVVM IR → PTX, for NVIDIA compute only |
NOTE
The README's own status line, verbatim: "This project is still heavily in development and is at an early stage. … while being technically usable, this project is not yet production-ready." (README.md). The project makes "no guarantees about backwards compatibility" and supports only main.
Overview
What it solves
Shader languages lag the host languages they sit beside: no package manager, weak generics, no shared types, no test tooling. Rust GPU's thesis is that a production systems language, not a new DSL, should be the shading language, so shader code is published on crates.io, shares structs and math with the CPU crate, and is unit-tested with cargo test. The README frames the gap directly (README.md):
"Historically in games GPU programming has been done through writing either HLSL, or to a lesser extent GLSL and WGSL. These are simple programming languages that have evolved along with rendering APIs over the years. However, these languages have failed to provide mechanisms for dealing with large codebases, and have generally stayed behind the curve compared to other programming languages."
The mechanism is a full rustc backend plugged in through -Z codegen-backend — "the same mechanism that rustc_codegen_cranelift and rustc_codegen_gcc use" — so the front end (borrow checker, trait solver, monomorphiser, MIR optimiser) is stock rustc, and only codegen differs.
Design philosophy
Three commitments shape everything:
Reuse the host ecosystem, including its math library. Vectors are
glam'sVec2/Vec3/Vec4, which the backend recognises and lowers toOpTypeVector;glammust be built withdefault-features = false, andspirv-stdswitches it tolibmon the GPU andstdon the CPU (structure.md).Declarations live in the entry point's signature. Inputs, outputs, built-ins, descriptors and push constants are parameters carrying
#[spirv(..)]attributes, never globals. The guide states the trade-off itself (shaders.md): "Unlike most other shader languages, inputs and outputs can't just be declared anywhere within our code and includes. Instead, they are passed as parameters to your entry point function, centralizing where they can be declared." — and admits "it makes it difficult to share these declarations across multiple shaders."Don't fail on what is unreachable. Anything the backend cannot represent (
u128, function pointers, somecoreinternals) becomes a zombie and is reported only if it survives dead-code elimination — which is how a large part ofcorecompiles at all (codegen_cx/mod.rs):"If something unrepresentable is encountered, we don't want to fail the compilation. Instead, we emit something bogus … and then mark the resulting ID as a "zombie". We continue compiling the rest of the crate, then, at the very end, anything that transitively references a zombie value is stripped from the binary. Errors will only be emitted (by
linker::zombies) for reachable zombies."
Rust GPU is the canonical host-language-backend data point in this catalog; compare it with Vcc/Shady (C++ via Clang's LLVM IR), Circle (C++ with reflection), Zig's SPIR-V backend, and with LDC's own dcompute, the substrate sparkles:shaders builds on.
How it works
The crate layout
A Rust GPU project is a Cargo workspace with (at least) a shader crate and a host crate (structure.md):
| Crate | Role |
|---|---|
mygraphics-shaders (#![no_std]) | Shader source; depends on spirv-std and glam. Compiled twice: by rustc_codegen_spirv and by the host rustc |
mygraphics (build.rs) | Host binary; its build script drives spirv-builder, which invokes the backend on the shader crate |
spirv-std | #[spirv] attribute macro, Image!, Sampler, intrinsics (arch::*), TypedBuffer, RuntimeArray |
rustc_codegen_spirv | The backend dylib; must match the spirv-std version exactly |
spirv-builder / cargo-gpu | Build-script API and CLI that install the pinned toolchain and build the backend |
The build script resolves the backend version from the shader crate's spirv-std dependency, builds it, compiles the shader crate, and hands the .spv path to the host via an environment variable that include_bytes! embeds:
// docs/src/getting-started/structure.md (abridged)
let install = Install::from_shader_crate(crate_path.clone())
.within_build_script()
.run()?;
let mut builder = install.to_spirv_builder(crate_path, "spirv-unknown-vulkan1.3");
builder.build_script.defaults = true;
let compile_result = builder.build()?;
let spv_path = compile_result.module.unwrap_single();
println!("cargo::rustc-env=SHADER_SPV_PATH={}", spv_path.display());An entry point, and the function it forwards to
The sky-shader example is exactly the pattern sparkles:shaders mandates (SHF1): a thin entry point that unpacks the interface and forwards to an ordinary function the CPU can also call (sky-shader/src/lib.rs):
pub fn fs(constants: &ShaderConstants, frag_coord: Vec2,
sun_intensity_extra_spec_const_factor: u32) -> Vec4 { /* … */ }
#[spirv(fragment)]
pub fn main_fs(
#[spirv(frag_coord)] in_frag_coord: Vec4,
#[spirv(push_constant)] constants: &ShaderConstants,
output: &mut Vec4,
#[spirv(spec_constant(id = 0x5007, default = 100))] sun_intensity_extra_spec_const_factor: u32,
) {
let frag_coord = vec2(in_frag_coord.x, in_frag_coord.y);
*output = fs(constants, frag_coord, sun_intensity_extra_spec_const_factor);
}The #[spirv(..)] macro itself is a cfg_attr: it expands to #[cfg_attr(target_arch="spirv", rust_gpu::spirv(..))] (macros/src/lib.rs), so on the CPU the attributes vanish and main_fs is an ordinary function.
The backend pipeline
rustc lowers MIR through rustc_codegen_ssa (a copy patched by build.rs into a "pqp" variant to keep typed allocas, lib.rs) into a SPIR-V module per codegen unit, emitted with rspirv. The real work happens in the linker (linker/mod.rs), in this order:
- Link and deduplicate the per-crate modules; check fragment-only instructions.
specialize_generic_storage_class— the storage-class inference pass (below).mem2regbefore inlining (possible because SPIR-T structurisation toleratesOpPhi).inline— not an optimisation but legalisation (inline.rs): "spir-v disallows things like aStorageClass::Functionpointer to aStorageClass::Inputpointer. Our frontend definitely allows it … So, we inline all functions that take these "illegal" pointers, then run mem2reg … to "unwrap" the Function pointer." It first callsdeny_recursion_in_module— "SPIR-V bans recursion".mem2regagain, composite destructuring, DCE, zombie reporting.- SPIR-V → SPIR-T → SPIR-V round trip:
lower_from_spv_bytes,convert_custom_aborts_to_unstructured_returns_in_entry_points,spirt::passes::legalize::structurize_func_cfgs, optional SPIR-T passes (qptr, …),explicit_layout::erase_when_invalid,validate, diagnostics,lift_to_spv_module_emitter. spirv-opt(when optimising) andspirv-val, then optionallynaga→ WGSL.
SPIR-T is the project's own IR: "as of rust-gpu 0.8.0, SPIR-🇹 is always being used and cannot be disabled", and it "replaces the existing structurizer with SPIR-🇹 structurization (which is more robust and can e.g. handle OpPhis)" (codegen-args.md). --no-structurize exists but "Probably results in invalid modules."
Execution model and stages
Every SPIR-V execution model is reachable: the attribute is the spirv_headers::ExecutionModel enum name in snakecase (#[spirv(vertex)], #[spirv(fragment)], #[spirv(compute(threads(32, 16)))], mesh/task since PR#44, ray-tracing stages via spirv_std::ray_tracing). Workgroup size is a literal in the attribute — trailing ones elide; it _cannot be a specialisation constant (compute.md). entry_point_name = "…" overrides the OpEntryPoint name. Only functions so marked are exported; everything else is inlined or discarded.
Fragment-only operations are checked at link time, not by the type system: check_fragment_insts walks the call graph from every non-fragment entry point and rejects OpDPdx/OpDPdy/OpFwidth (and their Fine/Coarse forms), every implicit-LOD OpImageSample*, OpImageQueryLod and OpKill (simple_passes.rs) — so a dfdx reached from a compute entry point is a link error, not a type error. Helper-lane semantics and uniformity are not modelled at all.
Type system and generic programming
Stock Rust: traits, generics, const generics, closures and iterators all work because they monomorphise and inline away before SPIR-V sees them. What the backend rejects is what cannot be lowered to logical SPIR-V:
| Feature | Status |
|---|---|
Generics, traits, impl Trait | Supported (monomorphised) |
dyn Trait, fn pointers | Rejected: "function pointer types are not allowed" (spirv_type.rs, test issue-452) |
| Recursion | Rejected at link: "module has recursion, which is not allowed" (issue_764) |
alloc (Vec, String, …) | Unavailable (no_std, no allocator) |
u128/i128 | Constants only (PR#595), as a zombie escape so more crates compile |
f16, f64, i8–i64 | Supported, subject to SPIR-V capabilities |
| Enums with data | Supported in-shader; UB across the CPU/GPU boundary if a buffer holds an invalid discriminant (every-GPU post) |
Vectors are recognised structurally. A struct marked #[rust_gpu::vector::v1] (as glam's scalar vector types are) becomes an OpTypeVector provided it has 2–4 members of one scalar type; "The layout of your type is unaffected, the size, alignment and member offsets will follow standard rustc layout rules" (vector.rs). spirv_std::Vector is the trait generic code bounds on. glam's 16-byte-aligned SIMD Vec3A is now disallowed in intrinsics and asm! (PR#660), so the device vec3 is a 12-byte type.
Swizzles are methods: glam generates v.xy(), v.zyx(), Vec2::xyxx() as rvalues; there is no swizzle assignment (v.xy = …), and construction from parts is Vec4::from((v3, 1.0)) or .extend(1.0).
Images are one const-generic type, spirv_std::image::Image, whose parameters are "incredibly tedious", hence the Image!(2D, type=f32, sampled) macro and aliases Image2d, Cubemap, … (images.md). A spirv-std-nightly variant (PR#636) uses adt_const_params for nicer image parameters.
Resources, interfaces and memory layout
Interface kinds are told apart by parameter shape plus attributes (attributes.md, shaders.md):
| Parameter | Meaning | GLSL equivalent |
|---|---|---|
vtx_color: Vec3 (by value) | stage input | in vec3 vtx_color; |
output: &mut Vec4 | stage output | out vec4 output; |
#[spirv(position)] p: &mut Vec4 | built-in | gl_Position |
#[spirv(flat)], #[spirv(invariant)] | interpolation / invariance | flat, invariant |
#[spirv(uniform, descriptor_set = 2, binding = 5)] u: &T | uniform block | layout(set=2, binding=5) uniform … |
#[spirv(storage_buffer, descriptor_set = 0, binding = 2)] c: &mut [u32] | SSBO (runtime-sized slice) | buffer { uint c[]; } |
#[spirv(push_constant)] k: &T | push constants | layout(push_constant) |
#[spirv(workgroup)] s: &mut [f32; 4] | shared memory | shared |
#[spirv(spec_constant(id = 9000, default = 123))] x: u32 | specialisation constant (u32 only) | layout(constant_id=9000) const uint x=123 |
&RuntimeArray<TypedBuffer<[u32]>> | bindless array of buffers | buffer B { … } bufs[]; |
Locations for plain inputs and outputs are assigned by the backend; descriptor sets and bindings are manual integers that must match the host — the very thing RFC 001 says it wants to avoid: "One thing we'd like to avoid is having a set of names or numbers that manually need to match up between GPU and CPU." The RFC is unimplemented.
Storage classes are inferred, not typed. Rust references have no address space, so every pointer is emitted with a generic storage-class variable and the specializer "monomorphizes" functions per distinct combination (specializer.rs): "For now, this is only used for pointer type storage classes, because Rust's pointer/reference types don't have an "address space" distinction, and we also wouldn't want users to annotate every single type anyway." Storage-class attributes are "only permitted on entry points". Pointers that are still illegal after specialisation (a Function pointer to an Input pointer) are removed by inlining.
WARNING
&mut on a shared buffer is a lie: "In Rust, mutable references don't just allow you to mutate the referenced memory, but also gives you exclusive access to it. Since this mutable references is shared between all the threads, it can't be exclusive. This is a mistake on rust-gpu's entry point API design" (compute.md). The same holds for #[spirv(workgroup)] memory.
Layout is rustc's, checked after the fact. Offset/ArrayStride decorations come from rustc's repr(C) layout (spirv_type.rs); the backend does not compute std140/std430. Instead spirv-val's block-layout check is configured with --relax-block-layout (default for Vulkan 1.1+), --uniform-buffer-standard-layout, --scalar-block-layout, or --skip-block-layout (codegen_cx/mod.rs). Host and device share the struct definition, and bytemuck::Pod is the recommended guard for "no padding" — yet the guide warns "rust-gpu does not verify that your declarations actually implement Pod" (shaders.md), and the project's own retrospective says "Care must still be taken to ensure data is padded correctly. … for now you must do so manually" (every-GPU post). explicit_layout::erase_when_invalid strips decorations from storage classes where Vulkan forbids them. Matrices with a non-OpTypeMatrix shape (Matrix4x3) "Cannot be used within buffers, push constants or anything that requires an "explicit layout"." (matrix.rs).
Buffer device address (physical pointers) is unsupported: the guide notes "rust-gpu doesn't support Buffer Device Address (BDA) yet" (introduction.md).
Built-in library and intrinsics
spirv-std provides the GPU-only surface (spirv-std/src/lib.rs): arch::{atomics, barrier, derivative, subgroup, mesh_shading, ray_tracing, demote_to_helper_invocation_ext, primitive}, image, Sampler, ByteAddressableBuffer, cooperative_matrix (KHR_cooperative_matrix, PR#589), debug_printf!, indirect_command.
Three implementation techniques coexist:
- libm interception.
f32::sinand friends route throughnum_traits::Float→libmnames, which the backend recognises by symbol and maps toGLSL.std.450ops or custom expansions (libm_intrinsics.rs):("acosf", GLOp(Acos)),("ceilf", GLOp(Ceil)), … withCustomlowering forcbrt,erf,tgamma,fmod,hypot,copysign,sincos. On the CPU the same calls run reallibm/std— so CPU and GPU precision differ by construction and nothing states the bound. - Inline SPIR-V assembly.
asm!with SPIR-V mnemonics,%idnames andtypeof*{x}type inference is the escape hatch and the implementation of most intrinsics (inline-asm.md);dfdxisasm!("%result = OpDPdx typeof*{1} %input", …)(derivative.rs). #[gpu_only]. Intrinsics with no CPU meaning compile on the CPU asunimplemented!("…is only available on SPIR-V platforms.")(macros/src/lib.rs) —spirv-stdsays it "deliberately provide[s] an unimplemented version of our API on CPU platforms so that code completion still works." Derivatives, image sampling, subgroup ops and barriers therefore panic in a CPU run rather than being simulated.
Control flow, memory model and restrictions
- Structured control flow is recovered, not required: Rust's MIR CFG is lowered unstructured and SPIR-T's
structurize_func_cfgsrebuilds selection/loop merges. Arbitrary Rust control flow (loop/break 'label/?/match) is accepted; there is nogototo worry about. - Panics become a custom abort instruction, lowered to a
returnfrom the entry point (the invocation silently stops) by default, or with--abort-strategy=debug-printf[+inputs][+backtrace]to adebugPrintfmessage (controlflow.rs);spirv-std's#[panic_handler]isloop {}. Bounds checks on slices therefore cost a branch and, on failure, a quiet early exit. - No recursion, no function pointers, no allocation, enforced by link-time errors or reachable-zombie errors rather than front-end diagnostics; error spans survive through
SrcLocDecoration. - Memory model: barriers are explicit intrinsics (
workgroup_memory_barrier_with_group_sync); the Rust aliasing model is not reconciled with SPIR-V's — the&mutwarning above is the visible symptom.NonUniformdecorations are added to every image/buffer access when the capability is enabled (PR#177) rather than inferred per access.
Compilation pipeline and targets
| Stage | Tool |
|---|---|
| Rust → MIR | stock nightly rustc |
| MIR → SPIR-V per CGU | rustc_codegen_spirv (patched rustc_codegen_ssa, rspirv) |
| Link, specialise, inline | backend linker passes |
| Structurise, legalise | SPIR-T |
| Optimise, validate | spirv-opt, spirv-val (via the spirv-tools crate) |
| SPIR-V → WGSL (optional) | naga in-process (spirv-unknown-naga-wgsl) |
| SPIR-V → MSL/HLSL/GLSL | out of scope; done at runtime by wgpu/naga |
The toolchain is the dominant cost. rustc_codegen_spirv links rustc_private crates, so it "can only be built using a very specific nightly version of the Rust toolchain" (backend README); every release bumps the pinned nightly (nightly-2026-04-11 → -07-03 → -08-15 across 0.10.0-alpha.1 → 0.11.0, CHANGELOG.md), and build.rs carries a REQUIRED_RUST_TOOLCHAIN copy that must be kept in sync (build.rs). cargo-gpu exists to install that toolchain on demand inside a build script, with file locks added because concurrent installs raced (PR#622, PR#631).
The README names the DXIL/WGSL future as speculative: "Possible a future version could support DXIL … or WGSL". Today non-Vulkan APIs consume the SPIR-V through naga at runtime, and the Shadertoy port surfaced and fixed naga bugs in that path ("Fixed a panic while processing SPIR-V", "Fixed incorrect translation of certain shader literals when targeting Metal" — Shadertoys post).
Testing is layered (testing.md): cargo compiletest (UI tests over SPIR-V output, blessed .stderr, run per --target-env), and difftests (tests/difftests/README.md) — "Difftests verify correctness by running multiple implementations of the same logic and comparing their outputs. Instead of relying on fixed reference outputs, they detect discrepancies across implementations" — comparing Rust-GPU against hand-written WGSL, ash against wgpu, and CPU against GPU, with optional per-test epsilon metadata (TestMetadata::f32(0.00001)).
Host integration and CPU execution
Because the shader crate is ordinary Rust, the host imports it as a normal dependency: ShaderConstants is defined once and written to a buffer with bytemuck::bytes_of (shaders.md). Bindings, though, are matched by hand-copied integers, and there is no generated reflection or descriptor-layout API.
CPU execution is first-class but shallow. The cpu runner (runners/cpu/src/main.rs) calls the shader's fs function per pixel under rayon:
// examples/runners/cpu/src/main.rs
let buffer = (0..WIDTH * HEIGHT)
.into_par_iter()
.map(|i| {
// …compute frag_coord…
let color = shader_module::fs(&push_constants, frag_coord, 100);
color_u32_from_vec4(color)
})
.collect::<Vec<_>>();It calls fs, not main_fs: the CPU path works for the stage-independent function, and stops at anything #[gpu_only] (derivatives, sampling, subgroups, barriers). There is no CPU simulator of the execution model — no quads, no workgroups, no image sampling — and the cpu runner has a FIXME for even mouse input. The project's pitch is nonetheless built on it: "GPU kernel code can be tested on the CPU using standard Rust testing tools … write the algorithm, test it thoroughly on CPU with familiar tools, then run it on GPU knowing the logic is likely correct." (every-GPU post).
Rust-CUDA is the sister project: "Rust CUDA enables you to write and run CUDA kernels in Rust, executing directly on NVIDIA GPUs using NVVM IR" (reboot post). The 2025 "Rust on every GPU" demo selects between them with Cargo features (--features wgpu vs --features cuda), and concedes "Rust GPU and Rust CUDA evolved independently and diverged in their APIs" — thread ids are annotated entry parameters in one and function calls in the other, so shared kernels need cfg shims (every-GPU post).
Lessons for sparkles:shaders
- Adopt the thin-entry-point split, and make the CPU path call the same function.
sky-shader'smain_fs→fsisSHF1verbatim, and thecpurunner proves the pattern carries a real effect. Unlike Rust GPU, make it the documented rule (it is, inSPEC.md) and test it: every@fragmententry's callee should have a host unittest. - Match the interface-as-parameters model, but derive bindings instead of hand-numbering them. Rust GPU's by-value = input,
&mut= output convention is clear and maps onto D'sin/out/ref. Its weak point is manualdescriptor_set/bindingintegers that RFC 001 wanted to remove; D's__traits(getAttributes)+ CTFE can emit those numbers and the host-side layout table from one declaration. - Own the layout rule; don't inherit the host ABI and hope
spirv-valcatches it. Rust GPU emits rustc'srepr(C)offsets and relies onspirv-valflags plus an unenforcedPodderive; its maintainers call padding a manual chore. Astatic assert-checkedStd140!T/Std430!T/Scalar!Tlayout computed by CTFE (extendingD9/SHV2) removes that class of bug before the SPIR-V exists. - Model address spaces in types, then monomorphise. Rust GPU had to build a whole specializer plus legalising inliner because references lack storage classes. D can carry the space in the type (
GlobalPointer!T,SharedPointer!Tfrom dcompute) or restrict device code toref/value parameters, so LDC never emits a pointer the SPIR-V backend must guess about. - Diagnose in the front end, not at link. Recursion, function pointers and unreachable-but-unrepresentable code are found by Rust GPU's linker (zombies). Zombies are a good idea for library code (let
std.mathcompile, error only if reached), but for user device modules a@compute-module check in the fork (D13) should rejectdelegate,class,new, recursion andthrowwith a D source span. - State the precision contract and simulate the GPU-only built-ins. Rust GPU's CPU path runs host
libmandunimplemented!()s derivatives and sampling.sparkles:shadersalready judges agreement by the Vulkan precision table (D12); extend the CPU half with a quad-aware scalar simulator fordFdx/fwidthand a reference sampler instead of panicking stubs. - Copy difftests as the conformance strategy. Rust GPU's harness runs N implementations of one computation and diffs bytes with an epsilon from metadata. The conformance corpus should do the same across D-on-CPU, D→SPIR-V→GLSL, and a hand-written GLSL/WGSL reference.
- Avoid a pinned-nightly toolchain tax on consumers. The
rustc_privatecoupling forces a nightly bump every release and a toolchain installer inside build scripts.sparkles:shadersalready confines the custom LDC to builds that generate GLSL (D6,D14); keep that boundary.
Strengths
- Full host language on the device: traits, generics, iterators, closures, crates.io packages,
cargo test. - One vector library (
glam) and one struct definition shared by CPU and GPU. - Every SPIR-V stage, including mesh, ray tracing and cooperative matrix.
- Robust structuriser (SPIR-T) that accepts arbitrary Rust control flow.
- Zombie system lets large parts of
coreand third-party crates (blake3,PR#634) compile. - Differential test harness that compares CPU, multiple GPU backends and hand-written WGSL.
- Inline SPIR-V
asm!with type inference as a complete escape hatch.
Weaknesses
- Pinned nightly
rustcand a backend version that must exactly matchspirv-std; no stability guarantees. - Manual
descriptor_set/bindingnumbers; no reflection or generated host bindings. - Layout follows rustc's ABI; padding correctness is the user's job (
Podunchecked). &muton shared buffers and workgroup memory violates Rust's own aliasing contract.- No buffer device address, no
dyn/function pointers/recursion; restrictions surface as link errors. - CPU execution panics on derivatives, sampling, subgroups and barriers; no execution-model simulation; CPU/GPU precision unspecified.
- Single target (SPIR-V); other APIs depend on
nagaat runtime.
Key design decisions and trade-offs
| Decision | Rationale | Trade-off |
|---|---|---|
A rustc codegen backend, not a DSL | Reuse the whole front end, type system and package ecosystem | Coupled to rustc_private; pinned nightly; backend must be built per user |
| Interface as attributed entry parameters | All declarations in one place; types checked by Rust | Hard to share declarations between shaders; &mut aliasing lie |
glam as the vector type | Same math on CPU and GPU; existing ecosystem | Swizzles are rvalue methods; version pinning across glam_0_30…glam_0_34 features |
| Storage classes inferred by a specializer | Rust references have no address space; users shouldn't annotate | Complex legalisation (specialise + inline + mem2reg); recursive pointer types unsupported |
Layout = rustc repr(C), verified by spirv-val | No second layout engine; host and device share the struct | Padding mistakes found late or not at all; std140 is the user's problem |
| Zombies (deferred errors) | Let core and crates compile; error only if reached | Errors appear at link time, far from the cause |
| SPIR-T for structurisation | Robust against OpPhi and arbitrary MIR CFGs | A second IR to maintain; SPIR-V round trip on every build |
#[gpu_only] stubs on CPU | Code completion and CPU compilation of mixed code | CPU runs panic on GPU-only built-ins instead of simulating them |
SPIR-V only; naga for everything else | One well-specified output | Non-Vulkan correctness rests on a runtime translator's bugs |
Sources
- Rust-GPU/rust-gpu repository, pinned at
57d0794:README.md,CHANGELOG.md,rust-toolchain.toml,Cargo.toml - Dev guide:
introduction.md,attributes.md,getting-started/shaders.md,getting-started/compute.md,getting-started/structure.md,getting-started/images.md,codegen-args.md,inline-asm.md,testing.md, RFC 001 resource binding syntax - Backend:
lib.rs,build.rs,linker/mod.rs,linker/inline.rs,linker/simple_passes.rs,linker/specializer.rs,linker/spirt_passes/controlflow.rs,linker/spirt_passes/explicit_layout.rs,codegen_cx/mod.rs,spirv_type.rs,builder/libm_intrinsics.rs,naga_transpile.rs,target.rs, backend README spirv-std:lib.rs,vector.rs,matrix.rs,arch/derivative.rs,typed_buffer.rs,runtime_array.rs,macros/src/lib.rs- Examples and tests:
sky-shader/src/lib.rs,runners/cpu/src/main.rs,tests/difftests/README.md,issue-452.stderr,issue_764.stderr - Blog: Transition announcement (2024-08-12), Rust on every GPU (2025-07-25), Porting Shadertoys (2025-04-10), Rust CUDA reboot (2025-01-27)
- SPIR-T
- Related: Vcc/Shady · Circle · Zig SPIR-V · dcompute · naga · Concepts · Comparison · Catalog
- Sparkles:
sparkles:shadersSPEC · decisions