[dxvk] Rework state cache object creation

This commit is contained in:
Philip Rebohle 2022-07-05 17:53:31 +02:00
parent 8b645f8563
commit 1c573a7fd5
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
7 changed files with 26 additions and 29 deletions

View File

@ -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);
}
}

View File

@ -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);
}

View File

@ -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<DxvkShader>& 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();
}

View File

@ -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<DxvkStateCache> m_stateCache;
DxvkDevice* m_device;
DxvkPipelineCache m_cache;
DxvkStateCache m_stateCache;
std::atomic<uint32_t> m_numComputePipelines = { 0 };
std::atomic<uint32_t> m_numGraphicsPipelines = { 0 };

View File

@ -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<DxvkShader>& shader) {
if (!m_enable)
return;
DxvkShaderKey key = shader->getShaderKey();
if (key.eq(g_nullShaderKey))

View File

@ -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<DxvkStateCacheEntry> m_entries;
std::atomic<bool> m_stopThreads = { false };

View File

@ -1,6 +1,7 @@
#pragma once
#include "dxvk_pipemanager.h"
#include "dxvk_compute.h"
#include "dxvk_graphics.h"
#include "dxvk_renderpass.h"
namespace dxvk {