diff --git a/src/dxvk/dxvk_compute.cpp b/src/dxvk/dxvk_compute.cpp index f233ae190..0baee54c8 100644 --- a/src/dxvk/dxvk_compute.cpp +++ b/src/dxvk/dxvk_compute.cpp @@ -37,7 +37,7 @@ namespace dxvk { DxvkComputePipeline::~DxvkComputePipeline() { for (const auto& instance : m_pipelines) - this->destroyPipeline(instance.pipeline); + this->destroyPipeline(instance.pipeline()); } @@ -47,15 +47,17 @@ namespace dxvk { { std::lock_guard lock(m_mutex); - if (this->findPipeline(state, newPipelineHandle)) - return newPipelineHandle; + auto instance = this->findInstance(state); + + if (instance) + return instance->pipeline(); // If no pipeline instance exists with the given state // vector, create a new one and add it to the list. newPipelineHandle = this->createPipeline(state); // Add new pipeline to the set - m_pipelines.push_back({ state, newPipelineHandle }); + m_pipelines.emplace_back(state, newPipelineHandle); m_pipeMgr->m_numComputePipelines += 1; } @@ -66,17 +68,14 @@ namespace dxvk { } - bool DxvkComputePipeline::findPipeline( - const DxvkComputePipelineStateInfo& state, - VkPipeline& pipeline) const { - for (const PipelineStruct& pair : m_pipelines) { - if (pair.stateVector == state) { - pipeline = pair.pipeline; - return true; - } + const DxvkComputePipelineInstance* DxvkComputePipeline::findInstance( + const DxvkComputePipelineStateInfo& state) const { + for (const auto& instance : m_pipelines) { + if (instance.isCompatible(state)) + return &instance; } - return false; + return nullptr; } diff --git a/src/dxvk/dxvk_compute.h b/src/dxvk/dxvk_compute.h index df87b46d0..9cd7bd131 100644 --- a/src/dxvk/dxvk_compute.h +++ b/src/dxvk/dxvk_compute.h @@ -32,6 +32,50 @@ namespace dxvk { DxvkBindingMask bsBindingMask; }; + + + /** + * \brief Compute pipeline instance + */ + class DxvkComputePipelineInstance { + + public: + + DxvkComputePipelineInstance() + : m_stateVector (), + m_pipeline (VK_NULL_HANDLE) { } + + DxvkComputePipelineInstance( + const DxvkComputePipelineStateInfo& state, + VkPipeline pipe) + : m_stateVector (state), + m_pipeline (pipe) { } + + /** + * \brief Checks for matching pipeline state + * + * \param [in] stateVector Graphics pipeline state + * \param [in] renderPass Render pass handle + * \returns \c true if the specialization is compatible + */ + bool isCompatible(const DxvkComputePipelineStateInfo& state) const { + return m_stateVector == state; + } + + /** + * \brief Retrieves pipeline + * \returns The pipeline handle + */ + VkPipeline pipeline() const { + return m_pipeline; + } + + private: + + DxvkComputePipelineStateInfo m_stateVector; + VkPipeline m_pipeline; + + }; /** @@ -75,11 +119,6 @@ namespace dxvk { private: - struct PipelineStruct { - DxvkComputePipelineStateInfo stateVector; - VkPipeline pipeline; - }; - Rc m_vkd; DxvkPipelineManager* m_pipeMgr; @@ -88,12 +127,11 @@ namespace dxvk { Rc m_layout; - sync::Spinlock m_mutex; - std::vector m_pipelines; + sync::Spinlock m_mutex; + std::vector m_pipelines; - bool findPipeline( - const DxvkComputePipelineStateInfo& state, - VkPipeline& pipeline) const; + const DxvkComputePipelineInstance* findInstance( + const DxvkComputePipelineStateInfo& state) const; VkPipeline createPipeline( const DxvkComputePipelineStateInfo& state) const;