mirror of
https://github.com/italicsjenga/portability.git
synced 2024-11-26 17:01:31 +11:00
Add present mode querying
This commit is contained in:
parent
3e716b08ad
commit
967cd9b445
8
Cargo.lock
generated
8
Cargo.lock
generated
|
@ -260,7 +260,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gfx-backend-dx12"
|
name = "gfx-backend-dx12"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/gfx-rs/gfx#61588a5a82a24552d45931c906ebd4150ee589b3"
|
source = "git+https://github.com/gfx-rs/gfx#39aff0d7cf5e756fafdc310731d426c7883f9414"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"derivative 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -276,7 +276,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gfx-backend-metal"
|
name = "gfx-backend-metal"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/gfx-rs/gfx#61588a5a82a24552d45931c906ebd4150ee589b3"
|
source = "git+https://github.com/gfx-rs/gfx#39aff0d7cf5e756fafdc310731d426c7883f9414"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"block 0.1.6 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -299,7 +299,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gfx-backend-vulkan"
|
name = "gfx-backend-vulkan"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/gfx-rs/gfx#61588a5a82a24552d45931c906ebd4150ee589b3"
|
source = "git+https://github.com/gfx-rs/gfx#39aff0d7cf5e756fafdc310731d426c7883f9414"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ash 0.24.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"byteorder 1.2.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
@ -317,7 +317,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "gfx-hal"
|
name = "gfx-hal"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
source = "git+https://github.com/gfx-rs/gfx#61588a5a82a24552d45931c906ebd4150ee589b3"
|
source = "git+https://github.com/gfx-rs/gfx#39aff0d7cf5e756fafdc310731d426c7883f9414"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"bitflags 1.0.3 (registry+https://github.com/rust-lang/crates.io-index)",
|
"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)",
|
"failure 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
|
||||||
|
|
|
@ -574,6 +574,12 @@ pub fn map_present_mode(present_mode: VkPresentModeKHR) -> window::PresentMode {
|
||||||
unsafe { mem::transmute(present_mode) }
|
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]
|
#[inline]
|
||||||
pub fn map_compare_op(op: VkCompareOp) -> pso::Comparison {
|
pub fn map_compare_op(op: VkCompareOp) -> pso::Comparison {
|
||||||
// Vulkan and HAL values are equal
|
// Vulkan and HAL values are equal
|
||||||
|
|
|
@ -3535,7 +3535,7 @@ pub extern "C" fn gfxGetPhysicalDeviceSurfaceCapabilitiesKHR(
|
||||||
surface: VkSurfaceKHR,
|
surface: VkSurfaceKHR,
|
||||||
pSurfaceCapabilities: *mut VkSurfaceCapabilitiesKHR,
|
pSurfaceCapabilities: *mut VkSurfaceCapabilitiesKHR,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
let (caps, _) = surface.capabilities_and_formats(&adapter.physical_device);
|
let (caps, _, _) = surface.compatibility(&adapter.physical_device);
|
||||||
|
|
||||||
let output = VkSurfaceCapabilitiesKHR {
|
let output = VkSurfaceCapabilitiesKHR {
|
||||||
minImageCount: caps.image_count.start,
|
minImageCount: caps.image_count.start,
|
||||||
|
@ -3570,7 +3570,7 @@ pub extern "C" fn gfxGetPhysicalDeviceSurfaceFormatsKHR(
|
||||||
pSurfaceFormats: *mut VkSurfaceFormatKHR,
|
pSurfaceFormats: *mut VkSurfaceFormatKHR,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
let formats = surface
|
let formats = surface
|
||||||
.capabilities_and_formats(&adapter.physical_device)
|
.compatibility(&adapter.physical_device)
|
||||||
.1
|
.1
|
||||||
.map(|formats| formats.into_iter().map(conv::format_from_hal).collect())
|
.map(|formats| formats.into_iter().map(conv::format_from_hal).collect())
|
||||||
.unwrap_or(vec![VkFormat::VK_FORMAT_UNDEFINED]);
|
.unwrap_or(vec![VkFormat::VK_FORMAT_UNDEFINED]);
|
||||||
|
@ -3597,27 +3597,38 @@ pub extern "C" fn gfxGetPhysicalDeviceSurfaceFormatsKHR(
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
pub extern "C" fn gfxGetPhysicalDeviceSurfacePresentModesKHR(
|
pub extern "C" fn gfxGetPhysicalDeviceSurfacePresentModesKHR(
|
||||||
_adapter: VkPhysicalDevice,
|
adapter: VkPhysicalDevice,
|
||||||
_surface: VkSurfaceKHR,
|
surface: VkSurfaceKHR,
|
||||||
pPresentModeCount: *mut u32,
|
pPresentModeCount: *mut u32,
|
||||||
pPresentModes: *mut VkPresentModeKHR,
|
pPresentModes: *mut VkPresentModeKHR,
|
||||||
) -> VkResult {
|
) -> VkResult {
|
||||||
let modes = vec![
|
let present_modes = surface
|
||||||
VkPresentModeKHR::VK_PRESENT_MODE_IMMEDIATE_KHR,
|
.compatibility(&adapter.physical_device)
|
||||||
VkPresentModeKHR::VK_PRESENT_MODE_MAILBOX_KHR,
|
.2;
|
||||||
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) };
|
|
||||||
|
|
||||||
if output.len() > modes.len() {
|
let num_present_modes = present_modes.len();
|
||||||
unsafe { *pPresentModeCount = modes.len() as u32 };
|
|
||||||
}
|
// If NULL, number of present modes is returned.
|
||||||
for (out, mode) in output.iter_mut().zip(modes) {
|
if pPresentModes.is_null() {
|
||||||
*out = mode;
|
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]
|
#[inline]
|
||||||
|
|
Loading…
Reference in a new issue