1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-12-05 01:24:14 +01:00

[dxvk] Use lock-free list for compute pipeline lookup

This commit is contained in:
Philip Rebohle 2022-02-19 16:45:03 +01:00
parent 67e2ee1b26
commit 477cb617ac
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 14 additions and 18 deletions

View File

@ -34,31 +34,25 @@ namespace dxvk {
VkPipeline DxvkComputePipeline::getPipelineHandle(
const DxvkComputePipelineStateInfo& state) {
DxvkComputePipelineInstance* instance = nullptr;
{ std::lock_guard<sync::Spinlock> lock(m_mutex);
DxvkComputePipelineInstance* instance = this->findInstance(state);
if (unlikely(!instance)) {
std::lock_guard<dxvk::mutex> lock(m_mutex);
instance = this->findInstance(state);
if (instance)
return instance->pipeline();
// If no pipeline instance exists with the given state
// vector, create a new one and add it to the list.
instance = this->createInstance(state);
if (!instance) {
instance = this->createInstance(state);
this->writePipelineStateToCache(state);
}
}
if (!instance)
return VK_NULL_HANDLE;
this->writePipelineStateToCache(state);
return instance->pipeline();
}
void DxvkComputePipeline::compilePipeline(
const DxvkComputePipelineStateInfo& state) {
std::lock_guard<sync::Spinlock> lock(m_mutex);
std::lock_guard<dxvk::mutex> lock(m_mutex);
if (!this->findInstance(state))
this->createInstance(state);
@ -70,7 +64,7 @@ namespace dxvk {
VkPipeline newPipelineHandle = this->createPipeline(state);
m_pipeMgr->m_numComputePipelines += 1;
return &m_pipelines.emplace_back(state, newPipelineHandle);
return &(*m_pipelines.emplace(state, newPipelineHandle));
}

View File

@ -1,8 +1,9 @@
#pragma once
#include <atomic>
#include <vector>
#include "../util/sync/sync_list.h"
#include "dxvk_bind_mask.h"
#include "dxvk_graphics_state.h"
#include "dxvk_pipecache.h"
@ -143,8 +144,9 @@ namespace dxvk {
Rc<DxvkPipelineLayout> m_layout;
sync::Spinlock m_mutex;
std::vector<DxvkComputePipelineInstance> m_pipelines;
alignas(CACHE_LINE_SIZE)
dxvk::mutex m_mutex;
sync::List<DxvkComputePipelineInstance> m_pipelines;
DxvkComputePipelineInstance* createInstance(
const DxvkComputePipelineStateInfo& state);