Skip to content
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

Add check to ensure vulkan::CommandEncoder::discard_encoding is not called multiple times in a row #5557

Merged
merged 7 commits into from
Apr 22, 2024

Conversation

villuna
Copy link
Contributor

@villuna villuna commented Apr 18, 2024

Connections
Addresses #5255

Description
I just followed the (very helpful) todo list in Erich's issue, so the info is mostly there.

The vulkan implementation for CommandEncoder was previously pushing its active CommandBuffer handle to its discard vector every time the discard_encoding function was called, even if the handle was null. So I made it only do this if the active handle is non-null, so as to make the function idempotent.

Testing
No new tests but I ran the existing test suite on Vulkan (on an Nvidia GTX1050) and it ran the same as on the trunk branch.

Checklist

  • Run cargo fmt.
  • Run cargo clippy. If applicable, add:
    • --target wasm32-unknown-unknown
    • --target wasm32-unknown-emscripten
  • Run cargo xtask test to run tests - I got one error every now and then, but this also happened on the main branch so I think it's fine.
  • Add change to CHANGELOG.md. See simple instructions inside file.

@villuna villuna requested a review from a team as a code owner April 18, 2024 14:14
Copy link
Member

@cwfitzgerald cwfitzgerald left a comment

Choose a reason for hiding this comment

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

Looks good, going to flag Erich on this one

wgpu-hal/src/lib.rs Outdated Show resolved Hide resolved
@jimblandy
Copy link
Member

I'm actually -0.5 on this PR. The idea is for wgpu_hal traits to permit implementations to track as little state as pratical, and put all state tracking, validation, resource management, etc. in common code in wgpu-hal. Properties like idempotence should be easily manageable in wgpu-core.

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

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

Having thought about this more, I'd like to put a temporary pause on this PR.

At least given my understanding of the role wgpu's core/hal distinction is supposed to play in keeping wgpu maintainable, adding obligations that wgpu-hal trait implementors must meet to make life easier for their users is putting the code in the wrong place. State tracking, validation, and resource management should be handled in common code within wgpu-core, not repeated in each wgpu_hal backend.

@villuna, apologies for the back-and-forth - there's nothing wrong with the code at all, and it looks like it correctly implements the intended change. I just want a day or so for the maintainers to talk things over and get a shared understanding.

wgpu-hal/src/lib.rs Outdated Show resolved Hide resolved
@jimblandy
Copy link
Member

For what it's worth, I've been looking into wgpu-core's handling of hal command encoders over the last week, in the process of trying to get a handle on our locking/synchronization story (see #5539, for example). I'd started to put together some ideas on how to clarify the life cycle of command encoders in core, and make it "correct by construction" that the wgpu_hal::CommandEncoder contract is satisfied. Clearly I'm not the only person with this on their mind!

Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

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

It sounds like we've got some consensus around #5566, so in that context:

wgpu-hal/src/lib.rs Outdated Show resolved Hide resolved
wgpu-hal/src/lib.rs Outdated Show resolved Hide resolved
wgpu-hal/src/vulkan/command.rs Outdated Show resolved Hide resolved
@villuna
Copy link
Contributor Author

villuna commented Apr 21, 2024

Thanks for the comments, I've made the changes you requested. I've also removed the drop implementation, since it was calling discard_encoding twice and triggering the assert panic 😅. I guess it's working

@villuna villuna changed the title Make wgpu_hal::vulkan::CommandEncoder::discard_encoding idempotent and implement Drop for the encoder. Add check to ensure vulkan::CommandEncoder::discard_encoding is not called multiple times in a row Apr 21, 2024
Copy link
Member

@jimblandy jimblandy left a comment

Choose a reason for hiding this comment

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

Looks good to me. I did some minor copy-editing.

@jimblandy jimblandy enabled auto-merge (squash) April 22, 2024 19:29
@jimblandy jimblandy dismissed cwfitzgerald’s stale review April 22, 2024 19:30

Superseded by subsequent reviews.

@jimblandy jimblandy merged commit 7840e75 into gfx-rs:trunk Apr 22, 2024
25 checks passed
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.

3 participants