From 8bcd47d6dcef06d9efc4203074bd9065f425ea50 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 25 Sep 2018 18:22:58 +0200 Subject: [PATCH] [dxvk] Simplify pipeline object locking Any more complex approach is not very useful at the moment because we have to put a lock around the actual compile function anyway. --- src/dxvk/dxvk_compute.cpp | 32 +++++++------------------- src/dxvk/dxvk_graphics.cpp | 46 ++++++++++++-------------------------- 2 files changed, 22 insertions(+), 56 deletions(-) diff --git a/src/dxvk/dxvk_compute.cpp b/src/dxvk/dxvk_compute.cpp index 8f5e6e4d..e05db143 100644 --- a/src/dxvk/dxvk_compute.cpp +++ b/src/dxvk/dxvk_compute.cpp @@ -48,34 +48,18 @@ namespace dxvk { VkPipeline DxvkComputePipeline::getPipelineHandle( const DxvkComputePipelineStateInfo& state) { - VkPipeline pipeline = VK_NULL_HANDLE; - - { std::lock_guard lock(m_mutex); - - if (this->findPipeline(state, pipeline)) - return pipeline; - } - - // If no pipeline instance exists with the given state - // vector, create a new one and add it to the list. - VkPipeline newPipelineBase = m_basePipeline.load(); + VkPipeline newPipelineBase = VK_NULL_HANDLE; VkPipeline newPipelineHandle = VK_NULL_HANDLE; - // FIXME for some reason, compiling the exact - // same pipeline crashes inside driver code { std::lock_guard lock(m_mutex); - newPipelineHandle = this->compilePipeline( - state, newPipelineBase); - } + + if (this->findPipeline(state, newPipelineHandle)) + return newPipelineHandle; - { std::lock_guard lock(m_mutex); - - // Discard the pipeline if another thread - // was faster compiling the same pipeline - if (this->findPipeline(state, pipeline)) { - this->destroyPipeline(newPipelineHandle); - return pipeline; - } + // If no pipeline instance exists with the given state + // vector, create a new one and add it to the list. + newPipelineBase = m_basePipeline.load(); + newPipelineHandle = this->compilePipeline(state, newPipelineBase); // Add new pipeline to the set m_pipelines.push_back({ state, newPipelineHandle }); diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index 41bdc90e..b8768514 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -85,45 +85,27 @@ namespace dxvk { const DxvkGraphicsPipelineStateInfo& state, const DxvkRenderPass& renderPass) { VkRenderPass renderPassHandle = renderPass.getDefaultHandle(); + + VkPipeline newPipelineBase = VK_NULL_HANDLE; + VkPipeline newPipelineHandle = VK_NULL_HANDLE; { std::lock_guard lock(m_mutex); - - const DxvkGraphicsPipelineInstance* instance = - this->findInstance(state, renderPassHandle); + + auto instance = this->findInstance(state, renderPassHandle); if (instance != nullptr) return instance->pipeline(); - } - // If the pipeline state vector is invalid, don't try - // to create a new pipeline, it won't work anyway. - if (!this->validatePipelineState(state)) - return VK_NULL_HANDLE; - - // If no pipeline instance exists with the given state - // vector, create a new one and add it to the list. - VkPipeline newPipelineBase = m_basePipeline.load(); - VkPipeline newPipelineHandle = VK_NULL_HANDLE; - - // FIXME for some reason, compiling the exact - // same pipeline crashes inside driver code - { std::lock_guard lock(m_mutex); - newPipelineHandle = this->compilePipeline( - state, renderPassHandle, newPipelineBase); - } + // If the pipeline state vector is invalid, don't try + // to create a new pipeline, it won't work anyway. + if (!this->validatePipelineState(state)) + return VK_NULL_HANDLE; + + // If no pipeline instance exists with the given state + // vector, create a new one and add it to the list. + newPipelineBase = m_basePipeline.load(); + newPipelineHandle = this->compilePipeline(state, renderPassHandle, newPipelineBase); - { std::lock_guard lock(m_mutex); - - // Discard the pipeline if another thread - // was faster compiling the same pipeline - const DxvkGraphicsPipelineInstance* instance = - this->findInstance(state, renderPassHandle); - - if (instance != nullptr) { - this->destroyPipeline(newPipelineHandle); - return instance->pipeline(); - } - // Add new pipeline to the set m_pipelines.emplace_back(state, renderPassHandle, newPipelineHandle); m_pipeMgr->m_numGraphicsPipelines += 1;