1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2024-11-29 19:24:10 +01:00

[dxvk] Implement context-local lookup cache for pipeline objects

On hit, looking up a pipeline becomes an extremly cheap O(1) operation,
avoiding a mutex lock and an expensive std::unordered_map lookup. This
works because we don't ever destroy pipeline objects.
This commit is contained in:
Philip Rebohle 2019-09-30 02:39:44 +02:00
parent 35a8cedbc2
commit ab51aac6d7
2 changed files with 33 additions and 2 deletions

View File

@ -3555,7 +3555,7 @@ namespace dxvk {
m_flags.clr(DxvkContextFlag::CpDirtyPipeline);
m_state.cp.state.bsBindingMask.clear();
m_state.cp.pipeline = m_common->pipelineManager().createComputePipeline(m_state.cp.shaders);
m_state.cp.pipeline = lookupComputePipeline(m_state.cp.shaders);
if (m_state.cp.pipeline != nullptr
&& m_state.cp.pipeline->layout()->pushConstRange().size)
@ -3601,7 +3601,7 @@ namespace dxvk {
m_flags.clr(DxvkContextFlag::GpDirtyPipeline);
m_state.gp.state.bsBindingMask.clear();
m_state.gp.pipeline = m_common->pipelineManager().createGraphicsPipeline(m_state.gp.shaders);
m_state.gp.pipeline = lookupGraphicsPipeline(m_state.gp.shaders);
m_state.gp.flags = DxvkGraphicsPipelineFlags();
if (m_state.gp.pipeline != nullptr) {
@ -4465,4 +4465,26 @@ namespace dxvk {
}
}
DxvkGraphicsPipeline* DxvkContext::lookupGraphicsPipeline(
const DxvkGraphicsPipelineShaders& shaders) {
auto idx = shaders.hash() % m_gpLookupCache.size();
if (unlikely(!m_gpLookupCache[idx] || !shaders.eq(m_gpLookupCache[idx]->shaders())))
m_gpLookupCache[idx] = m_common->pipelineManager().createGraphicsPipeline(shaders);
return m_gpLookupCache[idx];
}
DxvkComputePipeline* DxvkContext::lookupComputePipeline(
const DxvkComputePipelineShaders& shaders) {
auto idx = shaders.hash() % m_cpLookupCache.size();
if (unlikely(!m_cpLookupCache[idx] || !shaders.eq(m_cpLookupCache[idx]->shaders())))
m_cpLookupCache[idx] = m_common->pipelineManager().createComputePipeline(shaders);
return m_cpLookupCache[idx];
}
}

View File

@ -1031,6 +1031,9 @@ namespace dxvk {
std::array<DxvkDescriptorInfo, MaxNumActiveBindings> m_descInfos;
std::array<uint32_t, MaxNumActiveBindings> m_descOffsets;
std::array<DxvkGraphicsPipeline*, 4096> m_gpLookupCache = { };
std::array<DxvkComputePipeline*, 256> m_cpLookupCache = { };
std::unordered_map<
DxvkBufferSliceHandle,
DxvkGpuQueryHandle,
@ -1180,6 +1183,12 @@ namespace dxvk {
void trackDrawBuffer();
DxvkGraphicsPipeline* lookupGraphicsPipeline(
const DxvkGraphicsPipelineShaders& shaders);
DxvkComputePipeline* lookupComputePipeline(
const DxvkComputePipelineShaders& shaders);
};
}