-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Ugrade to wgpu
version 25.0
#19563
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?
Ugrade to wgpu
version 25.0
#19563
Conversation
You added a new example but didn't add metadata for it. Please update the root Cargo.toml file. |
} else { | ||
self.view_layout_no_motion_vectors.clone() | ||
}, | ||
self.empty_layout.clone(), |
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.
What's the purpose of this empty_layout?
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.
Wgpu gets upset if you have a gap in bind groups i guess. should double check that this doesn't have any perf implications but it seems to work.
could you also update |
Objective
Upgrade to
wgpu
version25.0
.Depends on bevyengine/naga_oil#121
Solution
Problem
The biggest issue we face upgrading is the following requirement:
This is a major difficulty for us, as there are a number of binding arrays that are used in the view bind group. Note, this requirement does not affect merely uniform buffors that use dynamic offset but the use of any uniform in a bind group that also has a binding array.
Attempted fixes
The easiest fix would be to change uniforms to be storage buffers whenever binding arrays are in use:
This requires passing the view index to the shader so that we know where to index into the buffer:
Using push constants is no problem because binding arrays are only usable on native anyway.
However, this greatly complicates the ability to access
view
in shaders. For example:Using this approach would work but would have the effect of polluting our shaders with ifdef spam basically everywhere.
Why not use a function? Unfortunately, the following is not valid wgsl as it returns a binding directly from a function in the uniform path.
This also poses problems for things like lights where we want to return a ptr to the light data. Returning ptrs from wgsl functions isn't allowed even if both bindings were buffers.
The next attempt was to simply use indexed buffers everywhere, in both the binding array and non binding array path. This would be viable if push constants were available everywhere to pass the view index, but unfortunately they are not available on webgpu. This means either passing the view index in a storage buffer (not ideal for such a small amount of state) or using push constants sometimes and uniform buffers only on webgpu. However, this kind of conditional layout infects absolutely everything.
Even if we were to accept just using storage buffer for the view index, there's also the additional problem that some dynamic offsets aren't actually per-view but per-use of a setting on a camera, which would require passing that uniform data on every camera regardless of whether that rendering feature is being used, which is also gross.
As such, although it's gross, the simplest solution just to bump binding arrays into
@group(1)
and all other bindings up one bind group. This should still bring us under the device limit of 4 for most users.Next steps / looking towards the future
I'd like to avoid needing split our view bind group into multiple parts. In the future, if
wgpu
were to add@builtin(draw_index)
, we could build a list of draw state in gpu processing and avoid the need for any kind of state change at all (see gfx-rs/wgpu#6823). This would also provide significantly more flexibility to handle things like offsets into other arrays that may not be per-view.Testing
Tested a number of examples, there are probably more that are still broken.