From 595ae7cb47fa56e546caf1b113fc3354dd6a33c0 Mon Sep 17 00:00:00 2001 From: teoxoy <28601907+teoxoy@users.noreply.github.com> Date: Mon, 2 Sep 2024 18:46:23 +0200 Subject: [PATCH] [wgpu-hal] add null terminations to symbols to avoid reallocation --- wgpu-hal/src/auxil/dxgi/time.rs | 2 +- wgpu-hal/src/dx12/mod.rs | 12 ++++++------ wgpu-hal/src/gles/egl.rs | 14 +++++++------- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/wgpu-hal/src/auxil/dxgi/time.rs b/wgpu-hal/src/auxil/dxgi/time.rs index 08bc3cee0..1b312fd65 100644 --- a/wgpu-hal/src/auxil/dxgi/time.rs +++ b/wgpu-hal/src/auxil/dxgi/time.rs @@ -62,7 +62,7 @@ impl PresentationTimer { let kernelbase = libloading::os::windows::Library::open_already_loaded("kernelbase.dll").unwrap(); // No concerns about lifetimes here as kernelbase is always there. - let ptr = unsafe { kernelbase.get(b"QueryInterruptTimePrecise").unwrap() }; + let ptr = unsafe { kernelbase.get(b"QueryInterruptTimePrecise\0").unwrap() }; Self::IPresentationManager { fnQueryInterruptTimePrecise: *ptr, } diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index 7a3b0216e..b871e1011 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -116,7 +116,7 @@ impl D3D12Lib { riid: *const windows_core::GUID, ppdevice: *mut *mut core::ffi::c_void, ) -> windows_core::HRESULT; - let func: libloading::Symbol = unsafe { self.lib.get(b"D3D12CreateDevice") }?; + let func: libloading::Symbol = unsafe { self.lib.get(b"D3D12CreateDevice\0") }?; let mut result__ = None; @@ -148,7 +148,7 @@ impl D3D12Lib { pperrorblob: *mut *mut core::ffi::c_void, ) -> windows_core::HRESULT; let func: libloading::Symbol = - unsafe { self.lib.get(b"D3D12SerializeRootSignature") }?; + unsafe { self.lib.get(b"D3D12SerializeRootSignature\0") }?; let desc = Direct3D12::D3D12_ROOT_SIGNATURE_DESC { NumParameters: parameters.len() as _, @@ -187,7 +187,7 @@ impl D3D12Lib { riid: *const windows_core::GUID, ppvdebug: *mut *mut core::ffi::c_void, ) -> windows_core::HRESULT; - let func: libloading::Symbol = unsafe { self.lib.get(b"D3D12GetDebugInterface") }?; + let func: libloading::Symbol = unsafe { self.lib.get(b"D3D12GetDebugInterface\0") }?; let mut result__ = None; @@ -217,7 +217,7 @@ impl DxgiLib { riid: *const windows_core::GUID, pdebug: *mut *mut core::ffi::c_void, ) -> windows_core::HRESULT; - let func: libloading::Symbol = unsafe { self.lib.get(b"DXGIGetDebugInterface1") }?; + let func: libloading::Symbol = unsafe { self.lib.get(b"DXGIGetDebugInterface1\0") }?; let mut result__ = None; @@ -239,7 +239,7 @@ impl DxgiLib { riid: *const windows_core::GUID, ppfactory: *mut *mut core::ffi::c_void, ) -> windows_core::HRESULT; - let func: libloading::Symbol = unsafe { self.lib.get(b"CreateDXGIFactory2") }?; + let func: libloading::Symbol = unsafe { self.lib.get(b"CreateDXGIFactory2\0") }?; let mut result__ = None; @@ -261,7 +261,7 @@ impl DxgiLib { riid: *const windows_core::GUID, ppfactory: *mut *mut core::ffi::c_void, ) -> windows_core::HRESULT; - let func: libloading::Symbol = unsafe { self.lib.get(b"CreateDXGIFactory1") }?; + let func: libloading::Symbol = unsafe { self.lib.get(b"CreateDXGIFactory1\0") }?; let mut result__ = None; diff --git a/wgpu-hal/src/gles/egl.rs b/wgpu-hal/src/gles/egl.rs index 86f104ba9..31b93da4d 100644 --- a/wgpu-hal/src/gles/egl.rs +++ b/wgpu-hal/src/gles/egl.rs @@ -143,7 +143,7 @@ impl Drop for DisplayOwner { match self.display { DisplayRef::X11(ptr) => unsafe { let func: libloading::Symbol = - self.library.get(b"XCloseDisplay").unwrap(); + self.library.get(b"XCloseDisplay\0").unwrap(); func(ptr.as_ptr()); }, DisplayRef::Wayland => {} @@ -155,7 +155,7 @@ fn open_x_display() -> Option { log::debug!("Loading X11 library to get the current display"); unsafe { let library = find_library(&["libX11.so.6", "libX11.so"])?; - let func: libloading::Symbol = library.get(b"XOpenDisplay").unwrap(); + let func: libloading::Symbol = library.get(b"XOpenDisplay\0").unwrap(); let result = func(ptr::null()); ptr::NonNull::new(result).map(|ptr| DisplayOwner { display: DisplayRef::X11(ptr), @@ -182,9 +182,9 @@ fn test_wayland_display() -> Option { let library = unsafe { let client_library = find_library(&["libwayland-client.so.0", "libwayland-client.so"])?; let wl_display_connect: libloading::Symbol = - client_library.get(b"wl_display_connect").unwrap(); + client_library.get(b"wl_display_connect\0").unwrap(); let wl_display_disconnect: libloading::Symbol = - client_library.get(b"wl_display_disconnect").unwrap(); + client_library.get(b"wl_display_disconnect\0").unwrap(); let display = ptr::NonNull::new(wl_display_connect(ptr::null()))?; wl_display_disconnect(display.as_ptr()); find_library(&["libwayland-egl.so.1", "libwayland-egl.so"])? @@ -1294,7 +1294,7 @@ impl crate::Surface for Surface { (WindowKind::Wayland, Rwh::Wayland(handle)) => { let library = &self.wsi.display_owner.as_ref().unwrap().library; let wl_egl_window_create: libloading::Symbol = - unsafe { library.get(b"wl_egl_window_create") }.unwrap(); + unsafe { library.get(b"wl_egl_window_create\0") }.unwrap(); let window = unsafe { wl_egl_window_create(handle.surface.as_ptr(), 640, 480) } .cast(); @@ -1403,7 +1403,7 @@ impl crate::Surface for Surface { if let Some(window) = wl_window { let library = &self.wsi.display_owner.as_ref().unwrap().library; let wl_egl_window_resize: libloading::Symbol = - unsafe { library.get(b"wl_egl_window_resize") }.unwrap(); + unsafe { library.get(b"wl_egl_window_resize\0") }.unwrap(); unsafe { wl_egl_window_resize( window, @@ -1475,7 +1475,7 @@ impl crate::Surface for Surface { .expect("unsupported window") .library; let wl_egl_window_destroy: libloading::Symbol = - unsafe { library.get(b"wl_egl_window_destroy") }.unwrap(); + unsafe { library.get(b"wl_egl_window_destroy\0") }.unwrap(); unsafe { wl_egl_window_destroy(window) }; } }