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

Prevent Metal from crashing when a still-open encoder is deallocated, resolve issue #2077. #4023

Merged
merged 22 commits into from
Aug 29, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
75b5056
This prevents Metal from crashing when an encoder is deallocated.
bradwerth Aug 9, 2023
7ce2f9a
Add note to CHANGELOG.md.
bradwerth Aug 9, 2023
baf3fa3
Add note to CHANGELOG.md.
bradwerth Aug 9, 2023
7e21d4c
Relocate additions in CHANGELOG.md.
bradwerth Aug 9, 2023
d896931
Merge branch 'endEncoding' of https://github.com/bradwerth/wgpu into …
bradwerth Aug 9, 2023
db5cb6d
Fix changelog and add code comment describing the motivation for thes…
bradwerth Aug 10, 2023
386eacc
Merge branch 'trunk' into endEncoding
bradwerth Aug 11, 2023
0425f63
Instead of implementing Drop for CommandState, implement it for
bradwerth Aug 11, 2023
00411bc
Merge branch 'trunk' into endEncoding
bradwerth Aug 15, 2023
a4eaa94
Implement Drop for DX12 CommandEncoders to also call discard_encoding.
bradwerth Aug 16, 2023
c4d5691
Update Changelog with notes about DX12 changes.
bradwerth Aug 16, 2023
3c44ed7
Merge branch 'trunk' into endEncoding
bradwerth Aug 16, 2023
9f55d32
Fix DX12 compilation problems, attempt 1.
bradwerth Aug 16, 2023
2cbb242
Merge branch 'trunk' into endEncoding
bradwerth Aug 16, 2023
59446b8
Update comment with the narrower finding of the endEncoding requirement.
bradwerth Aug 16, 2023
305fd55
Mark the drop_encoder_after_error test as failing on DX12.
bradwerth Aug 16, 2023
64a029f
Cleanup of some should-be-left-untouched DX12 implementation stuff.
bradwerth Aug 17, 2023
dd53269
Merge branch 'trunk' into endEncoding
bradwerth Aug 17, 2023
7215c93
Merge branch 'trunk' into endEncoding
bradwerth Aug 17, 2023
bdb4515
Merge branch 'trunk' into endEncoding
bradwerth Aug 18, 2023
e3afadc
Merge branch 'trunk' into endEncoding
bradwerth Aug 20, 2023
3e2ec42
CHANGELOG.md: Avoid duplicating "Bug Fixes" section
jimblandy Aug 28, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ Bottom level categories:
- Hal
-->

By @bradwerth in [#4203](https://github.com/gfx-rs/wgpu/pull/4023)
bradwerth marked this conversation as resolved.
Show resolved Hide resolved

### Bug Fixes

#### Metal

- Ensure that MTLCommandEncoder calls endEncoding before it is deallocated.

bradwerth marked this conversation as resolved.
Show resolved Hide resolved
## Unreleased

### Major changes
Expand All @@ -62,6 +70,14 @@ let render_pass = encoder.begin_render_pass(&wgpu::RenderPassDescriptor {
});
```

By @bradwerth in [#4203](https://github.com/gfx-rs/wgpu/pull/4023)

### Bug Fixes

#### Metal

- Ensure that MTLCommandEncoder calls endEncoding before it is deallocated.

By @Valaphee in [#3402](https://github.com/gfx-rs/wgpu/pull/3402)

### Changes
Expand All @@ -87,7 +103,7 @@ This release was fairly minor as breaking changes go.

#### `wgpu` types now `!Send` `!Sync` on wasm

Up until this point, wgpu has made the assumption that threads do not exist on wasm. With the rise of libraries like [`wasm_thread`](https://crates.io/crates/wasm_thread) making it easier and easier to do wasm multithreading this assumption is no longer sound. As all wgpu objects contain references into the JS heap, they cannot leave the thread they started on.
Up until this point, wgpu has made the assumption that threads do not exist on wasm. With the rise of libraries like [`wasm_thread`](https://crates.io/crates/wasm_thread) making it easier and easier to do wasm multithreading this assumption is no longer sound. As all wgpu objects contain references into the JS heap, they cannot leave the thread they started on.
bradwerth marked this conversation as resolved.
Show resolved Hide resolved

As we understand that this change might be very inconvenient for users who don't care about wasm threading, there is a crate feature which re-enables the old behavior: `fragile-send-sync-non-atomic-wasm`. So long as you don't compile your code with `-Ctarget-feature=+atomics`, `Send` and `Sync` will be implemented again on wgpu types on wasm. As the name implies, especially for libraries, this is very fragile, as you don't know if a user will want to compile with atomics (and therefore threads) or not.

Expand Down
14 changes: 14 additions & 0 deletions wgpu-hal/src/metal/command.rs
bradwerth marked this conversation as resolved.
Show resolved Hide resolved
bradwerth marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ impl Default for super::CommandState {
}
}

impl Drop for super::CommandState {
fn drop(&mut self) {
if let Some(ref encoder) = self.blit {
encoder.end_encoding();
}
if let Some(ref encoder) = self.render {
encoder.end_encoding();
}
if let Some(ref encoder) = self.compute {
encoder.end_encoding();
}
bradwerth marked this conversation as resolved.
Show resolved Hide resolved
bradwerth marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl super::CommandEncoder {
fn enter_blit(&mut self) -> &metal::BlitCommandEncoderRef {
if self.state.blit.is_none() {
Expand Down