Rust-Gpu cheat sheet

Siebencorgie published on
2 min, 263 words

Working with Rust-Gpu sometimes is unfamiliar if you are used to GLSL/HLSL. Below are some fixes/hints for problems I encountered.

Each bug description contains the date the problem was encountered. Problems, as specially bugs and missing features a probably fixed at some point. The workaround/fix might have become invalid in the meantime.

Errors

2022-10-03: missing panic_handler

Happens if you do not include spirv_std in your shader crate. It provides the handler.


2022-10-03: can't find/use std

Happens if you have miss the #![no_std] attribute in your crate or include a crate that does not include it.


2022-10-03: OpVariable, <id> '19[%some_variable]', is attempting to create memory for an illegal type, OpTypeRuntimeArray

Happens if you use a runtime array (slice) without setting the RuntimeArray Capability on the SpirvBuilder while compiling.


How to x

2022-10-03: Include unbond array of images. Basically layout(set = 1, binding = 0) uniform image2D all_images[]; in GLSL.

Use RuntimeArray<T>, note that T must be sized. Like this:

#[spirv(descriptor_set = 1, binding = 0)] all_images: &RuntimeArray<Image!(2D, type=f32, sampled=false)>

Doesn't work with buffers yet!


2022-10-03: Borrow a part of a slice into a function like this: foo(&my_array[4..10])

This currently does not work. What you can do however is borrow the whole slice and add additional arguments for the range. For instance like this:

fn foo(a: &[u32], start: u32, end: u32){
    for i in start..end{
        //...
    }
}