From 6e27f12e2235748505d47a43644da1f0a2c32852 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 29 Mar 2018 12:32:20 +0200 Subject: [PATCH] [dxvk] Move DxvkPipelineManager object to DxvkContext Since we create only one DxvkContext per D3D11Device, rather than per D3D11DeviceContext as originally planned, there is no need to keep the pipeline manager as a global thread-safe object. This may slightly reduce CPU overhead. --- src/dxvk/dxvk_context.cpp | 17 +++++++++++------ src/dxvk/dxvk_context.h | 10 ++++++++-- src/dxvk/dxvk_device.cpp | 21 +-------------------- src/dxvk/dxvk_device.h | 28 ---------------------------- src/dxvk/dxvk_pipemanager.cpp | 6 ++---- src/dxvk/dxvk_pipemanager.h | 3 --- 6 files changed, 22 insertions(+), 63 deletions(-) diff --git a/src/dxvk/dxvk_context.cpp b/src/dxvk/dxvk_context.cpp index d17ca9bc7..99598fcaf 100644 --- a/src/dxvk/dxvk_context.cpp +++ b/src/dxvk/dxvk_context.cpp @@ -6,8 +6,12 @@ namespace dxvk { - DxvkContext::DxvkContext(const Rc& device) - : m_device(device) { } + DxvkContext::DxvkContext( + const Rc& device, + const Rc& pipelineCache) + : m_device (device), + m_pipeCache (pipelineCache), + m_pipeMgr (new DxvkPipelineManager(device.ptr())) { } DxvkContext::~DxvkContext() { @@ -1372,8 +1376,8 @@ namespace dxvk { m_flags.clr(DxvkContextFlag::CpDirtyPipeline); m_state.cp.state.bsBindingState.clear(); - m_state.cp.pipeline = m_device->createComputePipeline( - m_state.cp.cs.shader); + m_state.cp.pipeline = m_pipeMgr->createComputePipeline( + m_pipeCache, m_state.cp.cs.shader); if (m_state.cp.pipeline != nullptr) m_cmd->trackResource(m_state.cp.pipeline); @@ -1403,8 +1407,9 @@ namespace dxvk { m_flags.clr(DxvkContextFlag::GpDirtyPipeline); m_state.gp.state.bsBindingState.clear(); - m_state.gp.pipeline = m_device->createGraphicsPipeline( - m_state.gp.vs.shader, m_state.gp.tcs.shader, m_state.gp.tes.shader, + m_state.gp.pipeline = m_pipeMgr->createGraphicsPipeline( + m_pipeCache, m_state.gp.vs.shader, + m_state.gp.tcs.shader, m_state.gp.tes.shader, m_state.gp.gs.shader, m_state.gp.fs.shader); if (m_state.gp.pipeline != nullptr) diff --git a/src/dxvk/dxvk_context.h b/src/dxvk/dxvk_context.h index 6a819ede2..02b32ded6 100644 --- a/src/dxvk/dxvk_context.h +++ b/src/dxvk/dxvk_context.h @@ -7,6 +7,8 @@ #include "dxvk_data.h" #include "dxvk_event.h" #include "dxvk_meta_resolve.h" +#include "dxvk_pipecache.h" +#include "dxvk_pipemanager.h" #include "dxvk_query.h" #include "dxvk_query_pool.h" #include "dxvk_util.h" @@ -24,7 +26,9 @@ namespace dxvk { public: - DxvkContext(const Rc& device); + DxvkContext( + const Rc& device, + const Rc& pipelineCache); ~DxvkContext(); /** @@ -561,7 +565,9 @@ namespace dxvk { private: - const Rc m_device; + const Rc m_device; + const Rc m_pipeCache; + const Rc m_pipeMgr; Rc m_cmd; DxvkContextFlags m_flags; diff --git a/src/dxvk/dxvk_device.cpp b/src/dxvk/dxvk_device.cpp index 8a9119ec2..2dddf0006 100644 --- a/src/dxvk/dxvk_device.cpp +++ b/src/dxvk/dxvk_device.cpp @@ -15,7 +15,6 @@ namespace dxvk { m_memory (new DxvkMemoryAllocator(adapter, vkd)), m_renderPassPool (new DxvkRenderPassPool (vkd)), m_pipelineCache (new DxvkPipelineCache (vkd)), - m_pipelineManager (new DxvkPipelineManager(this)), m_unboundResources(this), m_submissionQueue (this) { m_options.adjustAppOptions(env::getExeName()); @@ -103,7 +102,7 @@ namespace dxvk { Rc DxvkDevice::createContext() { - return new DxvkContext(this); + return new DxvkContext(this, m_pipelineCache); } @@ -172,24 +171,6 @@ namespace dxvk { } - Rc DxvkDevice::createComputePipeline( - const Rc& cs) { - return m_pipelineManager->createComputePipeline( - m_pipelineCache, cs); - } - - - Rc DxvkDevice::createGraphicsPipeline( - const Rc& vs, - const Rc& tcs, - const Rc& tes, - const Rc& gs, - const Rc& fs) { - return m_pipelineManager->createGraphicsPipeline( - m_pipelineCache, vs, tcs, tes, gs, fs); - } - - Rc DxvkDevice::createSwapchain( const Rc& surface, const DxvkSwapchainProperties& properties) { diff --git a/src/dxvk/dxvk_device.h b/src/dxvk/dxvk_device.h index 7f249da26..600a783d5 100644 --- a/src/dxvk/dxvk_device.h +++ b/src/dxvk/dxvk_device.h @@ -246,33 +246,6 @@ namespace dxvk { const DxvkInterfaceSlots& iface, const SpirvCodeBuffer& code); - /** - * \brief Retrieves a compute pipeline - * - * \param [in] layout Pipeline binding layout - * \param [in] cs Compute shader - * \returns The compute pipeline - */ - Rc createComputePipeline( - const Rc& cs); - - /** - * \brief Retrieves a graphics pipeline object - * - * \param [in] vs Vertex shader - * \param [in] tcs Tessellation control shader - * \param [in] tes Tessellation evaluation shader - * \param [in] gs Geometry shader - * \param [in] fs Fragment shader - * \returns The graphics pipeline - */ - Rc createGraphicsPipeline( - const Rc& vs, - const Rc& tcs, - const Rc& tes, - const Rc& gs, - const Rc& fs); - /** * \brief Creates a swap chain * @@ -338,7 +311,6 @@ namespace dxvk { Rc m_memory; Rc m_renderPassPool; Rc m_pipelineCache; - Rc m_pipelineManager; DxvkUnboundResources m_unboundResources; DxvkOptions m_options; diff --git a/src/dxvk/dxvk_pipemanager.cpp b/src/dxvk/dxvk_pipemanager.cpp index 76f106e9b..7b9f554f6 100644 --- a/src/dxvk/dxvk_pipemanager.cpp +++ b/src/dxvk/dxvk_pipemanager.cpp @@ -55,14 +55,13 @@ namespace dxvk { DxvkComputePipelineKey key; key.cs = cs; - std::lock_guard lock(m_mutex); auto pair = m_computePipelines.find(key); - if (pair != m_computePipelines.end()) return pair->second; const Rc pipeline = new DxvkComputePipeline(m_device, cache, cs); + m_computePipelines.insert(std::make_pair(key, pipeline)); return pipeline; } @@ -85,14 +84,13 @@ namespace dxvk { key.gs = gs; key.fs = fs; - std::lock_guard lock(m_mutex); auto pair = m_graphicsPipelines.find(key); - if (pair != m_graphicsPipelines.end()) return pair->second; const Rc pipeline = new DxvkGraphicsPipeline(m_device, cache, vs, tcs, tes, gs, fs); + m_graphicsPipelines.insert(std::make_pair(key, pipeline)); return pipeline; } diff --git a/src/dxvk/dxvk_pipemanager.h b/src/dxvk/dxvk_pipemanager.h index 2400cdc9c..3690bbd20 100644 --- a/src/dxvk/dxvk_pipemanager.h +++ b/src/dxvk/dxvk_pipemanager.h @@ -1,6 +1,5 @@ #pragma once -#include #include #include "dxvk_compute.h" @@ -100,8 +99,6 @@ namespace dxvk { const DxvkDevice* m_device; - std::mutex m_mutex; - std::unordered_map< DxvkComputePipelineKey, Rc,