-
Notifications
You must be signed in to change notification settings - Fork 973
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
Is there any chance that I can choose to enable what backend will be compiled into the binary? #1221
Comments
Are you concerned about the code size for the GL backend that becomes a part of the binary? It would be interesting to make a test, say with your application, by compile-time disabling GL and seeing how it affected the size. This would be done by checking out |
Yes, it is around 0.7MB using cargo-bloat. Another big library is spirv_cross. This is what I got under windows, after removing gl and dx11:
I'll get the output under linux later. |
SPIRV-Cross has just become an optional dependency in #1220, so maybe this is fine now? |
OK, I remembered it wrong... Basically the largest one is spirv_cross. Of course, this result is with
This what I got without lto:
Well, I guess that I found that spirv_cross is used by other backends. So I want to disable other backends. I won't close the issue. It is indeed possible that other backends will involve some unused dependencies. |
This is very informative, thank you! |
Here it is :)
I believe that wgpu can be made smaller somehow. You could also use |
It would be great to control backends. In Bevy, for example, wgpu is a public API. And to be able to run the same game logic on the server, I need to build Bevy with wgpu, but without backends: bevyengine/bevy#3155 (comment) |
If backends can be enabled individually with features, how can we make sure that people can just use "auto" mode - the logic that we have now? I.e. introducing features would immediately require the users to complicate their cargo manifests with something like this: [target.'cfg(target_arch = "wasm32")'.dependencies]
wgpu = { version = "0.11", features = ["gles"] }
[target.'cfg(all(not(target_arch = "wasm32"), any(target_os = "ios", target_os = "macos")))'.dependencies]
wgpu = { version = "0.11", features = ["metal"] }
[target.'cfg(all(not(target_arch = "wasm32"), unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies]
wgpu = { version = "0.11", features = ["vulkan", "gles", "renderdoc"] }
[target.'cfg(all(not(target_arch = "wasm32"), windows))'.dependencies]
wgpu = { version = "0.11", features = ["vulkan", "dx12", "renderdoc"] } I don't think our users are going to be excited for this... @Shatur it's clear you don't want to run the same rendering logic on client and server. So |
Totally agree, I understand why we have prereconfigured backends.
It would be great to avoid having wgpu on server. But for relatively complex games, the server uses exactly the same logic as the client. So in Bevy we could do the following:
@cart suggested to use the approach number 3, but it currently impossible due to preconfigured backends for specific platforms. So I decided to ask 😄 Is it possible to move this preconfigured |
Main blocker is that default features can't be platform dependent. I think it's rust-lang/cargo#1197, although Rust issues are sometimes hard to navigate... If it was possible, we'd take it in a heartbeat. There is another possible solution just for your case - via backends of wgpu-rs itself (as opposed to wgpu-core). It currently has the "web" backend and the wgpu-core backend. It needs also to have a "native header" backend, linking to an implementation to webgpu-headers. So we could add a "dummy" backend there. Problem is - this would only help your case but not @xhebox or other peoples similar needs. So I can't recommend this path. |
Hm... Yes, it would solve the problem.
Agree, it would be better to solve the problem globally via backend configuration. But now I'm not sure if there is an elegant solution. We could move out automatic backend selection into a separate crate that depends on wgpu, but it looks dirty. The |
The dummy backend for your specific case is ultimately better than other alternatives, since the whole wgpu-core gets compiled out from the server. I filed #2291 |
You are right, a dummy backend for wgpu is much better for servers then just disabling graphical backends and could be a separate feature. Thanks! |
I believe WGPU used to work in the way that @xhebox is asking for. Each backend was a compile time feature. It was kind of a pain to switch back and forth between backends while testing changes. Now we've moved to the opposite extreme where everything is compiled into the binary at all times and there is no way to exclude the backends that you don't need or care about. I think the situation is overall better now, but I do see still a use case for wanting to remove extra backends if you know you're not going to target them. Perhaps the suggestion above about having the backends as default features that you may opt-out of is the ideal middle ground. |
@aloucks we can't follow this suggestion because default features in cargo today can't be platform-dependent... |
@kvark I don't think they need to be. I was able to set I don't think this is terribly high priority to fix or anything, but I'd always be happy to have a way to reduce compile time :) $ git diff -p
diff --git a/wgpu-hal/Cargo.toml b/wgpu-hal/Cargo.toml
index 43e850ba..238e90ab 100644
--- a/wgpu-hal/Cargo.toml
+++ b/wgpu-hal/Cargo.toml
@@ -12,7 +12,7 @@ license = "MIT OR Apache-2.0"
[lib]
[features]
-default = []
+default = ["metal"]
metal = ["naga/msl-out", "block", "foreign-types"]
vulkan = ["naga/spv-out", "ash", "gpu-alloc", "gpu-descriptor", "libloading", "inplace_it"]
gles = ["naga/glsl-out", "glow", "egl", "libloading"]
diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs
index 4b292a3b..e12ebe63 100644
--- a/wgpu-hal/src/lib.rs
+++ b/wgpu-hal/src/lib.rs
@@ -47,8 +47,6 @@
clippy::pattern_type_mismatch,
)]
-#[cfg(all(feature = "metal", not(any(target_os = "macos", target_os = "ios"))))]
-compile_error!("Metal API enabled on non-Apple OS. If your project is not using resolver=\"2\" in Cargo.toml, it should.");
#[cfg(all(feature = "dx12", not(windows)))]
compile_error!("DX12 API enabled on non-Windows OS. If your project is not using resolver=\"2\" in Cargo.toml, it should.");
@@ -57,8 +55,10 @@ mod dx12;
mod empty;
#[cfg(all(feature = "gles"))]
mod gles;
-#[cfg(all(feature = "metal"))]
+#[cfg(all(feature = "metal", any(target_os = "macos", target_os = "ios")))]
mod metal;
+#[cfg(not(all(feature = "metal", any(target_os = "macos", target_os = "ios"))))]
+use empty as metal;
#[cfg(feature = "vulkan")]
mod vulkan; |
@aloucks we should probably discuss this on the matrix if you are able to.
If metal is in defaults, then these dependencies are enabled for all platforms, which is highly undesirable. |
We now only enable backends based on the target platform with the only exception being GLES which is always available. Lines 121 to 133 in 581b22e
I think this behavior makes sense, additionally we can expose a feature flag @xhebox @aloucks does it sound like a satisfactory solution? |
Sounds great! |
I opened a new issue to track it: #3514 since this issue is a bit old with more baggage behind it. |
Is your feature request related to a problem? Please describe.
I've tried gfx-hal, and that is good library. But wgpu is much easier to use than gfx. I prefer wgpu and I know clearly I only want to use vulkan. Despite what backend flags I passed to init the instance, gl backend is also compiled.
Describe the solution you'd like
Some features passed from wgpu-rs to wgpu, so that I can choose what I want to use.
Describe alternatives you've considered
None
Additional context
None
The text was updated successfully, but these errors were encountered: