diff --git a/Cargo.lock b/Cargo.lock index 19d1345..189fb18 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -260,7 +260,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" [[package]] name = "gfx-backend-dx12" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#61588a5a82a24552d45931c906ebd4150ee589b3" +source = "git+https://github.com/gfx-rs/gfx#39aff0d7cf5e756fafdc310731d426c7883f9414" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -276,7 +276,7 @@ dependencies = [ [[package]] name = "gfx-backend-metal" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#61588a5a82a24552d45931c906ebd4150ee589b3" +source = "git+https://github.com/gfx-rs/gfx#39aff0d7cf5e756fafdc310731d426c7883f9414" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)", @@ -299,7 +299,7 @@ dependencies = [ [[package]] name = "gfx-backend-vulkan" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#61588a5a82a24552d45931c906ebd4150ee589b3" +source = "git+https://github.com/gfx-rs/gfx#39aff0d7cf5e756fafdc310731d426c7883f9414" dependencies = [ "ash 0.24.3 (registry+https://github.com/rust-lang/crates.io-index)", "byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)", @@ -317,7 +317,7 @@ dependencies = [ [[package]] name = "gfx-hal" version = "0.1.0" -source = "git+https://github.com/gfx-rs/gfx#61588a5a82a24552d45931c906ebd4150ee589b3" +source = "git+https://github.com/gfx-rs/gfx#39aff0d7cf5e756fafdc310731d426c7883f9414" dependencies = [ "bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)", "failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/libportability-gfx/src/conv.rs b/libportability-gfx/src/conv.rs index fca8d15..7770cab 100644 --- a/libportability-gfx/src/conv.rs +++ b/libportability-gfx/src/conv.rs @@ -574,6 +574,12 @@ pub fn map_present_mode(present_mode: VkPresentModeKHR) -> window::PresentMode { unsafe { mem::transmute(present_mode) } } +#[inline] +pub fn map_present_mode_from_hal(present_mode: window::PresentMode) -> VkPresentModeKHR { + // Vulkan and HAL values are equal + unsafe { mem::transmute(present_mode) } +} + #[inline] pub fn map_compare_op(op: VkCompareOp) -> pso::Comparison { // Vulkan and HAL values are equal diff --git a/libportability-gfx/src/impls.rs b/libportability-gfx/src/impls.rs index e23e97c..8bbc7d2 100644 --- a/libportability-gfx/src/impls.rs +++ b/libportability-gfx/src/impls.rs @@ -3535,7 +3535,7 @@ pub extern "C" fn gfxGetPhysicalDeviceSurfaceCapabilitiesKHR( surface: VkSurfaceKHR, pSurfaceCapabilities: *mut VkSurfaceCapabilitiesKHR, ) -> VkResult { - let (caps, _) = surface.capabilities_and_formats(&adapter.physical_device); + let (caps, _, _) = surface.compatibility(&adapter.physical_device); let output = VkSurfaceCapabilitiesKHR { minImageCount: caps.image_count.start, @@ -3570,7 +3570,7 @@ pub extern "C" fn gfxGetPhysicalDeviceSurfaceFormatsKHR( pSurfaceFormats: *mut VkSurfaceFormatKHR, ) -> VkResult { let formats = surface - .capabilities_and_formats(&adapter.physical_device) + .compatibility(&adapter.physical_device) .1 .map(|formats| formats.into_iter().map(conv::format_from_hal).collect()) .unwrap_or(vec![VkFormat::VK_FORMAT_UNDEFINED]); @@ -3597,27 +3597,38 @@ pub extern "C" fn gfxGetPhysicalDeviceSurfaceFormatsKHR( #[inline] pub extern "C" fn gfxGetPhysicalDeviceSurfacePresentModesKHR( - _adapter: VkPhysicalDevice, - _surface: VkSurfaceKHR, + adapter: VkPhysicalDevice, + surface: VkSurfaceKHR, pPresentModeCount: *mut u32, pPresentModes: *mut VkPresentModeKHR, ) -> VkResult { - let modes = vec![ - VkPresentModeKHR::VK_PRESENT_MODE_IMMEDIATE_KHR, - VkPresentModeKHR::VK_PRESENT_MODE_MAILBOX_KHR, - VkPresentModeKHR::VK_PRESENT_MODE_FIFO_KHR, - VkPresentModeKHR::VK_PRESENT_MODE_FIFO_RELAXED_KHR - ]; //TODO - let output = unsafe { slice::from_raw_parts_mut(pPresentModes, *pPresentModeCount as usize) }; + let present_modes = surface + .compatibility(&adapter.physical_device) + .2; - if output.len() > modes.len() { - unsafe { *pPresentModeCount = modes.len() as u32 }; - } - for (out, mode) in output.iter_mut().zip(modes) { - *out = mode; + let num_present_modes = present_modes.len(); + + // If NULL, number of present modes is returned. + if pPresentModes.is_null() { + unsafe { *pPresentModeCount = num_present_modes as _ }; + return VkResult::VK_SUCCESS; } - VkResult::VK_SUCCESS + let output = unsafe { slice::from_raw_parts_mut(pPresentModes, *pPresentModeCount as _) }; + let num_output = output.len(); + let (code, count) = if num_output < num_present_modes { + (VkResult::VK_INCOMPLETE, num_output) + } else { + (VkResult::VK_SUCCESS, num_present_modes) + }; + + for (out, present_mode) in output.iter_mut().zip(present_modes) { + *out = conv::map_present_mode_from_hal(present_mode); + } + + unsafe { *pPresentModeCount = count as _ }; + + code } #[inline]