From 391cb4242e65e0547405e92e51c95d532f125252 Mon Sep 17 00:00:00 2001 From: hulakdar Date: Fri, 26 Aug 2022 13:03:28 +0300 Subject: [PATCH 1/2] Fix d3d12 gpu zones for multithreaded use --- public/tracy/TracyD3D12.hpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/public/tracy/TracyD3D12.hpp b/public/tracy/TracyD3D12.hpp index 47d8074f..df587d1d 100644 --- a/public/tracy/TracyD3D12.hpp +++ b/public/tracy/TracyD3D12.hpp @@ -69,7 +69,7 @@ namespace tracy // In-progress payload. uint32_t m_queryLimit = MaxQueries; - uint32_t m_queryCounter = 0; + std::atomic m_queryCounter = 0; uint32_t m_previousQueryCounter = 0; uint32_t m_activePayload = 0; @@ -180,7 +180,7 @@ namespace tracy void NewFrame() { m_payloadQueue.emplace(D3D12QueryPayload{ m_previousQueryCounter, m_queryCounter }); - m_previousQueryCounter += m_queryCounter; + m_previousQueryCounter += m_queryCounter.load(std::memory_order::memory_order_acquire); m_queryCounter = 0; if (m_previousQueryCounter >= m_queryLimit) @@ -297,10 +297,10 @@ namespace tracy private: tracy_force_inline uint32_t NextQueryId() { - assert(m_queryCounter < m_queryLimit && "Submitted too many GPU queries! Consider increasing MaxQueries."); + uint32_t localQueryCounter = m_queryCounter.fetch_add(2); + assert(localQueryCounter < m_queryLimit && "Submitted too many GPU queries! Consider increasing MaxQueries."); - const uint32_t id = (m_previousQueryCounter + m_queryCounter) % m_queryLimit; - m_queryCounter += 2; // Allocate space for a begin and end query. + const uint32_t id = (m_previousQueryCounter + localQueryCounter) % m_queryLimit; return id; } From e35db2657b2812b162903552f15b4aa5f51175b4 Mon Sep 17 00:00:00 2001 From: hulakdar Date: Fri, 26 Aug 2022 13:25:58 +0300 Subject: [PATCH 2/2] A bit more consistent usage of atomic --- public/tracy/TracyD3D12.hpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/public/tracy/TracyD3D12.hpp b/public/tracy/TracyD3D12.hpp index df587d1d..66f20bc0 100644 --- a/public/tracy/TracyD3D12.hpp +++ b/public/tracy/TracyD3D12.hpp @@ -179,9 +179,9 @@ namespace tracy void NewFrame() { - m_payloadQueue.emplace(D3D12QueryPayload{ m_previousQueryCounter, m_queryCounter }); - m_previousQueryCounter += m_queryCounter.load(std::memory_order::memory_order_acquire); - m_queryCounter = 0; + uint32_t queryCounter = m_queryCounter.exchange(0); + m_payloadQueue.emplace(D3D12QueryPayload{ m_previousQueryCounter, queryCounter }); + m_previousQueryCounter += queryCounter; if (m_previousQueryCounter >= m_queryLimit) { @@ -297,10 +297,10 @@ namespace tracy private: tracy_force_inline uint32_t NextQueryId() { - uint32_t localQueryCounter = m_queryCounter.fetch_add(2); - assert(localQueryCounter < m_queryLimit && "Submitted too many GPU queries! Consider increasing MaxQueries."); + uint32_t queryCounter = m_queryCounter.fetch_add(2); + assert(queryCounter < m_queryLimit && "Submitted too many GPU queries! Consider increasing MaxQueries."); - const uint32_t id = (m_previousQueryCounter + localQueryCounter) % m_queryLimit; + const uint32_t id = (m_previousQueryCounter + queryCounter) % m_queryLimit; return id; }