From d59db267109ac31197aac6c65eb21c323858358a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Verschelde?= Date: Wed, 14 Jan 2026 21:58:29 +0100 Subject: [PATCH] Revert "Core: Switch `RID_alloc::owns` to lock-free" This reverts commit bdfe8549b878f11d0622479030aaccc82d40d1d9. This caused a regression for GPUParticles3D emitters on macOS arm64, which is proving to be both tricky to reproduce and solve. Other parts of the engine using RID_Owner might be affected too. Given that we're about to release 4.6, reverting might be the safest option at this time, and this optimization can be re-attempted for 4.7. Fixes #114900. --- core/templates/rid_owner.h | 41 +++++++------------------------------- 1 file changed, 7 insertions(+), 34 deletions(-) diff --git a/core/templates/rid_owner.h b/core/templates/rid_owner.h index cfaaf1ecb1a8..c5e2b058686b 100644 --- a/core/templates/rid_owner.h +++ b/core/templates/rid_owner.h @@ -310,24 +310,16 @@ class RID_Alloc : public RID_AllocBase { } _FORCE_INLINE_ bool owns(const RID &p_rid) const { - if (p_rid == RID()) { - return false; - } - if constexpr (THREAD_SAFE) { - SYNC_ACQUIRE; + mutex.lock(); } uint64_t id = p_rid.get_id(); uint32_t idx = uint32_t(id & 0xFFFFFFFF); - uint32_t ma; - if constexpr (THREAD_SAFE) { - ma = ((std::atomic *)&max_alloc)->load(std::memory_order_relaxed); - } else { - ma = max_alloc; - } - - if (unlikely(idx >= ma)) { + if (unlikely(idx >= max_alloc)) { + if constexpr (THREAD_SAFE) { + mutex.unlock(); + } return false; } @@ -336,29 +328,10 @@ class RID_Alloc : public RID_AllocBase { uint32_t validator = uint32_t(id >> 32); - if constexpr (THREAD_SAFE) { -#ifdef TSAN_ENABLED - __tsan_acquire(&chunks[idx_chunk]); // We know not a race in practice. - __tsan_acquire(&chunks[idx_chunk][idx_element]); // We know not a race in practice. -#endif - } - - Chunk &c = chunks[idx_chunk][idx_element]; + bool owned = (chunks[idx_chunk][idx_element].validator & 0x7FFFFFFF) == validator; if constexpr (THREAD_SAFE) { -#ifdef TSAN_ENABLED - __tsan_release(&chunks[idx_chunk]); - __tsan_release(&chunks[idx_chunk][idx_element]); - __tsan_acquire(&c.validator); // We know not a race in practice. -#endif - } - - bool owned = (c.validator & 0x7FFFFFFF) == validator; - - if constexpr (THREAD_SAFE) { -#ifdef TSAN_ENABLED - __tsan_release(&c.validator); -#endif + mutex.unlock(); } return owned;