17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-10 21:58:41 +01:00

Instancing: skip the buckets of a cell lying wholly beyond the range of their instances (#225)

* perf(instancing): skip a cell's buckets lying wholly beyond the range of their instances

* perf(instancing): go only through the instances drawn one by one in the per-node pass

* perf(instancing): leave out of the color pass the cells holding only instances too far to be drawn

* refactor(instancing): keep the caches of the instances of a cell without mutable fields, set by the renderer when the cell is queued
This commit is contained in:
pawelw
2026-11-07 12:35:55 +01:00
committed by GitHub
parent 3a29a165a9
commit 55ba7a9f41
6 changed files with 119 additions and 2 deletions

View File

@@ -352,6 +352,7 @@ void
basic_cell::insert( TAnimModel *Instance ) {
m_active = true;
m_instancecache.boundsversion = 0; // the renderer builds it anew
auto const flags = Instance->Flags();
auto alpha =
@@ -454,6 +455,8 @@ basic_cell::unregister_end( TTrack *Path ) {
void
basic_cell::erase( TAnimModel *Instance ) {
m_instancecache.boundsversion = 0; // the renderer builds it anew
auto const flags = Instance->Flags();
auto alpha =
Instance->Material() != nullptr ? Instance->Material()->textures_alpha : 0x30300030;

View File

@@ -252,6 +252,18 @@ public:
// caches owned by the renderer; emptied whenever the content of the bucket changes
mutable std::vector<instance_bounds> bounds; // copies for the instances, in the same order
mutable unsigned int boundsversion { 0 };
// the largest rangesquaredmax of the copies - past it no instance of the bucket is drawn - and the version
// of the bounds it was taken with. set by the renderer before the cell is drawn, see Prepare_Instances()
float rangesquaredmax { 0.f };
unsigned int rangeversion { 0 };
};
// what the renderer keeps of the instances of the cell, set by it before the cell is drawn
struct instance_cache {
instance_sequence single; // the opaque instances drawn one by one, as they aren't instanceable
float rangesquaredmax { 0.f }; // the largest rangesquaredmax of the instance buckets
bool instancedonly { false }; // the cell holds nothing to draw but instances drawn with the instanced path
unsigned int boundsversion { 0 }; // version of the bounds of the renderer it was built with, 0: not built
unsigned int revoked { 0 }; // TAnimModel::s_instanceable_revoked at the time of the build
};
using instance_bucketdata_map = std::unordered_map< instance_bucket_key, instance_bucket, instance_bucket_key_hash >;
using sound_sequence = std::vector<sound_source *>;
@@ -275,6 +287,7 @@ public:
// m_instancesopaque for nodes whose TAnimModel::m_instanceable == true.
// The renderer uses these to amortise per-model state setup across many instances.
instance_bucketdata_map m_instancebuckets_opaque;
instance_cache m_instancecache;
traction_sequence m_traction;
sound_sequence m_sounds;
eventlauncher_sequence m_eventlaunchers;