diff options
-rw-r--r-- | core/templates/rid_owner.h | 56 | ||||
-rw-r--r-- | servers/rendering/renderer_scene_cull.cpp | 8 |
2 files changed, 24 insertions, 40 deletions
diff --git a/core/templates/rid_owner.h b/core/templates/rid_owner.h index 3ed81e76fd..95632cdec2 100644 --- a/core/templates/rid_owner.h +++ b/core/templates/rid_owner.h @@ -292,43 +292,32 @@ public: _FORCE_INLINE_ uint32_t get_rid_count() const { return alloc_count; } - - _FORCE_INLINE_ T *get_ptr_by_index(uint32_t p_index) { - ERR_FAIL_UNSIGNED_INDEX_V(p_index, alloc_count, nullptr); + void get_owned_list(List<RID> *p_owned) { if (THREAD_SAFE) { spin_lock.lock(); } - uint64_t idx = free_list_chunks[p_index / elements_in_chunk][p_index % elements_in_chunk]; - T *ptr = &chunks[idx / elements_in_chunk][idx % elements_in_chunk]; - if (THREAD_SAFE) { - spin_lock.unlock(); - } - return ptr; - } - - _FORCE_INLINE_ RID get_rid_by_index(uint32_t p_index) { - ERR_FAIL_INDEX_V(p_index, alloc_count, RID()); - if (THREAD_SAFE) { - spin_lock.lock(); + for (size_t i = 0; i < max_alloc; i++) { + uint64_t validator = validator_chunks[i / elements_in_chunk][i % elements_in_chunk]; + if (validator != 0xFFFFFFFF) { + p_owned->push_back(_make_from_id((validator << 32) | i)); + } } - uint64_t idx = free_list_chunks[p_index / elements_in_chunk][p_index % elements_in_chunk]; - uint64_t validator = validator_chunks[idx / elements_in_chunk][idx % elements_in_chunk]; - - RID rid = _make_from_id((validator << 32) | idx); if (THREAD_SAFE) { spin_lock.unlock(); } - return rid; } - void get_owned_list(List<RID> *p_owned) { + //used for fast iteration in the elements or RIDs + void fill_owned_buffer(RID *p_rid_buffer) { if (THREAD_SAFE) { spin_lock.lock(); } + uint32_t idx = 0; for (size_t i = 0; i < max_alloc; i++) { uint64_t validator = validator_chunks[i / elements_in_chunk][i % elements_in_chunk]; if (validator != 0xFFFFFFFF) { - p_owned->push_back(_make_from_id((validator << 32) | i)); + p_rid_buffer[idx] = _make_from_id((validator << 32) | i); + idx++; } } if (THREAD_SAFE) { @@ -425,18 +414,14 @@ public: return alloc.get_rid_count(); } - _FORCE_INLINE_ RID get_rid_by_index(uint32_t p_index) { - return alloc.get_rid_by_index(p_index); - } - - _FORCE_INLINE_ T *get_ptr_by_index(uint32_t p_index) { - return *alloc.get_ptr_by_index(p_index); - } - _FORCE_INLINE_ void get_owned_list(List<RID> *p_owned) { return alloc.get_owned_list(p_owned); } + void fill_owned_buffer(RID *p_rid_buffer) { + alloc.fill_owned_buffer(p_rid_buffer); + } + void set_description(const char *p_descrption) { alloc.set_description(p_descrption); } @@ -485,17 +470,12 @@ public: return alloc.get_rid_count(); } - _FORCE_INLINE_ RID get_rid_by_index(uint32_t p_index) { - return alloc.get_rid_by_index(p_index); - } - - _FORCE_INLINE_ T *get_ptr_by_index(uint32_t p_index) { - return alloc.get_ptr_by_index(p_index); - } - _FORCE_INLINE_ void get_owned_list(List<RID> *p_owned) { return alloc.get_owned_list(p_owned); } + void fill_owned_buffer(RID *p_rid_buffer) { + alloc.fill_owned_buffer(p_rid_buffer); + } void set_description(const char *p_descrption) { alloc.set_description(p_descrption); diff --git a/servers/rendering/renderer_scene_cull.cpp b/servers/rendering/renderer_scene_cull.cpp index 8ded180633..5b2be8e174 100644 --- a/servers/rendering/renderer_scene_cull.cpp +++ b/servers/rendering/renderer_scene_cull.cpp @@ -3871,8 +3871,12 @@ void RendererSceneCull::update_dirty_instances() { void RendererSceneCull::update() { //optimize bvhs - for (uint32_t i = 0; i < scenario_owner.get_rid_count(); i++) { - Scenario *s = scenario_owner.get_ptr_by_index(i); + + uint32_t rid_count = scenario_owner.get_rid_count(); + RID *rids = (RID *)alloca(sizeof(RID) * rid_count); + scenario_owner.fill_owned_buffer(rids); + for (uint32_t i = 0; i < rid_count; i++) { + Scenario *s = scenario_owner.get_or_null(rids[i]); s->indexers[Scenario::INDEXER_GEOMETRY].optimize_incremental(indexer_update_iterations); s->indexers[Scenario::INDEXER_VOLUMES].optimize_incremental(indexer_update_iterations); } |