Skip to content

How to properly read back data to the CPU? #6264

Answered by BGR360
geri1245 asked this question in Q&A
Discussion options

You must be logged in to vote

I think your order is a bit wrong. It should be:

  1. create buffer
  2. queue copy_texture_to_buffer
  3. submit
  4. map_async
  5. poll or wait for callback
  6. get_mapped_range to read the data
  7. drop all BufferViews
  8. unmap

Take a look at usages of map_async in the wgpu examples.

This blurb from the docs should clarify why what you're currently doing isn't quite right:

While a buffer is mapped, you may not submit any commands to the GPU that access it. You may record command buffers that use the buffer, but if you submit them while the buffer is mapped, submission will panic.

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.…

Replies: 1 comment 3 replies

Comment options

You must be logged in to vote
3 replies
@geri1245
Comment options

@BGR360
Comment options

Answer selected by geri1245
@geri1245
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants