From ea8d65a5718316b892371d67c05bb624d65921a2 Mon Sep 17 00:00:00 2001 From: Marijn Suijten Date: Wed, 2 Jul 2025 11:18:42 +0200 Subject: [PATCH] [d3d12 wgl] Upgrade to `windows 0.59` crates https://github.com/microsoft/windows-rs/releases/tag/0.61.0 The latest `windows 0.59` and `windows-core 0.59` crates were just released (strangely tagged `0.61`), including some minor code improvements for us. The MSRV has been bumped to `1.74`, but `wgpu` is already on `1.76` anyway. --- Cargo.lock | 64 ++++++++++++++++++++++++------ Cargo.toml | 12 ++++-- wgpu-hal/src/dx12/command.rs | 19 ++------- wgpu-hal/src/dx12/device.rs | 2 +- wgpu-hal/src/dx12/mod.rs | 2 +- wgpu-hal/src/dx12/suballocation.rs | 3 +- wgpu-hal/src/gles/wgl.rs | 12 +++--- 7 files changed, 75 insertions(+), 39 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index bc45233ccb4..6c970be97b3 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1835,8 +1835,7 @@ dependencies = [ [[package]] name = "gpu-allocator" version = "0.27.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "c151a2a5ef800297b4e79efa4f4bec035c5f51d5ae587287c9b952bdf734cacd" +source = "git+https://github.com/Traverse-Research/gpu-allocator?rev=955b13a#955b13a45bff8308b48d553032f9d6216c0e57e6" dependencies = [ "log", "presser", @@ -3902,12 +3901,12 @@ dependencies = [ [[package]] name = "socket2" -version = "0.5.10" +version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e22376abed350d73dd1cd119b57ffccad95b4e585a7cda43e286245ce23c0678" +checksum = "233504af464074f9d066d7b5416c5f9b894a5862a6506e306f7b816cdd6f1807" dependencies = [ "libc", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -4200,8 +4199,7 @@ dependencies = [ [[package]] name = "tokio" version = "1.46.1" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0cc3a2344dafbe23a245241fe8b09735b521110d30fcefbbd5feb1797ca35d17" +source = "git+https://github.com/tokio-rs/tokio?rev=aff24df#aff24dfbebf79c698abf16db24930d478c099252" dependencies = [ "backtrace", "bytes", @@ -4214,14 +4212,13 @@ dependencies = [ "slab", "socket2", "tokio-macros", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] name = "tokio-macros" version = "2.5.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" +source = "git+https://github.com/tokio-rs/tokio?rev=aff24df#aff24dfbebf79c698abf16db24930d478c099252" dependencies = [ "proc-macro2", "quote", @@ -5040,8 +5037,8 @@ dependencies = [ "wasm-bindgen", "web-sys", "wgpu-types", - "windows 0.58.0", - "windows-core 0.58.0", + "windows 0.59.0", + "windows-core 0.59.0", "winit 0.29.15", ] @@ -5199,6 +5196,16 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "7f919aee0a93304be7f62e8e5027811bbba96bcb1de84d6618be56e43f8a32a1" +dependencies = [ + "windows-core 0.59.0", + "windows-targets 0.53.2", +] + [[package]] name = "windows" version = "0.61.3" @@ -5234,6 +5241,19 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-core" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "810ce18ed2112484b0d4e15d022e5f598113e220c53e373fb31e67e21670c1ce" +dependencies = [ + "windows-implement 0.59.0", + "windows-interface 0.59.1", + "windows-result 0.3.4", + "windows-strings 0.3.1", + "windows-targets 0.53.2", +] + [[package]] name = "windows-core" version = "0.61.2" @@ -5269,6 +5289,17 @@ dependencies = [ "syn", ] +[[package]] +name = "windows-implement" +version = "0.59.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "83577b051e2f49a058c308f17f273b570a6a758386fc291b5f6a934dd84e48c1" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "windows-implement" version = "0.60.0" @@ -5346,6 +5377,15 @@ dependencies = [ "windows-targets 0.52.6", ] +[[package]] +name = "windows-strings" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "87fa48cc5d406560701792be122a10132491cff9d0aeb23583cc2dcafc847319" +dependencies = [ + "windows-link", +] + [[package]] name = "windows-strings" version = "0.4.2" diff --git a/Cargo.toml b/Cargo.toml index 52ef5175772..523ede523a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -165,7 +165,7 @@ pp-rs = "0.2.1" profiling = { version = "1", default-features = false } quote = "1.0.38" raw-window-handle = { version = "0.6.2", default-features = false } -rwh_05 = { version = "0.5.2", package = "raw-window-handle" } # temporary compatibility for glutin-winit +rwh_05 = { version = "0.5.2", package = "raw-window-handle" } # temporary compatibility for glutin-winit rayon = "1.3" regex-lite = "0.1" renderdoc-sys = "1" @@ -209,7 +209,7 @@ gpu-descriptor = "0.3.2" gpu-allocator = { version = "0.27", default-features = false } range-alloc = "0.1" mach-dxcompiler-rs = { version = "0.1.4", default-features = false } # remember to increase max_shader_model if applicable -windows-core = { version = "0.58", default-features = false } +windows-core = { version = "0.59", default-features = false } # Gles dependencies khronos-egl = "6" @@ -219,7 +219,7 @@ glutin-winit = { version = "0.4", default-features = false } glutin_wgl_sys = "0.6" # DX12 and GLES dependencies -windows = { version = "0.58", default-features = false } +windows = { version = "0.59", default-features = false } # wasm32 dependencies console_error_panic_hook = "0.1.5" @@ -250,6 +250,12 @@ ndk-sys = "0.6" [patch.crates-io] wgpu = { path = "./wgpu" } +# https://github.com/Traverse-Research/gpu-allocator/pull/258 +gpu-allocator = { git = "https://github.com/Traverse-Research/gpu-allocator", rev = "955b13a" } + +# https://github.com/tokio-rs/tokio/pull/7117 +tokio = { git = "https://github.com/tokio-rs/tokio", rev = "aff24df" } + [profile.release] lto = "thin" debug = true diff --git a/wgpu-hal/src/dx12/command.rs b/wgpu-hal/src/dx12/command.rs index f57e6b9238a..f7b8939c7ab 100644 --- a/wgpu-hal/src/dx12/command.rs +++ b/wgpu-hal/src/dx12/command.rs @@ -5,13 +5,13 @@ use windows::Win32::{ Foundation, Graphics::{Direct3D12, Dxgi}, }; -use windows_core::Interface; +use windows_core::Interface as _; use super::conv; use crate::{ auxil::{ self, - dxgi::{name::ObjectExt, result::HResult as _}, + dxgi::{name::ObjectExt as _, result::HResult as _}, }, dx12::borrow_interface_temporarily, AccelerationStructureEntries, @@ -864,23 +864,12 @@ impl crate::CommandEncoder for super::CommandEncoder { if let Some(ds_view) = ds_view { if flags != Direct3D12::D3D12_CLEAR_FLAGS::default() { unsafe { - // list.ClearDepthStencilView( - // ds_view, - // flags, - // ds.clear_value.0, - // ds.clear_value.1 as u8, - // None, - // ) - // TODO: Replace with the above in the next breaking windows-rs release, - // when https://github.com/microsoft/win32metadata/pull/1971 is in. - (Interface::vtable(list).ClearDepthStencilView)( - Interface::as_raw(list), + list.ClearDepthStencilView( ds_view, flags, ds.clear_value.0, ds.clear_value.1 as u8, - 0, - core::ptr::null(), + None, ) } } diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 24cd3826d4b..5a3b92b305c 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -23,7 +23,7 @@ use super::{conv, descriptor, D3D12Lib}; use crate::{ auxil::{ self, - dxgi::{name::ObjectExt, result::HResult}, + dxgi::{name::ObjectExt as _, result::HResult as _}, }, dx12::{ borrow_optional_interface_temporarily, shader_compilation, suballocation, diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index c8e6c3e0cfb..c1c3730f235 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -1293,7 +1293,7 @@ impl crate::Surface for Surface { .ok_or(crate::SurfaceError::Other("IDXGIFactoryMedia not found"))? .CreateSwapChainForCompositionSurfaceHandle( &device.present_queue, - handle, + Some(handle), &desc, None, ) diff --git a/wgpu-hal/src/dx12/suballocation.rs b/wgpu-hal/src/dx12/suballocation.rs index 8547f130088..747e71b322d 100644 --- a/wgpu-hal/src/dx12/suballocation.rs +++ b/wgpu-hal/src/dx12/suballocation.rs @@ -1,10 +1,11 @@ use alloc::sync::Arc; + use gpu_allocator::{d3d12::AllocationCreateDesc, MemoryLocation}; use parking_lot::Mutex; use windows::Win32::Graphics::{Direct3D12, Dxgi}; use crate::{ - auxil::dxgi::{name::ObjectExt, result::HResult as _}, + auxil::dxgi::{name::ObjectExt as _, result::HResult as _}, dx12::conv, }; diff --git a/wgpu-hal/src/gles/wgl.rs b/wgpu-hal/src/gles/wgl.rs index 6a4c3863bb8..bc8c38f12a8 100644 --- a/wgpu-hal/src/gles/wgl.rs +++ b/wgpu-hal/src/gles/wgl.rs @@ -128,7 +128,7 @@ impl WglContext { if unsafe { OpenGL::wglGetCurrentContext() }.is_invalid() { return Ok(()); } - unsafe { OpenGL::wglMakeCurrent(None, None) } + unsafe { OpenGL::wglMakeCurrent(Default::default(), Default::default()) } } } @@ -382,7 +382,7 @@ fn create_instance_device() -> Result { 1, None, None, - instance, + Some(instance.into()), None, ) } @@ -394,7 +394,7 @@ fn create_instance_device() -> Result { })?; let window = Window { window }; - let dc = unsafe { Gdi::GetDC(window.window) }; + let dc = unsafe { Gdi::GetDC(Some(window.window)) }; if dc.is_invalid() { return Err(crate::InstanceError::with_source( String::from("unable to create memory device"), @@ -636,7 +636,7 @@ struct DeviceContextHandle { impl Drop for DeviceContextHandle { fn drop(&mut self) { unsafe { - Gdi::ReleaseDC(self.window, self.device); + Gdi::ReleaseDC(Some(self.window), self.device); }; } } @@ -672,7 +672,7 @@ impl Surface { ) -> Result<(), crate::SurfaceError> { let swapchain = self.swapchain.read(); let sc = swapchain.as_ref().unwrap(); - let dc = unsafe { Gdi::GetDC(self.window) }; + let dc = unsafe { Gdi::GetDC(Some(self.window)) }; if dc.is_invalid() { log::error!( "unable to get the device context from window: {}", @@ -750,7 +750,7 @@ impl crate::Surface for Surface { // Remove the old configuration. unsafe { self.unconfigure(device) }; - let dc = unsafe { Gdi::GetDC(self.window) }; + let dc = unsafe { Gdi::GetDC(Some(self.window)) }; if dc.is_invalid() { log::error!( "unable to get the device context from window: {}",