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
Merged
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ Bottom level categories:
#### Vulkan

- Set object labels when the DEBUG flag is set, even if the VALIDATION flag is disabled. By @DJMcNab in [#5345](https://github.com/gfx-rs/wgpu/pull/5345).
- Add safety check to `wgpu_hal::vulkan::CommandEncoder` to make sure `discard_encoding` is not called in the closed state. By @villuna in [#5557](https://github.com/gfx-rs/wgpu/pull/5557)

#### Metal

Expand Down
6 changes: 5 additions & 1 deletion wgpu-hal/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
/// This `CommandEncoder` must be in the "closed" state.
unsafe fn begin_encoding(&mut self, label: Label) -> Result<(), DeviceError>;

/// Discard the command list under construction, if any.
/// Discard the command list under construction.
///
/// If an error has occurred while recording commands, this
/// is the only safe thing to do with the encoder.
Expand All @@ -655,6 +655,10 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug {
/// # Safety
///
/// This `CommandEncoder` must be in the "recording" state.
///
/// Callers must not assume that implementations of this
/// function are idempotent, and thus should not call it
/// multiple times in a row.
unsafe fn discard_encoding(&mut self);

/// Return a fresh [`CommandBuffer`] holding the recorded commands.
Expand Down
5 changes: 5 additions & 0 deletions wgpu-hal/src/vulkan/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,11 @@ impl crate::CommandEncoder for super::CommandEncoder {
}

unsafe fn discard_encoding(&mut self) {
// Safe use requires this is not called in the "closed" state, so the buffer
// shouldn't be null. Assert this to make sure we're not pushing null
// buffers to the discard pile.
assert_ne!(self.active, vk::CommandBuffer::null());

self.discarded.push(self.active);
self.active = vk::CommandBuffer::null();
}
Expand Down
Loading