Skip to content

Recompute AABBs #18742

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open

Recompute AABBs #18742

wants to merge 3 commits into from

Conversation

aevyrie
Copy link
Member

@aevyrie aevyrie commented Apr 7, 2025

Objective

Solution

  • Implement the things.

Testing

  • CI

…on to avoid component insertion where mutation is possible.
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.

Ooohh, this is such a nice longstanding issue to fix, really confused me the first time I hit it. So glad to see AssetChanged helping here. There's probably a bit of perf hit for the table scan but I think this is such a sharp edge and PostUpdate has a lot of noise anyway that I think it's totally worth it.

@aevyrie
Copy link
Member Author

aevyrie commented Apr 7, 2025

There's probably a bit of perf hit for the table scan

Agreed, but, I would expect entities with meshes is going to be a pretty manageable number, and would likely be render bottlenecked first. (could be wrong!)

@aevyrie
Copy link
Member Author

aevyrie commented Apr 7, 2025

That reminds me, let's make the mutation queries go brrrrr

@aevyrie
Copy link
Member Author

aevyrie commented Apr 7, 2025

Looks like this I open, need to review why: #7971

The notable bit:

Note: this only addresses when the Mesh is updated itself, not when the Handle has changed. I attempted to include a Ref<Handle>::is_changed check, but that easily added 1+ms on many_cubes to do what is basically zero work in that common case. I attempted to parallelize it with QueryParIter, which shrunk it down to 360us, but it still was an excessive amount of work for basically nothing. This current implementation only incurs a cost when a Mesh is created or modified.

I view this as a stop gap until we have a form of asset preprocessing that can be used to compute the Aabb offline, or force meshes to be immutable after construction and precompute it's Aabb ahead of time.

.before(CheckVisibility)
.after(TransformSystem::TransformPropagate)
.after(AssetEvents)
.ambiguous_with(CalculateBounds),
Copy link
Contributor

Choose a reason for hiding this comment

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

What does it mean to be ambiguous with itself?

Copy link
Member

Choose a reason for hiding this comment

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

Ignore all ambiguities between systems in the same set.

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.

Code looks good, might need an opt-out just to be on the safe side.

The previous versions of this seemed to suffer from various performance issues but they also didn't have access to AssetChanged that allows for such a simple implementation.

@IceSentry IceSentry added A-Rendering Drawing game state to the screen C-Performance A change motivated by improving speed, memory usage or compile times labels Apr 7, 2025
@IceSentry IceSentry added S-Needs-Review Needs reviewer attention (from anyone!) to move forward C-Bug An unexpected or incorrect behavior labels Apr 7, 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 A-Animation Make things move and change over time S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help and removed S-Needs-Review Needs reviewer attention (from anyone!) to move forward S-Ready-For-Final-Review This PR has been approved by the community. It's ready for a maintainer to consider merging it labels Apr 7, 2025
@alice-i-cecile
Copy link
Member

We should bench this before merging, but I'm inclined to merge even with a modest regression. This is a really nasty bug, and "fast but incorrect" really isn't very useful.

@JMS55 JMS55 added this to the 0.17 milestone Apr 7, 2025
@rparrett
Copy link
Contributor

rparrett commented Apr 7, 2025

As far as I can tell, with this setup, meshes spawned with Aabbs will have that Aabb immediately overwritten. This might just result in a double calculation for something like persisted scenes, or a pretty nasty situation in cases where the user actually needs a custom Aabb. (For example, with animated meshes)

@aevyrie
Copy link
Member Author

aevyrie commented Apr 8, 2025

Yep. There are a few ways we could solve this, I don't know if we have precedent for any. The closest I can think of is something like an opt-out ZST like NoAutoAabb.

There is no way to tell if a newly added Aabb is there as a default initialized value, or as a precomputed value. From what I can tell, it seems like you need to have some way of specifying this, and doing it via archetype (marker) is the most efficient.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Animation Make things move and change over time A-Rendering Drawing game state to the screen C-Bug An unexpected or incorrect behavior C-Performance A change motivated by improving speed, memory usage or compile times S-Needs-Benchmarking This set of changes needs performance benchmarking to double-check that they help
Projects
Status: No status
Development

Successfully merging this pull request may close these issues.

Mesh AABBs are never updated
6 participants