Skip to content
This repository has been archived by the owner on Nov 19, 2023. It is now read-only.

Better integration with gfx-hal #1

Open
zmerp opened this issue May 15, 2021 · 7 comments
Open

Better integration with gfx-hal #1

zmerp opened this issue May 15, 2021 · 7 comments

Comments

@zmerp
Copy link

zmerp commented May 15, 2021

Hi blaind,
I'm really interested in your work since I wanted to make ALVR switch its graphics code and VR runtime to bevy and OpenXR.
I saw your PRs and I wanted to give you some suggestions and and also a hand with the implementations. About gfx-hal, I think the OpenXR integration should be made into another crate. Currently there is no way of accessing gfx-hal internals, so I wanted to contribute an API to get backend-specific handles (like VkInstance and VkDevice) and to create gfx-hal objects from these handles. About wgpu, a similar API could be propagated, but I don't know if this is the right call, since the point of wgpu is to have a safe API. The best thing would be for bevy to switch from wgpu to gfx-hal directly, but this easier said than done.

@blaind
Copy link
Owner

blaind commented May 15, 2021

Hi @zarik5 - thank you for the message. ALVR seems like a great project! Regarding this PoC of xr on bevy, all help is welcome :)

I saw your message in gfx-issue, and had a bit of thought already. Some initial pointers:

  • taking the openxr-part from gfx-rs could be doable. Its mostly self-contained anyways
    • if possible, communication could be done through raw pointers. This would also encapsulate the openxr implementation, I like the idea
  • there's a few parts that'd require tinkering and/or support from gfx, though:
    • multiview (link)
    • supplying xr-required api version (I don't remember if this is really needed, though, have to double check): link)
    • getting a list of xr-enabled devices (link). This is something that's done at wgpu-side
    • on xr, setting only a subset of queue families link

There might also be some openxr-reconfiguration cases which I haven't hit yet. Also, my pull request for gfx support only vulkan currently, but openxr supports opengl too.

wgpu-rs and wgpu crates are ~34k lines of code in total, I guess bevy benefits quite a bit of the graphics handling done here. Moving away from wgpu might not be feasible...

My PoC uses 100% the rendering done by bevy (using wgpu), only change is the render target - whereas in non-xr environment the target is a swapchain supplied by wgpu, in XR environment I'm creating a xr-specific swapchain.

If wgpu is used, then the challenge of moving raw handles between bevy <-> wgpu-rs <-> wgpu <-> gfx-rs will persist. So far, I managed to get away with a solution where the handles need to be moved only in initialization, not during rendering. Not sure if that covers all the cases, though. Current solution is explained here

@zmerp
Copy link
Author

zmerp commented May 15, 2021

Thanks for the reply. I agree that cutting out wgpu is not feasible. I don't have much time (because of school) but I'll try to work on gfx-hal, starting from exposing the raw handles. I'll be working here. If your PR on wgpu gets dismissed I'll propose to expose the handles also there.

supplying xr-required api version (I don't remember if this is really needed, though, have to double check): link)

The example on openxrs uses Vulkan version 1.1.0. I don't think there is any restriction on this.

@zmerp
Copy link
Author

zmerp commented May 15, 2021

Looking more into wgpu I think there is a clean way of implementing this. Since wpgu-core is advertised as not usable by third-party crates, it should allow exposing low level details from gfx-hal. In contrary wpgu-rs API should remain safe and cross platform. wgpu-rs has two backends: wgpu-core and web native. So I think it would make sense to create at this level a new XR abstraction layer that uses OpenXR or WebXR depending on the target. I plan to port ALVR client app to web so I would be glad to contribute the WebXR backend (when I have the time). While WebXR must be implemented at wgpu-rs level, OpenXR could be implemented in wgpu-core, but I don't think it is a good idea. wpgu-core is used also by wgpu-native (for WebGPU in Firefox) which is only a graphics API. Implementing OpenXR in wgpu-core means also that the XR API needs to be wrapped one extra time. Depending on what feedback we get we might consider creating a wgpu-xr crate (that sits between wgpu-core and wgpu-rs), so an extra abstraction layer might be needed. And at that point I could work on a wgpu-codec crate to wrap WebCodecs and native decoding APIs

@blaind
Copy link
Owner

blaind commented May 16, 2021

Few thoughts:

(@ gfx-rs/gfx#3761)

@zmerp
Copy link
Author

zmerp commented May 16, 2021

here's a good explanation of gfx-rs architecture: https://gfx-rs.github.io/2020/11/16/big-picture.html

Thank you for the link!

(edit: I have no experience in webxr, do not really know how it fits into the picture)

If we can break the wgpu-rs abstraction with backend specific details (as proposed here), I think the better way of handling this would be outside wgpu-rs. This means that WebXR can be ignored for now, and OpenXR can be fully implemented inside bevy_openxr_core.

I'm working on gfx-hal, I hope to have something to show soon. My goal is to expose what you need in gfx-hal without implementing anything xr specific in it.

@zmerp
Copy link
Author

zmerp commented May 16, 2021

My development plan is to first finish gfx-hal low level interop with Vulkan and test it modifying the vulkan example in openxrs by replacing vulkan with gfx-hal. After the gfx-hal API is complete I will work on wpgu-core and then on wpgu-rs, modifing the same example for testing. Probably this will take a lot of time. @blaind If you want to work one the same parts we can coordinate on Discord (I'm zarik5#6062).

@blaind
Copy link
Owner

blaind commented May 16, 2021

That sounds a really great approach, will send a message on Discord

bors bot added a commit to gfx-rs/gfx that referenced this issue May 20, 2021
3762: Low level interop with Vulkan backend r=kvark a=zarik5

Related issues: #3698 #3761 blaind/xrbevy#1

This PR exposes some Vulkan-backend-specific details needed for interop with other low level APIs. In particular this PR aims to implement a minimum viable API to allow OpenXR integration as a separate crate.

This PR is nowhere complete. I opened it to get some feedback; this is my first PR on a project the size of gfx-hal.

This is the first of multiple PRs needed for OpenXR support in wgpu.

PR checklist:
- [ ] `make` succeeds (on *nix)
- [ ] `make reftests` succeeds
- [ ] tested examples with the following backends: Vulkan

EDIT: To make things clear, this is another take on #3761. Me and @blaind are working together on this route.

Co-authored-by: zarik5 <[email protected]>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants