use Surface.get_capabilities in all relevant places

This commit is contained in:
teoxoy 2024-07-02 21:01:41 +02:00 committed by Teodor Tanasoaia
parent ef7d27233e
commit a9c74f42d6
2 changed files with 15 additions and 26 deletions

View File

@ -1989,7 +1989,7 @@ impl Global {
device_id: DeviceId, device_id: DeviceId,
config: &wgt::SurfaceConfiguration<Vec<TextureFormat>>, config: &wgt::SurfaceConfiguration<Vec<TextureFormat>>,
) -> Option<present::ConfigureSurfaceError> { ) -> Option<present::ConfigureSurfaceError> {
use hal::{Adapter as _, Surface as _}; use hal::Surface as _;
use present::ConfigureSurfaceError as E; use present::ConfigureSurfaceError as E;
profiling::scope!("surface_configure"); profiling::scope!("surface_configure");
@ -2130,13 +2130,9 @@ impl Global {
Err(_) => break 'error E::InvalidSurface, Err(_) => break 'error E::InvalidSurface,
}; };
let caps = unsafe { let caps = match surface.get_capabilities(&device.adapter) {
let suf = A::surface_as_hal(surface); Ok(caps) => caps,
let adapter = &device.adapter; Err(_) => break 'error E::UnsupportedQueueFamily,
match adapter.raw.adapter.surface_capabilities(suf.unwrap()) {
Some(caps) => caps,
None => break 'error E::UnsupportedQueueFamily,
}
}; };
let mut hal_view_formats = vec![]; let mut hal_view_formats = vec![];

View File

@ -155,12 +155,18 @@ impl Surface {
pub fn get_capabilities<A: HalApi>( pub fn get_capabilities<A: HalApi>(
&self, &self,
adapter: &Adapter<A>, adapter: &Adapter<A>,
) -> Result<hal::SurfaceCapabilities, GetSurfaceSupportError> {
self.get_capabilities_with_raw(&adapter.raw)
}
pub fn get_capabilities_with_raw<A: HalApi>(
&self,
adapter: &hal::ExposedAdapter<A>,
) -> Result<hal::SurfaceCapabilities, GetSurfaceSupportError> { ) -> Result<hal::SurfaceCapabilities, GetSurfaceSupportError> {
let suf = A::surface_as_hal(self).ok_or(GetSurfaceSupportError::Unsupported)?; let suf = A::surface_as_hal(self).ok_or(GetSurfaceSupportError::Unsupported)?;
profiling::scope!("surface_capabilities"); profiling::scope!("surface_capabilities");
let caps = unsafe { let caps = unsafe {
adapter adapter
.raw
.adapter .adapter
.surface_capabilities(suf) .surface_capabilities(suf)
.ok_or(GetSurfaceSupportError::Unsupported)? .ok_or(GetSurfaceSupportError::Unsupported)?
@ -192,16 +198,11 @@ impl<A: HalApi> Adapter<A> {
} }
pub fn is_surface_supported(&self, surface: &Surface) -> bool { pub fn is_surface_supported(&self, surface: &Surface) -> bool {
let suf = A::surface_as_hal(surface); // If get_capabilities returns Err, then the API does not advertise support for the surface.
// If get_surface returns None, then the API does not advertise support for the surface.
// //
// This could occur if the user is running their app on Wayland but Vulkan does not support // This could occur if the user is running their app on Wayland but Vulkan does not support
// VK_KHR_wayland_surface. // VK_KHR_wayland_surface.
match suf { surface.get_capabilities(self).is_ok()
Some(suf) => unsafe { self.raw.adapter.surface_capabilities(suf) }.is_some(),
None => false,
}
} }
pub(crate) fn get_texture_format_features( pub(crate) fn get_texture_format_features(
@ -800,16 +801,8 @@ impl Global {
adapters.retain(|exposed| exposed.info.device_type == wgt::DeviceType::Cpu); adapters.retain(|exposed| exposed.info.device_type == wgt::DeviceType::Cpu);
} }
if let Some(surface) = compatible_surface { if let Some(surface) = compatible_surface {
let surface = &A::surface_as_hal(surface); adapters
adapters.retain(|exposed| unsafe { .retain(|exposed| surface.get_capabilities_with_raw(exposed).is_ok());
// If the surface does not exist for this backend,
// then the surface is not supported.
surface.is_some()
&& exposed
.adapter
.surface_capabilities(surface.unwrap())
.is_some()
});
} }
device_types.extend(adapters.iter().map(|ad| ad.info.device_type)); device_types.extend(adapters.iter().map(|ad| ad.info.device_type));
(id, adapters) (id, adapters)