|
1 | | -<div align="center"> |
2 | | - <img src="crabslab.png" alt="slabcraft for crabs" width="512" /> |
| 1 | +<div style="float: right; padding: 1em;"> |
| 2 | + <img src="https://github.com/schell/renderling/blob/main/crates/crabslab/crabslab.png?raw=true" alt="slabcraft for crabs" width="256" /> |
3 | 3 | </div> |
4 | 4 |
|
5 | 5 | ## What |
6 | 6 |
|
7 | 7 | `crabslab` is a slab implementation focused on marshalling data between CPUs and GPUs. |
8 | 8 |
|
9 | | -### example |
| 9 | +[See the example below](#example). |
| 10 | + |
| 11 | +## But Why? |
| 12 | +It's hard to get data onto GPUs in the form you expect. |
| 13 | + |
| 14 | +To marshall your data correctly you must know about the alignment and sizes of the underlying representation of your data. |
| 15 | +This will often surprise you! |
| 16 | + |
| 17 | +Working with a slab on the other hand, only requires that your types can be written into an array and read from an array. |
| 18 | + |
| 19 | +### Opinion |
| 20 | +Working with _shaders_ is much easier using a slab. |
| 21 | + |
| 22 | +Shader code can be written in Rust with [`rust-gpu`](https://github.com/EmbarkStudios/rust-gpu), |
| 23 | +which will enable you to use this crate on both CPU and GPU code. |
| 24 | + |
| 25 | +### rust-gpu |
| 26 | +This crate was made to work with [`rust-gpu`](https://github.com/EmbarkStudios/rust-gpu/). |
| 27 | +Specifically, with this crate it is possible to pack your types into a buffer on the CPU |
| 28 | +and then read your types from the slab on the GPU (in Rust). |
| 29 | + |
| 30 | +### Other no-std platforms |
| 31 | +Even though this crate was written with `rust-gpu` in mind, it should work in other `no-std` |
| 32 | +contexts. |
| 33 | + |
| 34 | +## And How |
| 35 | +`crabslab` includes: |
| 36 | +* a few traits: |
| 37 | + - `Slab` |
| 38 | + - `GrowableSlab` |
| 39 | + - `SlabItem` |
| 40 | +* a derive macro for `SlabItem` for your structs |
| 41 | +* a few new structs for working with slabs |
| 42 | + - `Id` |
| 43 | + - `Array` |
| 44 | + - `Offset` |
| 45 | +* a helper struct `CpuSlab` which wraps `Vec<u32>` or `WgpuBuffer` |
| 46 | +* a feature-gated helper for using slabs with `wgpu` - `WgpuBuffer` |
| 47 | + - [example](src/wgpu_slab.rs#L344) |
| 48 | + |
| 49 | +# Example |
10 | 50 | ```rust |
11 | 51 | use crabslab::{CpuSlab, Slab, GrowableSlab, SlabItem, Id}; |
12 | 52 | use glam::{Vec3, Vec4}; |
@@ -52,41 +92,3 @@ let (light_id, slab) = cpu_code(); |
52 | 92 | // marshalling your data depends on which GPU library you are using... |
53 | 93 | shader_code(light_id, &slab); |
54 | 94 | ``` |
55 | | - |
56 | | -## But Why? |
57 | | -It's hard to get data onto GPUs in the form you expect. |
58 | | - |
59 | | -To marshall your data correctly you must know about the alignment and sizes of the underlying representation of your data. |
60 | | -This will often surprise you! |
61 | | - |
62 | | -Working with a slab on the other hand, only requires that your types can be written into an array and read from an array. |
63 | | - |
64 | | -### Opinion |
65 | | -Working with _shaders_ is much easier using a slab. |
66 | | - |
67 | | -Shader code can be written in Rust with [`rust-gpu`](https://github.com/EmbarkStudios/rust-gpu), |
68 | | -which will enable you to use this crate on both CPU and GPU code. |
69 | | - |
70 | | -### rust-gpu |
71 | | -This crate was made to work with [`rust-gpu`](https://github.com/EmbarkStudios/rust-gpu/). |
72 | | -Specifically, with this crate it is possible to pack your types into a buffer on the CPU |
73 | | -and then read your types from the slab on the GPU (in Rust). |
74 | | - |
75 | | -### Other no-std platforms |
76 | | -Even though this crate was written with `rust-gpu` in mind, it should work in other `no-std` |
77 | | -contexts. |
78 | | - |
79 | | -## And How |
80 | | -`crabslab` includes: |
81 | | -* a few traits: |
82 | | - - `Slab` |
83 | | - - `GrowableSlab` |
84 | | - - `SlabItem` |
85 | | -* a derive macro for `SlabItem` for your structs |
86 | | -* a few new structs for working with slabs |
87 | | - - `Id` |
88 | | - - `Array` |
89 | | - - `Offset` |
90 | | -* a helper struct `CpuSlab` which wraps `Vec<u32>` or `WgpuBuffer` |
91 | | -* a feature-gated helper for using slabs with `wgpu` - `WgpuBuffer` |
92 | | - - [example](src/wgpu_slab.rs#L344) |
|
0 commit comments