-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Fix: Provide CPU mesh processing with MaterialBindingId #19083
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
base: main
Are you sure you want to change the base?
Changes from all commits
180e039
00e6b23
3b47e70
97c0636
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -837,12 +837,43 @@ pub struct RenderMeshInstanceGpuQueues(Parallel<RenderMeshInstanceGpuQueue>); | |
pub struct MeshesToReextractNextFrame(MainEntityHashSet); | ||
|
||
impl RenderMeshInstanceShared { | ||
fn from_components( | ||
/// A gpu builder will provide the mesh instance id | ||
/// during `RenderMeshGpuBuilder::update`. | ||
/// | ||
/// Therefore, this does not need to be queried. | ||
#[inline] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Unnecessary inline, see #2 https://matklad.github.io/2021/07/09/inline-in-rust.html#Inlining-in-Practice |
||
fn for_gpu_building( | ||
previous_transform: Option<&PreviousGlobalTransform>, | ||
mesh: &Mesh3d, | ||
tag: Option<&MeshTag>, | ||
not_shadow_caster: bool, | ||
no_automatic_batching: bool, | ||
) -> Self { | ||
Self::for_cpu_building( | ||
previous_transform, | ||
mesh, | ||
tag, | ||
default(), | ||
not_shadow_caster, | ||
no_automatic_batching, | ||
) | ||
} | ||
|
||
/// Build a struct with common properties between gpu and cpu builders for cpu builders. | ||
/// | ||
/// Unlike the gpu builder, the cpu builder does not have an equivalent | ||
/// [`RenderMeshGpuBuilder::update`]. Therefore, we need to have | ||
/// the [`MaterialBindingId`] ahead of time. | ||
/// | ||
/// Otherwise, a mesh with a handle to a base color texture will all appear identical | ||
/// based on the most recently inserted mesh. | ||
Comment on lines
+864
to
+869
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need a verification that this comment is true. That there really isn't an equivalent...and if there isn't, well...I need to find out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really think we need to document what will happen if this code doesn't work. In general, I think these comments might be saying a bit too much. It's important to document on the gpu side that this will be updated later but its's clear from the usage at the call site that we retrieve the binding id ahead of time. |
||
fn for_cpu_building( | ||
previous_transform: Option<&PreviousGlobalTransform>, | ||
mesh: &Mesh3d, | ||
tag: Option<&MeshTag>, | ||
material_bindings_index: MaterialBindingId, | ||
not_shadow_caster: bool, | ||
no_automatic_batching: bool, | ||
) -> Self { | ||
let mut mesh_instance_flags = RenderMeshInstanceFlags::empty(); | ||
mesh_instance_flags.set(RenderMeshInstanceFlags::SHADOW_CASTER, !not_shadow_caster); | ||
|
@@ -858,8 +889,7 @@ impl RenderMeshInstanceShared { | |
RenderMeshInstanceShared { | ||
mesh_asset_id: mesh.id(), | ||
flags: mesh_instance_flags, | ||
// This gets filled in later, during `RenderMeshGpuBuilder::update`. | ||
material_bindings_index: default(), | ||
material_bindings_index, | ||
lightmap_slab_index: None, | ||
tag: tag.map_or(0, |i| **i), | ||
} | ||
|
@@ -1305,6 +1335,8 @@ pub struct ExtractMeshesSet; | |
/// [`MeshUniform`] building. | ||
pub fn extract_meshes_for_cpu_building( | ||
mut render_mesh_instances: ResMut<RenderMeshInstances>, | ||
mesh_material_ids: Res<RenderMaterialInstances>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note: these appear to be correctly ordered via the constraints on |
||
render_material_bindings: Res<RenderMaterialBindings>, | ||
render_visibility_ranges: Res<RenderVisibilityRanges>, | ||
mut render_mesh_instance_queues: Local<Parallel<Vec<(Entity, RenderMeshInstanceCpu)>>>, | ||
meshes_query: Extract< | ||
|
@@ -1358,10 +1390,22 @@ pub fn extract_meshes_for_cpu_building( | |
transmitted_receiver, | ||
); | ||
|
||
let shared = RenderMeshInstanceShared::from_components( | ||
let mesh_material = mesh_material_ids.mesh_material(MainEntity::from(entity)); | ||
|
||
let material_bindings_index = (mesh_material != DUMMY_MESH_MATERIAL.untyped()) | ||
.then(|| { | ||
render_material_bindings | ||
.get(&mesh_material) | ||
.copied() | ||
.unwrap_or_default() | ||
}) | ||
.unwrap_or_default(); | ||
Comment on lines
+1395
to
+1402
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should we be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not really sure what the check for |
||
|
||
let shared = RenderMeshInstanceShared::for_cpu_building( | ||
previous_transform, | ||
mesh, | ||
tag, | ||
material_bindings_index, | ||
not_shadow_caster, | ||
no_automatic_batching, | ||
); | ||
|
@@ -1566,7 +1610,7 @@ fn extract_mesh_for_gpu_building( | |
transmitted_receiver, | ||
); | ||
|
||
let shared = RenderMeshInstanceShared::from_components( | ||
let shared = RenderMeshInstanceShared::for_gpu_building( | ||
previous_transform, | ||
mesh, | ||
tag, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.