Skip to content
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

Retain RenderMaterialInstances and RenderMeshMaterialIds from frame to frame. #16985

Merged
merged 19 commits into from
Jan 22, 2025

Conversation

pcwalton
Copy link
Contributor

This commit makes Bevy use change detection to only update RenderMaterialInstances and RenderMeshMaterialIds when meshes have been added, changed, or removed. extract_mesh_materials, the system that extracts these, now follows the pattern that
extract_meshes_for_gpu_building established.

This improves frame time of many_cubes from 3.9ms to approximately 3.1ms, which slightly surpasses the performance of Bevy 0.14.

(Resubmitted from #16878 to clean up history.)

Screenshot 2024-12-17 182109

to frame.

This commit makes Bevy use change detection to only update
`RenderMaterialInstances` and `RenderMeshMaterialIds` when meshes have
been added, changed, or removed. `extract_mesh_materials`, the system
that extracts these, now follows the pattern that
`extract_meshes_for_gpu_building` established.

This improves frame time of `many_cubes` from 3.9ms to approximately
3.1ms, which slightly surpasses the performance of Bevy 0.14.
@pcwalton pcwalton added A-Rendering Drawing game state to the screen S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Performance A change motivated by improving speed, memory usage or compile times labels Dec 26, 2024
@BenjaminBrienen BenjaminBrienen added the D-Straightforward Simple bug fixes and API improvements, docs, test and examples label Dec 31, 2024
@Elabajaba Elabajaba self-requested a review January 3, 2025 03:15
Copy link
Contributor

@IceSentry IceSentry left a comment

Choose a reason for hiding this comment

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

Very nice and simple. It's nice that we can finally take advantage of the retained world.

It's unfortunate that we need to duplicate this for 2d, but figuring out an abstraction for that is definitely future work.

Copy link
Contributor

@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.

I noticed that in practice the query for Changed<ViewVisibility> was firing every frame. It seems to be an issue in our lighting code see pcwalton#7.

@pcwalton pcwalton requested a review from tychedelia January 5, 2025 18:57
@pcwalton
Copy link
Contributor Author

pcwalton commented Jan 5, 2025

@tychedelia Cherry-picked over, thanks!

@tychedelia tychedelia added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 5, 2025
@pcwalton pcwalton added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jan 6, 2025
@pcwalton pcwalton marked this pull request as draft January 6, 2025 07:45
@pcwalton
Copy link
Contributor Author

pcwalton commented Jan 6, 2025

There are some fairly serious bugs that have required a rewrite of a good deal of this patch.

@pcwalton pcwalton added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 8, 2025
@alice-i-cecile
Copy link
Member

Running another example test run; I'll merge this in if that comes up clean :)

@alice-i-cecile
Copy link
Member

The colors in the examples in this PR seem messed up; are materials being batched correctly? See TheBevyFlock/bevy-example-runner#87 (comment)

@alice-i-cecile alice-i-cecile added S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged and removed S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Jan 15, 2025
@pcwalton
Copy link
Contributor Author

Hmm, I'm having trouble reproducing the failures. It may be some kind of race...

@pcwalton
Copy link
Contributor Author

OK, looks like that fixed the race. I'll look at the regressions.

@alice-i-cecile alice-i-cecile added this to the 0.16 milestone Jan 18, 2025
@pcwalton
Copy link
Contributor Author

All of the failures look either like things that were broken already (the pre-existing wireframe problem having to do with the fact that it breaks the 1:1 entity:material relationship), or are false positives. So I think this is ready to go.

@BenjaminBrienen BenjaminBrienen added S-Needs-Review Needs reviewer attention (from anyone!) to move forward and removed S-Waiting-on-Author The author needs to make changes or address concerns before this can be merged labels Jan 22, 2025
@alice-i-cecile alice-i-cecile added S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward labels Jan 22, 2025
@alice-i-cecile alice-i-cecile added this pull request to the merge queue Jan 22, 2025
Merged via the queue into bevyengine:main with commit 72ddac1 Jan 22, 2025
30 checks passed
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-Performance A change motivated by improving speed, memory usage or compile times D-Straightforward Simple bug fixes and API improvements, docs, test and examples S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

6 participants