What
crabslab is a slab implementation focused on marshalling data between CPUs and GPUs.
But Why?
It's hard to get data onto GPUs in the form you expect.
To marshall your data correctly you must know about the alignment and sizes of the underlying representation of your data. This will often surprise you!
Working with a slab on the other hand, only requires that your types can be written into an array and read from an array.
Opinion
Working with shaders is much easier using a slab.
Shader code can be written in Rust with rust-gpu,
which will enable you to use this crate on both CPU and GPU code.
rust-gpu
This crate was made to work with rust-gpu.
Specifically, with this crate it is possible to pack your types into a buffer on the CPU
and then read your types from the slab on the GPU (in Rust).
Other no-std platforms
Even though this crate was written with rust-gpu in mind, it should work in other no-std
contexts.
And How
crabslab includes:
- a few traits:
SlabGrowableSlabSlabItem
- a derive macro for
SlabItemfor your structs - a few new structs for working with slabs
IdArrayOffset
- a helper struct
CpuSlabwhich wrapsVec<u32>orWgpuBuffer - a feature-gated helper for using slabs with
wgpu-WgpuBuffer
Example
use ;
use ;
let = cpu_code;
// marshalling your data depends on which GPU library you are using...
shader_code;