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

[dxvk] Implement framebuffer cache

Reduces the number of object allocations per frame.
This commit is contained in:
Philip Rebohle 2021-11-09 17:49:42 +01:00
parent a987b729a7
commit 2abe2132a6
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 17 additions and 1 deletions

View File

@ -4004,7 +4004,7 @@ namespace dxvk {
const VkClearValue* clearValues) {
const DxvkFramebufferSize fbSize = framebufferInfo.size();
Rc<DxvkFramebuffer> framebuffer = m_device->createFramebuffer(framebufferInfo);
Rc<DxvkFramebuffer> framebuffer = this->lookupFramebuffer(framebufferInfo);
VkRect2D renderArea;
renderArea.offset = VkOffset2D { 0, 0 };
@ -5347,6 +5347,18 @@ namespace dxvk {
}
Rc<DxvkFramebuffer> DxvkContext::lookupFramebuffer(
const DxvkFramebufferInfo& framebufferInfo) {
DxvkFramebufferKey key = framebufferInfo.key();
size_t idx = key.hash() % m_framebufferCache.size();
if (m_framebufferCache[idx] == nullptr || !m_framebufferCache[idx]->key().eq(key))
m_framebufferCache[idx] = m_device->createFramebuffer(framebufferInfo);
return m_framebufferCache[idx];
}
Rc<DxvkBuffer> DxvkContext::createZeroBuffer(
VkDeviceSize size) {
if (m_zeroBuffer != nullptr && m_zeroBuffer->info().size >= size)

View File

@ -1108,6 +1108,7 @@ namespace dxvk {
std::array<DxvkShaderResourceSlot, MaxNumResourceSlots> m_rc;
std::array<DxvkGraphicsPipeline*, 4096> m_gpLookupCache = { };
std::array<DxvkComputePipeline*, 256> m_cpLookupCache = { };
std::array<Rc<DxvkFramebuffer>, 512> m_framebufferCache = { };
void blitImageFb(
const Rc<DxvkImage>& dstImage,
@ -1354,6 +1355,9 @@ namespace dxvk {
DxvkComputePipeline* lookupComputePipeline(
const DxvkComputePipelineShaders& shaders);
Rc<DxvkFramebuffer> lookupFramebuffer(
const DxvkFramebufferInfo& framebufferInfo);
Rc<DxvkBuffer> createZeroBuffer(
VkDeviceSize size);