-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Push Constants #4825
Comments
Previously discussed in #1733 and #1369.
I don't have the expertise to evaluate the matter further, but I figured I can surface the most relevant bits of the conversation. |
Thanks for the context. Assuming the mentioned rework is already done, this is still relevant. Push constants are still not exposed in Even if push constants will not be used with the "built-in" shaders, it would still make sense to make them available to people who want to write their own shaders / render pipelines. EDIT: I was wrong, |
I would like to support push constants. Things have changed a lot since #1733 and #1369. I think the only missing piece at this point is updating the RenderPipelineDescriptor to include the push constant layout and adapting LayoutCache to accept push constant layouts (and take them into account for layout identity ... they must be a part of the key used to identify the layout). |
@cart would you be opposed to having platform specific optimizations using push constants? The push constant size limitations are basically just big enough to fit two |
If this can be done without adding extra complexity to user-facing shader apis, I think I'm open to it. Hard to say before looking at the impl + perf tradeoffs first, but its an area I think we should explore. |
That and #4824. I got push constants working in my fork. It's not a lot of changes, but |
@MDeiml if you're comfortable, a link to that branch or a PR would be great. It doesn't need to be perfect to start, but having something tangible will help focus the discussion. |
# Objective Allow for creating pipelines that use push constants. To be able to use push constants. Fixes bevyengine#4825 As of right now, trying to call `RenderPass::set_push_constants` will trigger the following error: ``` thread 'main' panicked at 'wgpu error: Validation Error Caused by: In a RenderPass note: encoder = `<CommandBuffer-(0, 59, Vulkan)>` In a set_push_constant command provided push constant is for stage(s) VERTEX | FRAGMENT | VERTEX_FRAGMENT, however the pipeline layout has no push constant range for the stage(s) VERTEX | FRAGMENT | VERTEX_FRAGMENT ``` ## Solution Add a field push_constant_ranges to` RenderPipelineDescriptor` and `ComputePipelineDescriptor`. This PR supersedes bevyengine#4908 which now contains merge conflicts due to significant changes to `bevy_render`. Meanwhile, this PR also made the `layout` field of `RenderPipelineDescriptor` and `ComputePipelineDescriptor` non-optional. If the user do not need to specify the bind group layouts, they can simply supply an empty vector here. No need for it to be optional. --- ## Changelog - Add a field push_constant_ranges to RenderPipelineDescriptor and ComputePipelineDescriptor - Made the `layout` field of RenderPipelineDescriptor and ComputePipelineDescriptor non-optional. ## Migration Guide - Add push_constant_ranges: Vec::new() to every `RenderPipelineDescriptor` and `ComputePipelineDescriptor` - Unwrap the optional values on the `layout` field of `RenderPipelineDescriptor` and `ComputePipelineDescriptor`. If the descriptor has no layout, supply an empty vector. Co-authored-by: Zhixing Zhang <[email protected]>
What problem does this solve or what need does it fill?
It would be nice to support using push constants. Even though the initial wgsl spec will not have push constants (gpuweb/gpuweb#612) they are supported in naga (https://github.com/gfx-rs/naga/blob/master/tests/in/push-constants.wgsl) as well as wgpu.
But it seems that there was a decision not to include them. Specifically you cannot create pipelines with layouts that contain push constants. This is because the concept of a
RenderPipelineLayout
in wgpu was not translated to the bevy API and instead became just&[BindGroupLayout]
. To create aRenderPipelineLayout
in wgpu you specify bind group layouts and push constant ranges, so this seems like a weird design to me.I'm talking about this code, which always sets the push constant ranges to be empty:
bevy/crates/bevy_render/src/render_resource/pipeline_cache.rs
Lines 236 to 239 in fed93a0
What solution would you like?
Change
RenderPipelineDescriptor
or it'slayout
field so it's possible to specify push constant ranges.What alternative(s) have you considered?
Create a pipeline without using pipeline cache or don't use push constants.
Additional Context
In order to use push constants in shaders we would also need #4824
I'd be happy to implement this, but it would require minor breaking changes to
RenderPipelineDescriptor
and it seems to me that maybe there already was a decision to not support them, so I wanted to ask first.The text was updated successfully, but these errors were encountered: