Skip to content

Storage buffer: multidimensional array #5002

Closed Answered by kpreid
Alphapage asked this question in Q&A
Discussion options

You must be logged in to vote

A Vec<Vec<u32>> is a pointer to a memory allocation containing pointers to memory allocations containing u32s. You can't copy it directly into a GPU buffer for the same reason bytemuck doesn't straightforwardly accept it: it's not a single allocation, and it contains pointers which would be meaningless (or at least unsafe) on the GPU. For the same kind of reason, array<array<u32>> is not a valid WGSL array type.

What you need to do is design a data format which does use a single allocation for the data.

  • If the data is rectangular (each inner Vec is the same length) then this is simple: use a single Vec<u32>, and compute “flattened” indices in it as x + width * y — the same way you'd acce…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by cwfitzgerald
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants