Skip to content

Defer command buffer recycling until allocate#429

Merged
bors[bot] merged 2 commits intogfx-rs:masterfrom
LaylBongers:master
Jan 2, 2020
Merged

Defer command buffer recycling until allocate#429
bors[bot] merged 2 commits intogfx-rs:masterfrom
LaylBongers:master

Conversation

@LaylBongers
Copy link
Copy Markdown
Contributor

@LaylBongers LaylBongers commented Dec 31, 2019

As discussed on Matrix, this change defers command buffer recycling until allocation.
This lets a rendering thread clean up its own command buffers, making sure only the owning thread accesses anything from its command pool.

I have also added a TODO comment about cleaning up thread pools, which currently isn't happening as far as I can tell. This previously was an issue as well but now is a slightly bigger one as the command buffer wouldn't get recycled either.

I figured that, for now, fixing that issue is out of the scope of this PR. This PR focuses only on resolving the race condition causing the validation error.

This fixes #423

@kvark
Copy link
Copy Markdown
Member

kvark commented Jan 1, 2020

Please rebase instead of introducing the merge commit

);
{
let mut last_done_guard = self.last_done.lock();
*last_done_guard = last_done_guard.max(last_done);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think we need a Mutex here. After this function is called in submit, the device is re-locked for writing, so we can just assign the value in there directly.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

device.pending is locked but the device itself isn't given a write a lock. I could introduce a write lock between the maintain call and further uses of the device, if that works better.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I know what we can do to avoid this field. At any point, we can consider active[0].index to be the first undone submission index. So we can take that and pass it to the pool.maintain() as a different semantics (first undone), and in side the maintain() implementation just change the <= last_done comparison to < first_undone. How does that sound?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good to me, seems straightforward to implement as well.

);
{
let mut last_done_guard = self.last_done.lock();
*last_done_guard = last_done_guard.max(last_done);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, I think I know what we can do to avoid this field. At any point, we can consider active[0].index to be the first undone submission index. So we can take that and pass it to the pool.maintain() as a different semantics (first undone), and in side the maintain() implementation just change the <= last_done comparison to < first_undone. How does that sound?

Copy link
Copy Markdown
Member

@kvark kvark left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!
bors r+

// The first entry in the active list should have the lowest index
let lowest_active_index = device.pending.lock()
.active.get(0)
.map(|active| active.index)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: could use map_or

bors bot added a commit that referenced this pull request Jan 2, 2020
429: Defer command buffer recycling until allocate r=kvark a=LaylConway

As discussed on Matrix, this change defers command buffer recycling until allocation.
This lets a rendering thread clean up its own command buffers, making sure only the owning thread accesses anything from its command pool.

I have also added a TODO comment about cleaning up thread pools, which currently isn't happening as far as I can tell. This previously was an issue as well but now is a slightly bigger one as the command buffer wouldn't get recycled either.

I figured that, for now, fixing that issue is out of the scope of this PR. This PR focuses only on resolving the race condition causing the validation error.

This fixes #423

Co-authored-by: Layl <2385329-layl@users.noreply.gitlab.com>
@bors
Copy link
Copy Markdown
Contributor

bors bot commented Jan 2, 2020

Build succeeded

And happy new year from bors! 🎉

@bors bors bot merged commit ac8f752 into gfx-rs:master Jan 2, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Validation error, VkCommandPool used from multiple threads

2 participants