Skip to content

Commit

Permalink
Fix Vulkan surface capabilities being advertised when its query faile…
Browse files Browse the repository at this point in the history
…d. (#6510)
  • Loading branch information
Wumpf committed Nov 23, 2024
1 parent d4b0b2d commit 560d5d8
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 12 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ Bottom level categories:

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

#### Vulkan

- Fix surface capabilities being advertised when its query failed. By @wumpf in [#6510](https://github.com/gfx-rs/wgpu/pull/6510)

## 23.0.0 (2024-10-25)

### Themes of this release
Expand Down
14 changes: 8 additions & 6 deletions wgpu-core/src/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,13 +412,13 @@ impl Surface {
&self,
adapter: &hal::DynExposedAdapter,
) -> Result<hal::SurfaceCapabilities, GetSurfaceSupportError> {
let backend = adapter.backend();
let suf = self
.raw(adapter.backend())
.ok_or(GetSurfaceSupportError::Unsupported)?;
.raw(backend)
.ok_or(GetSurfaceSupportError::NotSupportedByBackend(backend))?;
profiling::scope!("surface_capabilities");
let caps = unsafe { adapter.adapter.surface_capabilities(suf) }
.ok_or(GetSurfaceSupportError::Unsupported)?;

.ok_or(GetSurfaceSupportError::FailedToRetrieveSurfaceCapabilitiesForAdapter)?;
Ok(caps)
}

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

#[derive(Clone, Debug, Error)]
Expand Down
6 changes: 4 additions & 2 deletions wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2254,7 +2254,8 @@ impl crate::Adapter for super::Adapter {
Ok(present_modes) => present_modes,
Err(e) => {
log::error!("get_physical_device_surface_present_modes: {}", e);
Vec::new()
// Per definition of `SurfaceCapabilities`, there must be at least one present mode.
return None;
}
}
};
Expand All @@ -2269,7 +2270,8 @@ impl crate::Adapter for super::Adapter {
Ok(formats) => formats,
Err(e) => {
log::error!("get_physical_device_surface_formats: {}", e);
Vec::new()
// Per definition of `SurfaceCapabilities`, there must be at least one present format.
return None;
}
}
};
Expand Down
5 changes: 1 addition & 4 deletions wgpu/src/backend/wgpu_core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -702,10 +702,7 @@ impl crate::Context for ContextWgpuCore {
.surface_get_capabilities(surface_data.id, *adapter_data)
{
Ok(caps) => caps,
Err(wgc::instance::GetSurfaceSupportError::Unsupported) => {
wgt::SurfaceCapabilities::default()
}
Err(err) => self.handle_error_fatal(err, "Surface::get_supported_formats"),
Err(_) => wgt::SurfaceCapabilities::default(),
}
}

Expand Down

0 comments on commit 560d5d8

Please sign in to comment.