Skip to content

Commit

Permalink
Fix surfaces only compatible with first enabled backend (#5535)
Browse files Browse the repository at this point in the history
  • Loading branch information
Wumpf authored Apr 17, 2024
1 parent ea77d56 commit cbace63
Show file tree
Hide file tree
Showing 11 changed files with 235 additions and 269 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,7 @@ Bottom level categories:
- Failing to set the device lost closure will call the closure before returning. By @bradwerth in [#5358](https://github.com/gfx-rs/wgpu/pull/5358).
- Use memory pooling for UsageScopes to avoid frequent large allocations. by @robtfm in [#5414](https://github.com/gfx-rs/wgpu/pull/5414)
- Fix deadlocks caused by recursive read-write lock acquisitions [#5426](https://github.com/gfx-rs/wgpu/pull/5426).
- Fix surfaces being only compatible with first backend enabled on an instance, causing failures when manually specifying an adapter. By @Wumpf in [#5535](https://github.com/gfx-rs/wgpu/pull/5535).

#### Naga
- In spv-in, remove unnecessary "gl_PerVertex" name check so unused builtins will always be skipped. By @Imberflur in [#5227](https://github.com/gfx-rs/wgpu/pull/5227).
Expand Down
95 changes: 0 additions & 95 deletions wgpu-core/src/any_surface.rs

This file was deleted.

4 changes: 2 additions & 2 deletions wgpu-core/src/device/global.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1969,7 +1969,7 @@ impl Global {
};

let caps = unsafe {
let suf = A::get_surface(surface);
let suf = A::surface_as_hal(surface);
let adapter = &device.adapter;
match adapter.raw.adapter.surface_capabilities(suf.unwrap()) {
Some(caps) => caps,
Expand Down Expand Up @@ -2055,7 +2055,7 @@ impl Global {
// https://github.com/gfx-rs/wgpu/issues/4105

match unsafe {
A::get_surface(surface)
A::surface_as_hal(surface)
.unwrap()
.configure(device.raw(), &hal_config)
} {
Expand Down
20 changes: 10 additions & 10 deletions wgpu-core/src/hal_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pub trait HalApi: hal::Api + 'static + WasmNotSendSync {
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance;
fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance>;
fn hub(global: &Global) -> &Hub<Self>;
fn get_surface(surface: &Surface) -> Option<&Self::Surface>;
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface>;
}

impl HalApi for hal::api::Empty {
Expand All @@ -25,7 +25,7 @@ impl HalApi for hal::api::Empty {
fn hub(_: &Global) -> &Hub<Self> {
unimplemented!("called empty api")
}
fn get_surface(_: &Surface) -> Option<&Self::Surface> {
fn surface_as_hal(_: &Surface) -> Option<&Self::Surface> {
unimplemented!("called empty api")
}
}
Expand All @@ -46,8 +46,8 @@ impl HalApi for hal::api::Vulkan {
fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.vulkan
}
fn get_surface(surface: &Surface) -> Option<&Self::Surface> {
surface.raw.downcast_ref::<Self>()
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface> {
surface.vulkan.as_ref()
}
}

Expand All @@ -67,8 +67,8 @@ impl HalApi for hal::api::Metal {
fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.metal
}
fn get_surface(surface: &Surface) -> Option<&Self::Surface> {
surface.raw.downcast_ref::<Self>()
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface> {
surface.metal.as_ref()
}
}

Expand All @@ -88,8 +88,8 @@ impl HalApi for hal::api::Dx12 {
fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.dx12
}
fn get_surface(surface: &Surface) -> Option<&Self::Surface> {
surface.raw.downcast_ref::<Self>()
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface> {
surface.dx12.as_ref()
}
}

Expand All @@ -110,7 +110,7 @@ impl HalApi for hal::api::Gles {
fn hub(global: &Global) -> &Hub<Self> {
&global.hubs.gl
}
fn get_surface(surface: &Surface) -> Option<&Self::Surface> {
surface.raw.downcast_ref::<Self>()
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface> {
surface.gl.as_ref()
}
}
2 changes: 1 addition & 1 deletion wgpu-core/src/hub.rs
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ impl<A: HalApi> Hub<A> {
if let Element::Occupied(ref surface, _epoch) = *element {
if let Some(ref mut present) = surface.presentation.lock().take() {
if let Some(device) = present.device.downcast_ref::<A>() {
let suf = A::get_surface(surface);
let suf = A::surface_as_hal(surface);
unsafe {
suf.unwrap().unconfigure(device.raw());
//TODO: we could destroy the surface here
Expand Down
Loading

0 comments on commit cbace63

Please sign in to comment.