17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-17 06:19:19 +02:00

perf(instancing): instances of scene cells culled by copies of their bounds kept with the buckets, before the instances themselves are fetched; instances past the range of the lod stages of their model left out; identity of the instance buffer restored once per bucket instead of after each batch

This commit is contained in:
2026-10-07 16:29:15 +02:00
parent bc99b80191
commit 398fdac6a1
4 changed files with 128 additions and 21 deletions

View File

@@ -379,7 +379,9 @@ basic_cell::insert( TAnimModel *Instance ) {
if( mat != nullptr ) {
for( int i = 0; i < 5; ++i ) { key.skins[i] = mat->replacable_skins[i]; }
}
m_instancebuckets_opaque[ key ].emplace_back( Instance );
auto &bucket { m_instancebuckets_opaque[ key ] };
bucket.instances.emplace_back( Instance );
bucket.bounds.clear();
}
}
// re-calculate cell bounding area, in case model extends outside the cell's boundaries
@@ -478,10 +480,12 @@ basic_cell::erase( TAnimModel *Instance ) {
// NOTE: searched by pointer rather than by key: the instance may have lost its instanceable
// status or changed its skins since it was inserted, which would leave a dangling pointer behind
for( auto bucket = m_instancebuckets_opaque.begin(); bucket != m_instancebuckets_opaque.end(); ) {
bucket->second.erase(
std::remove( std::begin( bucket->second ), std::end( bucket->second ), Instance ),
std::end( bucket->second ) );
if( bucket->second.empty() ) {
auto &instances { bucket->second.instances };
instances.erase(
std::remove( std::begin( instances ), std::end( instances ), Instance ),
std::end( instances ) );
bucket->second.bounds.clear();
if( instances.empty() ) {
bucket = m_instancebuckets_opaque.erase( bucket );
}
else {