-
Notifications
You must be signed in to change notification settings - Fork 1k
Generic Surface
for !Send
situations
#7549
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I wonder if we could split the difference and have a |
Discussing this in next week's maintainers meeting |
At a glance (so I'm prepared to be very wrong here), it seems like the Assuming the I'm not sure if this actually accomplishes that, but this example creates the lifetime bound without requiring that the underlying type be Edit: Tweaked the playground to improve the exposed generics on |
Discussion from this week's wgpu maintainers meeting: Instead of making |
Is your feature request related to a problem? Please describe.
I became aware of a public example of using
wgpu
which doesunsafe impl Send
to bypasswgpu::WindowHandle
'sSend + Sync
requirement:https://github.com/vhspace/sdl3-rs/blob/82ff24b43044c5ebacf004cabb04339ed93e8b05/examples/raw-window-handle-with-wgpu/main.rs#L205-L209
This is not ideal, and it would be helpful if
wgpu
could make this unsound unsafe code unnecessary for a basic usage with a!Send
windowing library. (By unsound, I mean: it is possible for code outside the unsafe module to misuse it to cause UB; specifically, by sending the resultingwgpu::Surface
.)Describe the solution you'd like
Change
wgpu::Surface
to, instead of type-erasing the provided window handle, be generic over the type of the handle (replacing the current lifetime parameter). The API for this could look likeIf a type-erased
Surface
is still needed (e.g. for a renderer library used on multiple platforms that wishes to avoid generics), this can be done by the application, especially ifwgpu
helps out with:which means the application can treat window-handle surfaces and canvas surfaces uniformly just by using
wgpu::Surface<Option<Box<dyn MyWindowHandle>>>
, essentially recovering the current type-erased API.Describe alternatives you've considered
wgpu
could expose a separatestruct SyncSurface
andstruct NonSyncSurface
, to not have any public generic code.Additional context
The idea of
Surface<W>
was part of the original discussion on safe surface creation #1463. It was omitted from the PR #4597 apparently on the grounds that it is desirable for the underlying implementation traits to bedyn
-compatible — but since the only thingwgpu::Surface
does with the handle is own and drop it, the generic does not have to leak into lower layers.The text was updated successfully, but these errors were encountered: