Skip to content

refactor(dx12): remove unsafe ops in Adapter::texture_format_capabilities #3194

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

Merged
Merged
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ use crate::{
auxil::{self, dxgi::result::HResult as _},
dx12::SurfaceTarget,
};
use std::{mem, sync::Arc, thread};
use std::{mem, ptr, sync::Arc, thread};
use winapi::{
shared::{dxgi, dxgi1_2, windef, winerror},
shared::{dxgi, dxgi1_2, minwindef::DWORD, windef, winerror},
um::{d3d12, d3d12sdklayers, winuser},
};

Expand Down Expand Up @@ -382,16 +382,17 @@ impl crate::Adapter<super::Api> for super::Adapter {
// the features that use SRV/UAVs using the no-depth format.
let mut data_no_depth = d3d12::D3D12_FEATURE_DATA_FORMAT_SUPPORT {
Format: no_depth_format,
Support1: unsafe { mem::zeroed() },
Support2: unsafe { mem::zeroed() },
Support1: d3d12::D3D12_FORMAT_SUPPORT1_NONE,
Support2: d3d12::D3D12_FORMAT_SUPPORT2_NONE,
};
if raw_format != no_depth_format {
// Only-recheck if we're using a different format
assert_eq!(winerror::S_OK, unsafe {
self.device.CheckFeatureSupport(
d3d12::D3D12_FEATURE_FORMAT_SUPPORT,
&mut data_no_depth as *mut _ as *mut _,
mem::size_of::<d3d12::D3D12_FEATURE_DATA_FORMAT_SUPPORT>() as _,
ptr::addr_of_mut!(data_no_depth).cast(),
DWORD::try_from(mem::size_of::<d3d12::D3D12_FEATURE_DATA_FORMAT_SUPPORT>())
Copy link
Member

Choose a reason for hiding this comment

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

My only hesitation is the verbosity of this

Copy link
Member Author

@ErichDonGubler ErichDonGubler Nov 14, 2022

Choose a reason for hiding this comment

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

Coming back to this with a fresh brain:

  1. RE: pointer slinging:
    1. We can definitely omit the explicit ::<c_void>. I've done so with 7c46b4b.
    2. We could fully qualify the addr_of_mut symbol, which would make this shorter and, IMO, easier to follow. In general, I think a lot of this code would be smaller with no loss of clarity (and therefore more friendly to the mental cache) without path qualifications for most symbols.
  2. RE: size_of: I've seen folks like @retep998 make utility crates for Windows specifically to convert size_of's usizes to DWORDs. Maybe adding something like an extension trait for this (in a separate PR) would be good?

Thoughts?

Copy link
Member

Choose a reason for hiding this comment

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

Honestly now that I look at this, this seems fine.

.unwrap(),
)
});
} else {
Expand Down