feat(raw_window_handle): Improve raw-window-handle api & bump wgpu version#394
feat(raw_window_handle): Improve raw-window-handle api & bump wgpu version#394What42Pizza wants to merge 10 commits into
Conversation
|
Also, I'm kinda questioning whether this raw-window-handle compatibility should be in the higher-level sdl3 crate considering the fact that the implementation only needs the functions and types from the sdl3-sys crate Here's what I'm envisioning: there's a new 'sdl3-raw-window-handle' crate that provides If this needs more explaining or an example implementation then let me know |
|
I've been looking into the safety of this caching approach some more, and safety documentation for handles like this are annoying absent, but it does seem like this should be safe. Here's a list of every pointer/id that is queried by the raw-window-handle compat code: If any of these values were to change while the window is still alive, that would cause huge issues with essentially any graphics api, so I think it's safe to assume that these values can be cached. Also, for what it's worth, SDL tends to document when values need to be re-queried, and it doesn't document that any of these values need to be re-queried. |
|
The overall approach here (querying the native handles once and caching them in a wrapper) is reasonable, and splitting the shared vs mut variants makes sense. A few things before it can land:
Unrelated to your change: the red Windows CI is a build-from-source break on the GitHub runners, fixed separately in #407. Once that lands a rebase should clear it. |
|
Thanks for the feedback, I did change the names as requested but I'm unsure of what to do for the unsafe impls. As far as I understand it, for a struct like Also, I'm not familiar with adding migration notes, so an example of what to do for that would be nice. And about the safety comment on It seems like the unsafe impls are the biggest problem, and the core of it is that the actual window and display pointers shouldn't be sent across threads, but wgpu requires the given window struct to be send/sync anyways. And even if the unsafe impls are removed, anyone who wants to use sdl3-rs with wgpu will just add their own unsafe impls, so the problem is just moved instead of fixed. So I'm in favor of keeping the unsafe impls, which now have a safety comment explaining why it technically isn't sound but is still likely safe in practice. |
This does three things:
sdl3::video::Windowas araw_window_handle::HasDisplayHandletype (previously the example needed a custom type with its own unsafe code, and now it's justwindow.as_window_handle()?)&mut selfmethods onsdl3::video::Windowdue to lifetime restrictionswgpu's version from 29.0.1 to 30.0.0Edit: latest safety review