12 releases

0.1.11 Mar 18, 2025
0.1.10 Feb 14, 2025
0.1.4 Jan 28, 2025

#2226 in Game dev

Download history 135/week @ 2025-01-02 182/week @ 2025-01-09 74/week @ 2025-01-16 80/week @ 2025-01-23 126/week @ 2025-01-30 559/week @ 2025-02-06 193/week @ 2025-02-13 11/week @ 2025-02-20 27/week @ 2025-02-27 26/week @ 2025-03-06 101/week @ 2025-03-13 38/week @ 2025-03-20 1/week @ 2025-03-27

140 downloads per month

MIT/Apache

1.5MB
2.5K SLoC

slabcraft for crabs

What

craballoc is a slab allocator built on top of crabslab that provides RAII primitives for synchronizing values across CPU and GPU code.

But Why?

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 your Rust types in CPU and GPU code, and this library helps marshal your types to the GPU.

Using a slab makes it pretty easy to marshal data to the GPU, and craballoc does the heavy lifting, with (almost) automatic synchronization and RAII.

And How

The idea is simple - craballoc provides SlabAllocator<T>, where T is the runtime of your choice. Enabling the feature wgpu (on by default) provides a WgpuRuntime to fill that T.

Your local types derive the trait SlabItem which allows them to be written to and read from to the slab.

You use SlabAllocator::new_value or SlabAllocator::new_array on the CPU to allocate new values and arrays on the slab, receiving a Hybrid<T> or HybridArray<T>, respectively.

To modify values, use Hybrid::modify.

To forget the CPU side of values, use Hybrid::into_gpu_only.

Finally, synchronize the slab once per frame (or more, or less) using SlabAllocator::commit.

On the GPU (using a shader written with spirv-std) use crabslab to read values in a no_std context. See the crabslab docs for more info.

Dependencies

~4–34MB
~516K SLoC