-
|
I am currently writing a MeshAllocator using wgpu-native and C++. if I allocate more data than the current vertex buffer can handle I create a new one, copy the vertex data, and call wgpuBufferRelease(WGPUBuffer buffer) on the old one to delete it. In Vulkan or Dx12, I would need to ensure that the Buffer is not used by the GPU anymore. How is this handled in wgpu? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
|
Preface: I only work on wgpu and not wgpu-native - this is based on a brief read of wgpu-native's rust side code and my knowledge of wgpu-core. Each wgpu buffer is reference counted using This means that wgpu will keep the buffer alive while the until the next device poll or queue submission after the submissions that use the buffer are complete (baring, of course, double frees which might cause this to fail). |
Beta Was this translation helpful? Give feedback.
Preface: I only work on wgpu and not wgpu-native - this is based on a brief read of wgpu-native's rust side code and my knowledge of wgpu-core.
Each wgpu buffer is reference counted using
Arcs, and each submission willclonethisArc(which, in effect, ups the reference count). These aredroped (that is, their reference count will be decremented) on the device poll (queue submits implicitly poll) after the submission is complete. From reading wgpu-native's code, it appears to get the reference to that buffer by a buffer id (This may change, but external behavior will remain the same) and store this in a newArcwhich is then exposed to you as a pointer. When all the references of this are…