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)

* distinguish `GetSurfaceSupportError` between backend unsupported and failing to get surface caps

* Fix vulkan backend returning invalid surface configuration

* changelog entry
  • Loading branch information
Wumpf authored Nov 12, 2024
1 parent 4311091 commit ae6c6fb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 16 deletions.
10 changes: 6 additions & 4 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,17 +123,19 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148]
#### General

- Handle query set creation failure as an internal error that loses the `Device`, rather than panicking. By @ErichDonGubler in [#6505](https://github.com/gfx-rs/wgpu/pull/6505).
- Ensure that `Features::TIMESTAMP_QUERY` is set when using timestamp writes in render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497).
- Check for device mismatches when beginning render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497).
- Lower `QUERY_SET_MAX_QUERIES` (and enforced limits) from 8192 to 4096 to match WebGPU spec. By @ErichDonGubler in [#6525](https://github.com/gfx-rs/wgpu/pull/6525).

#### Naga

- Fix crash when a texture argument is missing. By @aedm in [#6486](https://github.com/gfx-rs/wgpu/pull/6486)
- Emit an error in constant evaluation, rather than crash, in certain cases where `vecN` constructors have less than N arguments. By @ErichDonGubler in [#6508](https://github.com/gfx-rs/wgpu/pull/6508).

#### General
#### Vulkan

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

- Ensure that `Features::TIMESTAMP_QUERY` is set when using timestamp writes in render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497).
- Check for device mismatches when beginning render and compute passes. By @ErichDonGubler in [#6497](https://github.com/gfx-rs/wgpu/pull/6497).
- Lower `QUERY_SET_MAX_QUERIES` (and enforced limits) from 8192 to 4096 to match WebGPU spec. By @ErichDonGubler in [#6525](https://github.com/gfx-rs/wgpu/pull/6525).

## 23.0.0 (2024-10-25)

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 @@ -2262,7 +2262,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 @@ -2277,7 +2278,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 @@ -716,10 +716,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 ae6c6fb

Please sign in to comment.