Skip to content

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

Merged
merged 6 commits into from
May 12, 2025

Conversation

dsgallups
Copy link
Contributor

@dsgallups dsgallups commented May 5, 2025

Objective

Fixes #19027

Solution

Query for the material binding id if using fallback CPU processing

Testing

I've honestly no clue how to test for this, and I imagine that this isn't entirely failsafe :( but would highly appreciate a suggestion!

To verify this works, please run the the texture.rs example using WebGL 2.

Additionally, I'm extremely naive about the nuances of pbr. This PR is essentially to kinda get the ball rolling of sorts. Thanks :)

Copy link
Contributor

github-actions bot commented May 5, 2025

Welcome, new contributor!

Please make sure you've read our contributing guide and we look forward to reviewing your pull request shortly ✨

@dsgallups dsgallups changed the title Fix: Provide CPU processing with MaterialBindingId Fix: Provide CPU mesh processing with MaterialBindingId May 5, 2025
@alice-i-cecile alice-i-cecile added this to the 0.16.1 milestone May 5, 2025
@alice-i-cecile alice-i-cecile added C-Bug An unexpected or incorrect behavior A-Rendering Drawing game state to the screen O-WebGL2 Specific to the WebGL2 render API labels May 5, 2025
@alice-i-cecile alice-i-cecile requested a review from mockersf May 5, 2025 19:26
@alice-i-cecile alice-i-cecile added S-Needs-Review Needs reviewer attention (from anyone!) to move forward P-High This is particularly urgent, and deserves immediate attention labels May 5, 2025
Comment on lines 1395 to 1396
let material_bindings_index = (mesh_material != DUMMY_MESH_MATERIAL.untyped())
.then(|| {
render_material_bindings
.get(&mesh_material)
.copied()
.unwrap_or_default()
})
.unwrap_or_default();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should we be unwrap_or_defaulting here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure what the check for DUMMY_MESH_MATERIAL is doing here, is it's presumably already effectively covered by the unwrap_or_default when you call get on render_material_bindings -- if a dummy asset is being used we'll default there, which is the right call.

Copy link
Member

@tychedelia tychedelia May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, to be more clear, is there a reason this can't just be simplified to:

render_material_bindings
  .get(&mesh_material)
  .copied()
  .unwrap_or_default()

Maybe I'm missing something.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, no 😄

Copy link
Contributor Author

@dsgallups dsgallups May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that you've mentioned it...I've taken this from

https://github.com/dsgallups/bevy/blob/40d0b8692c18c0055d08fa500c197d7dbaa3684d/crates/bevy_pbr/src/render/mesh.rs#L1156-L1167

I feel like the changes made in this PR wouldn't resolve the case where the mesh is the dummy material...there is no mesh to re-extract next frame for cpus I believe...so this fix might be concealing a bug

Copy link
Member

@tychedelia tychedelia left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small comments, otherwise lgtm!

Comment on lines 1395 to 1396
let material_bindings_index = (mesh_material != DUMMY_MESH_MATERIAL.untyped())
.then(|| {
render_material_bindings
.get(&mesh_material)
.copied()
.unwrap_or_default()
})
.unwrap_or_default();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not really sure what the check for DUMMY_MESH_MATERIAL is doing here, is it's presumably already effectively covered by the unwrap_or_default when you call get on render_material_bindings -- if a dummy asset is being used we'll default there, which is the right call.

@@ -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>,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note: these appear to be correctly ordered via the constraints on late_sweep_material_instances.

dsgallups and others added 5 commits May 9, 2025 13:59
Using @Henauxg's request to create a new constructor for `RenderMeshInstanceShared`.

The `RenderMeshInstanceShare::from_components` now calls this method with default index id.
Added comments that appear correct on the surface. I'm *pretty sure* this is accurate.
- Pared down the comments of internal functions
- removed inline macro

Co-authored-by: charlotte <[email protected]>
@dsgallups dsgallups force-pushed the dsgallups/i-like-jam branch from 1327635 to 40d0b86 Compare May 9, 2025 18:00
Comment on lines 1395 to 1396
let material_bindings_index = (mesh_material != DUMMY_MESH_MATERIAL.untyped())
.then(|| {
render_material_bindings
.get(&mesh_material)
.copied()
.unwrap_or_default()
})
.unwrap_or_default();
Copy link
Member

@tychedelia tychedelia May 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, to be more clear, is there a reason this can't just be simplified to:

render_material_bindings
  .get(&mesh_material)
  .copied()
  .unwrap_or_default()

Maybe I'm missing something.

@dsgallups dsgallups requested a review from tychedelia May 12, 2025 18:03
@superdump superdump added this pull request to the merge queue May 12, 2025
Merged via the queue into bevyengine:main with commit eb0f4f7 May 12, 2025
32 checks passed
@dsgallups dsgallups deleted the dsgallups/i-like-jam branch May 12, 2025 18:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior O-WebGL2 Specific to the WebGL2 render API P-High This is particularly urgent, and deserves immediate attention S-Needs-Review Needs reviewer attention (from anyone!) to move forward
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

WebGPU Example 3D Rendering / Texture has error in the WebGL2 version
5 participants