From 83447975ac91b19bbfff7fbf2391ad46c6339487 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 21 Sep 2018 22:28:06 +0200 Subject: [PATCH] [dxvk] Refactor pipeline stat counters The stat counter struct no longer has to be passed to the pipeline compiler function. The new implementation uses atomic counters of the pipeline manager rather than per-command list counters, which removes the need to pass the counter structure to the compiler function. --- src/dxvk/dxvk_compute.cpp | 5 ++--- src/dxvk/dxvk_compute.h | 3 +-- src/dxvk/dxvk_context.cpp | 4 ++-- src/dxvk/dxvk_device.cpp | 7 +++++-- src/dxvk/dxvk_graphics.cpp | 6 ++---- src/dxvk/dxvk_graphics.h | 4 +--- src/dxvk/dxvk_pipemanager.cpp | 8 ++++++++ src/dxvk/dxvk_pipemanager.h | 20 ++++++++++++++++++++ 8 files changed, 41 insertions(+), 16 deletions(-) diff --git a/src/dxvk/dxvk_compute.cpp b/src/dxvk/dxvk_compute.cpp index ac575be0..f2021a6d 100644 --- a/src/dxvk/dxvk_compute.cpp +++ b/src/dxvk/dxvk_compute.cpp @@ -45,8 +45,7 @@ namespace dxvk { VkPipeline DxvkComputePipeline::getPipelineHandle( - const DxvkComputePipelineStateInfo& state, - DxvkStatCounters& stats) { + const DxvkComputePipelineStateInfo& state) { VkPipeline pipeline = VK_NULL_HANDLE; { std::lock_guard lock(m_mutex); @@ -70,11 +69,11 @@ namespace dxvk { // Add new pipeline to the set m_pipelines.push_back({ state, newPipeline }); + m_pipeMgr->m_numComputePipelines += 1; if (m_basePipeline == VK_NULL_HANDLE) m_basePipeline = newPipeline; - stats.addCtr(DxvkStatCounter::PipeCountCompute, 1); return newPipeline; } } diff --git a/src/dxvk/dxvk_compute.h b/src/dxvk/dxvk_compute.h index 530d59d4..fa28916e 100644 --- a/src/dxvk/dxvk_compute.h +++ b/src/dxvk/dxvk_compute.h @@ -61,8 +61,7 @@ namespace dxvk { * \returns Pipeline handle */ VkPipeline getPipelineHandle( - const DxvkComputePipelineStateInfo& state, - DxvkStatCounters& stats); + const DxvkComputePipelineStateInfo& state); private: diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index 7b43d37a..eea4a281 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -2013,7 +2013,7 @@ namespace dxvk { m_flags.clr(DxvkContextFlag::CpDirtyPipelineState); m_cpActivePipeline = m_state.cp.pipeline != nullptr - ? m_state.cp.pipeline->getPipelineHandle(m_state.cp.state, m_cmd->statCounters()) + ? m_state.cp.pipeline->getPipelineHandle(m_state.cp.state) : VK_NULL_HANDLE; if (m_cpActivePipeline != VK_NULL_HANDLE) { @@ -2071,7 +2071,7 @@ namespace dxvk { m_gpActivePipeline = m_state.gp.pipeline != nullptr && m_state.om.framebuffer != nullptr ? m_state.gp.pipeline->getPipelineHandle(m_state.gp.state, - m_state.om.framebuffer->getRenderPass(), m_cmd->statCounters()) + m_state.om.framebuffer->getRenderPass()) : VK_NULL_HANDLE; if (m_gpActivePipeline != VK_NULL_HANDLE) { diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index 45c08222..3cc2e10f 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -198,10 +198,13 @@ namespace dxvk { DxvkStatCounters DxvkDevice::getStatCounters() { DxvkMemoryStats mem = m_memory->getMemoryStats(); + DxvkPipelineCount pipe = m_pipelineManager->getPipelineCount(); DxvkStatCounters result; - result.setCtr(DxvkStatCounter::MemoryAllocated, mem.memoryAllocated); - result.setCtr(DxvkStatCounter::MemoryUsed, mem.memoryUsed); + result.setCtr(DxvkStatCounter::MemoryAllocated, mem.memoryAllocated); + result.setCtr(DxvkStatCounter::MemoryUsed, mem.memoryUsed); + result.setCtr(DxvkStatCounter::PipeCountGraphics, pipe.numGraphicsPipelines); + result.setCtr(DxvkStatCounter::PipeCountCompute, pipe.numComputePipelines); std::lock_guard lock(m_statLock); result.merge(m_statCounters); diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index 083e5182..a177aa27 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -82,8 +82,7 @@ namespace dxvk { VkPipeline DxvkGraphicsPipeline::getPipelineHandle( const DxvkGraphicsPipelineStateInfo& state, - const DxvkRenderPass& renderPass, - DxvkStatCounters& stats) { + const DxvkRenderPass& renderPass) { VkRenderPass renderPassHandle = renderPass.getDefaultHandle(); { std::lock_guard lock(m_mutex); @@ -120,8 +119,7 @@ namespace dxvk { // Add new pipeline to the set m_pipelines.emplace_back(state, renderPassHandle, newPipelineHandle); - - stats.addCtr(DxvkStatCounter::PipeCountGraphics, 1); + m_pipeMgr->m_numGraphicsPipelines += 1; } // Use the new pipeline as the base pipeline for derivative pipelines diff --git a/src/dxvk/dxvk_graphics.h b/src/dxvk/dxvk_graphics.h index 770cac0e..78e312f9 100644 --- a/src/dxvk/dxvk_graphics.h +++ b/src/dxvk/dxvk_graphics.h @@ -175,13 +175,11 @@ namespace dxvk { * state. If necessary, a new pipeline will be created. * \param [in] state Pipeline state vector * \param [in] renderPass The render pass - * \param [in,out] stats Stat counter * \returns Pipeline handle */ VkPipeline getPipelineHandle( const DxvkGraphicsPipelineStateInfo& state, - const DxvkRenderPass& renderPass, - DxvkStatCounters& stats); + const DxvkRenderPass& renderPass); private: diff --git a/src/dxvk/dxvk_pipemanager.cpp b/src/dxvk/dxvk_pipemanager.cpp index 2d1b4902..a1cb8515 100644 --- a/src/dxvk/dxvk_pipemanager.cpp +++ b/src/dxvk/dxvk_pipemanager.cpp @@ -100,5 +100,13 @@ namespace dxvk { m_graphicsPipelines.insert(std::make_pair(key, pipeline)); return pipeline; } + + + DxvkPipelineCount DxvkPipelineManager::getPipelineCount() const { + DxvkPipelineCount result; + result.numComputePipelines = m_numComputePipelines.load(); + result.numGraphicsPipelines = m_numGraphicsPipelines.load(); + return result; + } } \ No newline at end of file diff --git a/src/dxvk/dxvk_pipemanager.h b/src/dxvk/dxvk_pipemanager.h index f605953b..8fd5dd35 100644 --- a/src/dxvk/dxvk_pipemanager.h +++ b/src/dxvk/dxvk_pipemanager.h @@ -7,6 +7,17 @@ #include "dxvk_graphics.h" namespace dxvk { + + /** + * \brief Pipeline count + * + * Stores number of graphics and + * compute pipelines, individually. + */ + struct DxvkPipelineCount { + uint32_t numGraphicsPipelines; + uint32_t numComputePipelines; + }; /** * \brief Compute pipeline key @@ -95,10 +106,19 @@ namespace dxvk { const Rc& gs, const Rc& fs); + /** + * \brief Retrieves total pipeline count + * \returns Number of compute/graphics pipelines + */ + DxvkPipelineCount getPipelineCount() const; + private: const DxvkDevice* m_device; Rc m_cache; + + std::atomic m_numComputePipelines = { 0 }; + std::atomic m_numGraphicsPipelines = { 0 }; std::mutex m_mutex;