Skip to content

Conversation

@JMS55
Copy link
Contributor

@JMS55 JMS55 commented Nov 5, 2025

Supersedes #21725.

@JMS55 JMS55 added A-Rendering Drawing game state to the screen C-Dependencies A change to the crates that Bevy depends on S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Nov 5, 2025
@JMS55 JMS55 added this to the 0.18 milestone Nov 5, 2025
@github-actions
Copy link
Contributor

github-actions bot commented Nov 5, 2025

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>
Copy link
Contributor

@IceSentry IceSentry left a 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
Copy link
Contributor

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.

Copy link
Contributor Author

@JMS55 JMS55 Dec 1, 2025

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • The intent of this wgpu v27 API change is that the user of the API is opting in to testing experimental features that may cause undefined behavior, as marked by an unsafe operation.
  • Bevy here serves as a (very complex) API wrapping wgpu API.
  • Therefore, Bevy should not be exposing experimental features that may cause undefined behavior, without similarly marking it (which could consist of simply having the ExperimentalFeatures token be passed into the plugin configuration — there doesn't have to be any actual unsafe fn in 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]

Copy link
Contributor Author

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.

Copy link
Contributor

@kpreid kpreid Dec 1, 2025

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.

Copy link
Contributor

@IceSentry IceSentry Dec 2, 2025

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.

Copy link
Contributor

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.)

Copy link
Contributor

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 🙃.

Copy link
Contributor Author

@JMS55 JMS55 Dec 2, 2025

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.

Copy link
Member

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.

Copy link
Member

@tychedelia tychedelia left a 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Rendering Drawing game state to the screen C-Dependencies A change to the crates that Bevy depends on S-Needs-Review Needs reviewer attention (from anyone!) to move forward

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

7 participants