Skip to content

Commit 574bf7d

Browse files
VitalyAnkhjames7132
authored andcommitted
Update wgpu to 0.14.0, naga to 0.10.0, winit to 0.27.4, raw-window-handle to 0.5.0, ndk to 0.7 (bevyengine#6218)
# Objective - Update `wgpu` to 0.14.0, `naga` to `0.10.0`, `winit` to 0.27.4, `raw-window-handle` to 0.5.0, `ndk` to 0.7. ## Solution --- ## Changelog ### Changed - Changed `RawWindowHandleWrapper` to `RawHandleWrapper` which wraps both `RawWindowHandle` and `RawDisplayHandle`, which satisfies the `impl HasRawWindowHandle and HasRawDisplayHandle` that `wgpu` 0.14.0 requires. - Changed `bevy_window::WindowDescriptor`'s `cursor_locked` to `cursor_grab_mode`, change its type from `bool` to `bevy_window::CursorGrabMode`. ## Migration Guide - Adjust usage of `bevy_window::WindowDescriptor`'s `cursor_locked` to `cursor_grab_mode`, and adjust its type from `bool` to `bevy_window::CursorGrabMode`.
1 parent a672424 commit 574bf7d

File tree

17 files changed

+188
-134
lines changed

17 files changed

+188
-134
lines changed

crates/bevy_asset/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ wasm-bindgen-futures = "0.4"
4040
js-sys = "0.3"
4141

4242
[target.'cfg(target_os = "android")'.dependencies]
43-
ndk-glue = { version = "0.5" }
43+
ndk-glue = { version = "0.7" }
4444

4545
[dev-dependencies]
4646
futures-lite = "1.4.0"

crates/bevy_internal/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -100,4 +100,4 @@ bevy_gilrs = { path = "../bevy_gilrs", optional = true, version = "0.9.0-dev" }
100100
[target.'cfg(target_os = "android")'.dependencies]
101101
# This version *must* be the same as the version used by winit,
102102
# or Android will break: https://github.com/rust-windowing/winit#android
103-
ndk-glue = {version = "0.5", features = ["logger"]}
103+
ndk-glue = {version = "0.7", features = ["logger"]}

crates/bevy_render/Cargo.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ bevy_utils = { path = "../bevy_utils", version = "0.9.0-dev" }
4949
image = { version = "0.24", default-features = false }
5050

5151
# misc
52-
wgpu = { version = "0.13.1", features = ["spirv"] }
52+
wgpu = { version = "0.14.0", features = ["spirv"] }
5353
codespan-reporting = "0.11.0"
54-
naga = { version = "0.9.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] }
54+
naga = { version = "0.10.0", features = ["glsl-in", "spv-in", "spv-out", "wgsl-in", "wgsl-out"] }
5555
serde = { version = "1", features = ["derive"] }
5656
bitflags = "1.2.1"
5757
smallvec = { version = "1.6", features = ["union", "const_generics"] }

crates/bevy_render/src/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ impl Plugin for RenderPlugin {
149149

150150
let surface = windows
151151
.get_primary()
152-
.and_then(|window| window.raw_window_handle())
152+
.and_then(|window| window.raw_handle())
153153
.map(|wrapper| unsafe {
154154
let handle = wrapper.get_handle();
155155
instance.create_surface(&handle)

crates/bevy_render/src/view/window.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ use crate::{
66
use bevy_app::{App, Plugin};
77
use bevy_ecs::prelude::*;
88
use bevy_utils::{tracing::debug, HashMap, HashSet};
9-
use bevy_window::{PresentMode, RawWindowHandleWrapper, WindowClosed, WindowId, Windows};
9+
use bevy_window::{PresentMode, RawHandleWrapper, WindowClosed, WindowId, Windows};
1010
use std::ops::{Deref, DerefMut};
1111

1212
/// Token to ensure a system runs on the main thread.
@@ -38,7 +38,7 @@ impl Plugin for WindowRenderPlugin {
3838

3939
pub struct ExtractedWindow {
4040
pub id: WindowId,
41-
pub raw_window_handle: Option<RawWindowHandleWrapper>,
41+
pub raw_handle: Option<RawHandleWrapper>,
4242
pub physical_width: u32,
4343
pub physical_height: u32,
4444
pub present_mode: PresentMode,
@@ -83,7 +83,7 @@ fn extract_windows(
8383
.entry(window.id())
8484
.or_insert(ExtractedWindow {
8585
id: window.id(),
86-
raw_window_handle: window.raw_window_handle(),
86+
raw_handle: window.raw_handle(),
8787
physical_width: new_width,
8888
physical_height: new_height,
8989
present_mode: window.present_mode(),
@@ -164,17 +164,16 @@ pub fn prepare_windows(
164164
for window in windows
165165
.windows
166166
.values_mut()
167-
// value of raw_winndow_handle only None if synthetic test
168-
.filter(|x| x.raw_window_handle.is_some())
167+
// value of raw_handle is only None in synthetic tests
168+
.filter(|x| x.raw_handle.is_some())
169169
{
170170
let window_surfaces = window_surfaces.deref_mut();
171171
let surface = window_surfaces
172172
.surfaces
173173
.entry(window.id)
174174
.or_insert_with(|| unsafe {
175175
// NOTE: On some OSes this MUST be called from the main thread.
176-
render_instance
177-
.create_surface(&window.raw_window_handle.as_ref().unwrap().get_handle())
176+
render_instance.create_surface(&window.raw_handle.as_ref().unwrap().get_handle())
178177
});
179178

180179
let swap_chain_descriptor = wgpu::SurfaceConfiguration {
@@ -197,6 +196,7 @@ pub fn prepare_windows(
197196
PresentMode::AutoVsync => wgpu::PresentMode::AutoVsync,
198197
PresentMode::AutoNoVsync => wgpu::PresentMode::AutoNoVsync,
199198
},
199+
alpha_mode: wgpu::CompositeAlphaMode::Auto,
200200
};
201201

202202
// Do the initial surface configuration if it hasn't been configured yet. Or if size or

crates/bevy_window/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ bevy_reflect = { path = "../bevy_reflect", version = "0.9.0-dev" }
2121
bevy_utils = { path = "../bevy_utils", version = "0.9.0-dev" }
2222
# Used for close_on_esc
2323
bevy_input = { path = "../bevy_input", version = "0.9.0-dev" }
24-
raw-window-handle = "0.4.2"
24+
raw-window-handle = "0.5"
2525

2626
# other
2727
serde = { version = "1.0", features = ["derive"], optional = true }

crates/bevy_window/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#[warn(missing_docs)]
22
mod cursor;
33
mod event;
4-
mod raw_window_handle;
4+
mod raw_handle;
55
mod system;
66
mod window;
77
mod windows;
88

9-
pub use crate::raw_window_handle::*;
9+
pub use crate::raw_handle::*;
1010
pub use cursor::*;
1111
pub use event::*;
1212
pub use system::*;

crates/bevy_window/src/raw_handle.rs

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
use raw_window_handle::{
2+
HasRawDisplayHandle, HasRawWindowHandle, RawDisplayHandle, RawWindowHandle,
3+
};
4+
5+
/// A wrapper over [`RawWindowHandle`] and [`RawDisplayHandle`] that allows us to safely pass it across threads.
6+
///
7+
/// Depending on the platform, the underlying pointer-containing handle cannot be used on all threads,
8+
/// and so we cannot simply make it (or any type that has a safe operation to get a [`RawWindowHandle`] or [`RawDisplayHandle`])
9+
/// thread-safe.
10+
#[derive(Debug, Clone)]
11+
pub struct RawHandleWrapper {
12+
pub window_handle: RawWindowHandle,
13+
pub display_handle: RawDisplayHandle,
14+
}
15+
16+
impl RawHandleWrapper {
17+
/// Returns a [`HasRawWindowHandle`] + [`HasRawDisplayHandle`] impl, which exposes [`RawWindowHandle`] and [`RawDisplayHandle`].
18+
///
19+
/// # Safety
20+
///
21+
/// Some platforms have constraints on where/how this handle can be used. For example, some platforms don't support doing window
22+
/// operations off of the main thread. The caller must ensure the [`RawHandleWrapper`] is only used in valid contexts.
23+
pub unsafe fn get_handle(&self) -> ThreadLockedRawWindowHandleWrapper {
24+
ThreadLockedRawWindowHandleWrapper(self.clone())
25+
}
26+
27+
pub fn get_display_handle(&self) -> RawDisplayHandle {
28+
self.display_handle
29+
}
30+
31+
pub fn get_window_handle(&self) -> RawWindowHandle {
32+
self.window_handle
33+
}
34+
}
35+
36+
// SAFETY: [`RawHandleWrapper`] is just a normal "raw pointer", which doesn't impl Send/Sync. However the pointer is only
37+
// exposed via an unsafe method that forces the user to make a call for a given platform. (ex: some platforms don't
38+
// support doing window operations off of the main thread).
39+
// A recommendation for this pattern (and more context) is available here:
40+
// https://github.com/rust-windowing/raw-window-handle/issues/59
41+
unsafe impl Send for RawHandleWrapper {}
42+
unsafe impl Sync for RawHandleWrapper {}
43+
44+
/// A [`RawHandleWrapper`] that cannot be sent across threads.
45+
///
46+
/// This safely exposes [`RawWindowHandle`] and [`RawDisplayHandle`], but care must be taken to ensure that the construction itself is correct.
47+
///
48+
/// This can only be constructed via the [`RawHandleWrapper::get_handle()`] method;
49+
/// be sure to read the safety docs there about platform-specific limitations.
50+
/// In many cases, this should only be constructed on the main thread.
51+
pub struct ThreadLockedRawWindowHandleWrapper(RawHandleWrapper);
52+
53+
// SAFETY: the caller has validated that this is a valid context to get [`RawHandleWrapper`]
54+
// as otherwise an instance of this type could not have been constructed
55+
// NOTE: we cannot simply impl HasRawWindowHandle for RawHandleWrapper,
56+
// as the `raw_window_handle` method is safe. We cannot guarantee that all calls
57+
// of this method are correct (as it may be off the main thread on an incompatible platform),
58+
// and so exposing a safe method to get a [`RawWindowHandle`] directly would be UB.
59+
unsafe impl HasRawWindowHandle for ThreadLockedRawWindowHandleWrapper {
60+
fn raw_window_handle(&self) -> RawWindowHandle {
61+
self.0.get_window_handle()
62+
}
63+
}
64+
65+
// SAFETY: the caller has validated that this is a valid context to get [`RawDisplayHandle`]
66+
// as otherwise an instance of this type could not have been constructed
67+
// NOTE: we cannot simply impl HasRawDisplayHandle for RawHandleWrapper,
68+
// as the `raw_display_handle` method is safe. We cannot guarantee that all calls
69+
// of this method are correct (as it may be off the main thread on an incompatible platform),
70+
// and so exposing a safe method to get a [`RawDisplayHandle`] directly would be UB.
71+
unsafe impl HasRawDisplayHandle for ThreadLockedRawWindowHandleWrapper {
72+
fn raw_display_handle(&self) -> RawDisplayHandle {
73+
self.0.get_display_handle()
74+
}
75+
}

crates/bevy_window/src/raw_window_handle.rs

-54
This file was deleted.

0 commit comments

Comments
 (0)