bevy/crates
JMS55 f4dab8a4e8
Multithreaded render command encoding (#9172)
# Objective
- Encoding many GPU commands (such as in a renderpass with many draws,
such as the main opaque pass) onto a `wgpu::CommandEncoder` is very
expensive, and takes a long time.
- To improve performance, we want to perform the command encoding for
these heavy passes in parallel.

## Solution
- `RenderContext` can now queue up "command buffer generation tasks"
which are closures that will generate a command buffer when called.
- When finalizing the render context to produce the final list of
command buffers, these tasks are run in parallel on the
`ComputeTaskPool` to produce their corresponding command buffers.
- The general idea is that the node graph will run in serial, but in a
node, instead of doing rendering work, you can add tasks to do render
work in parallel with other node's tasks that get ran at the end of the
graph execution.

## Nodes Parallelized
- `MainOpaquePass3dNode`
- `PrepassNode`
- `DeferredGBufferPrepassNode`
- `ShadowPassNode` (One task per view)


## Future Work
- For large number of draws calls, might be worth further subdividing
passes into 2+ tasks.
- Extend this to UI, 2d, transparent, and transmissive nodes?
- Needs testing - small command buffers are inefficient - it may be
worth reverting to the serial command encoder usage for render phases
with few items.
- All "serial" (traditional) rendering work must finish before parallel
rendering tasks (the new stuff) can start to run.
- There is still only one submission to the graphics queue at the end of
the graph execution. There is still no ability to submit work earlier.

## Performance Improvement
Thanks to @Elabajaba for testing on Bistro.


![image](https://github.com/bevyengine/bevy/assets/47158642/be50dafa-85eb-4da5-a5cd-c0a044f1e76f)


TLDR: Without shadow mapping, this PR has no impact. _With_ shadow
mapping, this PR gives **~40 more fps** than main.

---

## Changelog
- `MainOpaquePass3dNode`, `PrepassNode`, `DeferredGBufferPrepassNode`,
and each shadow map within `ShadowPassNode` are now encoded in parallel,
giving _greatly_ increased CPU performance, mainly when shadow mapping
is enabled.
  - Does not work on WASM or AMD+Windows+Vulkan.
- Added `RenderContext::add_command_buffer_generation_task()`.
- `RenderContext::new()` now takes adapter info
- Some render graph and Node related types and methods now have
additional lifetime constraints.


## Migration Guide
`RenderContext::new()` now takes adapter info
- Some render graph and Node related types and methods now have
additional lifetime constraints.

---------

Co-authored-by: Elabajaba <Elabajaba@users.noreply.github.com>
Co-authored-by: François <mockersf@gmail.com>
2024-02-09 07:35:35 +00:00
..
bevy_a11y Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_animation Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_app Use TypeIdMap whenever possible (#11684) 2024-02-03 23:47:04 +00:00
bevy_asset Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
bevy_audio Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_core Missing registrations (#11736) 2024-02-06 16:33:17 +00:00
bevy_core_pipeline Multithreaded render command encoding (#9172) 2024-02-09 07:35:35 +00:00
bevy_derive Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_diagnostic Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_dylib Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_dynamic_plugin Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_ecs Mention Resource where missing from component/resource related type docs (#11769) 2024-02-08 06:31:48 +00:00
bevy_ecs_compile_fail_tests Deprecated Various Component Methods from Query and QueryState (#9920) 2024-02-04 01:01:59 +00:00
bevy_encase_derive Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_gilrs Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_gizmos fix(primitives): fix polygon gizmo rendering bug (#11699) 2024-02-05 15:09:49 +00:00
bevy_gltf Mesh insert indices (#11745) 2024-02-06 23:31:48 +00:00
bevy_hierarchy Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_input Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_internal Don't unconditionally enable bevy_render or bevy_assets if mutli-threaded feature is enabled (#11726) 2024-02-06 14:40:56 +00:00
bevy_log Update tracing-tracy requirement from 0.10.4 to 0.11.0 and tracy-client requirement from 0.16.4 to 0.17.0 (#11678) 2024-02-03 21:44:38 +00:00
bevy_macro_utils Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_macros_compile_fail_tests Standardize toml format with taplo (#10594) 2023-11-21 01:04:14 +00:00
bevy_math Implement Meshable for some 3D primitives (#11688) 2024-02-06 21:44:13 +00:00
bevy_mikktspace Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_pbr Multithreaded render command encoding (#9172) 2024-02-09 07:35:35 +00:00
bevy_ptr Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_reflect Add ReflectKind (#11664) 2024-02-07 00:36:23 +00:00
bevy_reflect_compile_fail_tests bevy_reflect: Type parameter bounds (#9046) 2024-01-28 16:24:03 +00:00
bevy_render Multithreaded render command encoding (#9172) 2024-02-09 07:35:35 +00:00
bevy_scene Send SceneInstanceReady only once per scene (#11002) 2024-02-05 13:54:54 +00:00
bevy_sprite UI Texture 9 slice (#11600) 2024-02-07 20:07:53 +00:00
bevy_tasks Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_text Use warn_once where relevant instead of manually implementing a single warn check (#11693) 2024-02-05 21:05:43 +00:00
bevy_time Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_transform Inverse missing_docs logic (#11676) 2024-02-03 21:40:55 +00:00
bevy_ui UI Texture 9 slice (#11600) 2024-02-07 20:07:53 +00:00
bevy_utils Deprecating hashbrown reexports (#11721) 2024-02-06 18:04:46 +00:00
bevy_window Add name to bevy:🪟:Window (#7650) 2024-02-05 13:35:35 +00:00
bevy_winit Add name to bevy:🪟:Window (#7650) 2024-02-05 13:35:35 +00:00