From 8b645f8563c132f673e05df6e3e93ba91a1be119 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Tue, 5 Jul 2022 17:44:02 +0200 Subject: [PATCH] [dxvk] Rework DxvkPipelineCache --- src/dxvk/dxvk_compute.cpp | 2 +- src/dxvk/dxvk_graphics.cpp | 3 +-- src/dxvk/dxvk_pipecache.cpp | 26 ++++++++++++-------------- src/dxvk/dxvk_pipecache.h | 18 ++++++------------ src/dxvk/dxvk_pipemanager.cpp | 6 +++--- src/dxvk/dxvk_pipemanager.h | 10 +++++----- 6 files changed, 28 insertions(+), 37 deletions(-) diff --git a/src/dxvk/dxvk_compute.cpp b/src/dxvk/dxvk_compute.cpp index 64d7ace74..9b4411378 100644 --- a/src/dxvk/dxvk_compute.cpp +++ b/src/dxvk/dxvk_compute.cpp @@ -111,7 +111,7 @@ namespace dxvk { VkPipeline pipeline = VK_NULL_HANDLE; if (m_vkd->vkCreateComputePipelines(m_vkd->device(), - m_pipeMgr->m_cache->handle(), 1, &info, nullptr, &pipeline) != VK_SUCCESS) { + m_pipeMgr->m_cache.handle(), 1, &info, nullptr, &pipeline) != VK_SUCCESS) { Logger::err("DxvkComputePipeline: Failed to compile pipeline"); Logger::err(str::format(" cs : ", m_shaders.cs->debugName())); return VK_NULL_HANDLE; diff --git a/src/dxvk/dxvk_graphics.cpp b/src/dxvk/dxvk_graphics.cpp index b1338970f..18a538af6 100644 --- a/src/dxvk/dxvk_graphics.cpp +++ b/src/dxvk/dxvk_graphics.cpp @@ -664,8 +664,7 @@ namespace dxvk { t0 = dxvk::high_resolution_clock::now(); VkPipeline pipeline = VK_NULL_HANDLE; - if (m_vkd->vkCreateGraphicsPipelines(m_vkd->device(), - m_pipeMgr->m_cache->handle(), 1, &info, nullptr, &pipeline) != VK_SUCCESS) { + if (m_vkd->vkCreateGraphicsPipelines(m_vkd->device(), m_pipeMgr->m_cache.handle(), 1, &info, nullptr, &pipeline) != VK_SUCCESS) { Logger::err("DxvkGraphicsPipeline: Failed to compile pipeline"); this->logPipelineState(LogLevel::Error, state); return VK_NULL_HANDLE; diff --git a/src/dxvk/dxvk_pipecache.cpp b/src/dxvk/dxvk_pipecache.cpp index 0ea775bce..8029e225a 100644 --- a/src/dxvk/dxvk_pipecache.cpp +++ b/src/dxvk/dxvk_pipecache.cpp @@ -1,26 +1,24 @@ #include "dxvk_pipecache.h" +#include "dxvk_device.h" namespace dxvk { - DxvkPipelineCache::DxvkPipelineCache( - const Rc& vkd) - : m_vkd(vkd) { - VkPipelineCacheCreateInfo info; - info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO; - info.pNext = nullptr; - info.flags = 0; - info.initialDataSize = 0; - info.pInitialData = nullptr; + DxvkPipelineCache::DxvkPipelineCache(DxvkDevice* device) + : m_device(device) { + auto vk = m_device->vkd(); + + // It's not critical if this fails since this is only an in-memory cache + VkPipelineCacheCreateInfo info = { VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO }; - if (m_vkd->vkCreatePipelineCache(m_vkd->device(), - &info, nullptr, &m_handle) != VK_SUCCESS) - throw DxvkError("DxvkPipelineCache: Failed to create cache"); + if (vk->vkCreatePipelineCache(vk->device(), &info, nullptr, &m_handle)) + Logger::err("DxvkPipelineCache: Failed to create cache"); } DxvkPipelineCache::~DxvkPipelineCache() { - m_vkd->vkDestroyPipelineCache( - m_vkd->device(), m_handle, nullptr); + auto vk = m_device->vkd(); + + vk->vkDestroyPipelineCache(vk->device(), m_handle, nullptr); } } diff --git a/src/dxvk/dxvk_pipecache.h b/src/dxvk/dxvk_pipecache.h index b39bf47c0..78e9a7981 100644 --- a/src/dxvk/dxvk_pipecache.h +++ b/src/dxvk/dxvk_pipecache.h @@ -1,28 +1,22 @@ #pragma once -#include -#include -#include - #include "dxvk_include.h" -#include "../util/sha1/sha1_util.h" -#include "../util/util_env.h" -#include "../util/util_time.h" - namespace dxvk { + class DxvkDevice; + /** * \brief Pipeline cache * * Allows the Vulkan implementation to * re-use previously compiled pipelines. */ - class DxvkPipelineCache : public RcObject { + class DxvkPipelineCache { public: - DxvkPipelineCache(const Rc& vkd); + DxvkPipelineCache(DxvkDevice* device); ~DxvkPipelineCache(); /** @@ -35,8 +29,8 @@ namespace dxvk { private: - Rc m_vkd; - VkPipelineCache m_handle; + DxvkDevice* m_device; + VkPipelineCache m_handle = VK_NULL_HANDLE; }; diff --git a/src/dxvk/dxvk_pipemanager.cpp b/src/dxvk/dxvk_pipemanager.cpp index 3e4d92b82..dc23bbf88 100644 --- a/src/dxvk/dxvk_pipemanager.cpp +++ b/src/dxvk/dxvk_pipemanager.cpp @@ -7,7 +7,7 @@ namespace dxvk { DxvkPipelineManager::DxvkPipelineManager( DxvkDevice* device) : m_device (device), - m_cache (new DxvkPipelineCache(device->vkd())) { + m_cache (device) { std::string useStateCache = env::getEnvVar("DXVK_STATE_CACHE"); if (useStateCache != "0" && device->config().enableStateCache) @@ -88,7 +88,7 @@ namespace dxvk { auto iter = m_vertexInputLibraries.emplace( std::piecewise_construct, std::tuple(state), - std::tuple(m_device, state, m_cache->handle())); + std::tuple(m_device, state, m_cache.handle())); return &iter.first->second; } @@ -104,7 +104,7 @@ namespace dxvk { auto iter = m_fragmentOutputLibraries.emplace( std::piecewise_construct, std::tuple(state), - std::tuple(m_device, state, m_cache->handle())); + std::tuple(m_device, state, m_cache.handle())); return &iter.first->second; } diff --git a/src/dxvk/dxvk_pipemanager.h b/src/dxvk/dxvk_pipemanager.h index fbb764522..709c1227a 100644 --- a/src/dxvk/dxvk_pipemanager.h +++ b/src/dxvk/dxvk_pipemanager.h @@ -114,12 +114,12 @@ namespace dxvk { private: - DxvkDevice* m_device; - Rc m_cache; - Rc m_stateCache; + DxvkDevice* m_device; + DxvkPipelineCache m_cache; + Rc m_stateCache; - std::atomic m_numComputePipelines = { 0 }; - std::atomic m_numGraphicsPipelines = { 0 }; + std::atomic m_numComputePipelines = { 0 }; + std::atomic m_numGraphicsPipelines = { 0 }; dxvk::mutex m_mutex;