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

Add a default feature for wgpu that enables Vulkan & GLES on Windows & Linux #3514

Open
teoxoy opened this issue Feb 21, 2023 · 11 comments · May be fixed by #6949
Open

Add a default feature for wgpu that enables Vulkan & GLES on Windows & Linux #3514

teoxoy opened this issue Feb 21, 2023 · 11 comments · May be fixed by #6949
Assignees
Labels
area: ecosystem Help the connected projects grow and prosper help required We need community help to make this happen. type: enhancement New feature or request

Comments

@teoxoy
Copy link
Member

teoxoy commented Feb 21, 2023

We currently only enable backends based on the target platform with the only exception being GLES which is always available.

We should expose a new feature flag (enabled by default) that covers the GLES and DX11 backends so that users not interested in those backends can avoid compiling them in their binaries.

Feature name ideas:

  • legacy
  • compat (mapping to a future WebGPU Compat; might not be the best choice since we support even lower limits/features than what WebGPU Compat is aiming for; i.e. GLES 3.1+ and DX11 FL10+)

See background for this: #1221 (comment)

@teoxoy teoxoy added type: enhancement New feature or request help required We need community help to make this happen. area: ecosystem Help the connected projects grow and prosper labels Feb 21, 2023
@daxpedda
Copy link
Contributor

daxpedda commented Dec 1, 2023

I was recently looking into this but the first roadblock I hit is that we can't differentiate between a new gles crate feature and the current angle crate feature, both enable wgc/gles.

A solution could be to introduce target-specific features in wgpu-core and wgpu-hal that are no-op on certain platforms.
E.g. gles-native (no-op on MacOS) and gles-angle (no-op on everything but MacOS). This proposal would be similar to #3466.

I'd be happy to make a PR!

@cwfitzgerald
Copy link
Member

I think we're moving in the direction of every backend being feature flagged. We have all the infrastructure in place, we just haven't lifted this to the wgpu level.

Distinguishing between angle and native would be useful!

@daxpedda
Copy link
Contributor

daxpedda commented Dec 1, 2023

So after playing around with it a bit I was so unsatisfied it doesn't make sense to me to proceed like that.
The issue basically boils down to Cargo not being able to connect crate features that activate optional dependencies to specific targets.

Introducing gles-native and gles-angle we can use cfgs to guard code to specific targets, but the dependencies these features activate will be active nevertheless. E.g. if we use default = ["gles-native"], OpenGL won't work on MacOS, but the dependencies will still be present.

So the only good solution I can come up with to this problem is to create a separate crate that adds these defaults.

[package]
name = "wgpu-default-features"

# We want the wgpu-core Metal backend on macOS and iOS.
[target.'cfg(any(target_os = "macos", target_os = "ios"))'.dependencies.wgc]
workspace = true
features = ["metal"]

# We want the wgpu-core Direct3D backends and OpenGL (via WGL) on Windows.
[target.'cfg(windows)'.dependencies.wgc]
workspace = true
features = ["dx11", "dx12", "gles"]

# We want the wgpu-core Vulkan backend on Unix (but not emscripten, macOS, iOS) and Windows.
[target.'cfg(any(windows, all(unix, not(target_os = "emscripten"), not(target_os = "ios"), not(target_os = "macos"))))'.dependencies.wgc]
workspace = true
features = ["vulkan"]

# We want the wgpu-core GLES backend on Unix (but not macOS, iOS).
[target.'cfg(all(unix, not(target_os = "ios"), not(target_os = "macos")))'.dependencies.wgc]
workspace = true
features = ["gles"]

And then we can use default ["dep:wgpu-default-features"] in wgpu.

Just for completeness, not actually proposing this: we could abandon default features.

@daxpedda
Copy link
Contributor

daxpedda commented Dec 2, 2023

Cc rust-lang/cargo#1197.
Left a user story there as well.

@Wumpf
Copy link
Member

Wumpf commented Dec 3, 2023

cont' conversation thread from #4815 (comment)
to quickly recap (plz correct me if needed): I suggested going all in on a style like gles-linux, gles-windows, gles-mac which is then translated to just gles in the code via https://docs.rs/cfg_aliases/latest/cfg_aliases/
As @daxpedda points out (and described here already!) this doesn't quite work since for instance gles-linux = ["wgc/gles"] would drag inwgc/gles for on Mac no matter what.

It's pretty awful, but it might be better than the alternative to just hand this problem on to wgc in turn? I.e. gles-linux = ["wgc/gles-linux"]. It seems to me that this is the least invasive situation and gives the same feature (literally) to the few direct users for wgpu-core where the problem would bubble up otherwise in the exact same way.

@daxpedda
Copy link
Contributor

daxpedda commented Dec 4, 2023

It's pretty awful, but it might be better than the alternative to just hand this problem on to wgc in turn?

We would have to go further into hal though, because in wgc we are having the exact same problem: gles-linux = ["hal/gles"]. Looking at hal, the gles feature activates the following dependencies:

  • naga/glsl-out
  • glow
  • glutin_wgl_sys
  • khronos-egl
  • libloading

Both naga/glsl-out and glow are not target specific dependencies, so we would be hitting the same problem again in hal as well: enabling hal/gles-linux would still bring in these dependencies no matter the target.

@teoxoy
Copy link
Member Author

teoxoy commented Dec 4, 2023

Why is it an issue that the dependencies will be present on the dev machine? They won't be compiled for the targets that don't support them.

Introducing gles-native and gles-angle we can use cfgs to guard code to specific targets, but the dependencies these features activate will be active nevertheless.

What does "active" mean in this context?

@daxpedda
Copy link
Contributor

daxpedda commented Dec 4, 2023

Why is it an issue that the dependencies will be present on the dev machine? They won't be compiled for the targets that don't support them.

Dead code elimination is not perfect, especially with things that rely on FFI and linked libraries, I don't have any data on that though. But it also does increase compile time, which is not insignificant when looking at the size and amount of dependencies we are talking about here.
E.g. I know it was reported somewhere that MoltenVK is a problem because of linking, which is why it was removed from the default set in wgpu.

Introducing gles-native and gles-angle we can use cfgs to guard code to specific targets, but the dependencies these features activate will be active nevertheless.

What does "active" mean in this context?

I should probably stick with the word "enable".
It means that a feature that enables a dependency pulls it in, it becomes part of the dependency graph and has to be compiled and such.

@Wumpf Wumpf changed the title Add a default feature for wgpu that enables the GLES and DX11 backends Add a default feature for wgpu that enables Vulkan & GLES on Windows & Linux Dec 17, 2023
@9SMTM6

This comment has been minimized.

@Wumpf

This comment has been minimized.

@9SMTM6

This comment has been minimized.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ecosystem Help the connected projects grow and prosper help required We need community help to make this happen. type: enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants