Skip to content

Commit

Permalink
platform_types: Convert Windows HANDLE types to isize
Browse files Browse the repository at this point in the history
The `windows` crate treats these as `isize` rather than raw void
pointers:
https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Foundation/struct.HWND.html

And `raw-window-handle 0.6` recently started to do the same:
rust-windowing/raw-window-handle#136

However, the win32 documentation still states that these should be
`PVOID`:
https://learn.microsoft.com/en-us/windows/win32/winprog/windows-data-types
  • Loading branch information
MarijnS95 committed Oct 11, 2023
1 parent 3f5b96b commit 9b1223a
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 21 deletions.
4 changes: 2 additions & 2 deletions ash-window/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ pub unsafe fn create_surface(
match (display_handle, window_handle) {
(RawDisplayHandle::Windows(_), RawWindowHandle::Win32(window)) => {
let surface_desc = vk::Win32SurfaceCreateInfoKHR::default()
.hinstance(window.hinstance)
.hwnd(window.hwnd);
.hinstance(window.hinstance as isize)
.hwnd(window.hwnd as isize);
let surface_fn = khr::Win32Surface::new(entry, instance);
surface_fn.create_win32_surface(&surface_desc, allocation_callbacks)
}
Expand Down
8 changes: 4 additions & 4 deletions ash/src/extensions/khr/external_fence_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
use std::mem::MaybeUninit;

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_fence_win32.html>
#[derive(Clone)]
Expand Down Expand Up @@ -36,9 +36,9 @@ impl ExternalFenceWin32 {
&self,
get_info: &vk::FenceGetWin32HandleInfoKHR,
) -> VkResult<vk::HANDLE> {
let mut handle = ptr::null_mut();
(self.fp.get_fence_win32_handle_khr)(self.handle, get_info, &mut handle)
.result_with_success(handle)
let mut handle = MaybeUninit::uninit();
(self.fp.get_fence_win32_handle_khr)(self.handle, get_info, handle.as_mut_ptr())
.assume_init_on_success(handle)
}

pub const NAME: &'static CStr = vk::KhrExternalFenceWin32Fn::NAME;
Expand Down
8 changes: 4 additions & 4 deletions ash/src/extensions/khr/external_memory_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
use std::mem::MaybeUninit;

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_memory_win32.html>
#[derive(Clone)]
Expand All @@ -27,9 +27,9 @@ impl ExternalMemoryWin32 {
&self,
create_info: &vk::MemoryGetWin32HandleInfoKHR,
) -> VkResult<vk::HANDLE> {
let mut handle = ptr::null_mut();
(self.fp.get_memory_win32_handle_khr)(self.handle, create_info, &mut handle)
.result_with_success(handle)
let mut handle = MaybeUninit::uninit();
(self.fp.get_memory_win32_handle_khr)(self.handle, create_info, handle.as_mut_ptr())
.assume_init_on_success(handle)
}

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/vkGetMemoryWin32HandlePropertiesKHR.html>
Expand Down
8 changes: 4 additions & 4 deletions ash/src/extensions/khr/external_semaphore_win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::vk;
use crate::{Device, Instance};
use std::ffi::CStr;
use std::mem;
use std::ptr;
use std::mem::MaybeUninit;

/// <https://www.khronos.org/registry/vulkan/specs/1.3-extensions/man/html/VK_KHR_external_semaphore_win32.html>
#[derive(Clone)]
Expand Down Expand Up @@ -36,9 +36,9 @@ impl ExternalSemaphoreWin32 {
&self,
get_info: &vk::SemaphoreGetWin32HandleInfoKHR,
) -> VkResult<vk::HANDLE> {
let mut handle = ptr::null_mut();
(self.fp.get_semaphore_win32_handle_khr)(self.handle, get_info, &mut handle)
.result_with_success(handle)
let mut handle = MaybeUninit::uninit();
(self.fp.get_semaphore_win32_handle_khr)(self.handle, get_info, handle.as_mut_ptr())
.assume_init_on_success(handle)
}

pub const NAME: &'static CStr = vk::KhrExternalSemaphoreWin32Fn::NAME;
Expand Down
12 changes: 8 additions & 4 deletions ash/src/vk/platform_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,16 @@ pub type xcb_window_t = u32;
pub type xcb_visualid_t = u32;
pub type MirConnection = *const c_void;
pub type MirSurface = *const c_void;
pub type HINSTANCE = *const c_void;
pub type HWND = *const c_void;
/// https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Foundation/struct.HANDLE.html
pub type HANDLE = isize;
/// https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Foundation/struct.HINSTANCE.html
pub type HINSTANCE = HANDLE;
/// https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Foundation/struct.HWND.html
pub type HWND = HANDLE;
/// https://microsoft.github.io/windows-docs-rs/doc/windows/Win32/Graphics/Gdi/struct.HMONITOR.html
pub type HMONITOR = HANDLE;
pub type wl_display = c_void;
pub type wl_surface = c_void;
pub type HANDLE = *mut c_void;
pub type HMONITOR = HANDLE;
pub type DWORD = c_ulong;
pub type LPCWSTR = *const u16;
pub type zx_handle_t = u32;
Expand Down
6 changes: 3 additions & 3 deletions generator/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ pub trait ConstantExt {
fn variant_ident(&self, enum_name: &str) -> Ident;
fn notation(&self) -> Option<&str>;
fn formatted_notation(&self) -> Option<Cow<'_, str>> {
static DOC_LINK: Lazy<Regex> = Lazy::new(|| Regex::new(r#"<<([\w-]+)>>"#).unwrap());
static DOC_LINK: Lazy<Regex> = Lazy::new(|| Regex::new(r"<<([\w-]+)>>").unwrap());
self.notation().map(|n| {
DOC_LINK.replace(
n,
Expand Down Expand Up @@ -2968,13 +2968,13 @@ pub fn write_source_code<P: AsRef<Path>>(vk_headers_dir: &Path, src_dir: P) {
let mut has_lifetimes = definitions
.iter()
.filter_map(get_variant!(vkxml::DefinitionsElement::Struct))
.filter_map(|s| {
.filter(|&s| {
s.elements
.iter()
.filter_map(get_variant!(vkxml::StructElement::Member))
.any(|x| x.reference.is_some())
.then(|| name_to_tokens(&s.name))
})
.map(|s| name_to_tokens(&s.name))
.collect::<HashSet<Ident>>();
for def in &definitions {
match def {
Expand Down

0 comments on commit 9b1223a

Please sign in to comment.