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

Optimized Mesh Merging #61729

Merged
merged 1 commit into from
Jun 8, 2022
Merged

Conversation

lawnjelly
Copy link
Member

@lawnjelly lawnjelly commented Jun 5, 2022

Changes from PoolVector to LocalVector and pre-reserving vectors rather than push_back.

Tests show more than factor of 3 speedup for merging 200,000 boxes.

Notes

  • LocalVector is generally more efficient than PoolVector for single threaded operations.
  • Although mesh merging is already available through rooms & portals and the MeshInstance::merge_meshes() function, it may be exposed further in 3.6 so it makes sense to make it as fast as possible, especially for use at runtime at level load, rather than pre-baking.

Side issue - copy initialization in LocalVector

I noticed that both when assigning a Vector to LocalVector and also for assigning PoolVector, it seems to have to be done as two expression as follows, rather than LocalVector blah = PoolVector(foo);. I just copied the code for assigning Vector, but it would be nice if this can be solved:

	LocalVector<Vector3> normals;
	normals = PoolVector<Vector3>(arrays[VS::ARRAY_NORMAL]);

If you try it as a single expression there is a compile error.

EDIT: Solved the above, the problem was this needs copy initialization rather than assignment operator overload. LocalVector needed an operator LocalVector::LocalVector(const PoolVector<T> &p_from). I've also added one for LocalVector::LocalVector(const Vector<T> &p_from) as I had previously noted this expression didn't work. The PR is now changed to use this short form rather than the longer form assignment quoted above.

@lawnjelly lawnjelly requested review from a team as code owners June 5, 2022 19:46
@Chaosus Chaosus added this to the 3.x milestone Jun 5, 2022
@lawnjelly lawnjelly force-pushed the faster_mesh_merging branch 2 times, most recently from 797f707 to 91ed604 Compare June 6, 2022 07:28
@akien-mga akien-mga requested a review from a team June 7, 2022 12:26
scene/3d/mesh_instance.cpp Outdated Show resolved Hide resolved
Changes from PoolVector to LocalVector and pre-reserving vectors rather than push_back.
Copy link
Member

@clayjohn clayjohn left a comment

Choose a reason for hiding this comment

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

Great work! Its amazing to see the difference using LocalVector can make. We will have to keep our eyes open for other similar places that will benefit.

@akien-mga akien-mga merged commit 6ec7e2c into godotengine:3.x Jun 8, 2022
@akien-mga
Copy link
Member

Thanks!

@lawnjelly lawnjelly deleted the faster_mesh_merging branch June 8, 2022 05:57
@akien-mga akien-mga modified the milestones: 3.x, 3.5 Jun 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants