New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
webgpu: Use safe callbacks & try_recv_timeout #32008
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
NOTE-TO-SELF: Ipc-channel created from |
This comment was marked as outdated.
This comment was marked as outdated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So I've looked a bit into https://docs.rs/wgpu-core/0.20.0/src/wgpu_core/device/global.rs.html#2391, and I'm wondering if we really need the callbacks for the map asyncs. It seems to just makes things more complicated, see for example the lock around webrender.
This is different from the closures of submitted work done, because those are actually called at a later stage from when they are submitted. But the map asyncs callbacks are just called right then and there.
I think https://docs.rs/wgpu/latest/wgpu/struct.BufferSlice.html#method.map_async only applies to when you are using the higher-level wgpu API. the wgpu-core buffer_map_async
calls the callback synchronously.
If that is correct(I think it is, but let me know if you think otherwise), I would say we should remove the callbacks, and the locks.
let wgpu_image_map = Arc::clone(&self.wgpu_image_map); | ||
let webrender_api = Arc::clone(&self.webrender_api); | ||
let webrender_document = self.webrender_document; | ||
let callback = BufferMapCallback::from_rust(Box::from(move |result| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we not just call global.buffer_map_async
synchronously, and then handle the result and do the webrender stuff?
global.buffer_get_mapped_range(info.buffer_id, 0, None)) | ||
let glob = Arc::clone(&self.global); | ||
let resp_sender = sender.clone(); | ||
let callback = BufferMapCallback::from_rust(Box::from(move |result| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same here: do we need the callback?
Callback is called synchronously only when result if there is immediate failure (mostly validation): https://docs.rs/wgpu-core/0.20.0/src/wgpu_core/device/global.rs.html#2388 (we currently handle this twice, see #32172) I think I can see why you get confused by callbacks (I got too for few moments), but So yeah I think callbacks are really needed (if they were not, they would not be in wgpu). You can always ask in wgpu matrix channel if my explanation is to messy. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So yeah I think callbacks are really needed
Ok, I now see the callback is stored over at https://github.com/gfx-rs/wgpu/blob/bdf30fa45aa86b827749f7ee45ed342ce27b0fbb/wgpu-core/src/device/global.rs#L2498
LGTM!
It also removes the need for HashMaps and BufferMaps struct that keep data alive until it was used by C callback.
Callbacks now do not send request to self anymore so https://sagudev.github.io/briefcase/fastgame.html actually works now.
We now do try_recv_timeout instead of running loop continuously.
./mach build -d
does not report any errors./mach test-tidy
does not report any errors