1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-03-15 07:29:17 +01:00

[dxvk] Implemented local pipeline cache

This commit is contained in:
Philip Rebohle 2018-01-13 22:18:32 +01:00
parent 9f53521e19
commit c1f16d36bd
11 changed files with 123 additions and 38 deletions

View File

@ -3,9 +3,10 @@
namespace dxvk { namespace dxvk {
DxvkComputePipeline::DxvkComputePipeline( DxvkComputePipeline::DxvkComputePipeline(
const Rc<vk::DeviceFn>& vkd, const Rc<vk::DeviceFn>& vkd,
const Rc<DxvkShader>& cs) const Rc<DxvkPipelineCache>& cache,
: m_vkd(vkd) { const Rc<DxvkShader>& cs)
: m_vkd(vkd), m_cache(cache) {
DxvkDescriptorSlotMapping slotMapping; DxvkDescriptorSlotMapping slotMapping;
cs->defineResourceSlots(slotMapping); cs->defineResourceSlots(slotMapping);
@ -38,7 +39,7 @@ namespace dxvk {
info.basePipelineIndex = -1; info.basePipelineIndex = -1;
if (m_vkd->vkCreateComputePipelines(m_vkd->device(), if (m_vkd->vkCreateComputePipelines(m_vkd->device(),
VK_NULL_HANDLE, 1, &info, nullptr, &m_pipeline) != VK_SUCCESS) m_cache->handle(), 1, &info, nullptr, &m_pipeline) != VK_SUCCESS)
throw DxvkError("DxvkComputePipeline::DxvkComputePipeline: Failed to compile pipeline"); throw DxvkError("DxvkComputePipeline::DxvkComputePipeline: Failed to compile pipeline");
} }

View File

@ -1,5 +1,6 @@
#pragma once #pragma once
#include "dxvk_pipecache.h"
#include "dxvk_pipelayout.h" #include "dxvk_pipelayout.h"
#include "dxvk_resource.h" #include "dxvk_resource.h"
#include "dxvk_shader.h" #include "dxvk_shader.h"
@ -19,8 +20,9 @@ namespace dxvk {
public: public:
DxvkComputePipeline( DxvkComputePipeline(
const Rc<vk::DeviceFn>& vkd, const Rc<vk::DeviceFn>& vkd,
const Rc<DxvkShader>& cs); const Rc<DxvkPipelineCache>& cache,
const Rc<DxvkShader>& cs);
~DxvkComputePipeline(); ~DxvkComputePipeline();
/** /**
@ -46,6 +48,7 @@ namespace dxvk {
private: private:
Rc<vk::DeviceFn> m_vkd; Rc<vk::DeviceFn> m_vkd;
Rc<DxvkPipelineCache> m_cache;
Rc<DxvkBindingLayout> m_layout; Rc<DxvkBindingLayout> m_layout;
Rc<DxvkShaderModule> m_cs; Rc<DxvkShaderModule> m_cs;

View File

@ -12,6 +12,7 @@ namespace dxvk {
m_features (features), m_features (features),
m_memory (new DxvkMemoryAllocator(adapter, vkd)), m_memory (new DxvkMemoryAllocator(adapter, vkd)),
m_renderPassPool (new DxvkRenderPassPool (vkd)), m_renderPassPool (new DxvkRenderPassPool (vkd)),
m_pipelineCache (new DxvkPipelineCache (vkd)),
m_pipelineManager (new DxvkPipelineManager(vkd)), m_pipelineManager (new DxvkPipelineManager(vkd)),
m_submissionQueue (this) { m_submissionQueue (this) {
m_vkd->vkGetDeviceQueue(m_vkd->device(), m_vkd->vkGetDeviceQueue(m_vkd->device(),
@ -161,7 +162,8 @@ namespace dxvk {
Rc<DxvkComputePipeline> DxvkDevice::createComputePipeline( Rc<DxvkComputePipeline> DxvkDevice::createComputePipeline(
const Rc<DxvkShader>& cs) { const Rc<DxvkShader>& cs) {
return m_pipelineManager->createComputePipeline(cs); return m_pipelineManager->createComputePipeline(
m_pipelineCache, cs);
} }
@ -171,7 +173,8 @@ namespace dxvk {
const Rc<DxvkShader>& tes, const Rc<DxvkShader>& tes,
const Rc<DxvkShader>& gs, const Rc<DxvkShader>& gs,
const Rc<DxvkShader>& fs) { const Rc<DxvkShader>& fs) {
return m_pipelineManager->createGraphicsPipeline(vs, tcs, tes, gs, fs); return m_pipelineManager->createGraphicsPipeline(
m_pipelineCache, vs, tcs, tes, gs, fs);
} }

View File

@ -8,6 +8,7 @@
#include "dxvk_framebuffer.h" #include "dxvk_framebuffer.h"
#include "dxvk_image.h" #include "dxvk_image.h"
#include "dxvk_memory.h" #include "dxvk_memory.h"
#include "dxvk_pipecache.h"
#include "dxvk_pipemanager.h" #include "dxvk_pipemanager.h"
#include "dxvk_queue.h" #include "dxvk_queue.h"
#include "dxvk_recycler.h" #include "dxvk_recycler.h"
@ -303,6 +304,7 @@ namespace dxvk {
Rc<DxvkMemoryAllocator> m_memory; Rc<DxvkMemoryAllocator> m_memory;
Rc<DxvkRenderPassPool> m_renderPassPool; Rc<DxvkRenderPassPool> m_renderPassPool;
Rc<DxvkPipelineCache> m_pipelineCache;
Rc<DxvkPipelineManager> m_pipelineManager; Rc<DxvkPipelineManager> m_pipelineManager;
std::mutex m_submissionLock; std::mutex m_submissionLock;

View File

@ -33,13 +33,14 @@ namespace dxvk {
DxvkGraphicsPipeline::DxvkGraphicsPipeline( DxvkGraphicsPipeline::DxvkGraphicsPipeline(
const Rc<vk::DeviceFn>& vkd, const Rc<vk::DeviceFn>& vkd,
const Rc<DxvkShader>& vs, const Rc<DxvkPipelineCache>& cache,
const Rc<DxvkShader>& tcs, const Rc<DxvkShader>& vs,
const Rc<DxvkShader>& tes, const Rc<DxvkShader>& tcs,
const Rc<DxvkShader>& gs, const Rc<DxvkShader>& tes,
const Rc<DxvkShader>& fs) const Rc<DxvkShader>& gs,
: m_vkd(vkd) { const Rc<DxvkShader>& fs)
: m_vkd(vkd), m_cache(cache) {
DxvkDescriptorSlotMapping slotMapping; DxvkDescriptorSlotMapping slotMapping;
if (vs != nullptr) vs ->defineResourceSlots(slotMapping); if (vs != nullptr) vs ->defineResourceSlots(slotMapping);
if (tcs != nullptr) tcs->defineResourceSlots(slotMapping); if (tcs != nullptr) tcs->defineResourceSlots(slotMapping);
@ -229,7 +230,7 @@ namespace dxvk {
VkPipeline pipeline = VK_NULL_HANDLE; VkPipeline pipeline = VK_NULL_HANDLE;
if (m_vkd->vkCreateGraphicsPipelines(m_vkd->device(), if (m_vkd->vkCreateGraphicsPipelines(m_vkd->device(),
VK_NULL_HANDLE, 1, &info, nullptr, &pipeline) != VK_SUCCESS) m_cache->handle(), 1, &info, nullptr, &pipeline) != VK_SUCCESS)
throw DxvkError("DxvkGraphicsPipeline::DxvkGraphicsPipeline: Failed to compile pipeline"); throw DxvkError("DxvkGraphicsPipeline::DxvkGraphicsPipeline: Failed to compile pipeline");
return pipeline; return pipeline;
} }

View File

@ -5,7 +5,7 @@
#include "dxvk_binding.h" #include "dxvk_binding.h"
#include "dxvk_constant_state.h" #include "dxvk_constant_state.h"
#include "dxvk_hash.h" #include "dxvk_pipecache.h"
#include "dxvk_pipelayout.h" #include "dxvk_pipelayout.h"
#include "dxvk_resource.h" #include "dxvk_resource.h"
#include "dxvk_shader.h" #include "dxvk_shader.h"
@ -88,12 +88,13 @@ namespace dxvk {
public: public:
DxvkGraphicsPipeline( DxvkGraphicsPipeline(
const Rc<vk::DeviceFn>& vkd, const Rc<vk::DeviceFn>& vkd,
const Rc<DxvkShader>& vs, const Rc<DxvkPipelineCache>& cache,
const Rc<DxvkShader>& tcs, const Rc<DxvkShader>& vs,
const Rc<DxvkShader>& tes, const Rc<DxvkShader>& tcs,
const Rc<DxvkShader>& gs, const Rc<DxvkShader>& tes,
const Rc<DxvkShader>& fs); const Rc<DxvkShader>& gs,
const Rc<DxvkShader>& fs);
~DxvkGraphicsPipeline(); ~DxvkGraphicsPipeline();
/** /**
@ -110,6 +111,10 @@ namespace dxvk {
/** /**
* \brief Pipeline handle * \brief Pipeline handle
*
* Retrieves a pipeline handle for the given pipeline
* state. If necessary, a new pipeline will be created.
* \param [in] state Pipeline state vector
* \returns Pipeline handle * \returns Pipeline handle
*/ */
VkPipeline getPipelineHandle( VkPipeline getPipelineHandle(
@ -123,6 +128,7 @@ namespace dxvk {
}; };
Rc<vk::DeviceFn> m_vkd; Rc<vk::DeviceFn> m_vkd;
Rc<DxvkPipelineCache> m_cache;
Rc<DxvkBindingLayout> m_layout; Rc<DxvkBindingLayout> m_layout;
Rc<DxvkShaderModule> m_vs; Rc<DxvkShaderModule> m_vs;

View File

@ -0,0 +1,27 @@
#include "dxvk_pipecache.h"
namespace dxvk {
DxvkPipelineCache::DxvkPipelineCache(
const Rc<vk::DeviceFn>& vkd)
: m_vkd(vkd) {
// TODO read pipeline cache from file
VkPipelineCacheCreateInfo info;
info.sType = VK_STRUCTURE_TYPE_PIPELINE_CACHE_CREATE_INFO;
info.pNext = nullptr;
info.flags = 0;
info.initialDataSize = 0;
info.pInitialData = nullptr;
if (m_vkd->vkCreatePipelineCache(m_vkd->device(),
&info, nullptr, &m_handle) != VK_SUCCESS)
throw DxvkError("DxvkPipelineCache: Failed to create cache");
}
DxvkPipelineCache::~DxvkPipelineCache() {
m_vkd->vkDestroyPipelineCache(
m_vkd->device(), m_handle, nullptr);
}
}

35
src/dxvk/dxvk_pipecache.h Normal file
View File

@ -0,0 +1,35 @@
#pragma once
#include "dxvk_include.h"
namespace dxvk {
/**
* \brief Pipeline cache
*
* Allows the Vulkan implementation to
* re-use previously compiled pipelines.
*/
class DxvkPipelineCache : public RcObject {
public:
DxvkPipelineCache(const Rc<vk::DeviceFn>& vkd);
~DxvkPipelineCache();
/**
* \brief Pipeline cache handle
* \returns Pipeline cache handle
*/
VkPipelineCache handle() const {
return m_handle;
}
private:
Rc<vk::DeviceFn> m_vkd;
VkPipelineCache m_handle;
};
}

View File

@ -36,7 +36,9 @@ namespace dxvk {
DxvkPipelineManager::DxvkPipelineManager(const Rc<vk::DeviceFn>& vkd) DxvkPipelineManager::DxvkPipelineManager(const Rc<vk::DeviceFn>& vkd)
: m_vkd(vkd) { } : m_vkd(vkd) {
}
DxvkPipelineManager::~DxvkPipelineManager() { DxvkPipelineManager::~DxvkPipelineManager() {
@ -45,7 +47,8 @@ namespace dxvk {
Rc<DxvkComputePipeline> DxvkPipelineManager::createComputePipeline( Rc<DxvkComputePipeline> DxvkPipelineManager::createComputePipeline(
const Rc<DxvkShader>& cs) { const Rc<DxvkPipelineCache>& cache,
const Rc<DxvkShader>& cs) {
if (cs == nullptr) if (cs == nullptr)
return nullptr; return nullptr;
@ -59,18 +62,19 @@ namespace dxvk {
return pair->second; return pair->second;
const Rc<DxvkComputePipeline> pipeline const Rc<DxvkComputePipeline> pipeline
= new DxvkComputePipeline(m_vkd, cs); = new DxvkComputePipeline(m_vkd, cache, cs);
m_computePipelines.insert(std::make_pair(key, pipeline)); m_computePipelines.insert(std::make_pair(key, pipeline));
return pipeline; return pipeline;
} }
Rc<DxvkGraphicsPipeline> DxvkPipelineManager::createGraphicsPipeline( Rc<DxvkGraphicsPipeline> DxvkPipelineManager::createGraphicsPipeline(
const Rc<DxvkShader>& vs, const Rc<DxvkPipelineCache>& cache,
const Rc<DxvkShader>& tcs, const Rc<DxvkShader>& vs,
const Rc<DxvkShader>& tes, const Rc<DxvkShader>& tcs,
const Rc<DxvkShader>& gs, const Rc<DxvkShader>& tes,
const Rc<DxvkShader>& fs) { const Rc<DxvkShader>& gs,
const Rc<DxvkShader>& fs) {
if (vs == nullptr) if (vs == nullptr)
return nullptr; return nullptr;
@ -88,7 +92,7 @@ namespace dxvk {
return pair->second; return pair->second;
const Rc<DxvkGraphicsPipeline> pipeline const Rc<DxvkGraphicsPipeline> pipeline
= new DxvkGraphicsPipeline(m_vkd, vs, tcs, tes, gs, fs); = new DxvkGraphicsPipeline(m_vkd, cache, vs, tcs, tes, gs, fs);
m_graphicsPipelines.insert(std::make_pair(key, pipeline)); m_graphicsPipelines.insert(std::make_pair(key, pipeline));
return pipeline; return pipeline;
} }

View File

@ -73,7 +73,8 @@ namespace dxvk {
* \returns Compute pipeline object * \returns Compute pipeline object
*/ */
Rc<DxvkComputePipeline> createComputePipeline( Rc<DxvkComputePipeline> createComputePipeline(
const Rc<DxvkShader>& cs); const Rc<DxvkPipelineCache>& cache,
const Rc<DxvkShader>& cs);
/** /**
* \brief Retrieves a graphics pipeline object * \brief Retrieves a graphics pipeline object
@ -89,11 +90,12 @@ namespace dxvk {
* \returns Graphics pipeline object * \returns Graphics pipeline object
*/ */
Rc<DxvkGraphicsPipeline> createGraphicsPipeline( Rc<DxvkGraphicsPipeline> createGraphicsPipeline(
const Rc<DxvkShader>& vs, const Rc<DxvkPipelineCache>& cache,
const Rc<DxvkShader>& tcs, const Rc<DxvkShader>& vs,
const Rc<DxvkShader>& tes, const Rc<DxvkShader>& tcs,
const Rc<DxvkShader>& gs, const Rc<DxvkShader>& tes,
const Rc<DxvkShader>& fs); const Rc<DxvkShader>& gs,
const Rc<DxvkShader>& fs);
private: private:

View File

@ -22,6 +22,7 @@ dxvk_src = files([
'dxvk_lifetime.cpp', 'dxvk_lifetime.cpp',
'dxvk_main.cpp', 'dxvk_main.cpp',
'dxvk_memory.cpp', 'dxvk_memory.cpp',
'dxvk_pipecache.cpp',
'dxvk_pipelayout.cpp', 'dxvk_pipelayout.cpp',
'dxvk_pipemanager.cpp', 'dxvk_pipemanager.cpp',
'dxvk_queue.cpp', 'dxvk_queue.cpp',