Open mcclure opened 1 year ago
It has now been explained to me why the code does not work but I still think the error message is situationally wrong.
@mcclure: An explanation here, even only linked or copy-pasted, would be much more easy to find than only within Matrix chat! 🙏🏻 EDIT: Before we correct diagnostics, of course. 🙂
This link to the Matrix discussion should work:
But TLDR is that before submitting any commands that make use of a buffer, you must unmap that buffer before entering the queue.submit() call. I don't like this (my expectation would have been that queue.submit() would have blocked), but apparently it is dictated by the constraints of the upstream WebGPU spec.
Incidentally, if the message something said something like "Buffer referenced in submit() is still mapped" rather than just "Buffer is still mapped", that would have been helpful to me (because it would have made it more clear which api requirement I failed)
Warning: Sample code plays a loud noise.
Consider this branch:
https://github.com/mcclure/webgpu-tutorial-rs/tree/bug-still-mapped (Current head 2b73f96)
This builds a command buffer, the final step of which is to write some data into
readback_buffer
. Immediately after all commands, it runs:As far as I know, I am doing the right thing here: I clone readback_buffer (an
std::sync::Arc<wgpu::Buffer>
, I closure-move it into a callback to map_async, I do not call get_mapped_range until I am inside the callback, I unmap as soon as possible.Running this prints:
(Full backtrace below)
There are two problems here
label: Some("Readback buffer")
, so it should be called that, notBuffer (21, 1, Metal)
.Notes:
cargo run
. I have not tested elsewhere..submit
is called again. I think it is attempting to process the commands submitted (which includes writing into readback_buffer) before executing the pending mapAsync callback.Full stacktrace: TERMINAL-OUTPUT.TXT