mirror of
https://github.com/italicsjenga/portability.git
synced 2025-02-17 06:37:43 +11:00
Ensure instance and device extensions exist
This commit is contained in:
parent
4c2b2f13e5
commit
6f76d2c7c6
1 changed files with 49 additions and 15 deletions
|
@ -70,14 +70,20 @@ pub extern "C" fn gfxCreateInstance(
|
||||||
let enabled_extensions = if create_info.enabledExtensionCount == 0 {
|
let enabled_extensions = if create_info.enabledExtensionCount == 0 {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
} else {
|
} else {
|
||||||
slice::from_raw_parts(create_info.ppEnabledExtensionNames, create_info.enabledExtensionCount as _)
|
let extensions = slice::from_raw_parts(create_info.ppEnabledExtensionNames, create_info.enabledExtensionCount as _)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|raw| CStr::from_ptr(*raw)
|
.map(|raw| CStr::from_ptr(*raw)
|
||||||
.to_str()
|
.to_str()
|
||||||
.expect("Invalid extension name")
|
.expect("Invalid extension name")
|
||||||
.to_owned()
|
.to_owned()
|
||||||
)
|
)
|
||||||
.collect()
|
.collect::<Vec<_>>();
|
||||||
|
for extension in &extensions {
|
||||||
|
if !INSTANCE_EXTENSION_NAMES.contains(&extension.as_str()) {
|
||||||
|
return VkResult::VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
extensions
|
||||||
};
|
};
|
||||||
|
|
||||||
*pInstance = Handle::new(RawInstance {
|
*pInstance = Handle::new(RawInstance {
|
||||||
|
@ -384,13 +390,12 @@ pub extern "C" fn gfxGetInstanceProcAddr(
|
||||||
"vkGetPhysicalDeviceSurfacePresentModesKHR" |
|
"vkGetPhysicalDeviceSurfacePresentModesKHR" |
|
||||||
"vkDestroySurfaceKHR"
|
"vkDestroySurfaceKHR"
|
||||||
=> {
|
=> {
|
||||||
let surface_ext = unsafe { *VK_KHR_SURFACE_EXTENSION_NAME.as_ptr() };
|
|
||||||
let surface_extension_enabled = instance
|
let surface_extension_enabled = instance
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.enabled_extensions
|
.enabled_extensions
|
||||||
.iter()
|
.iter()
|
||||||
.any(|e| unsafe { *e.as_ptr() } == surface_ext);
|
.any(|e| e == INSTANCE_EXTENSION_NAME_VK_KHR_SURFACE);
|
||||||
if !surface_extension_enabled {
|
if !surface_extension_enabled {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -454,13 +459,12 @@ pub extern "C" fn gfxGetDeviceProcAddr(
|
||||||
"vkAcquireNextImageKHR" |
|
"vkAcquireNextImageKHR" |
|
||||||
"vkQueuePresentKHR"
|
"vkQueuePresentKHR"
|
||||||
=> {
|
=> {
|
||||||
let swapchain_ext = unsafe { *VK_KHR_SWAPCHAIN_EXTENSION_NAME.as_ptr() };
|
|
||||||
let swapchain_extension_enabled = device
|
let swapchain_extension_enabled = device
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
.enabled_extensions
|
.enabled_extensions
|
||||||
.iter()
|
.iter()
|
||||||
.any(|e| unsafe { *e.as_ptr() } == swapchain_ext);
|
.any(|e| e == DEVICE_EXTENSION_NAME_VK_KHR_SWAPCHAIN);
|
||||||
if !swapchain_extension_enabled {
|
if !swapchain_extension_enabled {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
|
@ -677,16 +681,22 @@ pub extern "C" fn gfxCreateDevice(
|
||||||
let enabled_extensions = if dev_info.enabledExtensionCount == 0 {
|
let enabled_extensions = if dev_info.enabledExtensionCount == 0 {
|
||||||
Vec::new()
|
Vec::new()
|
||||||
} else {
|
} else {
|
||||||
unsafe {
|
let extensions = unsafe {
|
||||||
slice::from_raw_parts(dev_info.ppEnabledExtensionNames, dev_info.enabledExtensionCount as _)
|
slice::from_raw_parts(dev_info.ppEnabledExtensionNames, dev_info.enabledExtensionCount as _)
|
||||||
.iter()
|
.iter()
|
||||||
.map(|raw| CStr::from_ptr(*raw)
|
.map(|raw| CStr::from_ptr(*raw)
|
||||||
.to_str()
|
.to_str()
|
||||||
.expect("Invalid extension name")
|
.expect("Invalid extension name")
|
||||||
.to_owned()
|
.to_owned()
|
||||||
)
|
)
|
||||||
.collect()
|
.collect::<Vec<_>>()
|
||||||
|
};
|
||||||
|
for extension in &extensions {
|
||||||
|
if !DEVICE_EXTENSION_NAMES.contains(&extension.as_ref()) {
|
||||||
|
return VkResult::VK_ERROR_EXTENSION_NOT_PRESENT;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
extensions
|
||||||
};
|
};
|
||||||
|
|
||||||
let gpu = Gpu {
|
let gpu = Gpu {
|
||||||
|
@ -728,8 +738,26 @@ pub extern "C" fn gfxDestroyDevice(gpu: VkDevice, _pAllocator: *const VkAllocati
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// TODO: Avoid redefining these somehow
|
||||||
|
static INSTANCE_EXTENSION_NAME_VK_KHR_SURFACE: &str = "VK_KHR_surface";
|
||||||
|
#[cfg(target_os="windows")]
|
||||||
|
static INSTANCE_EXTENSION_NAME_VK_KHR_WIN32_SURFACE: &str = "VK_KHR_win32_surface";
|
||||||
|
#[cfg(target_os="macos")]
|
||||||
|
static INSTANCE_EXTENSION_NAME_VK_MACOS_SURFACE: &str = "VK_MVK_macos_surface";
|
||||||
|
static DEVICE_EXTENSION_NAME_VK_KHR_SWAPCHAIN: &str = "VK_KHR_swapchain";
|
||||||
|
|
||||||
lazy_static! {
|
lazy_static! {
|
||||||
// TODO: Request from backend
|
// TODO: Request from backend
|
||||||
|
static ref INSTANCE_EXTENSION_NAMES: Vec<&'static str> = {
|
||||||
|
vec![
|
||||||
|
INSTANCE_EXTENSION_NAME_VK_KHR_SURFACE,
|
||||||
|
#[cfg(target_os="windows")]
|
||||||
|
INSTANCE_EXTENSION_NAME_VK_KHR_WIN32_SURFACE,
|
||||||
|
#[cfg(target_os="macos")]
|
||||||
|
INSTANCE_EXTENSION_NAME_VK_MACOS_SURFACE,
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
static ref INSTANCE_EXTENSIONS: Vec<VkExtensionProperties> = {
|
static ref INSTANCE_EXTENSIONS: Vec<VkExtensionProperties> = {
|
||||||
let mut extensions = [
|
let mut extensions = [
|
||||||
VkExtensionProperties {
|
VkExtensionProperties {
|
||||||
|
@ -769,6 +797,12 @@ lazy_static! {
|
||||||
extensions.to_vec()
|
extensions.to_vec()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static ref DEVICE_EXTENSION_NAMES: Vec<&'static str> = {
|
||||||
|
vec![
|
||||||
|
DEVICE_EXTENSION_NAME_VK_KHR_SWAPCHAIN,
|
||||||
|
]
|
||||||
|
};
|
||||||
|
|
||||||
static ref DEVICE_EXTENSIONS: Vec<VkExtensionProperties> = {
|
static ref DEVICE_EXTENSIONS: Vec<VkExtensionProperties> = {
|
||||||
let mut extensions = [
|
let mut extensions = [
|
||||||
VkExtensionProperties {
|
VkExtensionProperties {
|
||||||
|
|
Loading…
Add table
Reference in a new issue