-
Notifications
You must be signed in to change notification settings - Fork 924
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
[wgpu-hal] Migrate d3d12 backend over to windows-rs
#5956
Conversation
05cb537
to
b6c5854
Compare
94cce3b
to
662998b
Compare
Tested some of the wgpu examples and it seems to work fine on windows 11 + amd, apart from the |
Oh, don't you worry about testing. We'll put this through the entire WebGPU CTS on Firefox for you, just to make sure this safe to merge. 🤪 I'm quite excited. |
@ErichDonGubler that would be very nice, but not before we answered some basic questions above about the validity of |
@MarijnS95: Ah, of course. The |
@ErichDonGubler correct, I don't think we can land this without settling, and documenting it. If my mind serves me correctly the original backend implementation does not assume ownership and does not drop the pointers, which we could replicate by wrapping the COM objects in |
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.
This is really amazing stuff! I have a few really small comments, but none that I think should block this landing. Let me make sure moz has everything they need to land this PR, and we can get rolling on this.
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.
This looks fantastic. Assuming that this depends on windows 0.58, it should be fine for Firefox.
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.
Things look straightforward now, great stuff!
One thing I noticed is that we still use |
It should only do the linking when those symbols are actually used/called, which they are currently not. I assumed If there's no particular reason to use runtime loading I'd be very happy to throw the extra code all right out, but it's a bit of a pity since it has already been written (ported from the linked functions inside the |
Yeah the idea is to allow running on windows 7-8.1, as the d3d12 functions don't exist there. How valueable that is is debatable, but that's what we've been doing. |
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.
I didn't actually finish self-reviewing my PR. Here are some notes taken while very lightly scrubbing the changes, that I'll perhaps PR changes for later (or someone else can look into them).
fn prepare_marker(&mut self, marker: &str) -> (&[u16], u32) { | ||
// TODO: Store in HSTRING | ||
self.marker.clear(); | ||
self.marker.extend(marker.encode_utf16()); | ||
self.marker.push(0); |
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.
👀
// TODO: Empty slice vs None? | ||
unsafe { list.ClearRenderTargetView(*rtv, &value, Some(&[])) }; |
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.
👀
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.
I feel like None
would be more obvious.
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 like the old clear_render_target_view()
in d3d12/src/command_list.rs
used to map an empty slice to ptr::null()
, so I'm changing it to None
too. If anything this is one of the few strange semantic differences to perhaps have an effect on #6162?
@MarijnS95 thanks for being so thorough! |
I left some 👍 on the things I think would be good to address in a follow-up; if you'd be up for that :) |
flags, | ||
ds.clear_value.0, | ||
ds.clear_value.1 as u8, | ||
&[], |
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.
This one used to be ptr::null()
too, but there's no None
mapping in Direct3D12 here because someone only reported this issue (and hence fixed it) for clearRenderTargetView()
🤦🤦.
Thanks @teoxoy: I've prepared a branch locally to batch some of these together, and will open a PR soon. |
PR gfx-rs#5956 wasn't fully complete and still had some outstanding minor issues and cleanups to be done, as well as hidden semantic changes. This addresses a bunch of them: - Remove unnecessary `Error` mapping to `String` as `windows-rs`'s `Error` has a more complete `Display` representation by itself. - Remove `into_result()` as every call could have formatted the `windows-rs` `Error` in a log call directly. - Pass `None` instead of a pointer to an empty slice wherever possible (waiting for microsoft/win32metadata#1971 to trickle down into `windows-rs`). - Remove `.clone()` on COM objects (temporarily increasing the refcount) when it can be avoided by inverting the order of operations on `raw` variables.
PR gfx-rs#5956 wasn't fully complete and still had some outstanding minor issues and cleanups to be done, as well as hidden semantic changes. This addresses a bunch of them: - Remove unnecessary `Error` mapping to `String` as `windows-rs`'s `Error` has a more complete `Display` representation by itself. - Remove `into_result()` as every call could have formatted the `windows-rs` `Error` in a log call directly. - Pass `None` instead of a pointer to an empty slice wherever possible (waiting for microsoft/win32metadata#1971 to trickle down into `windows-rs`). - Remove `.clone()` on COM objects (temporarily increasing the refcount) when it can be avoided by inverting the order of operations on `raw` variables.
PR gfx-rs#5956 wasn't fully complete and still had some outstanding minor issues and cleanups to be done, as well as hidden semantic changes. This addresses a bunch of them: - Remove unnecessary `Error` mapping to `String` as `windows-rs`'s `Error` has a more complete `Display` representation by itself. - Remove `into_result()` as every call could have formatted the `windows-rs` `Error` in a log call directly. - Pass `None` instead of a pointer to an empty slice wherever possible (waiting for microsoft/win32metadata#1971 to trickle down into `windows-rs`). - Remove `.clone()` on COM objects (temporarily increasing the refcount) when it can be avoided by inverting the order of operations on `raw` variables.
PR gfx-rs#5956 wasn't fully complete and still had some outstanding minor issues and cleanups to be done, as well as hidden semantic changes. This addresses a bunch of them: - Remove unnecessary `Error` mapping to `String` as `windows-rs`'s `Error` has a more complete `Display` representation by itself. - Remove `into_result()` as every call could have formatted the `windows-rs` `Error` in a log call directly. - Pass `None` instead of a pointer to an empty slice wherever possible (waiting for microsoft/win32metadata#1971 to trickle down into `windows-rs`). - Remove `.clone()` on COM objects (temporarily increasing the refcount) when it can be avoided by inverting the order of operations on `raw` variables.
PR gfx-rs#5956 wasn't fully complete and still had some outstanding minor issues and cleanups to be done, as well as hidden semantic changes. This addresses a bunch of them: - Remove unnecessary `Error` mapping to `String` as `windows-rs`'s `Error` has a more complete `Display` representation by itself. - Remove `into_result()` as every call could have formatted the `windows-rs` `Error` in a log call directly. - Pass `None` instead of a pointer to an empty slice wherever possible (waiting for microsoft/win32metadata#1971 to trickle down into `windows-rs`). - Remove `.clone()` on COM objects (temporarily increasing the refcount) when it can be avoided by inverting the order of operations on `raw` variables.
PR gfx-rs#5956 wasn't fully complete and still had some outstanding minor issues and cleanups to be done, as well as hidden semantic changes. This addresses a bunch of them: - Remove unnecessary `Error` mapping to `String` as `windows-rs`'s `Error` has a more complete `Display` representation by itself. - Remove `into_result()` as every call could have formatted the `windows-rs` `Error` in a log call directly. - Pass `None` instead of a pointer to an empty slice wherever possible (waiting for microsoft/win32metadata#1971 to trickle down into `windows-rs`). - Remove `.clone()` on COM objects (temporarily increasing the refcount) when it can be avoided by inverting the order of operations on `raw` variables.
PR gfx-rs#5956 wasn't fully complete and still had some outstanding minor issues and cleanups to be done, as well as hidden semantic changes. This addresses a bunch of them: - Remove unnecessary `Error` mapping to `String` as `windows-rs`'s `Error` has a more complete `Display` representation by itself. - Remove `into_result()` as every call could have formatted the `windows-rs` `Error` in a log call directly. - Pass `None` instead of a pointer to an empty slice wherever possible (waiting for microsoft/win32metadata#1971 to trickle down into `windows-rs`). - Remove `.clone()` on COM objects (temporarily increasing the refcount) when it can be avoided by inverting the order of operations on `raw` variables.
PR #5956 wasn't fully complete and still had some outstanding minor issues and cleanups to be done, as well as hidden semantic changes. This addresses a bunch of them: - Remove unnecessary `Error` mapping to `String` as `windows-rs`'s `Error` has a more complete `Display` representation by itself. - Remove `into_result()` as every call could have formatted the `windows-rs` `Error` in a log call directly. - Pass `None` instead of a pointer to an empty slice wherever possible (waiting for microsoft/win32metadata#1971 to trickle down into `windows-rs`). - Remove `.clone()` on COM objects (temporarily increasing the refcount) when it can be avoided by inverting the order of operations on `raw` variables.
Caution
This is a draft that is still a work-in-progress! See this as a reminder that work has actively been performed to get the migration done, and to familiarize yourself (as reader) with
windows-rs
!I am still heavily self-reviewing, cleaning and refactoring this PR - reviewing will be a waste of time until this is taken out of draft!
Connections
Closes #3207 (once
wgl.rs
is also over)Fixes #5813
Description
winapi
is barely typed, doesn't care about object lifetime, and is unmaintaned above all. Microsoft officially provides up-to-date and completely typed bindings that make it much more natural, convenient, and safe to interface any API on Windows systems, including DXGI and Direct3D12! By migrating we make it much easier to write, review and maintain the d3d12 backend, and have improved interoperability with support crates likegpu-allocator
that already migrated long ago.One thing you'll also see is the
windows
crate embracingResult
and#[must_use]
- there are still a hanful of clippy errors pointing out that the original code forgot to check the returnedHRESULT
, leading to potential UB.Testing
Still in progress - a qick showdown was done using:
Checklist
cargo fmt
.cargo clippy
. If applicable, add:--target wasm32-unknown-unknown
--target wasm32-unknown-emscripten
cargo xtask test
to run tests.CHANGELOG.md
. See simple instructions inside file.TODO
windows 0.67
(with e.g. Change WindowsHANDLE
types back to*mut c_void
**again** 😩? rust-windowing/raw-window-handle#171);gpu-allocator
;enum Surface..
holders...