Skip to content

Commit 35db26b

Browse files
authored
Make HasDisplayHandle optional in WindowHandle (#8782)
1 parent ce631c1 commit 35db26b

File tree

26 files changed

+221
-88
lines changed

26 files changed

+221
-88
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ depth_stencil: Some(wgpu::DepthStencilState::stencil(
141141
- Added `TextureFormat::channels` method to get some information about which color channels are covered by the texture format. By @TornaxO7 in [#9167](https://github.com/gfx-rs/wgpu/pull/9167)
142142
- BREAKING: Add `V6_8` variant to `DxcShaderModel` and `naga::back::hlsl::ShaderModel`. By @inner-daemons in [#8882](https://github.com/gfx-rs/wgpu/pull/8882) and @ErichDonGubler in [#9083](https://github.com/gfx-rs/wgpu/pull/9083).
143143
- BREAKING: Add `V6_9` variant to `DxcShaderModel` and `naga::back::hlsl::ShaderModel`. By @ErichDonGubler in [#????](https://github.com/gfx-rs/wgpu/pull/????).
144+
- `DisplayHandle` is now optional in surface creation if it was passed to `InstanceDescriptor::display`. By @MarijnS95 in [#8782](https://github.com/gfx-rs/wgpu/pull/8782)
144145

145146
#### naga
146147

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

benches/benches/wgpu-benchmark/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl DeviceState {
2929

3030
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
3131
backends: wgpu::Backends::from_env().unwrap_or(base_backend),
32-
..wgpu::InstanceDescriptor::from_env_or_default()
32+
..wgpu::InstanceDescriptor::new_without_display_handle_from_env()
3333
});
3434

3535
let adapter = block_on(wgpu::util::initialize_adapter_from_env_or_default(

deno_webgpu/byow.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ impl<'a> FromV8<'a> for UnsafeWindowSurfaceOptions {
276276

277277
type RawHandles = (
278278
raw_window_handle::RawWindowHandle,
279-
raw_window_handle::RawDisplayHandle,
279+
Option<raw_window_handle::RawDisplayHandle>,
280280
);
281281

282282
#[cfg(target_os = "macos")]
@@ -298,7 +298,7 @@ fn raw_window(
298298
let display_handle = raw_window_handle::RawDisplayHandle::AppKit(
299299
raw_window_handle::AppKitDisplayHandle::new(),
300300
);
301-
Ok((win_handle, display_handle))
301+
Ok((win_handle, Some(display_handle)))
302302
}
303303

304304
#[cfg(target_os = "windows")]
@@ -324,7 +324,7 @@ fn raw_window(
324324

325325
let display_handle =
326326
raw_window_handle::RawDisplayHandle::Windows(WindowsDisplayHandle::new());
327-
Ok((win_handle, display_handle))
327+
Ok((win_handle, Some(display_handle)))
328328
}
329329

330330
#[cfg(any(
@@ -366,7 +366,7 @@ fn raw_window(
366366
return Err(ByowError::InvalidSystem);
367367
}
368368

369-
Ok((win_handle, display_handle))
369+
Ok((win_handle, Some(display_handle)))
370370
}
371371

372372
#[cfg(not(any(

examples/features/src/framework.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ impl ExampleContext {
260260
async fn init_async<E: Example>(surface: &mut SurfaceWrapper, window: Arc<Window>) -> Self {
261261
log::info!("Initializing wgpu...");
262262

263-
let instance_descriptor = wgpu::InstanceDescriptor::from_env_or_default()
264-
.with_display_handle(Box::new(
263+
let instance_descriptor =
264+
wgpu::InstanceDescriptor::new_with_display_handle_from_env(Box::new(
265265
// TODO: Use event_loop.owned_display_handle() with winit 0.30
266266
window.clone(),
267267
));

examples/features/src/hello_triangle/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ async fn run(event_loop: EventLoop<()>, window: Window) {
1212
size.width = size.width.max(1);
1313
size.height = size.height.max(1);
1414

15-
let instance = wgpu::Instance::new(
16-
wgpu::InstanceDescriptor::from_env_or_default()
17-
// TODO: Use event_loop.owned_display_handle() with winit 0.30
18-
.with_display_handle(Box::new(window.clone())),
19-
);
15+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_with_display_handle_from_env(
16+
// TODO: Use event_loop.owned_display_handle() with winit 0.30
17+
Box::new(window.clone()),
18+
));
2019

2120
let surface = instance.create_surface(&window).unwrap();
2221
let adapter = instance

examples/features/src/timestamp_queries/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,8 @@ impl Queries {
193193

194194
async fn run() {
195195
// Instantiates instance of wgpu
196-
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::from_env_or_default());
196+
let instance =
197+
wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle_from_env());
197198

198199
// `request_adapter` instantiates the general connection to the GPU
199200
let adapter = instance

examples/standalone/01_hello_compute/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ fn main() {
3838
// We first initialize an wgpu `Instance`, which contains any "global" state wgpu needs.
3939
//
4040
// This is what loads the vulkan/dx12/metal/opengl libraries.
41-
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::default());
41+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle());
4242

4343
// We then create an `Adapter` which represents a physical gpu in the system. It allows
4444
// us to query information about it and create a `Device` from it.

examples/standalone/02_hello_window/src/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ struct State {
1818

1919
impl State {
2020
async fn new(display: OwnedDisplayHandle, window: Arc<Window>) -> State {
21-
let instance = wgpu::Instance::new(
22-
wgpu::InstanceDescriptor::default().with_display_handle(Box::new(display)),
23-
);
21+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_with_display_handle(
22+
Box::new(display),
23+
));
2424
let adapter = instance
2525
.request_adapter(&wgpu::RequestAdapterOptions::default())
2626
.await

player/src/bin/play.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ fn main() {
1717
};
1818

1919
#[cfg(feature = "winit")]
20-
use raw_window_handle::{HasDisplayHandle, HasWindowHandle};
20+
use raw_window_handle::HasWindowHandle;
2121
#[cfg(feature = "winit")]
2222
use winit::{
2323
event::KeyEvent,
@@ -71,21 +71,16 @@ fn main() {
7171
.unwrap(),
7272
);
7373

74-
let instance_desc = wgt::InstanceDescriptor::from_env_or_default();
74+
let instance_desc = wgt::InstanceDescriptor::new_without_display_handle_from_env();
7575
#[cfg(feature = "winit")]
7676
// TODO: Use event_loop.owned_display_handle() with winit 0.30
7777
let instance_desc = instance_desc.with_display_handle(Box::new(window.clone()));
7878
let instance_flags = instance_desc.flags;
7979
let instance = wgc::instance::Instance::new("player", instance_desc, None);
8080

8181
#[cfg(feature = "winit")]
82-
let surface = unsafe {
83-
instance.create_surface(
84-
window.display_handle().unwrap().into(),
85-
window.window_handle().unwrap().into(),
86-
)
87-
}
88-
.unwrap();
82+
let surface =
83+
unsafe { instance.create_surface(None, window.window_handle().unwrap().into()) }.unwrap();
8984
#[cfg(feature = "winit")]
9085
let mut configured_surface_id = None;
9186

0 commit comments

Comments
 (0)