Skip to content

Commit 70276b2

Browse files
committed
Add MeshPass
1 parent d87d491 commit 70276b2

File tree

14 files changed

+2084
-1326
lines changed

14 files changed

+2084
-1326
lines changed

crates/bevy_mesh/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ bitflags! {
4242
/// downward. The PBR mesh pipeline key bits start from the lowest bit and
4343
/// go upward. This allows the PBR bits in the downstream crate `bevy_pbr`
4444
/// to coexist in the same field without any shifts.
45-
#[derive(Clone, Debug)]
45+
#[derive(Copy, Clone, Debug)]
4646
pub struct BaseMeshPipelineKey: u64 {
4747
const MORPH_TARGETS = 1 << (u64::BITS - 1);
4848
}

crates/bevy_pbr/src/dummy_phase.rs

Lines changed: 173 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,173 @@
1+
use core::{marker::PhantomData, ops::Range};
2+
3+
use bevy_core_pipeline::core_3d::{Opaque3dBatchSetKey, Opaque3dBinKey};
4+
use bevy_ecs::entity::Entity;
5+
use bevy_render::{
6+
render_phase::{
7+
BinnedPhaseItem, BinnedRenderPhase, BinnedRenderPhasePlugin, CachedRenderPipelinePhaseItem,
8+
DrawFunctionId, PhaseItem, PhaseItemExtraIndex, ViewBinnedRenderPhases,
9+
},
10+
render_resource::CachedRenderPipelineId,
11+
sync_world::MainEntity,
12+
};
13+
14+
use crate::{MeshPass, MeshPipeline, PhaseContext, PhaseItemExt, PhaseItems, RenderPhaseType};
15+
16+
const DUMMY_PHASE_ERROR: &str = "Dummy phase should never be instantiated.";
17+
18+
macro_rules! define_dummy_phase {
19+
($name:ident) => {
20+
pub struct $name<P>(PhantomData<P>);
21+
22+
impl<P: MeshPass> PhaseItemExt for $name<P> {
23+
// Important: It must be empty to ensure it does not match any material.
24+
const PHASE_TYPES: RenderPhaseType = RenderPhaseType::empty();
25+
26+
type RenderPhase = BinnedRenderPhase<Self>;
27+
type RenderPhases = ViewBinnedRenderPhases<Self>;
28+
type PhasePlugin = BinnedRenderPhasePlugin<Self, MeshPipeline>;
29+
30+
fn queue(_render_phase: &mut Self::RenderPhase, _context: &PhaseContext) {
31+
panic!("{}", DUMMY_PHASE_ERROR)
32+
}
33+
}
34+
35+
impl<P: MeshPass> PhaseItem for $name<P> {
36+
fn entity(&self) -> Entity {
37+
panic!("{}", DUMMY_PHASE_ERROR)
38+
}
39+
40+
fn main_entity(&self) -> MainEntity {
41+
panic!("{}", DUMMY_PHASE_ERROR)
42+
}
43+
44+
fn draw_function(&self) -> DrawFunctionId {
45+
panic!("{}", DUMMY_PHASE_ERROR)
46+
}
47+
48+
fn batch_range(&self) -> &Range<u32> {
49+
panic!("{}", DUMMY_PHASE_ERROR)
50+
}
51+
52+
fn batch_range_mut(&mut self) -> &mut Range<u32> {
53+
panic!("{}", DUMMY_PHASE_ERROR)
54+
}
55+
56+
fn extra_index(&self) -> PhaseItemExtraIndex {
57+
panic!("{}", DUMMY_PHASE_ERROR)
58+
}
59+
60+
fn batch_range_and_extra_index_mut(
61+
&mut self,
62+
) -> (&mut Range<u32>, &mut PhaseItemExtraIndex) {
63+
panic!("{}", DUMMY_PHASE_ERROR)
64+
}
65+
}
66+
67+
impl<P: MeshPass> BinnedPhaseItem for $name<P> {
68+
type BatchSetKey = Opaque3dBatchSetKey;
69+
type BinKey = Opaque3dBinKey;
70+
71+
fn new(
72+
_batch_set_key: Self::BatchSetKey,
73+
_bin_key: Self::BinKey,
74+
_representative_entity: (Entity, MainEntity),
75+
_batch_range: Range<u32>,
76+
_extra_index: PhaseItemExtraIndex,
77+
) -> Self {
78+
panic!("{}", DUMMY_PHASE_ERROR)
79+
}
80+
}
81+
82+
impl<P: MeshPass> CachedRenderPipelinePhaseItem for $name<P> {
83+
fn cached_pipeline(&self) -> CachedRenderPipelineId {
84+
panic!("{}", DUMMY_PHASE_ERROR)
85+
}
86+
}
87+
};
88+
}
89+
90+
define_dummy_phase!(DummyPhase2);
91+
define_dummy_phase!(DummyPhase3);
92+
define_dummy_phase!(DummyPhase4);
93+
94+
impl<P, PIE> PhaseItems<P> for PIE
95+
where
96+
P: MeshPass,
97+
PIE: PhaseItemExt,
98+
{
99+
type Phase1 = PIE;
100+
type Phase2 = DummyPhase2<P>;
101+
type Phase3 = DummyPhase3<P>;
102+
type Phase4 = DummyPhase4<P>;
103+
104+
fn count() -> usize {
105+
1
106+
}
107+
}
108+
109+
impl<P, PIE1> PhaseItems<P> for (PIE1,)
110+
where
111+
P: MeshPass,
112+
PIE1: PhaseItemExt,
113+
{
114+
type Phase1 = PIE1;
115+
type Phase2 = DummyPhase2<P>;
116+
type Phase3 = DummyPhase3<P>;
117+
type Phase4 = DummyPhase4<P>;
118+
119+
fn count() -> usize {
120+
1
121+
}
122+
}
123+
124+
impl<P, PIE1, PIE2> PhaseItems<P> for (PIE1, PIE2)
125+
where
126+
P: MeshPass,
127+
PIE1: PhaseItemExt,
128+
PIE2: PhaseItemExt,
129+
{
130+
type Phase1 = PIE1;
131+
type Phase2 = PIE2;
132+
type Phase3 = DummyPhase3<P>;
133+
type Phase4 = DummyPhase4<P>;
134+
135+
fn count() -> usize {
136+
2
137+
}
138+
}
139+
140+
impl<P, PIE1, PIE2, PIE3> PhaseItems<P> for (PIE1, PIE2, PIE3)
141+
where
142+
P: MeshPass,
143+
PIE1: PhaseItemExt,
144+
PIE2: PhaseItemExt,
145+
PIE3: PhaseItemExt,
146+
{
147+
type Phase1 = PIE1;
148+
type Phase2 = PIE2;
149+
type Phase3 = PIE3;
150+
type Phase4 = DummyPhase4<P>;
151+
152+
fn count() -> usize {
153+
3
154+
}
155+
}
156+
157+
impl<P, PIE1, PIE2, PIE3, PIE4> PhaseItems<P> for (PIE1, PIE2, PIE3, PIE4)
158+
where
159+
P: MeshPass,
160+
PIE1: PhaseItemExt,
161+
PIE2: PhaseItemExt,
162+
PIE3: PhaseItemExt,
163+
PIE4: PhaseItemExt,
164+
{
165+
type Phase1 = PIE1;
166+
type Phase2 = PIE2;
167+
type Phase3 = PIE3;
168+
type Phase4 = PIE4;
169+
170+
fn count() -> usize {
171+
4
172+
}
173+
}

crates/bevy_pbr/src/lib.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ mod components;
3030
pub mod decal;
3131
pub mod deferred;
3232
pub mod diagnostic;
33+
mod dummy_phase;
3334
mod extended_material;
3435
mod fog;
3536
mod light_probe;
3637
mod lightmap;
38+
mod main_pass;
3739
mod material;
3840
mod material_bind_groups;
3941
mod medium;
@@ -61,6 +63,7 @@ pub use extended_material::*;
6163
pub use fog::*;
6264
pub use light_probe::*;
6365
pub use lightmap::*;
66+
pub use main_pass::*;
6467
pub use material::*;
6568
pub use material_bind_groups::*;
6669
pub use medium::*;
@@ -222,7 +225,7 @@ impl Plugin for PbrPlugin {
222225
use_gpu_instance_buffer_builder: self.use_gpu_instance_buffer_builder,
223226
debug_flags: self.debug_flags,
224227
},
225-
MaterialsPlugin {
228+
MainPassPlugin {
226229
debug_flags: self.debug_flags,
227230
},
228231
MaterialPlugin::<StandardMaterial> {
@@ -327,7 +330,6 @@ impl Plugin for PbrPlugin {
327330
extract_ambient_light_resource,
328331
extract_ambient_light,
329332
extract_shadow_filtering_method,
330-
late_sweep_material_instances,
331333
),
332334
)
333335
.add_systems(

crates/bevy_pbr/src/lightmap/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ pub struct Lightmap {
111111
///
112112
/// There is one of these per visible lightmapped mesh instance.
113113
#[derive(Debug)]
114-
pub(crate) struct RenderLightmap {
114+
pub struct RenderLightmap {
115115
/// The rectangle within the lightmap texture that the UVs are relative to.
116116
///
117117
/// The top left coordinate is the `min` part of the rect, and the bottom
@@ -130,7 +130,7 @@ pub(crate) struct RenderLightmap {
130130
pub(crate) slot_index: LightmapSlotIndex,
131131

132132
// Whether or not bicubic sampling should be used for this lightmap.
133-
pub(crate) bicubic_sampling: bool,
133+
pub bicubic_sampling: bool,
134134
}
135135

136136
/// Stores data for all lightmaps in the render world.

0 commit comments

Comments
 (0)