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

[Merged by Bors] - Compute Pipeline Specialization #3979

Closed
wants to merge 7 commits into from

Conversation

kurtkuehnert
Copy link
Contributor

Objective

  • Fixes Compute Shader Integration #3970
  • To support Bevy's shader abstraction(shader defs, shader imports and hot shader reloading) for compute shaders, I have followed carts advice and change the PipelinenCache to accommodate both compute and render pipelines.

Solution

  • renamed RenderPipelineCache to PipelineCache
  • Cached Pipelines are now represented by an enum (render, compute)
  • split the SpecializedPipelines into SpecializedRenderPipelines and SpecializedComputePipelines
  • updated the game of life example

Open Questions

  • should SpecializedRenderPipelines and SpecializedComputePipelines be merged and how would we do that?
  • should the get_render_pipeline and get_compute_pipeline methods be merged?
  • is pipeline specialization for different entry points a good pattern

@github-actions github-actions bot added the S-Needs-Triage This issue needs to be labelled label Feb 18, 2022
@kurtkuehnert
Copy link
Contributor Author

Clippy complains, that the newly introduced PipelineDescriptor has two variants with a large size difference. https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
I think it is fine to just ignore it since there wont be too many pipelines for it to really matter, but what do you think?

@mockersf
Copy link
Member

error: large size difference between variants
  --> crates/bevy_render/src/render_resource/pipeline_cache.rs:21:5
   |
21 |     RenderPipelineDescriptor(RenderPipelineDescriptor),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ this variant is 432 bytes
   |
   = note: `-D clippy::large-enum-variant` implied by `-D warnings`
note: and the second-largest variant is 160 bytes:
  --> crates/bevy_render/src/render_resource/pipeline_cache.rs:22:5
   |
22 |     ComputePipelineDescriptor(ComputePipelineDescriptor),
   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
   |
21 |     RenderPipelineDescriptor(Box<RenderPipelineDescriptor>),
   |                              ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

That means each ComputePipelineDescriptor will waste 272 bytes...

@alice-i-cecile alice-i-cecile added A-Rendering Drawing game state to the screen C-Usability A targeted quality-of-life change that makes Bevy easier to use and removed S-Needs-Triage This issue needs to be labelled labels Feb 18, 2022
@superdump
Copy link
Contributor

So I guess we should try Boxing them and see if it has any negative impact on performance?

@kurtkuehnert
Copy link
Contributor Author

So I guess we should try Boxing them and see if it has any negative impact on performance?

Ok, will do that later. 😃

@kurtkuehnert
Copy link
Contributor Author

I did something wrong while rebasing. ...again

@kurtkuehnert kurtkuehnert force-pushed the compute-shader branch 2 times, most recently from be2b972 to 65ec025 Compare March 6, 2022 14:25
Copy link
Contributor

@superdump superdump left a comment

Choose a reason for hiding this comment

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

This looks generally in the right ballpark. I wonder if there is a way to duplicate less of the code for render vs compute. I have a mild wonder about whether it impacts performance of render stuff in any way. Does it affect bevymark performance at all?

@cart
Copy link
Member

cart commented Mar 16, 2022

Yup I like the general direction of a consolidated RenderPipeline type, although I think we might want to have separate CachedRenderPipelineId and CachedComputePipelineId (and internally remove and "switching" on compute and render pipelines). That would eliminate a class of user error where they pass a "render pipeline" CachedPipelineId into get_compute_pipeline (or vice versa). Likewise, it would eliminate all of the "internal switching" thats going on right now. It would mean duplicating some code, but I think its worth it.

@kurtkuehnert
Copy link
Contributor Author

I will test performance and experiment with the distinct IDs tomorrow. 👍

@kurtkuehnert
Copy link
Contributor Author

I have done some form of a split, but I don't really think it is much of an improvement. I still believe there is some way to make all of this pretty with some rust magic, but I am not experienced enough to see how.

@cart cart added this to the Bevy 0.7 milestone Mar 19, 2022
@cart
Copy link
Member

cart commented Mar 23, 2022

I think your changes made a good compromise between code reuse and "separate code paths". Splitting out the remaining enums would start bleeding in to the shader caching logic, which would make things pretty nasty.

I removed specialization from the game of life example as I think it hindered legibility. Imo specialization should only be used if you really need it. In this case it added over 30 lines of code / extra type complexity for no real benefit.

