Skip to content

Commit b3eeb45

Browse files
committed
Fix Vulkan surface capabilities being advertised when its query failed. (#6510)
1 parent 5ea7288 commit b3eeb45

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ Bottom level categories:
5353

5454
- Fix surface creation crashing on iOS. By @mockersf in [#6535](https://github.com/gfx-rs/wgpu/pull/6535)
5555

56+
#### Vulkan
57+
58+
- Fix surface capabilities being advertised when its query failed. By @wumpf in [#6510](https://github.com/gfx-rs/wgpu/pull/6510)
59+
5660
## 23.0.0 (2024-10-25)
5761

5862
### Themes of this release

wgpu-core/src/instance.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -412,13 +412,13 @@ impl Surface {
412412
&self,
413413
adapter: &hal::DynExposedAdapter,
414414
) -> Result<hal::SurfaceCapabilities, GetSurfaceSupportError> {
415+
let backend = adapter.backend();
415416
let suf = self
416-
.raw(adapter.backend())
417-
.ok_or(GetSurfaceSupportError::Unsupported)?;
417+
.raw(backend)
418+
.ok_or(GetSurfaceSupportError::NotSupportedByBackend(backend))?;
418419
profiling::scope!("surface_capabilities");
419420
let caps = unsafe { adapter.adapter.surface_capabilities(suf) }
420-
.ok_or(GetSurfaceSupportError::Unsupported)?;
421-
421+
.ok_or(GetSurfaceSupportError::FailedToRetrieveSurfaceCapabilitiesForAdapter)?;
422422
Ok(caps)
423423
}
424424

@@ -649,8 +649,10 @@ crate::impl_storage_item!(Adapter);
649649
#[derive(Clone, Debug, Error)]
650650
#[non_exhaustive]
651651
pub enum GetSurfaceSupportError {
652-
#[error("Surface is not supported by the adapter")]
653-
Unsupported,
652+
#[error("Surface is not supported for the specified backend {0}")]
653+
NotSupportedByBackend(Backend),
654+
#[error("Failed to retrieve surface capabilities for the specified adapter.")]
655+
FailedToRetrieveSurfaceCapabilitiesForAdapter,
654656
}
655657

656658
#[derive(Clone, Debug, Error)]

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2254,7 +2254,8 @@ impl crate::Adapter for super::Adapter {
22542254
Ok(present_modes) => present_modes,
22552255
Err(e) => {
22562256
log::error!("get_physical_device_surface_present_modes: {}", e);
2257-
Vec::new()
2257+
// Per definition of `SurfaceCapabilities`, there must be at least one present mode.
2258+
return None;
22582259
}
22592260
}
22602261
};
@@ -2269,7 +2270,8 @@ impl crate::Adapter for super::Adapter {
22692270
Ok(formats) => formats,
22702271
Err(e) => {
22712272
log::error!("get_physical_device_surface_formats: {}", e);
2272-
Vec::new()
2273+
// Per definition of `SurfaceCapabilities`, there must be at least one present format.
2274+
return None;
22732275
}
22742276
}
22752277
};

wgpu/src/backend/wgpu_core.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -702,10 +702,7 @@ impl crate::Context for ContextWgpuCore {
702702
.surface_get_capabilities(surface_data.id, *adapter_data)
703703
{
704704
Ok(caps) => caps,
705-
Err(wgc::instance::GetSurfaceSupportError::Unsupported) => {
706-
wgt::SurfaceCapabilities::default()
707-
}
708-
Err(err) => self.handle_error_fatal(err, "Surface::get_supported_formats"),
705+
Err(_) => wgt::SurfaceCapabilities::default(),
709706
}
710707
}
711708

0 commit comments

Comments
 (0)