Skip to content

Commit cbace63

Browse files
authored
Fix surfaces only compatible with first enabled backend (#5535)
1 parent ea77d56 commit cbace63

File tree

11 files changed

+235
-269
lines changed

11 files changed

+235
-269
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ Bottom level categories:
153153
- 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).
154154
- Use memory pooling for UsageScopes to avoid frequent large allocations. by @robtfm in [#5414](https://github.com/gfx-rs/wgpu/pull/5414)
155155
- Fix deadlocks caused by recursive read-write lock acquisitions [#5426](https://github.com/gfx-rs/wgpu/pull/5426).
156+
- 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).
156157

157158
#### Naga
158159
- 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).

wgpu-core/src/any_surface.rs

Lines changed: 0 additions & 95 deletions
This file was deleted.

wgpu-core/src/device/global.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1969,7 +1969,7 @@ impl Global {
19691969
};
19701970

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

20572057
match unsafe {
2058-
A::get_surface(surface)
2058+
A::surface_as_hal(surface)
20592059
.unwrap()
20602060
.configure(device.raw(), &hal_config)
20612061
} {

wgpu-core/src/hal_api.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub trait HalApi: hal::Api + 'static + WasmNotSendSync {
1111
fn create_instance_from_hal(name: &str, hal_instance: Self::Instance) -> Instance;
1212
fn instance_as_hal(instance: &Instance) -> Option<&Self::Instance>;
1313
fn hub(global: &Global) -> &Hub<Self>;
14-
fn get_surface(surface: &Surface) -> Option<&Self::Surface>;
14+
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface>;
1515
}
1616

1717
impl HalApi for hal::api::Empty {
@@ -25,7 +25,7 @@ impl HalApi for hal::api::Empty {
2525
fn hub(_: &Global) -> &Hub<Self> {
2626
unimplemented!("called empty api")
2727
}
28-
fn get_surface(_: &Surface) -> Option<&Self::Surface> {
28+
fn surface_as_hal(_: &Surface) -> Option<&Self::Surface> {
2929
unimplemented!("called empty api")
3030
}
3131
}
@@ -46,8 +46,8 @@ impl HalApi for hal::api::Vulkan {
4646
fn hub(global: &Global) -> &Hub<Self> {
4747
&global.hubs.vulkan
4848
}
49-
fn get_surface(surface: &Surface) -> Option<&Self::Surface> {
50-
surface.raw.downcast_ref::<Self>()
49+
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface> {
50+
surface.vulkan.as_ref()
5151
}
5252
}
5353

@@ -67,8 +67,8 @@ impl HalApi for hal::api::Metal {
6767
fn hub(global: &Global) -> &Hub<Self> {
6868
&global.hubs.metal
6969
}
70-
fn get_surface(surface: &Surface) -> Option<&Self::Surface> {
71-
surface.raw.downcast_ref::<Self>()
70+
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface> {
71+
surface.metal.as_ref()
7272
}
7373
}
7474

@@ -88,8 +88,8 @@ impl HalApi for hal::api::Dx12 {
8888
fn hub(global: &Global) -> &Hub<Self> {
8989
&global.hubs.dx12
9090
}
91-
fn get_surface(surface: &Surface) -> Option<&Self::Surface> {
92-
surface.raw.downcast_ref::<Self>()
91+
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface> {
92+
surface.dx12.as_ref()
9393
}
9494
}
9595

@@ -110,7 +110,7 @@ impl HalApi for hal::api::Gles {
110110
fn hub(global: &Global) -> &Hub<Self> {
111111
&global.hubs.gl
112112
}
113-
fn get_surface(surface: &Surface) -> Option<&Self::Surface> {
114-
surface.raw.downcast_ref::<Self>()
113+
fn surface_as_hal(surface: &Surface) -> Option<&Self::Surface> {
114+
surface.gl.as_ref()
115115
}
116116
}

wgpu-core/src/hub.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ impl<A: HalApi> Hub<A> {
241241
if let Element::Occupied(ref surface, _epoch) = *element {
242242
if let Some(ref mut present) = surface.presentation.lock().take() {
243243
if let Some(device) = present.device.downcast_ref::<A>() {
244-
let suf = A::get_surface(surface);
244+
let suf = A::surface_as_hal(surface);
245245
unsafe {
246246
suf.unwrap().unconfigure(device.raw());
247247
//TODO: we could destroy the surface here

0 commit comments

Comments
 (0)