-
Notifications
You must be signed in to change notification settings - Fork 183
Case for using wgpu-core #156
Comments
I think I slightly prefer to go through wgpu-native (keeping the middle step), even if only to ensure that the C API works well through dog-fooding. We could also decide to skip wgpu-native later if it turns out to be problematic. We do pay slightly for the indirection through the FFI layer but we could try to measure the cost of this to understand whether it's actually meaningful in typical use cases. In contrast, with gfx-hal we were focused on as little indirection as possible, which is why we didn't end up implementing the traits from ash or implement the Vulkan API directly. But maybe some amount of indirection isn't too bad in wgpu, especially because of the API design. |
Either keeping |
@grovesNL another feature I found to be important, that opens up if we depend on wgpu-core directly, is avoiding the global state. |
@kvark will we end up moving globals into |
I don't think we can do what @Kangz described there (without rewriting a large piece, that it). Our approach requires us to have |
Disclaimer: I'm coming more from a "web dev" perspective and do not yet understand the nuance of WebGPU or the lower-level api's like Vulkan/Metal it builds upon, so I may be missing out on exactly what decisions For the browser target, if I understand the ecosystem correctly I think it's like this:
With that in mind, I'd like to ask the same question as the issue here in terms of where the it fits in the above. If it's mostly an issue of making an idiomatic Rust API to work with |
The idea is that wgpu-rs will support both:
In this issue we're talking about the first point: pros/cons of using wgpu-native vs. wgpu-core directly when running natively. For the second point, I think wrappers such as gloo probably aren't necessary within wgpu itself because it will be easier to use web-sys directly. Although we do want to make it possible to easily use with gloo, like requestAnimationFrame wrappers, but that shouldn't be a problem. |
Yeah - wasn't sure which issue to comment on since the web target is also the third bullet on the original post here... forgive me for muddying the waters a bit :) But since we're already talking about it... I think I understand better now, the plan is for wgpu-rs to not need wgpu at all, not even wgpu-core? i.e. it'd be completely feature-gated out when targeting web? |
Yeah, wgpu-rs when targeting the web would use web-sys directly (i.e. wgpu-native and wgpu-core wouldn't be included in the wasm bundle). wgpu-rs when targeting native would use either wgpu-native or wgpu-core. We will probably still share some common types or helper functions between both web and native. |
Part of the allure of |
Now that we have wgpu-native in a separate repository, updating the chain of wgpu / wgpu-native / wgpu-rs becomes pretty tedious. I think we should start working on the wgpu-core backend in order to exclude one link from that chain, and coincidentally make it a bit faster. As for the "native" backend for wgpu-rs, I think what we should do is, instead of linking directly to wgpu-native, is to link to a dynamic native library that implements webgpu-native. This means that we don't explicitly make wgpu-rs dependent on wgpu-native at all. Instead, we use GetProcAddress in a dynamically loaded library, and we are hypothetically compatible to both wgpu-native and Dawn. A nice side effect is that we don't have to update wgpu-native in sync with everything else. It can have releases less often, and there is a very strong incentive for it to align with Dawn (gfx-rs/wgpu-native#6). |
Currently,
wgpu-rs
uses the C API ofwgpu-native
, which then useswgpu-core
for the gory details. This issue raises the question of whether the middle step can be skipped. In order to answer the question, we need to consider all the possible targets forwgpu-rs
:wgpu
. This is the only target supported right now. It could easily bypasswgpu-native
and call intowgpu-core
.wgpu-native
implements the headers and becomes a drop-in replacement for Dawn. The target is incompatible with usingwgpu-core
directly. cc @Kangzweb-sys
directly and thus it doesn't depend onwgpu
. cc @grovesNLWith that in mind, the only blocker for using
wgpu-core
directly is running on Dawn. This is somewhat a minor goal for us, given that we are trying to makewgpu
a batter (or comparable) solution.My proposal would be to turn
wgpu-rs
into a multi-backend library (likegfx-rs
is), enforcing the API with traits. The backends are:wgpu-core
- for fastest native development, no FFI boundary.webgpu-headers
- for generic standard-compatible target withwgpu-native
,dawn
, and possibly someemscripten
drop-in libraries implementing the headers.web-sys
- for web developmentThe text was updated successfully, but these errors were encountered: