1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-31 14:52:11 +01:00

[dxvk] Rework DxvkPipelineCache

This commit is contained in:
Philip Rebohle 2022-07-05 17:44:02 +02:00
parent dbcd0333d9
commit 8b645f8563
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
6 changed files with 28 additions and 37 deletions

View File

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

View File

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

View File

@ -1,26 +1,24 @@
#include "dxvk_pipecache.h"
#include "dxvk_device.h"
namespace dxvk {
DxvkPipelineCache::DxvkPipelineCache(
const Rc<vk::DeviceFn>& 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);
}
}

View File

@ -1,28 +1,22 @@
#pragma once
#include <atomic>
#include <condition_variable>
#include <fstream>
#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<vk::DeviceFn>& vkd);
DxvkPipelineCache(DxvkDevice* device);
~DxvkPipelineCache();
/**
@ -35,8 +29,8 @@ namespace dxvk {
private:
Rc<vk::DeviceFn> m_vkd;
VkPipelineCache m_handle;
DxvkDevice* m_device;
VkPipelineCache m_handle = VK_NULL_HANDLE;
};

View File

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

View File

@ -114,12 +114,12 @@ namespace dxvk {
private:
DxvkDevice* m_device;
Rc<DxvkPipelineCache> m_cache;
Rc<DxvkStateCache> m_stateCache;
DxvkDevice* m_device;
DxvkPipelineCache m_cache;
Rc<DxvkStateCache> m_stateCache;
std::atomic<uint32_t> m_numComputePipelines = { 0 };
std::atomic<uint32_t> m_numGraphicsPipelines = { 0 };
std::atomic<uint32_t> m_numComputePipelines = { 0 };
std::atomic<uint32_t> m_numGraphicsPipelines = { 0 };
dxvk::mutex m_mutex;