From 74b37916db391aeb22b411beaa17aa562e86ee56 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Thu, 3 Apr 2025 13:20:59 -0400 Subject: [PATCH] [d3d12] Move `private_capabilities` to `DeviceShared` --- wgpu-hal/src/dx12/device.rs | 8 +++++--- wgpu-hal/src/dx12/mod.rs | 3 ++- wgpu-hal/src/dx12/shader_compilation.rs | 2 ++ wgpu-hal/src/dx12/suballocation.rs | 18 +++++++++--------- 4 files changed, 18 insertions(+), 13 deletions(-) diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 290ece8efd..0cbf3ed777 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -149,6 +149,7 @@ impl super::Device { capacity_views, )?, sampler_heap: super::sampler::SamplerHeap::new(&raw, &private_caps)?, + private_caps, }; let mut rtv_pool = @@ -180,7 +181,6 @@ impl super::Device { fence: idle_fence, event: Event::create(false, false)?, }, - private_caps, features, shared: Arc::new(shared), rtv_pool: Mutex::new(rtv_pool), @@ -502,7 +502,9 @@ impl crate::Device for super::Device { desc.format, desc.usage, !desc.view_formats.is_empty(), - self.private_caps.casting_fully_typed_format_supported, + self.shared + .private_caps + .casting_fully_typed_format_supported, ), SampleDesc: Dxgi::Common::DXGI_SAMPLE_DESC { Count: desc.sample_count, @@ -1351,7 +1353,7 @@ impl crate::Device for super::Device { }, bind_group_infos, naga_options: hlsl::Options { - shader_model: self.private_caps.shader_model, + shader_model: self.shared.private_caps.shader_model, binding_map, fake_missing_bindings: false, special_constants_binding, diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index 3099e7614d..293acabcc5 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -630,6 +630,7 @@ struct DeviceShared { cmd_signatures: CommandSignatures, heap_views: descriptor::GeneralHeap, sampler_heap: sampler::SamplerHeap, + private_caps: PrivateCapabilities, } unsafe impl Send for DeviceShared {} @@ -639,7 +640,6 @@ pub struct Device { raw: Direct3D12::ID3D12Device, present_queue: Direct3D12::ID3D12CommandQueue, idler: Idler, - private_caps: PrivateCapabilities, features: wgt::Features, shared: Arc, // CPU only pools @@ -660,6 +660,7 @@ impl Drop for Device { fn drop(&mut self) { self.rtv_pool.lock().free_handle(self.null_rtv_handle); if self + .shared .private_caps .instance_flags .contains(wgt::InstanceFlags::VALIDATION) diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index 834409eefc..3aec4ccb60 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -23,6 +23,7 @@ pub(super) fn compile_fxc( let mut shader_data = None; let mut compile_flags = Fxc::D3DCOMPILE_ENABLE_STRICTNESS; if device + .shared .private_caps .instance_flags .contains(wgt::InstanceFlags::DEBUG) @@ -290,6 +291,7 @@ pub(super) fn compile_dxc( } if device + .shared .private_caps .instance_flags .contains(wgt::InstanceFlags::DEBUG) diff --git a/wgpu-hal/src/dx12/suballocation.rs b/wgpu-hal/src/dx12/suballocation.rs index 89ce6c5d0b..f4d3c0627a 100644 --- a/wgpu-hal/src/dx12/suballocation.rs +++ b/wgpu-hal/src/dx12/suballocation.rs @@ -57,7 +57,7 @@ pub(crate) fn create_buffer_resource( let is_cpu_write = desc.usage.contains(wgt::BufferUses::MAP_WRITE); // Workaround for Intel Xe drivers - if !device.private_caps.suballocation_supported { + if !device.shared.private_caps.suballocation_supported { return create_committed_buffer_resource(device, desc, raw_desc) .map(|resource| (resource, None)); } @@ -110,7 +110,7 @@ pub(crate) fn create_texture_resource( raw_desc: Direct3D12::D3D12_RESOURCE_DESC, ) -> Result<(Direct3D12::ID3D12Resource, Option), crate::DeviceError> { // Workaround for Intel Xe drivers - if !device.private_caps.suballocation_supported { + if !device.shared.private_caps.suballocation_supported { return create_committed_texture_resource(device, desc, raw_desc) .map(|resource| (resource, None)); } @@ -157,7 +157,7 @@ pub(crate) fn create_acceleration_structure_resource( raw_desc: Direct3D12::D3D12_RESOURCE_DESC, ) -> Result<(Direct3D12::ID3D12Resource, Option), crate::DeviceError> { // Workaround for Intel Xe drivers - if !device.private_caps.suballocation_supported { + if !device.shared.private_caps.suballocation_supported { return create_committed_acceleration_structure_resource(device, desc, raw_desc) .map(|resource| (resource, None)); } @@ -301,7 +301,7 @@ pub(crate) fn create_committed_buffer_resource( } else { Direct3D12::D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE }, - MemoryPoolPreference: match device.private_caps.memory_architecture { + MemoryPoolPreference: match device.shared.private_caps.memory_architecture { crate::dx12::MemoryArchitecture::NonUnified if !is_cpu_read && !is_cpu_write => { Direct3D12::D3D12_MEMORY_POOL_L1 } @@ -316,7 +316,7 @@ pub(crate) fn create_committed_buffer_resource( unsafe { device.raw.CreateCommittedResource( &heap_properties, - if device.private_caps.heap_create_not_zeroed { + if device.shared.private_caps.heap_create_not_zeroed { Direct3D12::D3D12_HEAP_FLAG_CREATE_NOT_ZEROED } else { Direct3D12::D3D12_HEAP_FLAG_NONE @@ -340,7 +340,7 @@ pub(crate) fn create_committed_texture_resource( let heap_properties = Direct3D12::D3D12_HEAP_PROPERTIES { Type: Direct3D12::D3D12_HEAP_TYPE_CUSTOM, CPUPageProperty: Direct3D12::D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE, - MemoryPoolPreference: match device.private_caps.memory_architecture { + MemoryPoolPreference: match device.shared.private_caps.memory_architecture { crate::dx12::MemoryArchitecture::NonUnified => Direct3D12::D3D12_MEMORY_POOL_L1, crate::dx12::MemoryArchitecture::Unified { .. } => Direct3D12::D3D12_MEMORY_POOL_L0, }, @@ -353,7 +353,7 @@ pub(crate) fn create_committed_texture_resource( unsafe { device.raw.CreateCommittedResource( &heap_properties, - if device.private_caps.heap_create_not_zeroed { + if device.shared.private_caps.heap_create_not_zeroed { Direct3D12::D3D12_HEAP_FLAG_CREATE_NOT_ZEROED } else { Direct3D12::D3D12_HEAP_FLAG_NONE @@ -377,7 +377,7 @@ pub(crate) fn create_committed_acceleration_structure_resource( let heap_properties = Direct3D12::D3D12_HEAP_PROPERTIES { Type: Direct3D12::D3D12_HEAP_TYPE_CUSTOM, CPUPageProperty: Direct3D12::D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE, - MemoryPoolPreference: match device.private_caps.memory_architecture { + MemoryPoolPreference: match device.shared.private_caps.memory_architecture { crate::dx12::MemoryArchitecture::NonUnified => Direct3D12::D3D12_MEMORY_POOL_L1, _ => Direct3D12::D3D12_MEMORY_POOL_L0, }, @@ -390,7 +390,7 @@ pub(crate) fn create_committed_acceleration_structure_resource( unsafe { device.raw.CreateCommittedResource( &heap_properties, - if device.private_caps.heap_create_not_zeroed { + if device.shared.private_caps.heap_create_not_zeroed { Direct3D12::D3D12_HEAP_FLAG_CREATE_NOT_ZEROED } else { Direct3D12::D3D12_HEAP_FLAG_NONE