Improve recast performance for .ply files#10
Open
dilirity wants to merge 6 commits intor5valkyrie:S16-S21-MERGEfrom
Open
Improve recast performance for .ply files#10dilirity wants to merge 6 commits intor5valkyrie:S16-S21-MERGEfrom
.ply files#10dilirity wants to merge 6 commits intor5valkyrie:S16-S21-MERGEfrom
Conversation
6176f94 to
8f2a798
Compare
8f2a798 to
790bbaf
Compare
Rewrite PLY loader to read the entire file in one fread with bulk memcpy for vertices instead of millions of tiny ifstream reads. Parallelize normal calculation across all cores for both OBJ and PLY loaders. Parallelize BVH bounds computation in chunky tri mesh builder. Replace qsort with std::sort (inlined comparators) and use std::execution::par for large arrays. Parallelize BVH subdivision by pre-computing subtree sizes and recursing left/right on separate threads for the top 4 levels. Upload cached display list vertex data to GPU via VBOs (glBufferData with GL_STATIC_DRAW) so each frame just binds and draws from GPU memory instead of transferring from CPU RAM every frame. Load GL buffer extension function pointers via SDL_GL_GetProcAddress.
029def1 to
5caac7f
Compare
Guard parallel BVH subdivision against maxNodes overflow by validating pre-computed node counts fit before spawning threads. Use GL_DYNAMIC_DRAW instead of GL_STATIC_DRAW for VBO uploads since display list data can change on cache invalidation. Validate GL extension function pointers on startup and exit gracefully if VBO support is unavailable.
Replace atoi with strtol for vertex/face count parsing to detect overflow and malformed values. Use long long instead of ssize_t for file size and vertex byte calculations to avoid truncation on 32-bit.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Optimize PLY mesh loading, parallelize shared pipeline stages (normals, BVH, rendering), and harden the PLY parser against malformed files. Builds on the OBJ performance work merged in #13.
What changed
PLY loader rewrite (
MeshLoaderPly.cpp)std::ifstreamwith singlefreadinto a memory buffer -- eliminates millions of tiny I/O callsmemcpyfor vertex data (binary layout matchesrdVec3D)strtollandINT_MAXbounds[0, m_vertCount)before uselong longarithmetic,m_triCount <= INT_MAX/3guard)Parallel normal calculation (
MeshLoaderObj.cpp,MeshLoaderPly.cpp)std::atomiccounterhardware_concurrency - 1worker threads writing to non-overlapping output rangesParallel BVH construction (
ChunkyTriMesh.cpp)qsort+ C comparators withstd::sort+ inlined lambdasstd::execution::parfor sorting arrays >= 32K itemsmaxNodesguard prevents overlap if pre-computed counts exceed allocationVBO rendering (
Editor.cpp,EditorInterfaces.cpp)glBufferDatawithGL_DYNAMIC_DRAW)SDL_GL_GetProcAddresswith null validation at startupNavmesh cache invalidation (
Editor.cpp,Editor_SoloMesh.cpp,Editor_TempObstacles.cpp,NavMeshPruneTool.cpp)invalidateNavMeshCache()calls after mesh rebuild, navmesh load, traverse link rebuild, and static pathing rebuildHow to test