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

Implement push constants for pipeline cache #4908

Closed
wants to merge 3 commits into from

Conversation

MDeiml
Copy link
Contributor

@MDeiml MDeiml commented Jun 3, 2022

Objective

Allow for creating pipelines that use push constants. To be able to use push constants this depends on #4824. Fixes #4825.

Solution

Add a field push_constant_ranges to RenderPipelineDescriptor and ComputePipelineDescriptor


Changelog

  • Add a field push_constant_ranges to RenderPipelineDescriptor and ComputePipelineDescriptor
  • Update bevy_sprite, bevy_ui and bevy_pbr to declare the new field

Migration Guide

  • Add push_constant_ranges: None to every RenderPipelineDescriptor and ComputePipelineDescriptor

@james7132 james7132 requested a review from superdump June 3, 2022 10:10
@james7132 james7132 added C-Enhancement A new feature A-Rendering Drawing game state to the screen labels Jun 3, 2022
@@ -218,26 +223,31 @@ impl ShaderCache {

#[derive(Default)]
struct LayoutCache {
layouts: HashMap<Vec<BindGroupLayoutId>, wgpu::PipelineLayout>,
layouts: HashMap<(Vec<BindGroupLayoutId>, Vec<PushConstantRange>), wgpu::PipelineLayout>,
Copy link
Member

Choose a reason for hiding this comment

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

This key is getting pretty darn big. We should probably consider making this a dedicated type and use bevy_utils::PreHashMap

Copy link
Contributor

Choose a reason for hiding this comment

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

@james7132 I don't understand how PreHashMap helps in this case. Hashed<K> also stores K. If anything, using PreHashMap makes the key bigger because it memoizes the u64 hash.

I'm necromancing this thread b/c @Neo-Zhixing is trying to do something similar in #7681 .

crates/bevy_render/src/render_resource/shader.rs Outdated Show resolved Hide resolved
@MDeiml MDeiml force-pushed the push_constants branch 5 times, most recently from a83116e to cd8482c Compare June 4, 2022 10:00
@Neo-Zhixing
Copy link
Contributor

This feature would be super useful. Any updates on this? It's been a while. @cart @superdump

@alice-i-cecile
Copy link
Member

Adopted in #7681.

bors bot pushed a commit that referenced this pull request Feb 17, 2023
# Objective

Allow for creating pipelines that use push constants. To be able to use push constants. Fixes #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 #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 <me@neoto.xin>
myreprise1 pushed a commit to myreprise1/bevy that referenced this pull request Feb 18, 2023
# 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 <me@neoto.xin>
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-Enhancement A new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Push Constants
5 participants