-
Hi! I am trying to read back some data from the GPU to the CPU. What I am trying to do is giving each object a unique ID and render that to a texture, so I can tell which object the mouse is hovering over. Rendering into the texture is working well, now I just have to get the data from the texture. Seems like the way to read back data is using
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
It sounds like you're trying to have a single buffer alternate between being written by the GPU and read by the CPU. This is not a practical solution — if you do it successfully, your frame rate will be terrible because of all the required waiting. Instead, have two buffers (“double buffering”) such that at most one of them is mapped at a time. That way, the CPU can be reading from the mapped buffer while the GPU writes to the unmapped buffer. Then, swap the roles of the two buffers while neither one is mapped. |
Beta Was this translation helpful? Give feedback.
I think your order is a bit wrong. It should be:
Take a look at usages of
map_async
in thewgpu
examples.This blurb from the docs should clarify why what you're currently doing isn't quite right:
When you call map_async before calling submit, you might have your callback called right away because the buffer is not in use by the GPU.…