mirror of
https://github.com/gfx-rs/wgpu.git
synced 2024-11-22 06:44:14 +00:00
use Surface.get_capabilities
in all relevant places
This commit is contained in:
parent
ef7d27233e
commit
a9c74f42d6
@ -1989,7 +1989,7 @@ impl Global {
|
||||
device_id: DeviceId,
|
||||
config: &wgt::SurfaceConfiguration<Vec<TextureFormat>>,
|
||||
) -> Option<present::ConfigureSurfaceError> {
|
||||
use hal::{Adapter as _, Surface as _};
|
||||
use hal::Surface as _;
|
||||
use present::ConfigureSurfaceError as E;
|
||||
profiling::scope!("surface_configure");
|
||||
|
||||
@ -2130,13 +2130,9 @@ impl Global {
|
||||
Err(_) => break 'error E::InvalidSurface,
|
||||
};
|
||||
|
||||
let caps = unsafe {
|
||||
let suf = A::surface_as_hal(surface);
|
||||
let adapter = &device.adapter;
|
||||
match adapter.raw.adapter.surface_capabilities(suf.unwrap()) {
|
||||
Some(caps) => caps,
|
||||
None => break 'error E::UnsupportedQueueFamily,
|
||||
}
|
||||
let caps = match surface.get_capabilities(&device.adapter) {
|
||||
Ok(caps) => caps,
|
||||
Err(_) => break 'error E::UnsupportedQueueFamily,
|
||||
};
|
||||
|
||||
let mut hal_view_formats = vec![];
|
||||
|
@ -155,12 +155,18 @@ impl Surface {
|
||||
pub fn get_capabilities<A: HalApi>(
|
||||
&self,
|
||||
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> {
|
||||
let suf = A::surface_as_hal(self).ok_or(GetSurfaceSupportError::Unsupported)?;
|
||||
profiling::scope!("surface_capabilities");
|
||||
let caps = unsafe {
|
||||
adapter
|
||||
.raw
|
||||
.adapter
|
||||
.surface_capabilities(suf)
|
||||
.ok_or(GetSurfaceSupportError::Unsupported)?
|
||||
@ -192,16 +198,11 @@ impl<A: HalApi> Adapter<A> {
|
||||
}
|
||||
|
||||
pub fn is_surface_supported(&self, surface: &Surface) -> bool {
|
||||
let suf = A::surface_as_hal(surface);
|
||||
|
||||
// If get_surface returns None, then the API does not advertise support for the surface.
|
||||
// If get_capabilities returns Err, 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
|
||||
// VK_KHR_wayland_surface.
|
||||
match suf {
|
||||
Some(suf) => unsafe { self.raw.adapter.surface_capabilities(suf) }.is_some(),
|
||||
None => false,
|
||||
}
|
||||
surface.get_capabilities(self).is_ok()
|
||||
}
|
||||
|
||||
pub(crate) fn get_texture_format_features(
|
||||
@ -800,16 +801,8 @@ impl Global {
|
||||
adapters.retain(|exposed| exposed.info.device_type == wgt::DeviceType::Cpu);
|
||||
}
|
||||
if let Some(surface) = compatible_surface {
|
||||
let surface = &A::surface_as_hal(surface);
|
||||
adapters.retain(|exposed| unsafe {
|
||||
// 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()
|
||||
});
|
||||
adapters
|
||||
.retain(|exposed| surface.get_capabilities_with_raw(exposed).is_ok());
|
||||
}
|
||||
device_types.extend(adapters.iter().map(|ad| ad.info.device_type));
|
||||
(id, adapters)
|
||||
|
Loading…
Reference in New Issue
Block a user