Skip to content
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

feat(extensions/webgpu): swapchain support #10690

Closed
wants to merge 11 commits into from

Conversation

crowlKats
Copy link
Member

No description provided.

crowlKats and others added 11 commits March 23, 2021 02:22
# Conflicts:
#	Cargo.lock
#	extensions/webgpu/Cargo.toml
#	extensions/webgpu/swapchain.rs
#	op_crates/webgpu/lib.rs
# Conflicts:
#	Cargo.lock
#	extensions/webgpu/Cargo.toml
@EnzoAlbornoz
Copy link

Fantastic work! Is there anything missing yet? Maybe I could help. I was trying to do something like this and I've found this PR.

@crowlKats
Copy link
Member Author

@EnzoAlbornoz currently only the JS code is missing, but this where it gets tricky: we want to be web compatible, but the spec wasn't designed to work with native windowing, so we are waiting for discussion by the webgpu people in regards to this issue

@EnzoAlbornoz
Copy link

There already is a discussion opened in the WebGPU repository that I could track? Or we need to open it?

@crowlKats
Copy link
Member Author

use serde::Deserialize;
use std::borrow::Cow;

struct WebGpuRawWindowHandle(DynHasRawWindowHandle);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This struct shouldn't be public? I mean, how can I integrate with Winit Window with this struct? When I tried to use the Winit window this error occurred:

error: Uncaught (in promise) BadResource: Bad resource ID

@EnzoAlbornoz
Copy link

EnzoAlbornoz commented May 23, 2021

I tried to use this implementation, but TypeId from dynamic load libraries is different.
Rc<WebGpuRawWindowHandle> in Deno binary -> 1254897155336868536
Rc<WebGpuRawWindowHandle> in Extension/Plugin lib -> 12790201640706278645

Because they have different ids, the resource table returns bad_resource_id.

There is some way to solve this? I'm trying to test this for more than two days

@lucacasonato
Copy link
Member

There is some way to solve this? I'm trying to test this for more than two days

Yeah this is a limitation of Rust compilation. @eliassjogreen had some unsafe workaround for it via means of casts, but I don't remember what exactly.

@eliassjogreen
Copy link
Contributor

Yes, the unsafe workaround is as follows:

  let resource_dyn = state
    .resource_table
    .get_any(args.rid)
    .ok_or_else(bad_resource_id)?;
  let resource_ptr = &resource_dyn as *const Rc<_> as *const Rc<WebGpuRawWindowHandle>;
  let resource = unsafe { &*resource_ptr };

It is however pretty safe because the ResourceTable is keyed by ResourceId instead of TypeId like GothamState is which means as long as you pass a valid window resource with the same internal types the TypeId shouldn't matter. The workaround is pretty much the same thing as ResourceTable::get does internally but without the TypeId check. Another solution could be using something like unique-type-id or checking TypeName instead of TypeId when downcasting in the ResourceTable.

@EnzoAlbornoz
Copy link

EnzoAlbornoz commented May 23, 2021

Yes, the unsafe workaround is as follows:

  let resource_dyn = state
    .resource_table
    .get_any(args.rid)
    .ok_or_else(bad_resource_id)?;
  let resource_ptr = &resource_dyn as *const Rc<_> as *const Rc<WebGpuRawWindowHandle>;
  let resource = unsafe { &*resource_ptr };

It is however pretty safe because the ResourceTable is keyed by ResourceId instead of TypeId like GothamState is which means as long as you pass a valid window resource with the same internal types the TypeId shouldn't matter. The workaround is pretty much the same thing as ResourceTable::get does internally but without the TypeId check. Another solution could be using something like unique-type-id or checking TypeName instead of TypeId when downcasting in the ResourceTable.

It worked!. But now I'm having the following problem:

  • Window created
  • Call to create surface (no panic) (execution stopped in instance.instance_create_surface)
  • Window closes instantly (Using denosaurs/pane)

Anyone had this problem too?

@eliassjogreen
Copy link
Contributor

I have played around with my module too and had the same problem, when looking at the exit code it usually exits with a segfault if I am not mistaken.

@stale
Copy link

stale bot commented Jul 27, 2021

This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale label Jul 27, 2021
@stale stale bot closed this Aug 3, 2021
@crowlKats crowlKats deleted the swapchain branch September 17, 2021 13:01
@smolck
Copy link

smolck commented Oct 5, 2021

Any plans to continue working on this in another PR, or what's the status here?

@crowlKats
Copy link
Member Author

This is still stuck on webgpu-native/webgpu-headers#88

@chances
Copy link

chances commented Sep 4, 2022

Looks like there's progress on the blockers. 🎉 See webgpu-native/webgpu-headers#164

@DiThi
Copy link

DiThi commented Nov 5, 2022

This should be reopened. Progress is slow but there is progress. The stale bot only made this more difficult to find...

@itsjoekent
Copy link

Seems like it's merged?

webgpu-native/webgpu-headers#203

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants