bevy/examples/shader
James Liu a85b740f24 Support recording multiple CommandBuffers in RenderContext (#7248)
# Objective
`RenderContext`, the core abstraction for running the render graph, currently only supports recording one `CommandBuffer` across the entire render graph. This means the entire buffer must be recorded sequentially, usually via the render graph itself. This prevents parallelization and forces users to only encode their commands in the render graph.

## Solution
Allow `RenderContext` to store a `Vec<CommandBuffer>` that it progressively appends to. By default, the context will not have a command encoder, but will create one as soon as either `begin_tracked_render_pass` or the `command_encoder` accesor is first called. `RenderContext::add_command_buffer` allows users to interrupt the current command encoder, flush it to the vec, append a user-provided `CommandBuffer` and reset the command encoder to start a new buffer. Users or the render graph will call `RenderContext::finish` to retrieve the series of buffers for submitting to the queue.

This allows users to encode their own `CommandBuffer`s outside of the render graph, potentially in different threads, and store them in components or resources.

Ideally, in the future, the core pipeline passes can run in `RenderStage::Render` systems and end up saving the completed command buffers to either `Commands` or a field in `RenderPhase`. 

## Alternatives
The alternative is to use to use wgpu's `RenderBundle`s, which can achieve similar results; however it's not universally available (no OpenGL, WebGL, and DX11).

---

## Changelog
Added: `RenderContext::new`
Added: `RenderContext::add_command_buffer`
Added: `RenderContext::finish`
Changed: `RenderContext::render_device` is now private. Use the accessor `RenderContext::render_device()` instead.
Changed: `RenderContext::command_encoder` is now private. Use the accessor `RenderContext::command_encoder()` instead.
Changed: `RenderContext` now supports adding external `CommandBuffer`s for inclusion into the render graphs. These buffers can be encoded outside of the render graph (i.e. in a system).

## Migration Guide
`RenderContext`'s fields are now private. Use the accessors on `RenderContext` instead, and construct it with `RenderContext::new`.
2023-01-22 00:21:55 +00:00
..
animate_shader.rs add globals to mesh view bind group (#5409) 2022-09-28 04:20:27 +00:00
array_texture.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
compute_shader_game_of_life.rs Support recording multiple CommandBuffers in RenderContext (#7248) 2023-01-22 00:21:55 +00:00
custom_vertex_attribute.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
post_processing.rs Windows as Entities (#5589) 2023-01-19 00:38:28 +00:00
shader_defs.rs Shader defs can now have a value (#5900) 2022-11-21 22:38:29 +00:00
shader_instancing.rs fix shader_instancing (#7305) 2023-01-20 23:10:37 +00:00
shader_material.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
shader_material_glsl.rs Fix various typos (#7096) 2023-01-06 00:43:30 +00:00
shader_material_screenspace_texture.rs Spawn now takes a Bundle (#6054) 2022-09-23 19:55:54 +00:00
shader_prepass.rs Add depth and normal prepass (#6284) 2023-01-19 22:11:13 +00:00