-
-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Upgrade to wgpu 27 and associated crates #21746
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
base: main
Are you sure you want to change the base?
Conversation
|
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
Co-authored-by: Ben Cochrane <ben.cochrane2112@gmail.com>
IceSentry
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM other than CI failing on dlss_wgpu
| label: options.device_label.as_ref().map(AsRef::as_ref), | ||
| required_features: features, | ||
| required_limits: limits, | ||
| // SAFETY: We're ok using experimental wgpu features in Bevy |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Note that experimental features are not just features that may not work properly — they are features that can cause undefined behavior, which is why this is unsafe. Consider that a user of Bevy rendering might prefer not to enter that territory. Are you sure that you want to enable this unconditionally?
Regardless of the answer to that question, this // SAFETY comment could be improved.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Bevy, we enable all wgpu features by default.
Then, specific plugins can check if certain features are enabled or not, and either say the plugin is not supported on this platform or fallback to other options.
I don't think there's much of a use case for limiting experimental features at the device level.
If you don't want e.g. raytracing to be available, you just shouldn't use Bevy plugins that depend on raytracing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- The intent of this
wgpuv27 API change is that the user of the API is opting in to testing experimental features that may cause undefined behavior, as marked by anunsafeoperation. - Bevy here serves as a (very complex) API wrapping
wgpuAPI. - Therefore, Bevy should not be exposing experimental features that may cause undefined behavior, without similarly marking it (which could consist of simply having the
ExperimentalFeaturestoken be passed into the plugin configuration — there doesn't have to be any actualunsafe fnin Bevy).
This is a (somewhat atypical) case of the general Rust principle that it should not be possible to cause UB via calling safe functions. “The user can just not call the function” is not considered sufficient in Rust.
[cc @cwfitzgerald who implemented this requirement in #8163]
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Therefore, Bevy should not be exposing experimental features that may cause undefined behavior, without similarly marking it
Generally this is done via feature flags in Bevy. For instance bevy_solari is not part of DefaultPlugins - you need to specifically compile with the feature for Bevy's raytracing functionality.
But we don't gate it at the device level, and I feel strongly that this is a good design choice for us, as otherwise it requires specific plugin setup ordering.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
“Can cause undefined behavior from safe code” makes something not a good design choice. Avoiding that situation is the whole point of Rust. Please don't do this. I speak both as a contributor to wgpu and a user of Bevy.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, yeah, I mean, it can be called "unsafe_wgpu_experimental", I was more wondering if having a feature would be enough for this. The actual name of that feature I don't really mind. Makes sense to have unsafe in the name I guess.
I'm not sure what you mean in 1.? Isn't using a feature flag exposing the decision to use the unsafe api to the user already? I guess I never specified but I was assuming the feature would not be part of the default features so a user would have to specify it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what you mean in 1.? Isn't using a feature flag exposing the decision to use the unsafe api to the user already?
Features don’t have “the” user. A feature is enabled if any dependent enables it. That dependent could be a random plugin library which enables it "because we need it" without documenting that fact, leaving the application developer unaware that the risk is being taken. (I admit this gets into “well, people can write bad code no matter what” territory.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, right, I see what you mean. I'm not sure how we can avoid that though. Even if we used some kind of runtime check instead of feature flag a plugin could still set it without a user knowing. Right now I can't think of a way to make sure a user is always aware that they are opting into it. Other than maybe logging a warning at the start if it's set to make sure users are at least aware of it. But then people will likely want a way to hide that warning and then we are back to plugins hiding it unknowingly 🙃.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My perspective is that 99% of users are not using experimental wgpu features directly. The only real people using them are developers of rendering plugins.
Bevy users should be able to trust that plugin authors used GPU features correctly, and not have to deal with enabling experimental flags themselves just to use a plugin.
We already disable stuff like checked shader code and indirect draw call validation in Bevy, it's trivial to misuse GPU APIs if you really want to.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even if we used some kind of runtime check instead of feature flag a plugin could still set it without a user knowing.
Not advocating this necessarily, but it could be a flag you have to set on app, which plugins don't control. We could also have an unsafe plugin API which doesn't solve your plugins adding plugins but could help.
Bevy users should be able to trust that plugin authors used GPU features correctly, and not have to deal with enabling experimental flags themselves just to use a plugin.
IMO this is dangerously close to the "git gud" argument used by C++ partisans against safety in general. If anything, the fact that GPU APIs are easy to misuse makes safety more important. I also think it's important to distinguish UB on the GPU which sucks but is mostly limited to DoS and UB within the driver which is much more classically UB scary.
I take your point that the use of these features is already behind a flag and explicitly noted as experimental, but I think there's a tension here between having experimental features in tree (which inherently get a bit less review and testing, fewer developers working on them, etc) and safety.
I think an additional flag is a good practical middle ground. But minimally, whatever rationale we choose should be documented here more explicitly even if we are just okay blanket enabling this.
tychedelia
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM provided we resolve the safety question.
Supersedes #21725.