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

Port to d3d12 0.7 with ownership #3936

Merged
merged 1 commit into from
Jul 18, 2023
Merged
Show file tree
Hide file tree
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
9 changes: 5 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion wgpu-hal/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ gpu-allocator = { version = "0.22", default_features = false, features = ["d3d12
hassle-rs = { version = "0.10", optional = true }

winapi = { version = "0.3", features = ["profileapi", "libloaderapi", "windef", "winuser", "dcomp"] }
d3d12 = { version = "0.6.0", git = "https://github.com/gfx-rs/d3d12-rs", rev = "b940b1d71", features = ["libloading"], optional = true }
d3d12 = { version = "0.7", features = ["libloading"], optional = true }

[target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies]
# backend: Metal
Expand Down
15 changes: 3 additions & 12 deletions wgpu-hal/src/auxil/dxgi/factory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ pub fn enumerate_adapters(factory: d3d12::DxgiFactory) -> Vec<d3d12::DxgiAdapter
if let Some(factory6) = factory.as_factory6() {
profiling::scope!("IDXGIFactory6::EnumAdapterByGpuPreference");
// We're already at dxgi1.6, we can grab IDXGIAdapater4 directly
let mut adapter4 = d3d12::WeakPtr::<dxgi1_6::IDXGIAdapter4>::null();
let mut adapter4 = d3d12::ComPtr::<dxgi1_6::IDXGIAdapter4>::null();
let hr = unsafe {
factory6.EnumAdapterByGpuPreference(
cur_index,
Expand All @@ -43,7 +43,7 @@ pub fn enumerate_adapters(factory: d3d12::DxgiFactory) -> Vec<d3d12::DxgiAdapter
}

profiling::scope!("IDXGIFactory1::EnumAdapters1");
let mut adapter1 = d3d12::WeakPtr::<dxgi::IDXGIAdapter1>::null();
let mut adapter1 = d3d12::ComPtr::<dxgi::IDXGIAdapter1>::null();
let hr = unsafe { factory.EnumAdapters1(cur_index, adapter1.mut_self()) };

if hr == winerror::DXGI_ERROR_NOT_FOUND {
Expand All @@ -60,7 +60,6 @@ pub fn enumerate_adapters(factory: d3d12::DxgiFactory) -> Vec<d3d12::DxgiAdapter
unsafe {
match adapter1.cast::<dxgi1_4::IDXGIAdapter3>().into_result() {
Ok(adapter3) => {
adapter1.destroy();
adapters.push(d3d12::DxgiAdapter::Adapter3(adapter3));
continue;
}
Expand All @@ -74,7 +73,6 @@ pub fn enumerate_adapters(factory: d3d12::DxgiFactory) -> Vec<d3d12::DxgiAdapter
unsafe {
match adapter1.cast::<dxgi1_2::IDXGIAdapter2>().into_result() {
Ok(adapter2) => {
adapter1.destroy();
adapters.push(d3d12::DxgiAdapter::Adapter2(adapter2));
continue;
}
Expand Down Expand Up @@ -107,8 +105,7 @@ pub fn create_factory(
// we check for whether it exists first.
match lib_dxgi.get_debug_interface1() {
Ok(pair) => match pair.into_result() {
Ok(debug_controller) => {
unsafe { debug_controller.destroy() };
Ok(_debug_controller) => {
factory_flags |= d3d12::FactoryCreationFlags::DEBUG;
}
Err(err) => {
Expand Down Expand Up @@ -151,9 +148,6 @@ pub fn create_factory(
let factory6 = unsafe { factory4.cast::<dxgi1_6::IDXGIFactory6>().into_result() };
match factory6 {
Ok(factory6) => {
unsafe {
factory4.destroy();
}
return Ok((lib_dxgi, d3d12::DxgiFactory::Factory6(factory6)));
}
// If we require factory6, hard error.
Expand Down Expand Up @@ -189,9 +183,6 @@ pub fn create_factory(
let factory2 = unsafe { factory1.cast::<dxgi1_2::IDXGIFactory2>().into_result() };
match factory2 {
Ok(factory2) => {
unsafe {
factory1.destroy();
}
return Ok((lib_dxgi, d3d12::DxgiFactory::Factory2(factory2)));
}
// If we require factory2, hard error.
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx11/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl crate::Instance<super::Api> for super::Instance {
}

unsafe fn enumerate_adapters(&self) -> Vec<crate::ExposedAdapter<super::Api>> {
let adapters = auxil::dxgi::factory::enumerate_adapters(self.factory);
let adapters = auxil::dxgi::factory::enumerate_adapters(self.factory.clone());

adapters
.into_iter()
Expand Down
4 changes: 1 addition & 3 deletions wgpu-hal/src/dx11/library.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ impl D3D11Lib {
d3dcommon::D3D_FEATURE_LEVEL_9_1,
];

let mut device = d3d12::WeakPtr::<d3d11::ID3D11Device>::null();
let mut device = d3d12::ComPtr::<d3d11::ID3D11Device>::null();
let mut feature_level: d3dcommon::D3D_FEATURE_LEVEL = 0;

// We need to try this twice. If the first time fails due to E_INVALIDARG
Expand Down Expand Up @@ -117,7 +117,6 @@ impl D3D11Lib {
unsafe {
match device.cast::<d3d11_2::ID3D11Device2>().into_result() {
Ok(device2) => {
device.destroy();
return Some((super::D3D11Device::Device2(device2), feature_level));
}
Err(hr) => {
Expand All @@ -130,7 +129,6 @@ impl D3D11Lib {
unsafe {
match device.cast::<d3d11_1::ID3D11Device1>().into_result() {
Ok(device1) => {
device.destroy();
return Some((super::D3D11Device::Device1(device1), feature_level));
}
Err(hr) => {
Expand Down
2 changes: 1 addition & 1 deletion wgpu-hal/src/dx11/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ unsafe impl Send for Adapter {}
unsafe impl Sync for Adapter {}

d3d12::weak_com_inheritance_chain! {
#[derive(Debug, Copy, Clone, PartialEq)]
#[derive(Debug, Clone, PartialEq)]
enum D3D11Device {
Device(d3d11::ID3D11Device), from_device, as_device, device;
Device1(d3d11_1::ID3D11Device1), from_device1, as_device1, unwrap_device1;
Expand Down
10 changes: 3 additions & 7 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,6 @@ impl Drop for super::Adapter {
self.report_live_objects();
}
}
unsafe {
self.raw.destroy();
}
}
}

Expand All @@ -39,7 +36,6 @@ impl super::Adapter {
d3d12sdklayers::D3D12_RLDO_SUMMARY | d3d12sdklayers::D3D12_RLDO_IGNORE_INTERNAL,
)
};
unsafe { debug_device.destroy() };
}
}

Expand All @@ -57,7 +53,7 @@ impl super::Adapter {
// Create the device so that we can get the capabilities.
let device = {
profiling::scope!("ID3D12Device::create_device");
match library.create_device(*adapter, d3d12::FeatureLevel::L11_0) {
match library.create_device(&adapter, d3d12::FeatureLevel::L11_0) {
Ok(pair) => match pair.into_result() {
Ok(device) => device,
Err(err) => {
Expand Down Expand Up @@ -396,8 +392,8 @@ impl crate::Adapter<super::Api> for super::Adapter {
};

let device = super::Device::new(
self.device,
queue,
self.device.clone(),
queue.clone(),
self.private_caps,
&self.library,
self.dx12_shader_compiler.clone(),
Expand Down
Loading