fix(core): Flush pending writes before mapAsync, if needed#9307
fix(core): Flush pending writes before mapAsync, if needed#9307andyleiserson merged 4 commits intogfx-rs:trunkfrom
Conversation
0f42fa3 to
29bff7a
Compare
There was a problem hiding this comment.
If I understand correctly, this patch could invoke user callbacks from Buffer::map_async. This is new user-visible behavior (potentially unexpected, but I bet it'll be okay). There are a few places in the wgpu documentation that explain when callbacks get invoked that should be updated. For example:
- the docs for
Buffer::map_async - the module-level documentation for
Buffer - the docs for
Queue::on_submitted_work_done
There may be other spots. i'd look for references to poll.
|
Oh, and obviously, the change in callback behavior needs prominent mention in the CHANGELOG. |
jimblandy
left a comment
There was a problem hiding this comment.
It is not correct to hoist the snatch lock acquisition outside Queue::submit. The user's callbacks must always be invoked while wgpu-core is holding no locks, but this change lets submit_inner invoke them while its caller holds the Device's snatch lock.
It doesn't hold the snatch lock while calling callbacks -- the guard is moved into |
Okay, I was misreading the code. Yes, this isn't a problem after all. |
|
I have a version of this updated based on #9361, but it has a new test failure in |
|
What is the new test failure? |
29bff7a to
19bce18
Compare
The new test failure was a silly mistake in the refactoring I did of |
|
In the latest version I've also added a flush of pending writes in |
teoxoy
left a comment
There was a problem hiding this comment.
Looks good, I only have one last concern.
| submission | ||
| .surface_textures | ||
| .insert(Arc::as_ptr(texture), texture.clone()); | ||
|
|
There was a problem hiding this comment.
I'm not sure if this is actually needed here. We've added the texture to pending_writes, and submission already scans for surface textures in pending writes.
I'm actually not sure whether we need to have submission.surface_textures at all. Instead of collecting surface textures in validate_command_buffer and transitioning them in submit, we could combine that with the texture transition logic for pending writes in submit_pending_submission. But that would be a bigger refactoring.
There was a problem hiding this comment.
That does sound right, pending_writes.insert_texture(texture); was added in a later revision of #9361, so I think we can simplify things now.
22982ae to
5d45aa0
Compare
27fa2c4 to
94fd657
Compare
Extend the command_index lock through submission
94fd657 to
9db6f10
Compare
map_async now uses a refactored submission codepath that does not invoke callbacks.
Fixes #5173. Also fixes an open TODO to flush pending writes in
on_submitted_work_done.Based on top of #9439 and #9444. The changes for this PR are the commits after the merge commit.
This implements the strategy @teoxoy suggested in bug 1994733, comment 6: if
mapAsyncfinds thatPendingWritesholds writes for the buffer being mapped, thenPendingWritesis flushed/submitted before mapping the buffer.This strategy never makes
Queue::writeBufferorunmapperform a submission. A submission only happens if/whenmapAsyncis called for a buffer with pending writes. This has the nice property thatmapAsyncwas already an operation that might have to wait on the queue, although this change broadens the circumstances when that will happen and may increase the amount of queued work thatmapAsynchas to wait on. (More sophisticated approaches would be to only flush the pending writes for the buffer in question, rather than all of them, or to proactively flush pending writes if the queue is idle, to reduce the chance thatmapAsyncends up waiting on them.)There is a long-standing TODO in
mapAsyncabout possibly needing a barrier. I briefly considered trying to address that as part of that change, but I think it's a separable concern, and comes with its own set of performance risks that it is better not to lump together with this change.Testing
Adds a directed test and some CTS tests.
Squash or Rebase? Rebase
Checklist
CHANGELOG.mdentry.