Skip to content

Commit

Permalink
Fix physical device surface querying regression vulkano-rs#2026 by re…
Browse files Browse the repository at this point in the history
…moving surface caching (vulkano-rs#2027)

* removed cache check for PhysicalDevice::surface_capabilities_unchecked, fixing window resize bug

* Fixed bug where new caching functionality caused surface queries to be
out of date. surface_capabilities, surface_formats,
surface_present_modes and surface_support are no longer cached as it is
proven that surface properties can change at runtime for a given
surface/physical device.

* Re-added caching for VK_KHR_surface structs surface_formats, surface_present_modes and surface_support, because unlike surface_capabilities, it is almost certain they won't change at runtime.

* remove surface_capabilities cache from macos/ios to fix builds
  • Loading branch information
lilly-lizard authored and fayalalebrun committed Oct 22, 2022
1 parent 6740142 commit 32ecdc6
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 154 deletions.
261 changes: 125 additions & 136 deletions vulkano/src/device/physical.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1548,159 +1548,148 @@ impl PhysicalDevice {
surface: &Surface<W>,
surface_info: SurfaceInfo,
) -> Result<SurfaceCapabilities, VulkanError> {
surface.surface_capabilities.get_or_try_insert(
(self.handle, surface_info),
|(_, surface_info)| {
/* Input */
/* Input */

let &SurfaceInfo {
full_screen_exclusive,
win32_monitor,
_ne: _,
} = surface_info;

let mut info2 = ash::vk::PhysicalDeviceSurfaceInfo2KHR {
surface: surface.internal_object(),
..Default::default()
};
let mut full_screen_exclusive_info = None;
let mut full_screen_exclusive_win32_info = None;
let SurfaceInfo {
full_screen_exclusive,
win32_monitor,
_ne: _,
} = surface_info;

if self.supported_extensions().ext_full_screen_exclusive {
let next = full_screen_exclusive_info.insert(
ash::vk::SurfaceFullScreenExclusiveInfoEXT {
full_screen_exclusive: full_screen_exclusive.into(),
..Default::default()
},
);
let mut info2 = ash::vk::PhysicalDeviceSurfaceInfo2KHR {
surface: surface.internal_object(),
..Default::default()
};
let mut full_screen_exclusive_info = None;
let mut full_screen_exclusive_win32_info = None;

next.p_next = info2.p_next as *mut _;
info2.p_next = next as *const _ as *const _;
}
if self.supported_extensions().ext_full_screen_exclusive {
let next =
full_screen_exclusive_info.insert(ash::vk::SurfaceFullScreenExclusiveInfoEXT {
full_screen_exclusive: full_screen_exclusive.into(),
..Default::default()
});

if let Some(win32_monitor) = win32_monitor {
let next = full_screen_exclusive_win32_info.insert(
ash::vk::SurfaceFullScreenExclusiveWin32InfoEXT {
hmonitor: win32_monitor.0,
..Default::default()
},
);
next.p_next = info2.p_next as *mut _;
info2.p_next = next as *const _ as *const _;
}

next.p_next = info2.p_next as *mut _;
info2.p_next = next as *const _ as *const _;
}
if let Some(win32_monitor) = win32_monitor {
let next = full_screen_exclusive_win32_info.insert(
ash::vk::SurfaceFullScreenExclusiveWin32InfoEXT {
hmonitor: win32_monitor.0,
..Default::default()
},
);

/* Output */
next.p_next = info2.p_next as *mut _;
info2.p_next = next as *const _ as *const _;
}

let mut capabilities2 = ash::vk::SurfaceCapabilities2KHR::default();
let mut capabilities_full_screen_exclusive = None;
let mut protected_capabilities = None;
/* Output */

if full_screen_exclusive_info.is_some() {
let next = capabilities_full_screen_exclusive
.insert(ash::vk::SurfaceCapabilitiesFullScreenExclusiveEXT::default());
let mut capabilities2 = ash::vk::SurfaceCapabilities2KHR::default();
let mut capabilities_full_screen_exclusive = None;
let mut protected_capabilities = None;

next.p_next = info2.p_next as *mut _;
info2.p_next = next as *const _ as *const _;
}
if full_screen_exclusive_info.is_some() {
let next = capabilities_full_screen_exclusive
.insert(ash::vk::SurfaceCapabilitiesFullScreenExclusiveEXT::default());

if self
.instance
.enabled_extensions()
.khr_surface_protected_capabilities
{
let next = protected_capabilities
.insert(ash::vk::SurfaceProtectedCapabilitiesKHR::default());
next.p_next = info2.p_next as *mut _;
info2.p_next = next as *const _ as *const _;
}

next.p_next = info2.p_next as *mut _;
info2.p_next = next as *const _ as *const _;
}
if self
.instance
.enabled_extensions()
.khr_surface_protected_capabilities
{
let next =
protected_capabilities.insert(ash::vk::SurfaceProtectedCapabilitiesKHR::default());

let fns = self.instance.fns();
next.p_next = info2.p_next as *mut _;
info2.p_next = next as *const _ as *const _;
}

if self
.instance
.enabled_extensions()
.khr_get_surface_capabilities2
{
(fns.khr_get_surface_capabilities2
.get_physical_device_surface_capabilities2_khr)(
self.internal_object(),
&info2,
&mut capabilities2,
)
.result()
.map_err(VulkanError::from)?;
} else {
(fns.khr_surface.get_physical_device_surface_capabilities_khr)(
self.internal_object(),
info2.surface,
&mut capabilities2.surface_capabilities,
)
.result()
.map_err(VulkanError::from)?;
};
let fns = self.instance.fns();

Ok(SurfaceCapabilities {
min_image_count: capabilities2.surface_capabilities.min_image_count,
max_image_count: if capabilities2.surface_capabilities.max_image_count == 0 {
None
} else {
Some(capabilities2.surface_capabilities.max_image_count)
},
current_extent: if capabilities2.surface_capabilities.current_extent.width
== 0xffffffff
&& capabilities2.surface_capabilities.current_extent.height == 0xffffffff
{
None
} else {
Some([
capabilities2.surface_capabilities.current_extent.width,
capabilities2.surface_capabilities.current_extent.height,
])
},
min_image_extent: [
capabilities2.surface_capabilities.min_image_extent.width,
capabilities2.surface_capabilities.min_image_extent.height,
],
max_image_extent: [
capabilities2.surface_capabilities.max_image_extent.width,
capabilities2.surface_capabilities.max_image_extent.height,
],
max_image_array_layers: capabilities2
.surface_capabilities
.max_image_array_layers,
supported_transforms: capabilities2
.surface_capabilities
.supported_transforms
.into(),
if self
.instance
.enabled_extensions()
.khr_get_surface_capabilities2
{
(fns.khr_get_surface_capabilities2
.get_physical_device_surface_capabilities2_khr)(
self.internal_object(),
&info2,
&mut capabilities2,
)
.result()
.map_err(VulkanError::from)?;
} else {
(fns.khr_surface.get_physical_device_surface_capabilities_khr)(
self.internal_object(),
info2.surface,
&mut capabilities2.surface_capabilities,
)
.result()
.map_err(VulkanError::from)?;
};

current_transform: SupportedSurfaceTransforms::from(
capabilities2.surface_capabilities.current_transform,
)
.iter()
.next()
.unwrap(), // TODO:
supported_composite_alpha: capabilities2
.surface_capabilities
.supported_composite_alpha
.into(),
supported_usage_flags: {
let usage = ImageUsage::from(
capabilities2.surface_capabilities.supported_usage_flags,
);
debug_assert!(usage.color_attachment); // specs say that this must be true
usage
},
Ok(SurfaceCapabilities {
min_image_count: capabilities2.surface_capabilities.min_image_count,
max_image_count: if capabilities2.surface_capabilities.max_image_count == 0 {
None
} else {
Some(capabilities2.surface_capabilities.max_image_count)
},
current_extent: if capabilities2.surface_capabilities.current_extent.width == 0xffffffff
&& capabilities2.surface_capabilities.current_extent.height == 0xffffffff
{
None
} else {
Some([
capabilities2.surface_capabilities.current_extent.width,
capabilities2.surface_capabilities.current_extent.height,
])
},
min_image_extent: [
capabilities2.surface_capabilities.min_image_extent.width,
capabilities2.surface_capabilities.min_image_extent.height,
],
max_image_extent: [
capabilities2.surface_capabilities.max_image_extent.width,
capabilities2.surface_capabilities.max_image_extent.height,
],
max_image_array_layers: capabilities2.surface_capabilities.max_image_array_layers,
supported_transforms: capabilities2
.surface_capabilities
.supported_transforms
.into(),

current_transform: SupportedSurfaceTransforms::from(
capabilities2.surface_capabilities.current_transform,
)
.iter()
.next()
.unwrap(), // TODO:
supported_composite_alpha: capabilities2
.surface_capabilities
.supported_composite_alpha
.into(),
supported_usage_flags: {
let usage =
ImageUsage::from(capabilities2.surface_capabilities.supported_usage_flags);
debug_assert!(usage.color_attachment); // specs say that this must be true
usage
},

supports_protected: protected_capabilities
.map_or(false, |c| c.supports_protected != 0),
supports_protected: protected_capabilities.map_or(false, |c| c.supports_protected != 0),

full_screen_exclusive_supported: capabilities_full_screen_exclusive
.map_or(false, |c| c.full_screen_exclusive_supported != 0),
})
},
)
full_screen_exclusive_supported: capabilities_full_screen_exclusive
.map_or(false, |c| c.full_screen_exclusive_supported != 0),
})
}

/// Returns the combinations of format and color space that are supported by the physical device
Expand Down
Loading

0 comments on commit 32ecdc6

Please sign in to comment.