@cart
Copy link
Member

cart commented Mar 23, 2022

bors r+

bors bot pushed a commit that referenced this pull request Mar 23, 2022
# Objective

- Fixes #3970
- To support Bevy's shader abstraction(shader defs, shader imports and hot shader reloading) for compute shaders, I have followed carts advice and change the `PipelinenCache` to accommodate both compute and render pipelines.

## Solution

- renamed `RenderPipelineCache` to `PipelineCache`
- Cached Pipelines are now represented by an enum (render, compute)
- split the `SpecializedPipelines` into `SpecializedRenderPipelines` and `SpecializedComputePipelines`
- updated the game of life example

## Open Questions

- should `SpecializedRenderPipelines` and `SpecializedComputePipelines` be merged and how would we do that?
- should the `get_render_pipeline` and `get_compute_pipeline` methods be merged?
- is pipeline specialization for different entry points a good pattern




Co-authored-by: Kurt Kühnert <[email protected]>
Co-authored-by: Carter Anderson <[email protected]>
@bors bors bot changed the title Compute Pipeline Specialization [Merged by Bors] - Compute Pipeline Specialization Mar 23, 2022
@bors bors bot closed this Mar 23, 2022
ChristopherBiscardi added a commit to ChristopherBiscardi/kayak_ui that referenced this pull request Apr 17, 2022
- [x] `GpuImage` requires `texture_format` now.
- [ ] `ActiveCameras` was removed
  - bevyengine/bevy@bf6de89
- [x] `CachedPipelineId` is now `CachedRenderPipelineId` and renamed `RenderPipelineCache` to `PipelineCache`
  - bevyengine/bevy#3979
ChristopherBiscardi added a commit to ChristopherBiscardi/kayak_ui that referenced this pull request Apr 17, 2022
- [x] `GpuImage` requires `texture_format` now.
- [ ] `ActiveCameras` was removed
  - bevyengine/bevy@bf6de89
- [x] `CachedPipelineId` is now `CachedRenderPipelineId` and renamed `RenderPipelineCache` to `PipelineCache`
  - bevyengine/bevy#3979
@Shatur Shatur mentioned this pull request Apr 17, 2022
aevyrie pushed a commit to aevyrie/bevy that referenced this pull request Jun 7, 2022
# Objective

- Fixes bevyengine#3970
- To support Bevy's shader abstraction(shader defs, shader imports and hot shader reloading) for compute shaders, I have followed carts advice and change the `PipelinenCache` to accommodate both compute and render pipelines.

## Solution

- renamed `RenderPipelineCache` to `PipelineCache`
- Cached Pipelines are now represented by an enum (render, compute)
- split the `SpecializedPipelines` into `SpecializedRenderPipelines` and `SpecializedComputePipelines`
- updated the game of life example

## Open Questions

- should `SpecializedRenderPipelines` and `SpecializedComputePipelines` be merged and how would we do that?
- should the `get_render_pipeline` and `get_compute_pipeline` methods be merged?
- is pipeline specialization for different entry points a good pattern




Co-authored-by: Kurt Kühnert <[email protected]>
Co-authored-by: Carter Anderson <[email protected]>
ItsDoot pushed a commit to ItsDoot/bevy that referenced this pull request Feb 1, 2023
# Objective

- Fixes bevyengine#3970
- To support Bevy's shader abstraction(shader defs, shader imports and hot shader reloading) for compute shaders, I have followed carts advice and change the `PipelinenCache` to accommodate both compute and render pipelines.

## Solution

- renamed `RenderPipelineCache` to `PipelineCache`
- Cached Pipelines are now represented by an enum (render, compute)
- split the `SpecializedPipelines` into `SpecializedRenderPipelines` and `SpecializedComputePipelines`
- updated the game of life example

## Open Questions

- should `SpecializedRenderPipelines` and `SpecializedComputePipelines` be merged and how would we do that?
- should the `get_render_pipeline` and `get_compute_pipeline` methods be merged?
- is pipeline specialization for different entry points a good pattern




Co-authored-by: Kurt Kühnert <[email protected]>
Co-authored-by: Carter Anderson <[email protected]>
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-Usability A targeted quality-of-life change that makes Bevy easier to use
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Compute Shader Integration
6 participants