-
Notifications
You must be signed in to change notification settings - Fork 938
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
Improve lifetime management of command encoders and buffers #6544
Conversation
0a5b313
to
6eedd2f
Compare
I couldn't repro the issue in CI, thanks for pairing @ErichDonGubler and helping to debug it! |
f5af55a
to
e1f6a2c
Compare
@ErichDonGubler I added the comment on the |
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.
praise: New code makes sense, and actually helped me understand the old code after many "wat"s ("why did we represent things this way before, am confoozed"). Nice!
Just got some questions I'd like resolved before merging, but I'm sure they'll be straightforward.
If it's acceptable for unexpected operations in the |
That's how the code used to look in a previous iteration of the patch, the issue was that we can't replace I don't like the macro either but it seemed appropriate to hide the ugliness. Something else we could try is to match twice in the methods, will put up a commit for that to see if we like it more. |
I guess we could also just reassign the finished state back. |
40d11fa
to
1726a84
Compare
I think I addressed all the comments. |
One interesting wrinkle in this is that, since struct fields are dropped in order, dropping a |
Sorry, I'm very close to done with this review. Will finish tomorrow morning. |
This is the case right now but is a bit problematic that we now have I'm not sure what the best solution is but I'm leaning towards adding |
Right now, the
|
In any case, this PR as it stands doesn't respect modified wgpu-hal/src/lib.rs
@@ -1108,7 +1108,9 @@ pub trait Queue: WasmNotSendSync {
/// - A `CommandBuffer` must not outlive the `CommandEncoder` that
/// built it.
///
-/// - A `CommandEncoder` must not outlive its `Device`.
+/// - A `CommandEncoder` may outlive the `Device` that created it. But once the
+/// `Device` has been dropped, the only operation permitted on the
+/// `CommandEncoder` is to drop it.
///
/// It is the user's responsibility to meet these requirements. This
/// allows `CommandEncoder` implementations to keep their state |
Wow, so dropping a |
There's a third alternative:
This wouldn't be a |
That sounds good to me too. I can make the change tomorrow but let me know if there is anything else I should address. |
Having thought about how Broadly speaking, I think As long as their types don't have lifetime parameters, safe code can drop two values in any order it wants. This means that
Given ownership of a Now, since But that would be pretty delicate, and it seems like We would want to consider whether |
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.
Two minor omissions, but otherwise this looks fantastic.
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.
Oh, and also, the wgpu_hal
safety docs need to be updated to reflect whatever policy we settle on.
This sounds good to me as well. I will remove the comment that says it must not outlive its
I think it's fine if we allow using |
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.
Looks great - thank you!
…ions instead Co-Authored-By: Erich Gubler <[email protected]>
…iants to hold `CommandBufferMutable` This makes the code more straightforward, we were previously holding invalidity state in 2 places: `CommandBuffer::data` could hold `None` and in `CommandEncoderStatus::Error`. This commit also implements `Drop` for `CommandEncoder` which makes the destruction/reclamation code automatic. We were previously not reclaiming all command encoders (`CommandBufferMutable::destroy` didn't call `release_encoder`) even though all encoders are coming from a pool.
The spec requires us to invalidate the encoder if there was any error during the body of these operations.
This PR improves the lifetime management of command encoders (it's now automatic on drop, no more manual destruction), it also removes duplicate invalidity state from command encodes and with the last commit, we now invalidate the command encoder if there have been any errors while recording (per spec).