Skip to content

Commit

Permalink
[wgpu-hal] add null terminations to symbols to avoid reallocation
Browse files Browse the repository at this point in the history
  • Loading branch information
teoxoy committed Sep 3, 2024
1 parent 9d24888 commit 595ae7c
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 14 deletions.
2 changes: 1 addition & 1 deletion wgpu-hal/src/auxil/dxgi/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down
12 changes: 6 additions & 6 deletions wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Fun> = unsafe { self.lib.get(b"D3D12CreateDevice") }?;
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"D3D12CreateDevice\0") }?;

let mut result__ = None;

Expand Down Expand Up @@ -148,7 +148,7 @@ impl D3D12Lib {
pperrorblob: *mut *mut core::ffi::c_void,
) -> windows_core::HRESULT;
let func: libloading::Symbol<Fun> =
unsafe { self.lib.get(b"D3D12SerializeRootSignature") }?;
unsafe { self.lib.get(b"D3D12SerializeRootSignature\0") }?;

let desc = Direct3D12::D3D12_ROOT_SIGNATURE_DESC {
NumParameters: parameters.len() as _,
Expand Down Expand Up @@ -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<Fun> = unsafe { self.lib.get(b"D3D12GetDebugInterface") }?;
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"D3D12GetDebugInterface\0") }?;

let mut result__ = None;

Expand Down Expand Up @@ -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<Fun> = unsafe { self.lib.get(b"DXGIGetDebugInterface1") }?;
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"DXGIGetDebugInterface1\0") }?;

let mut result__ = None;

Expand All @@ -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<Fun> = unsafe { self.lib.get(b"CreateDXGIFactory2") }?;
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"CreateDXGIFactory2\0") }?;

let mut result__ = None;

Expand All @@ -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<Fun> = unsafe { self.lib.get(b"CreateDXGIFactory1") }?;
let func: libloading::Symbol<Fun> = unsafe { self.lib.get(b"CreateDXGIFactory1\0") }?;

let mut result__ = None;

Expand Down
14 changes: 7 additions & 7 deletions wgpu-hal/src/gles/egl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ impl Drop for DisplayOwner {
match self.display {
DisplayRef::X11(ptr) => unsafe {
let func: libloading::Symbol<XCloseDisplayFun> =
self.library.get(b"XCloseDisplay").unwrap();
self.library.get(b"XCloseDisplay\0").unwrap();
func(ptr.as_ptr());
},
DisplayRef::Wayland => {}
Expand All @@ -155,7 +155,7 @@ fn open_x_display() -> Option<DisplayOwner> {
log::debug!("Loading X11 library to get the current display");
unsafe {
let library = find_library(&["libX11.so.6", "libX11.so"])?;
let func: libloading::Symbol<XOpenDisplayFun> = library.get(b"XOpenDisplay").unwrap();
let func: libloading::Symbol<XOpenDisplayFun> = library.get(b"XOpenDisplay\0").unwrap();
let result = func(ptr::null());
ptr::NonNull::new(result).map(|ptr| DisplayOwner {
display: DisplayRef::X11(ptr),
Expand All @@ -182,9 +182,9 @@ fn test_wayland_display() -> Option<DisplayOwner> {
let library = unsafe {
let client_library = find_library(&["libwayland-client.so.0", "libwayland-client.so"])?;
let wl_display_connect: libloading::Symbol<WlDisplayConnectFun> =
client_library.get(b"wl_display_connect").unwrap();
client_library.get(b"wl_display_connect\0").unwrap();
let wl_display_disconnect: libloading::Symbol<WlDisplayDisconnectFun> =
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"])?
Expand Down Expand Up @@ -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<WlEglWindowCreateFun> =
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();
Expand Down Expand Up @@ -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<WlEglWindowResizeFun> =
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,
Expand Down Expand Up @@ -1475,7 +1475,7 @@ impl crate::Surface for Surface {
.expect("unsupported window")
.library;
let wl_egl_window_destroy: libloading::Symbol<WlEglWindowDestroyFun> =
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) };
}
}
Expand Down

0 comments on commit 595ae7c

Please sign in to comment.