Skip to content

Commit 78195de

Browse files
committed
rebase + cleanup
1 parent 218a848 commit 78195de

File tree

3 files changed

+54
-34
lines changed

3 files changed

+54
-34
lines changed

crates/bevy_core_pipeline/src/core_3d/mod.rs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,8 @@ use bevy_render::{
2929
prelude::Msaa,
3030
render_graph::{EmptyNode, RenderGraph, SlotInfo, SlotType},
3131
render_phase::{
32-
<<<<<<< HEAD
3332
sort_phase_system, CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions, PhaseItem,
3433
RenderPhase,
35-
=======
36-
sort_phase_system, CachedRenderPipelinePhaseItem, DrawFunctionId, DrawFunctions,
37-
PhaseItem, RenderPhase,
38-
>>>>>>> b411da63f (Flatten EntityPhaseItem into PhaseItem)
3934
},
4035
render_resource::{
4136
CachedRenderPipelineId, Extent3d, TextureDescriptor, TextureDimension, TextureFormat,

crates/bevy_render/src/render_phase/draw.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,11 @@ use std::{any::TypeId, fmt::Debug, hash::Hash};
2222
///
2323
/// Therefore the draw function can retrieve and query the required ECS data from the render world.
2424
///
25-
/// This trait can either be implemented directly or implicitly composed out of multiple modular [`RenderCommand`]s.
25+
/// This trait can either be implemented directly or implicitly composed out of multiple modular
26+
/// [`RenderCommand`]s.
2627
pub trait Draw<P: PhaseItem>: Send + Sync + 'static {
2728
/// Prepares the draw function to be used. This is called once and only once before the phase
28-
/// begins. There may be zero or more `draw` calls following a call to this function..
29+
/// begins. There may be zero or more `draw` calls following a call to this function.
2930
/// Implementing this is optional.
3031
#[allow(unused_variables)]
3132
fn prepare(&mut self, world: &'_ World) {}
@@ -54,7 +55,7 @@ pub struct DrawFunctionsInternal<P: PhaseItem> {
5455
}
5556

5657
impl<P: PhaseItem> DrawFunctionsInternal<P> {
57-
// Todo: add comment
58+
/// Prepares all draw function. This is called once and only once before the phase begins.
5859
pub fn prepare(&mut self, world: &World) {
5960
for function in &mut self.draw_functions {
6061
function.prepare(world);
@@ -132,13 +133,19 @@ impl<P: PhaseItem> DrawFunctions<P> {
132133
}
133134
}
134135

135-
/// [`RenderCommand`]s are modular standardized pieces of render logic that can be composed into [`Draw`] functions.
136+
/// [`RenderCommand`]s are modular standardized pieces of render logic that can be composed into
137+
/// [`Draw`] functions.
136138
///
137-
/// To turn a stateless render command into a usable draw function it has to be wrapped by a [`RenderCommandState`].
138-
/// This is done automatically when registering a render command as a [`Draw`] function via the [`AddRenderCommand::add_render_command`] method.
139+
/// To turn a stateless render command into a usable draw function it has to be wrapped by a
140+
/// [`RenderCommandState`].
141+
/// This is done automatically when registering a render command as a [`Draw`] function via the
142+
/// [`AddRenderCommand::add_render_command`] method.
139143
///
140-
/// Compared to the draw function the required ECS data is fetched automatically (by the [`RenderCommandState`]) from the render world.
141-
/// Therefore the three types [`Param`](RenderCommand::Param), [`ViewWorldQuery`](RenderCommand::ViewWorldQuery) and [`WorldQuery`](RenderCommand::WorldQuery) are used.
144+
/// Compared to the draw function the required ECS data is fetched automatically
145+
/// (by the [`RenderCommandState`]) from the render world.
146+
/// Therefore the three types [`Param`](RenderCommand::Param),
147+
/// [`ViewWorldQuery`](RenderCommand::ViewWorldQuery) and
148+
/// [`ItemWorldQuery`](RenderCommand::ItemWorldQuery) are used.
142149
/// They specify which information is required to execute the render command.
143150
///
144151
/// Multiple render commands can be combined together by wrapping them in a tuple.
@@ -157,15 +164,18 @@ impl<P: PhaseItem> DrawFunctions<P> {
157164
/// );
158165
/// ```
159166
pub trait RenderCommand<P: PhaseItem> {
160-
/// Specifies all ECS data required by [`RenderCommand::render`].
167+
/// Specifies the general ECS data (e.g. resources) required by [`RenderCommand::render`].
161168
/// All parameters have to be read only.
162169
type Param: SystemParam + 'static;
163-
// Todo: add comment
170+
/// Specifies the ECS data of the view required by [`RenderCommand::render`].
171+
/// All components have to be accessed read only.
164172
type ViewWorldQuery: ReadOnlyWorldQuery;
165-
// Todo: add comment
173+
/// Specifies the ECS data of the item required by [`RenderCommand::render`].
174+
/// All components have to be accessed read only.
166175
type ItemWorldQuery: ReadOnlyWorldQuery;
167176

168-
/// Renders a [`PhaseItem`] by recording commands (e.g. setting pipelines, binding bind groups, issuing draw calls, etc.) via the [`TrackedRenderPass`].
177+
/// Renders a [`PhaseItem`] by recording commands (e.g. setting pipelines, binding bind groups,
178+
/// issuing draw calls, etc.) via the [`TrackedRenderPass`].
169179
fn render<'w>(
170180
item: &P,
171181
view: ROQueryItem<'w, Self::ViewWorldQuery>,
@@ -208,7 +218,8 @@ macro_rules! render_command_tuple_impl {
208218
all_tuples!(render_command_tuple_impl, 0, 15, C, V, E);
209219

210220
/// Wraps a [`RenderCommand`] into a state so that it can be used as a [`Draw`] function.
211-
/// Therefore the [`RenderCommand::Param`], [`RenderCommand::ViewWorldQuery`] and [`RenderCommand::WorldQuery`] are queried from the ECS and passed to the command.
221+
/// Therefore the [`RenderCommand::Param`], [`RenderCommand::ViewWorldQuery`] and
222+
/// [`RenderCommand::ItemWorldQuery`] are queried from the ECS and passed to the command.
212223
pub struct RenderCommandState<P: PhaseItem + 'static, C: RenderCommand<P>> {
213224
state: SystemState<C::Param>,
214225
view: QueryState<C::ViewWorldQuery>,
@@ -230,7 +241,8 @@ impl<P: PhaseItem, C: RenderCommand<P> + Send + Sync + 'static> Draw<P> for Rend
230241
where
231242
C::Param: ReadOnlySystemParam,
232243
{
233-
// Todo: add comment
244+
/// Prepares the render command to be used. This is called once and only once before the phase
245+
/// begins. There may be zero or more `draw` calls following a call to this function.
234246
fn prepare(&mut self, world: &'_ World) {
235247
self.view.update_archetypes(world);
236248
self.entity.update_archetypes(world);
@@ -297,8 +309,7 @@ pub struct SetItemPipeline;
297309
impl<P: CachedRenderPipelinePhaseItem> RenderCommand<P> for SetItemPipeline {
298310
type Param = SRes<PipelineCache>;
299311
type ViewWorldQuery = ();
300-
type WorldQuery = ();
301-
312+
type ItemWorldQuery = ();
302313
#[inline]
303314
fn render<'w>(
304315
item: &P,

crates/bevy_render/src/render_phase/mod.rs

Lines changed: 27 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,43 @@
1-
//! The modular rendering abstractions that queue, prepare, sort and draw entities as part of separate phases.
1+
//! A modular rendering abstraction responsible for queuing, preparing, sorting and drawing entities
2+
//! as part of separate phases.
23
//!
3-
//! To draw an entity, a corresponding [`PhaseItem`] has to be added to one of the renderers multiple [`RenderPhase`]s (e.g. opaque, transparent, shadow, etc).
4+
//! To draw an entity, a corresponding [`PhaseItem`] has to be added to one of the renderers
5+
//! multiple [`RenderPhase`]s (e.g. opaque, transparent, shadow, etc).
46
//! This must be done in the [`RenderStage::Queue`](crate::RenderStage::Queue).
5-
//! After that the [`RenderPhase`] sorts them in the [`RenderStage::PhaseSort`](crate::RenderStage::PhaseSort).
6-
//! Finally the [`PhaseItem`]s are rendered using a single [`TrackedRenderPass`], during the [`RenderStage::Render`](crate::RenderStage::Render).
7+
//! After that the [`RenderPhase`] sorts them in the
8+
//! [`RenderStage::PhaseSort`](crate::RenderStage::PhaseSort).
9+
//! Finally the [`PhaseItem`]s are rendered using a single [`TrackedRenderPass`], during the
10+
//! [`RenderStage::Render`](crate::RenderStage::Render).
711
//!
812
//! Therefore each [`PhaseItem`] is assigned a [`Draw`] function.
9-
//! These set up the state of the [`TrackedRenderPass`] (i.e. select the [`RenderPipeline`](crate::render_resource::RenderPipeline), configure the [`BindGroup`](crate::render_resource::BindGroup)s, etc.) and then issue a draw call, for the corresponding [`PhaseItem`].
13+
//! These set up the state of the [`TrackedRenderPass`] (i.e. select the
14+
//! [`RenderPipeline`](crate::render_resource::RenderPipeline), configure the
15+
//! [`BindGroup`](crate::render_resource::BindGroup)s, etc.) and then issue a draw call,
16+
//! for the corresponding [`PhaseItem`].
1017
//!
11-
//! The [`Draw`] function trait can either be implemented directly or such a function can be created by composing multiple [`RenderCommand`]s.
18+
//! The [`Draw`] function trait can either be implemented directly or such a function can be
19+
//! created by composing multiple [`RenderCommand`]s.
1220
1321
mod draw;
1422
mod draw_state;
1523
mod rangefinder;
1624

17-
use bevy_ecs::entity::Entity;
1825
pub use draw::*;
1926
pub use draw_state::*;
2027
pub use rangefinder::*;
2128

2229
use bevy_ecs::prelude::*;
23-
use bevy_ecs::world::World;
2430
use std::ops::Range;
2531

2632
/// A render phase sorts and renders all [`PhaseItem`]s (entities) that are assigned to it.
2733
///
28-
/// It corresponds to exactly one [`TrackedRenderPass`] and thus renders all items into the same texture attachments (e.g. color, depth, stencil).
34+
/// Each view (camera, or shadow-casting light, etc.) can have one or multiple render phases.
35+
/// They are used to queue entities for rendering.
36+
/// Multiple phases might be required due to different sorting/batching behaviours
37+
/// (e.g. opaque: front to back, transparent: back to front) or because one phase depends on
38+
/// the rendered texture of the previous phase (e.g. for screen-space reflections).
39+
/// All phase items are then rendered using a single [`TrackedRenderPass`].
40+
/// This render pass might be reused for multiple phases.
2941
#[derive(Component)]
3042
pub struct RenderPhase<I: PhaseItem> {
3143
pub items: Vec<I>,
@@ -49,6 +61,7 @@ impl<I: PhaseItem> RenderPhase<I> {
4961
I::sort(&mut self.items);
5062
}
5163

64+
/// Renders all of its [`PhaseItem`]s using their corresponding draw functions.
5265
pub fn render<'w>(
5366
&self,
5467
render_pass: &mut TrackedRenderPass<'w>,
@@ -93,12 +106,13 @@ impl<I: BatchedPhaseItem> RenderPhase<I> {
93106
}
94107
}
95108

96-
/// An item (entity) which will be drawn to the screen.
109+
/// An item (entity) which will be drawn to a texture or the screen, as part of a [`RenderPhase`].
97110
///
98-
/// A phase item has to be queued up for rendering during the [`RenderStage::Queue`](crate::RenderStage::Queue) stage.
111+
/// A phase item has to be queued up for rendering during the
112+
/// [`RenderStage::Queue`](crate::RenderStage::Queue).
99113
/// Afterwards it will be sorted and rendered automatically in the
100-
/// [`RenderStage::PhaseSort`](crate::RenderStage::PhaseSort) stage and
101-
/// [`RenderStage::Render`](crate::RenderStage::Render) stage, respectively.
114+
/// [`RenderStage::PhaseSort`](crate::RenderStage::PhaseSort) and
115+
/// [`RenderStage::Render`](crate::RenderStage::Render), respectively.
102116
pub trait PhaseItem: Sized + Send + Sync + 'static {
103117
/// The type used for ordering the items. The smallest values are drawn first.
104118
/// This order can be calculated using the [`ViewRangefinder3d`],

0 commit comments

Comments
 (0)