gfx-rs / gfx

[maintenance mode] A low-overhead Vulkan-like GPU API for Rust.
http://gfx-rs.github.io/
Apache License 2.0
5.35k stars 551 forks source link

Is there a way to access raw handles for components? #3698

Open jdu opened 3 years ago

jdu commented 3 years ago

Short info header:

Is there way to expose the raw handle for things like the Device in order "shim" libraries into gfx-rs?

For example the skulpin project using rafx, can get a raw handle to instance, device, etc.. to pass into skia-safe to bind to a skia BackendContext. You can see how skulpin does this here https://github.com/aclysma/skulpin/blob/master/skulpin-renderer/src/skia_support.rs#L48 with rafx.

Is there a way to get a passable handle from gfx-rs to perform something similar in order to allow shimming of skia into the gfx-backend-* I've looked through the docs a fair bit and tried a few different things, but i'm coming up empty-handed to see how I could achieve this.

kvark commented 3 years ago

There is no portable way to get the raw handles off gfx-rs objects, since there isn't always 1:1 mapping to anything under the API. Instead, each backend can expose its own raw APIs as needed. For example, Vulkan Instance could make the inner here public: https://github.com/gfx-rs/gfx/blob/2ac006f7fe86f32dd5b5e07f9daf44cd876a66f0/src/backend/vulkan/src/lib.rs#L74

If you make a list of things you'd need exposed, we can make sure they are available.

jdu commented 3 years ago

I'll have a look at what exactly needs to be made public and see if I can come up with a concrete list based on the different backends. I can do PRs to the individual backends to mark the items public if that's easier than dumping a list here and you can approve/reject depending on whether it aligns with the project.

kvark commented 3 years ago

The PRs are definitely preferred and much appreciated. Thank you!

zarik5 commented 3 years ago

I'm also interested in this. Personally I would use this to connect gfx-hal with OpenXR, OpenVR (driver API) and FFmpeg hardware acceleration API. Integrating these APIs directly into gfx-hal would not make much sense to me.