56: Support for Vulkan Samples with ICD r=kvark a=msiglreith

Add a few missing piece to get Vulkan Samples working with ICD (dx12, windows):
* Expose device extensions (partially)
* Expose addr to CreateWin32SurfaceKHR

Additionally, fixing vkMapMemory for the `VK_WHOLE_SIZE` case.

Co-authored-by: msiglreith <m.siglreith@gmail.com>
This commit is contained in:
bors[bot] 2018-04-17 17:50:11 +00:00
commit 0a30e0a29d
2 changed files with 54 additions and 8 deletions

View file

@ -84,7 +84,7 @@ pub extern "C" fn gfxEnumeratePhysicalDevices(
} else {
(VkResult::VK_SUCCESS, num_adapters)
};
output.copy_from_slice(&instance.adapters[..count]);
unsafe { *pPhysicalDeviceCount = count as _ };
@ -343,6 +343,8 @@ pub extern "C" fn gfxGetInstanceProcAddr(
vkGetPhysicalDeviceSurfaceCapabilitiesKHR, PFN_vkGetPhysicalDeviceSurfaceCapabilitiesKHR => gfxGetPhysicalDeviceSurfaceCapabilitiesKHR,
vkGetPhysicalDeviceSurfaceFormatsKHR, PFN_vkGetPhysicalDeviceSurfaceFormatsKHR => gfxGetPhysicalDeviceSurfaceFormatsKHR,
vkGetPhysicalDeviceSurfacePresentModesKHR, PFN_vkGetPhysicalDeviceSurfacePresentModesKHR => gfxGetPhysicalDeviceSurfacePresentModesKHR,
vkCreateWin32SurfaceKHR, PFN_vkCreateWin32SurfaceKHR => gfxCreateWin32SurfaceKHR,
}
}
@ -566,6 +568,7 @@ pub extern "C" fn gfxDestroyDevice(gpu: VkDevice, _pAllocator: *const VkAllocati
}
lazy_static! {
// TODO: Request from backend
static ref INSTANCE_EXTENSIONS: Vec<VkExtensionProperties> = {
let mut extensions = [
VkExtensionProperties {
@ -593,6 +596,23 @@ lazy_static! {
extensions.to_vec()
};
static ref DEVICE_EXTENSIONS: Vec<VkExtensionProperties> = {
let mut extensions = [
VkExtensionProperties {
extensionName: [0; 256], // VK_KHR_SWAPCHAIN_EXTENSION_NAME
specVersion: VK_KHR_SWAPCHAIN_SPEC_VERSION,
},
];
extensions[0]
.extensionName[..VK_KHR_SWAPCHAIN_EXTENSION_NAME.len()]
.copy_from_slice(unsafe {
mem::transmute(VK_KHR_SWAPCHAIN_EXTENSION_NAME as &[u8])
});
extensions.to_vec()
};
}
#[inline]
@ -629,10 +649,27 @@ pub extern "C" fn gfxEnumerateDeviceExtensionProperties(
_physicalDevice: VkPhysicalDevice,
_pLayerName: *const ::std::os::raw::c_char,
pPropertyCount: *mut u32,
_pProperties: *mut VkExtensionProperties,
pProperties: *mut VkExtensionProperties,
) -> VkResult {
// TODO: dummy implementation
unsafe { *pPropertyCount = 0; }
let property_count = unsafe { &mut *pPropertyCount };
let num_extensions = DEVICE_EXTENSIONS.len() as u32;
if pProperties.is_null() {
*property_count = num_extensions;
} else {
if *property_count > num_extensions {
*property_count = num_extensions;
}
let properties =
unsafe { slice::from_raw_parts_mut(pProperties, *property_count as usize) };
for i in 0..*property_count as usize {
properties[i] = DEVICE_EXTENSIONS[i];
}
if *property_count < num_extensions {
return VkResult::VK_INCOMPLETE;
}
}
VkResult::VK_SUCCESS
}
@ -756,13 +793,15 @@ pub extern "C" fn gfxMapMemory(
_flags: VkMemoryMapFlags,
ppData: *mut *mut ::std::os::raw::c_void,
) -> VkResult {
if size == VK_WHOLE_SIZE as VkDeviceSize {
unimplemented!()
}
let range = if size == VK_WHOLE_SIZE as VkDeviceSize {
(Some(offset), None)
} else {
(Some(offset), Some(offset + size))
};
unsafe {
*ppData = gpu.device
.map_memory(&memory, offset..offset + size)
.map_memory(&memory, range)
.unwrap() as *mut _; // TODO
}

View file

@ -6828,3 +6828,10 @@ pub type PFN_vkDestroyInstance = ::std::option::Option<unsafe extern "C" fn(
instance: VkInstance,
pAllocator: *const VkAllocationCallbacks,
)>;
pub type PFN_vkCreateWin32SurfaceKHR = ::std::option::Option<unsafe extern "C" fn(
instance: VkInstance,
pCreateInfo: *const VkWin32SurfaceCreateInfoKHR,
pAllocator: *const VkAllocationCallbacks,
pSurface: *mut VkSurfaceKHR,
) -> VkResult>;