From 368eea73108159a430f27f5bcef0e3dafcb0dd63 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Sun, 13 May 2018 15:36:44 +0200 Subject: [PATCH] [dxvk] Use derivative pipelines again --- src/dxvk/dxvk_graphics.cpp | 14 ++++++++++++-- src/dxvk/dxvk_graphics.h | 7 ++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index 79f3503b..b1bc125d 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -118,8 +118,9 @@ namespace dxvk { // If no pipeline instance exists with the given state // vector, create a new one and add it to the list. + VkPipeline newPipelineBase = m_basePipelineBase.load(); VkPipeline newPipelineHandle = this->compilePipeline(state, renderPassHandle, - VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT, VK_NULL_HANDLE); + VK_PIPELINE_CREATE_DISABLE_OPTIMIZATION_BIT, newPipelineBase); Rc newPipeline = new DxvkGraphicsPipelineInstance(m_device->vkd(), state, @@ -141,6 +142,10 @@ namespace dxvk { stats.addCtr(DxvkStatCounter::PipeCountGraphics, 1); } + // Use the new pipeline as the base pipeline for derivative pipelines + if (newPipelineBase == VK_NULL_HANDLE && newPipelineHandle != VK_NULL_HANDLE) + m_basePipelineBase.compare_exchange_strong(newPipelineBase, newPipelineHandle); + // Compile optimized pipeline asynchronously m_compiler->queueCompilation(this, newPipeline); return newPipelineHandle; @@ -150,9 +155,14 @@ namespace dxvk { void DxvkGraphicsPipeline::compileInstance( const Rc& instance) { // Compile an optimized version of the pipeline + VkPipeline newPipelineBase = m_fastPipelineBase.load(); VkPipeline newPipelineHandle = this->compilePipeline( instance->m_stateVector, instance->m_renderPass, - 0, VK_NULL_HANDLE); + 0, m_fastPipelineBase); + + // Use the new pipeline as the base pipeline for derivative pipelines + if (newPipelineBase == VK_NULL_HANDLE && newPipelineHandle != VK_NULL_HANDLE) + m_fastPipelineBase.compare_exchange_strong(newPipelineBase, newPipelineHandle); // If an optimized version has been compiled // in the meantime, discard the new pipeline diff --git a/src/dxvk/dxvk_graphics.h b/src/dxvk/dxvk_graphics.h index 2032c332..ad1de14b 100644 --- a/src/dxvk/dxvk_graphics.h +++ b/src/dxvk/dxvk_graphics.h @@ -249,9 +249,14 @@ namespace dxvk { DxvkGraphicsCommonPipelineStateInfo m_common; - sync::Spinlock m_mutex; + // List of pipeline instances, shared between threads + alignas(CACHE_LINE_SIZE) sync::Spinlock m_mutex; std::vector> m_pipelines; + // Pipeline handles used for derivative pipelines + std::atomic m_basePipelineBase = { VK_NULL_HANDLE }; + std::atomic m_fastPipelineBase = { VK_NULL_HANDLE }; + DxvkGraphicsPipelineInstance* findInstance( const DxvkGraphicsPipelineStateInfo& state, VkRenderPass renderPass) const;