diff --git a/Cargo.lock b/Cargo.lock index bfc1b4a9db6..a023f16f7dd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -891,7 +891,6 @@ version = "0.7.0" dependencies = [ "bitflags 2.4.1", "libloading 0.8.1", - "winapi", ] [[package]] @@ -1619,7 +1618,7 @@ dependencies = [ "presser", "thiserror", "winapi", - "windows", + "windows 0.44.0", ] [[package]] diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index 0f0b22b004a..f5ca0a30591 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -116,7 +116,7 @@ use thiserror::Error; pub(crate) use buffer::{BufferBindGroupState, BufferTracker, BufferUsageScope}; use metadata::{ResourceMetadata, ResourceMetadataProvider}; -pub(crate) use stateless::{StatelessBindGroupSate, StatelessTracker}; +pub(crate) use stateless::{StatelessBindGroupState, StatelessTracker}; pub(crate) use texture::{ TextureBindGroupState, TextureSelector, TextureTracker, TextureUsageScope, }; @@ -325,8 +325,8 @@ impl fmt::Display for InvalidUse { pub(crate) struct BindGroupStates { pub buffers: BufferBindGroupState, pub textures: TextureBindGroupState, - pub views: StatelessBindGroupSate>, - pub samplers: StatelessBindGroupSate>, + pub views: StatelessBindGroupState>, + pub samplers: StatelessBindGroupState>, } impl BindGroupStates { @@ -334,8 +334,8 @@ impl BindGroupStates { Self { buffers: BufferBindGroupState::new(), textures: TextureBindGroupState::new(), - views: StatelessBindGroupSate::new(), - samplers: StatelessBindGroupSate::new(), + views: StatelessBindGroupState::new(), + samplers: StatelessBindGroupState::new(), } } diff --git a/wgpu-core/src/track/stateless.rs b/wgpu-core/src/track/stateless.rs index b33905f5125..6f10025d05e 100644 --- a/wgpu-core/src/track/stateless.rs +++ b/wgpu-core/src/track/stateless.rs @@ -17,11 +17,11 @@ use super::ResourceTracker; /// Stores all the resources that a bind group stores. #[derive(Debug)] -pub(crate) struct StatelessBindGroupSate> { +pub(crate) struct StatelessBindGroupState> { resources: Mutex)>>, } -impl> StatelessBindGroupSate { +impl> StatelessBindGroupState { pub fn new() -> Self { Self { resources: Mutex::new(Vec::new()), diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml index d715bf58d54..9249ad22ced 100644 --- a/wgpu-hal/Cargo.toml +++ b/wgpu-hal/Cargo.toml @@ -48,6 +48,7 @@ dx12 = [ "naga/hlsl-out", "d3d12", "bit-set", + "gpu-allocator", "libloading", "range-alloc", "winapi/std", @@ -56,6 +57,7 @@ dx12 = [ "winapi/d3d12shader", "winapi/d3d12sdklayers", "winapi/dxgi1_6", + "winapi/errhandlingapi", ] # TODO: This is a separate feature until Mozilla okays windows-rs, see https://github.com/gfx-rs/wgpu/issues/3207 for the tracking issue. windows_rs = ["gpu-allocator"] @@ -130,6 +132,16 @@ winapi = { version = "0.3", features = [ d3d12 = { path = "../d3d12/", version = "0.7.0", optional = true, features = [ "libloading", ] } +windows = { version = "0.48.0", features = [ + "Win32_Foundation", + "Win32_Graphics_Direct3D", + "Win32_Graphics_Direct3D12", + "Win32_Graphics_Direct3D_Fxc", + "Win32_Graphics_Dxgi", + "Win32_Graphics_Dxgi_Common", + "Win32_Security", + "Win32_System_Threading", +] } [target.'cfg(any(target_os="macos", target_os="ios"))'.dependencies] # backend: Metal diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 1db9b0877da..79e92a7553b 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -4,12 +4,6 @@ use crate::{ }; use parking_lot::Mutex; use std::{mem, ptr, sync::Arc, thread}; -use winapi::{ - shared::{ - dxgi, dxgi1_2, dxgiformat::DXGI_FORMAT_B8G8R8A8_UNORM, minwindef::DWORD, windef, winerror, - }, - um::{d3d12 as d3d12_ty, d3d12sdklayers, winuser}, -}; impl Drop for super::Adapter { fn drop(&mut self) { @@ -29,15 +23,9 @@ impl Drop for super::Adapter { impl super::Adapter { pub unsafe fn report_live_objects(&self) { - if let Ok(debug_device) = unsafe { - self.raw - .cast::() - .into_result() - } { + if let Ok(debug_device) = unsafe { self.raw.as_debug_device() } { unsafe { - debug_device.ReportLiveDeviceObjects( - d3d12sdklayers::D3D12_RLDO_SUMMARY | d3d12sdklayers::D3D12_RLDO_IGNORE_INTERNAL, - ) + debug_device.report_live_device_objects(RldoFlags::SUMMARY | RldoFlags::INTERNAL) }; } } diff --git a/wgpu-hal/src/dx12/command.rs b/wgpu-hal/src/dx12/command.rs index c5d0d16b2c5..c6db494df8c 100644 --- a/wgpu-hal/src/dx12/command.rs +++ b/wgpu-hal/src/dx12/command.rs @@ -2,7 +2,6 @@ use crate::auxil::{self, dxgi::result::HResult as _}; use super::conv; use std::{mem, ops::Range, ptr}; -use winapi::um::d3d12 as d3d12_ty; fn make_box(origin: &wgt::Origin3d, size: &crate::CopyExtent) -> d3d12_ty::D3D12_BOX { d3d12_ty::D3D12_BOX { diff --git a/wgpu-hal/src/dx12/conv.rs b/wgpu-hal/src/dx12/conv.rs index 2b6c1d959e0..9b247856984 100644 --- a/wgpu-hal/src/dx12/conv.rs +++ b/wgpu-hal/src/dx12/conv.rs @@ -1,8 +1,4 @@ use std::iter; -use winapi::{ - shared::minwindef::BOOL, - um::{d3d12 as d3d12_ty, d3dcommon}, -}; pub fn map_buffer_usage_to_resource_flags( usage: crate::BufferUses, diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 74cc09d6cd0..bb7e6e31be2 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -6,11 +6,6 @@ use crate::{ use super::{conv, descriptor, view}; use parking_lot::Mutex; use std::{ffi, mem, num::NonZeroU32, ptr, sync::Arc}; -use winapi::{ - shared::{dxgiformat, dxgitype, minwindef::BOOL, winerror}, - um::{d3d12 as d3d12_ty, synchapi, winbase}, - Interface, -}; // this has to match Naga's HLSL backend, and also needs to be null-terminated const NAGA_LOCATION_SEMANTIC: &[u8] = b"LOC\0"; diff --git a/wgpu-hal/src/dx12/instance.rs b/wgpu-hal/src/dx12/instance.rs index 7bf5f3ef755..ce28d589880 100644 --- a/wgpu-hal/src/dx12/instance.rs +++ b/wgpu-hal/src/dx12/instance.rs @@ -1,5 +1,4 @@ use parking_lot::RwLock; -use winapi::shared::{dxgi1_5, minwindef}; use super::SurfaceTarget; use crate::auxil::{self, dxgi::result::HResult as _}; diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index e0cd1c15cf6..d2c3f7d8048 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -49,11 +49,6 @@ use crate::auxil::{self, dxgi::result::HResult as _}; use arrayvec::ArrayVec; use parking_lot::{Mutex, RwLock}; use std::{ffi, fmt, mem, num::NonZeroU32, sync::Arc}; -use winapi::{ - shared::{dxgi, dxgi1_4, dxgitype, windef, winerror}, - um::{d3d12 as d3d12_ty, dcomp, synchapi, winbase, winnt}, - Interface as _, -}; #[derive(Clone, Debug)] pub struct Api; diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index a034f54a7fc..c1717d5f5fe 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -1,7 +1,6 @@ use std::ptr; pub(super) use dxc::{compile_dxc, get_dxc_container, DxcContainer}; -use winapi::um::d3dcompiler; use crate::auxil::dxgi::result::HResult; diff --git a/wgpu-hal/src/dx12/suballocation.rs b/wgpu-hal/src/dx12/suballocation.rs index 3b9696e4555..75b1a89e0e1 100644 --- a/wgpu-hal/src/dx12/suballocation.rs +++ b/wgpu-hal/src/dx12/suballocation.rs @@ -3,30 +3,13 @@ pub(crate) use allocation::{ free_buffer_allocation, free_texture_allocation, AllocationWrapper, GpuAllocatorWrapper, }; -#[cfg(not(feature = "windows_rs"))] -use committed as allocation; -#[cfg(feature = "windows_rs")] +// TODO: inline module use placed as allocation; -// This exists to work around https://github.com/gfx-rs/wgpu/issues/3207 -// Currently this will work the older, slower way if the windows_rs feature is disabled, -// and will use the fast path of suballocating buffers and textures using gpu_allocator if -// the windows_rs feature is enabled. - -// This is the fast path using gpu_allocator to suballocate buffers and textures. -#[cfg(feature = "windows_rs")] mod placed { - use d3d12::ComPtr; use parking_lot::Mutex; use std::ptr; use wgt::assertions::StrictAssertUnwrapExt; - use winapi::{ - um::{ - d3d12::{self as d3d12_ty, ID3D12Resource}, - winnt::HRESULT, - }, - Interface, - }; use gpu_allocator::{ d3d12::{AllocationCreateDesc, ToWinapi, ToWindows}, @@ -44,12 +27,10 @@ mod placed { } pub(crate) fn create_allocator_wrapper( - raw: &d3d12::Device, + device: &d3d12::Device, ) -> Result>, crate::DeviceError> { - let device = raw.as_ptr(); - match gpu_allocator::d3d12::Allocator::new(&gpu_allocator::d3d12::AllocatorCreateDesc { - device: gpu_allocator::d3d12::ID3D12DeviceVersion::Device(device.as_windows().clone()), + device: gpu_allocator::d3d12::ID3D12DeviceVersion::Device(device.clone()), debug_settings: Default::default(), allocation_sizes: gpu_allocator::AllocationSizes::default(), }) { @@ -219,135 +200,3 @@ mod placed { } } } - -// This is the older, slower path where it doesn't suballocate buffers. -// Tracking issue for when it can be removed: https://github.com/gfx-rs/wgpu/issues/3207 -mod committed { - use d3d12::ComPtr; - use parking_lot::Mutex; - use std::ptr; - use winapi::{ - um::{ - d3d12::{self as d3d12_ty, ID3D12Resource}, - winnt::HRESULT, - }, - Interface, - }; - - // https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_heap_flags - const D3D12_HEAP_FLAG_CREATE_NOT_ZEROED: d3d12_ty::D3D12_HEAP_FLAGS = 0x1000; - - // Allocator isn't needed when not suballocating with gpu_allocator - #[derive(Debug)] - pub(crate) struct GpuAllocatorWrapper {} - - // Allocations aren't needed when not suballocating with gpu_allocator - #[derive(Debug)] - pub(crate) struct AllocationWrapper {} - - #[allow(unused)] - pub(crate) fn create_allocator_wrapper( - _raw: &d3d12::Device, - ) -> Result>, crate::DeviceError> { - Ok(None) - } - - pub(crate) fn create_buffer_resource( - device: &crate::dx12::Device, - desc: &crate::BufferDescriptor, - raw_desc: d3d12_ty::D3D12_RESOURCE_DESC, - resource: &mut ComPtr, - ) -> Result<(HRESULT, Option), crate::DeviceError> { - let is_cpu_read = desc.usage.contains(crate::BufferUses::MAP_READ); - let is_cpu_write = desc.usage.contains(crate::BufferUses::MAP_WRITE); - - let heap_properties = d3d12_ty::D3D12_HEAP_PROPERTIES { - Type: d3d12_ty::D3D12_HEAP_TYPE_CUSTOM, - CPUPageProperty: if is_cpu_read { - d3d12_ty::D3D12_CPU_PAGE_PROPERTY_WRITE_BACK - } else if is_cpu_write { - d3d12_ty::D3D12_CPU_PAGE_PROPERTY_WRITE_COMBINE - } else { - d3d12_ty::D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE - }, - MemoryPoolPreference: match device.private_caps.memory_architecture { - crate::dx12::MemoryArchitecture::NonUnified if !is_cpu_read && !is_cpu_write => { - d3d12_ty::D3D12_MEMORY_POOL_L1 - } - _ => d3d12_ty::D3D12_MEMORY_POOL_L0, - }, - CreationNodeMask: 0, - VisibleNodeMask: 0, - }; - - let hr = unsafe { - device.raw.CreateCommittedResource( - &heap_properties, - if device.private_caps.heap_create_not_zeroed { - D3D12_HEAP_FLAG_CREATE_NOT_ZEROED - } else { - d3d12_ty::D3D12_HEAP_FLAG_NONE - }, - &raw_desc, - d3d12_ty::D3D12_RESOURCE_STATE_COMMON, - ptr::null(), - &d3d12_ty::ID3D12Resource::uuidof(), - resource.mut_void(), - ) - }; - - Ok((hr, None)) - } - - pub(crate) fn create_texture_resource( - device: &crate::dx12::Device, - _desc: &crate::TextureDescriptor, - raw_desc: d3d12_ty::D3D12_RESOURCE_DESC, - resource: &mut ComPtr, - ) -> Result<(HRESULT, Option), crate::DeviceError> { - let heap_properties = d3d12_ty::D3D12_HEAP_PROPERTIES { - Type: d3d12_ty::D3D12_HEAP_TYPE_CUSTOM, - CPUPageProperty: d3d12_ty::D3D12_CPU_PAGE_PROPERTY_NOT_AVAILABLE, - MemoryPoolPreference: match device.private_caps.memory_architecture { - crate::dx12::MemoryArchitecture::NonUnified => d3d12_ty::D3D12_MEMORY_POOL_L1, - crate::dx12::MemoryArchitecture::Unified { .. } => d3d12_ty::D3D12_MEMORY_POOL_L0, - }, - CreationNodeMask: 0, - VisibleNodeMask: 0, - }; - - let hr = unsafe { - device.raw.CreateCommittedResource( - &heap_properties, - if device.private_caps.heap_create_not_zeroed { - D3D12_HEAP_FLAG_CREATE_NOT_ZEROED - } else { - d3d12_ty::D3D12_HEAP_FLAG_NONE - }, - &raw_desc, - d3d12_ty::D3D12_RESOURCE_STATE_COMMON, - ptr::null(), // clear value - &d3d12_ty::ID3D12Resource::uuidof(), - resource.mut_void(), - ) - }; - - Ok((hr, None)) - } - - #[allow(unused)] - pub(crate) fn free_buffer_allocation( - _allocation: AllocationWrapper, - _allocator: &Mutex, - ) { - // No-op when not using gpu-allocator - } - - #[allow(unused)] - pub(crate) fn free_texture_allocation( - _allocation: AllocationWrapper, - _allocator: &Mutex, - ) { - // No-op when not using gpu-allocator - } -} diff --git a/wgpu-hal/src/dx12/types.rs b/wgpu-hal/src/dx12/types.rs index b4ad38324a6..4054cab4841 100644 --- a/wgpu-hal/src/dx12/types.rs +++ b/wgpu-hal/src/dx12/types.rs @@ -1,43 +1,43 @@ -#![allow(non_camel_case_types)] -#![allow(non_snake_case)] - -// use here so that the recursive RIDL macro can find the crate -use winapi::um::unknwnbase::{IUnknown, IUnknownVtbl}; -use winapi::RIDL; - -RIDL! {#[uuid(0x63aad0b8, 0x7c24, 0x40ff, 0x85, 0xa8, 0x64, 0x0d, 0x94, 0x4c, 0xc3, 0x25)] -interface ISwapChainPanelNative(ISwapChainPanelNativeVtbl): IUnknown(IUnknownVtbl) { - fn SetSwapChain(swapChain: *const winapi::shared::dxgi1_2::IDXGISwapChain1,) -> winapi::um::winnt::HRESULT, -}} - -winapi::ENUM! { - enum D3D12_VIEW_INSTANCING_TIER { - D3D12_VIEW_INSTANCING_TIER_NOT_SUPPORTED = 0, - D3D12_VIEW_INSTANCING_TIER_1 = 1, - D3D12_VIEW_INSTANCING_TIER_2 = 2, - D3D12_VIEW_INSTANCING_TIER_3 = 3, - } -} - -winapi::ENUM! { - enum D3D12_COMMAND_LIST_SUPPORT_FLAGS { - D3D12_COMMAND_LIST_SUPPORT_FLAG_NONE = 0, - // D3D12_COMMAND_LIST_SUPPORT_FLAG_DIRECT, - // D3D12_COMMAND_LIST_SUPPORT_FLAG_BUNDLE, - // D3D12_COMMAND_LIST_SUPPORT_FLAG_COMPUTE, - // D3D12_COMMAND_LIST_SUPPORT_FLAG_COPY, - // D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_DECODE, - // D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_PROCESS, - // D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_ENCODE, - } -} - -winapi::STRUCT! { - struct D3D12_FEATURE_DATA_D3D12_OPTIONS3 { - CopyQueueTimestampQueriesSupported: winapi::shared::minwindef::BOOL, - CastingFullyTypedFormatSupported: winapi::shared::minwindef::BOOL, - WriteBufferImmediateSupportFlags: D3D12_COMMAND_LIST_SUPPORT_FLAGS, - ViewInstancingTier: D3D12_VIEW_INSTANCING_TIER, - BarycentricsSupported: winapi::shared::minwindef::BOOL, - } -} +// #![allow(non_camel_case_types)] +// #![allow(non_snake_case)] +// +// // use here so that the recursive RIDL macro can find the crate +// use winapi::um::unknwnbase::{IUnknown, IUnknownVtbl}; +// use winapi::RIDL; +// +// RIDL! {#[uuid(0x63aad0b8, 0x7c24, 0x40ff, 0x85, 0xa8, 0x64, 0x0d, 0x94, 0x4c, 0xc3, 0x25)] +// interface ISwapChainPanelNative(ISwapChainPanelNativeVtbl): IUnknown(IUnknownVtbl) { +// fn SetSwapChain(swapChain: *const winapi::shared::dxgi1_2::IDXGISwapChain1,) -> winapi::um::winnt::HRESULT, +// }} +// +// winapi::ENUM! { +// enum D3D12_VIEW_INSTANCING_TIER { +// D3D12_VIEW_INSTANCING_TIER_NOT_SUPPORTED = 0, +// D3D12_VIEW_INSTANCING_TIER_1 = 1, +// D3D12_VIEW_INSTANCING_TIER_2 = 2, +// D3D12_VIEW_INSTANCING_TIER_3 = 3, +// } +// } +// +// winapi::ENUM! { +// enum D3D12_COMMAND_LIST_SUPPORT_FLAGS { +// D3D12_COMMAND_LIST_SUPPORT_FLAG_NONE = 0, +// // D3D12_COMMAND_LIST_SUPPORT_FLAG_DIRECT, +// // D3D12_COMMAND_LIST_SUPPORT_FLAG_BUNDLE, +// // D3D12_COMMAND_LIST_SUPPORT_FLAG_COMPUTE, +// // D3D12_COMMAND_LIST_SUPPORT_FLAG_COPY, +// // D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_DECODE, +// // D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_PROCESS, +// // D3D12_COMMAND_LIST_SUPPORT_FLAG_VIDEO_ENCODE, +// } +// } +// +// winapi::STRUCT! { +// struct D3D12_FEATURE_DATA_D3D12_OPTIONS3 { +// CopyQueueTimestampQueriesSupported: winapi::shared::minwindef::BOOL, +// CastingFullyTypedFormatSupported: winapi::shared::minwindef::BOOL, +// WriteBufferImmediateSupportFlags: D3D12_COMMAND_LIST_SUPPORT_FLAGS, +// ViewInstancingTier: D3D12_VIEW_INSTANCING_TIER, +// BarycentricsSupported: winapi::shared::minwindef::BOOL, +// } +// } diff --git a/wgpu-hal/src/dx12/view.rs b/wgpu-hal/src/dx12/view.rs index 6cbad7bd1d3..4b08db4075c 100644 --- a/wgpu-hal/src/dx12/view.rs +++ b/wgpu-hal/src/dx12/view.rs @@ -1,6 +1,5 @@ use crate::auxil; use std::mem; -use winapi::um::d3d12 as d3d12_ty; pub(crate) const D3D12_DEFAULT_SHADER_4_COMPONENT_MAPPING: u32 = 0x1688; diff --git a/wgpu/Cargo.toml b/wgpu/Cargo.toml index ef199068e1e..6b9a2a1d7b3 100644 --- a/wgpu/Cargo.toml +++ b/wgpu/Cargo.toml @@ -145,7 +145,6 @@ hal = { workspace = true, features = ["renderdoc"] } hal = { workspace = true, features = [ "dxc_shader_compiler", "renderdoc", - "windows_rs", ] } [target.'cfg(target_arch = "wasm32")'.dependencies.hal] @@ -313,4 +312,4 @@ web-sys = { workspace = true, features = [ wasm-bindgen.workspace = true js-sys.workspace = true wasm-bindgen-futures.workspace = true -parking_lot.workspace = true +parking_lot.workspace = true \ No newline at end of file