diff --git a/src/dxvk/dxvk_queue.cpp b/src/dxvk/dxvk_queue.cpp index 53cf838b1..746475a22 100644 --- a/src/dxvk/dxvk_queue.cpp +++ b/src/dxvk/dxvk_queue.cpp @@ -137,9 +137,16 @@ namespace dxvk { std::unique_lock lock(m_mutex); while (!m_stopped.load()) { - m_submitCond.wait(lock, [this] { - return m_stopped.load() || !m_finishQueue.empty(); - }); + if (m_finishQueue.empty()) { + auto t0 = std::chrono::high_resolution_clock::now(); + + m_submitCond.wait(lock, [this] { + return m_stopped.load() || !m_finishQueue.empty(); + }); + + auto t1 = std::chrono::high_resolution_clock::now(); + m_gpuIdle += std::chrono::duration_cast(t1 - t0).count(); + } if (m_stopped.load()) return; diff --git a/src/dxvk/dxvk_queue.h b/src/dxvk/dxvk_queue.h index 59b77fb87..50ea26b52 100644 --- a/src/dxvk/dxvk_queue.h +++ b/src/dxvk/dxvk_queue.h @@ -80,6 +80,18 @@ namespace dxvk { uint32_t pendingSubmissions() const { return m_pending.load(); } + + /** + * \brief Retrieves estimated GPU idle time + * + * This is a monotonically increasing counter + * which can be evaluated periodically in order + * to calculate the GPU load. + * \returns Accumulated GPU idle time, in us + */ + uint64_t gpuIdleTicks() const { + return m_gpuIdle.load(); + } /** * \brief Submits a command list asynchronously @@ -147,6 +159,7 @@ namespace dxvk { std::atomic m_stopped = { false }; std::atomic m_pending = { 0u }; + std::atomic m_gpuIdle = { 0ull }; std::mutex m_mutex; std::mutex m_mutexQueue;