From b50ed2ceca7232089130125caf719b53f8df50c7 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Wed, 6 Jul 2022 04:15:31 +0200 Subject: [PATCH] [dxvk] Deal with multiple pipeline handles for graphics pipeline instances Also make the handles atomic since worker threads may access them when compiling optimized pipeline variants. --- src/dxvk/dxvk_graphics.cpp | 17 +++++++++++++---- src/dxvk/dxvk_graphics.h | 12 +++++++++--- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index 020afd29..5dc946a5 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -492,8 +492,10 @@ namespace dxvk { DxvkGraphicsPipeline::~DxvkGraphicsPipeline() { - for (const auto& instance : m_pipelines) - this->destroyPipeline(instance.handle); + for (const auto& instance : m_pipelines) { + this->destroyPipeline(instance.baseHandle.load()); + this->destroyPipeline(instance.fastHandle.load()); + } } @@ -545,7 +547,14 @@ namespace dxvk { } } - return std::make_pair(instance->handle, DxvkGraphicsPipelineType::FastPipeline); + // Find a pipeline handle to use. If no optimized pipeline has + // been compiled yet, use the slower base pipeline instead. + VkPipeline fastHandle = instance->fastHandle.load(); + + if (likely(fastHandle != VK_NULL_HANDLE)) + return std::make_pair(fastHandle, DxvkGraphicsPipelineType::FastPipeline); + + return std::make_pair(instance->baseHandle.load(), DxvkGraphicsPipelineType::BasePipeline); } @@ -569,7 +578,7 @@ namespace dxvk { VkPipeline pipeline = this->createPipeline(state); m_stats->numGraphicsPipelines += 1; - return &(*m_pipelines.emplace(state, pipeline)); + return &(*m_pipelines.emplace(state, VK_NULL_HANDLE, pipeline)); } diff --git a/src/dxvk/dxvk_graphics.h b/src/dxvk/dxvk_graphics.h index b4623bd2..967e8134 100644 --- a/src/dxvk/dxvk_graphics.h +++ b/src/dxvk/dxvk_graphics.h @@ -249,11 +249,17 @@ namespace dxvk { DxvkGraphicsPipelineInstance() { } DxvkGraphicsPipelineInstance( const DxvkGraphicsPipelineStateInfo& state_, - VkPipeline handle_) - : state(state_), handle(handle_) { } + VkPipeline baseHandle_, + VkPipeline fastHandle_) + : state (state_), + baseHandle (baseHandle_), + fastHandle (fastHandle_), + isCompiling (fastHandle_ != VK_NULL_HANDLE) { } DxvkGraphicsPipelineStateInfo state; - VkPipeline handle = VK_NULL_HANDLE; + std::atomic baseHandle = { VK_NULL_HANDLE }; + std::atomic fastHandle = { VK_NULL_HANDLE }; + std::atomic isCompiling = { VK_FALSE }; };