Closed DoeringChristian closed 1 year ago
The operation is submitted to the device with submit(...)
but it hasn't finished execution yet, so mapping the buffer isn't synchronized in any way with the completion of the command buffer.
Internally a command buffer exists in the lazy pool with a fence for this operation. Perhaps it could be exposed or something to help you signal on it. I think the event loop being successful is just the frame delay happening to be long enough for this to finish.
One way to get this to run correctly in the mean time is to force the device to finish all commands prior to mapping the slice:
unsafe { sc13.device.device_wait_idle().unwrap(); }
Thanks for the quick response. It works now.
I think the documentation needs to be improved to explain that submit is asynchronous and results won't be available until things finish. Exposing the fence being used could help, but I feel like that's all the Vulkan complexity that people didn't want to know about. Of course device resources like images and device buffers are synchronized and so those cases are "ready" as soon as you submit. It's only host-mapped buffers which hit this.
One option to improve the code here is to add a submit_and_wait
function so we would be clearly waiting for the work to actually finish.
Changes to the mapping function alone wouldn't help because this requires a command buffer to submit synchronization commands or vk::Device::wait_for_fence
. I'll ponder improvements in this area.
I'm still not quite sure about how Vulkan works but maybe it would be possible to "schedule" some buffers for evaluation and all shaders that modify that buffer would be executed while the cpu waits only on these executions. Though this would probably be pretty complicated.
Update: I've added two new helper functions to CommandBuffer
and exposed it as the return value of Resolver::submit()
; you can now easily check for submitted work. See examples/cpu_readback.rs
for the details.
Hi, I want to use screen-13 to ray trace into an image and not necessarily display it every frame. I tried to write a basic compute shader that reads from one buffer and writes into another.
However this doesn't seem to work when calling submit on the resolver. When calling the compute shader every frame in an event loop the result is correct. What does it take to enforce the execution of the compute shader? Thanks for your help.