What is the correct way to write unified memory code? #9433
Replies: 1 comment
-
This should not have significant performance effects unless you are blocking on the mapping completing. If that's what you're doing, you need to avoid it — usually by using multiple buffers ("triple buffering" — one for the GPU, one for the CPU, and one potentially in transit).
You mean the requirements of |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I've been using WGPU for my engine and I largely enjoy the API, and the idiomatic integration with Rust makes it especially pleasant. Despite the recent-ish switch to the
CurrentSurfaceTexturemodel - which admittedly took me a few hours to debug before realizing that suboptimal frames needed to be handled separately to ensure the frame was actually dropped - I have found it very intuitive. However, proper optimization for unified memory architectures is not obvious to me.I have an M2 Pro as my main chip (running Asahi linux) and I'm interested in what the correct way to utilize the unified memory architecture is. My game engine based on voxels and so I have a function to rebuild the draw data (indirect buffer and storage buffer to position chunks) whenever needed (though admittedly this function is currently called rather pervasively).
You can see that this function simply allocates two vectors which data is written into before that data is copied to their respective buffers. My understanding is that
write_bufferclones the data provided by the slice to a temporary staging buffer, which itself then gets cloned to be sent off to the gpu, and this all requires a separateVecallocation.My question is, being on a unified memory architecture, how would I write to these buffers directly? I have tried using
map_asyncwithget_mapped_range_mut, however this resulted in a extremely noticeable stuttering, and the move requirements leave me unsure of how I could possibly write each element in without making a separate allocation.Beta Was this translation helpful? Give feedback.
All reactions