diff --git a/src/dxvk/dxvk_compute.cpp b/src/dxvk/dxvk_compute.cpp index 9b4411378..52849d8d0 100644 --- a/src/dxvk/dxvk_compute.cpp +++ b/src/dxvk/dxvk_compute.cpp @@ -134,15 +134,12 @@ namespace dxvk { void DxvkComputePipeline::writePipelineStateToCache( const DxvkComputePipelineStateInfo& state) const { - if (m_pipeMgr->m_stateCache == nullptr) - return; - DxvkStateCacheKey key; if (m_shaders.cs != nullptr) key.cs = m_shaders.cs->getShaderKey(); - m_pipeMgr->m_stateCache->addComputePipeline(key, state); + m_pipeMgr->m_stateCache.addComputePipeline(key, state); } } diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index 18a538af6..614f8a3ee 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -838,9 +838,6 @@ namespace dxvk { void DxvkGraphicsPipeline::writePipelineStateToCache( const DxvkGraphicsPipelineStateInfo& state) const { - if (m_pipeMgr->m_stateCache == nullptr) - return; - DxvkStateCacheKey key; if (m_shaders.vs != nullptr) key.vs = m_shaders.vs->getShaderKey(); if (m_shaders.tcs != nullptr) key.tcs = m_shaders.tcs->getShaderKey(); @@ -848,7 +845,7 @@ namespace dxvk { if (m_shaders.gs != nullptr) key.gs = m_shaders.gs->getShaderKey(); if (m_shaders.fs != nullptr) key.fs = m_shaders.fs->getShaderKey(); - m_pipeMgr->m_stateCache->addGraphicsPipeline(key, state); + m_pipeMgr->m_stateCache.addGraphicsPipeline(key, state); } diff --git a/src/dxvk/dxvk_pipemanager.cpp b/src/dxvk/dxvk_pipemanager.cpp index dc23bbf88..680c45728 100644 --- a/src/dxvk/dxvk_pipemanager.cpp +++ b/src/dxvk/dxvk_pipemanager.cpp @@ -7,11 +7,8 @@ namespace dxvk { DxvkPipelineManager::DxvkPipelineManager( DxvkDevice* device) : m_device (device), - m_cache (device) { - std::string useStateCache = env::getEnvVar("DXVK_STATE_CACHE"); - - if (useStateCache != "0" && device->config().enableStateCache) - m_stateCache = new DxvkStateCache(device, this); + m_cache (device), + m_stateCache(device, this) { } @@ -111,8 +108,7 @@ namespace dxvk { void DxvkPipelineManager::registerShader( const Rc& shader) { - if (m_stateCache != nullptr) - m_stateCache->registerShader(shader); + m_stateCache.registerShader(shader); } @@ -125,14 +121,12 @@ namespace dxvk { bool DxvkPipelineManager::isCompilingShaders() const { - return m_stateCache != nullptr - && m_stateCache->isCompilingShaders(); + return m_stateCache.isCompilingShaders(); } - void DxvkPipelineManager::stopWorkerThreads() const { - if (m_stateCache != nullptr) - m_stateCache->stopWorkerThreads(); + void DxvkPipelineManager::stopWorkerThreads() { + m_stateCache.stopWorkerThreads(); } diff --git a/src/dxvk/dxvk_pipemanager.h b/src/dxvk/dxvk_pipemanager.h index 709c1227a..ba18f50ed 100644 --- a/src/dxvk/dxvk_pipemanager.h +++ b/src/dxvk/dxvk_pipemanager.h @@ -6,6 +6,7 @@ #include "dxvk_compute.h" #include "dxvk_graphics.h" +#include "dxvk_state_cache.h" namespace dxvk { @@ -110,13 +111,13 @@ namespace dxvk { /** * \brief Stops async compiler threads */ - void stopWorkerThreads() const; + void stopWorkerThreads(); private: - DxvkDevice* m_device; - DxvkPipelineCache m_cache; - Rc m_stateCache; + DxvkDevice* m_device; + DxvkPipelineCache m_cache; + DxvkStateCache m_stateCache; std::atomic m_numComputePipelines = { 0 }; std::atomic m_numGraphicsPipelines = { 0 }; diff --git a/src/dxvk/dxvk_state_cache.cpp b/src/dxvk/dxvk_state_cache.cpp index 4ffa58b91..e3a6466f2 100644 --- a/src/dxvk/dxvk_state_cache.cpp +++ b/src/dxvk/dxvk_state_cache.cpp @@ -217,6 +217,9 @@ namespace dxvk { DxvkPipelineManager* pipeManager) : m_device (device), m_pipeManager (pipeManager) { + std::string useStateCache = env::getEnvVar("DXVK_STATE_CACHE"); + m_enable = useStateCache != "0" && device->config().enableStateCache; + bool newFile = !readCacheFile(); if (newFile) { @@ -257,7 +260,7 @@ namespace dxvk { void DxvkStateCache::addGraphicsPipeline( const DxvkStateCacheKey& shaders, const DxvkGraphicsPipelineStateInfo& state) { - if (shaders.vs.eq(g_nullShaderKey)) + if (!m_enable || shaders.vs.eq(g_nullShaderKey)) return; // Do not add an entry that is already in the cache @@ -284,7 +287,7 @@ namespace dxvk { void DxvkStateCache::addComputePipeline( const DxvkStateCacheKey& shaders, const DxvkComputePipelineStateInfo& state) { - if (shaders.cs.eq(g_nullShaderKey)) + if (!m_enable || shaders.cs.eq(g_nullShaderKey)) return; // Do not add an entry that is already in the cache @@ -307,6 +310,9 @@ namespace dxvk { void DxvkStateCache::registerShader(const Rc& shader) { + if (!m_enable) + return; + DxvkShaderKey key = shader->getShaderKey(); if (key.eq(g_nullShaderKey)) diff --git a/src/dxvk/dxvk_state_cache.h b/src/dxvk/dxvk_state_cache.h index a3033037d..9fb6b52a9 100644 --- a/src/dxvk/dxvk_state_cache.h +++ b/src/dxvk/dxvk_state_cache.h @@ -23,7 +23,7 @@ namespace dxvk { * of time instead of compiling them on the first * draw. */ - class DxvkStateCache : public RcObject { + class DxvkStateCache { public: @@ -78,7 +78,7 @@ namespace dxvk { * \brief Checks whether compiler threads are busy * \returns \c true if we're compiling shaders */ - bool isCompilingShaders() { + bool isCompilingShaders() const { return m_workerBusy.load() > 0; } @@ -93,6 +93,7 @@ namespace dxvk { DxvkDevice* m_device; DxvkPipelineManager* m_pipeManager; + bool m_enable = false; std::vector m_entries; std::atomic m_stopThreads = { false }; diff --git a/src/dxvk/dxvk_state_cache_types.h b/src/dxvk/dxvk_state_cache_types.h index e0098905f..1e65b4260 100644 --- a/src/dxvk/dxvk_state_cache_types.h +++ b/src/dxvk/dxvk_state_cache_types.h @@ -1,6 +1,7 @@ #pragma once -#include "dxvk_pipemanager.h" +#include "dxvk_compute.h" +#include "dxvk_graphics.h" #include "dxvk_renderpass.h" namespace dxvk {