From 807dd726565a2238e2c7f8fb1ede7f30b1147662 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Thu, 8 Feb 2018 12:48:54 +0100 Subject: [PATCH] [hud] Use buffer invalidation instead of synchronization The previously used synchronization may have had a negative impact on performance, whereas the new approach is similar to what D3D11 apps do. --- src/dxvk/hud/dxvk_hud.cpp | 25 +++++++------------------ src/dxvk/hud/dxvk_hud.h | 2 -- src/dxvk/hud/dxvk_hud_text.cpp | 5 ++++- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/dxvk/hud/dxvk_hud.cpp b/src/dxvk/hud/dxvk_hud.cpp index 6c893fac..302c1e54 100644 --- a/src/dxvk/hud/dxvk_hud.cpp +++ b/src/dxvk/hud/dxvk_hud.cpp @@ -29,9 +29,8 @@ namespace dxvk::hud { m_hudFps.update(); - this->synchronize(); - this->updateUniformBuffer(); this->beginRenderPass(recreateFbo); + this->updateUniformBuffer(); this->renderText(); this->endRenderPass(); } @@ -73,24 +72,13 @@ namespace dxvk::hud { } - void Hud::synchronize() { - // Wait for previous frame to complete so that we can - // safely write to the uniform/vertex buffers. We could - // actually avoid this by double-buffering the data, but - // it is probably not worth the effort. - if (m_syncFence != nullptr) { - m_syncFence->wait( - std::numeric_limits::max()); - } - } - - void Hud::updateUniformBuffer() { HudUniformData uniformData; uniformData.surfaceSize = m_surfaceSize; - std::memcpy(m_uniformBuffer->mapPtr(0), - &uniformData, sizeof(uniformData)); + auto slice = m_uniformBuffer->allocPhysicalSlice(); + m_context->invalidateBuffer(m_uniformBuffer, slice); + std::memcpy(slice.mapPtr(0), &uniformData, sizeof(uniformData)); } @@ -139,8 +127,9 @@ namespace dxvk::hud { void Hud::endRenderPass() { - m_syncFence = m_device->submitCommandList( - m_context->endRecording(), nullptr, nullptr); + m_device->submitCommandList( + m_context->endRecording(), + nullptr, nullptr); } diff --git a/src/dxvk/hud/dxvk_hud.h b/src/dxvk/hud/dxvk_hud.h index 2b949a6b..1ac256dd 100644 --- a/src/dxvk/hud/dxvk_hud.h +++ b/src/dxvk/hud/dxvk_hud.h @@ -68,7 +68,6 @@ namespace dxvk::hud { HudTextRenderer m_textRenderer; VkExtent2D m_surfaceSize = { 0, 0 }; - Rc m_syncFence; Rc m_uniformBuffer; Rc m_renderTarget; Rc m_renderTargetView; @@ -81,7 +80,6 @@ namespace dxvk::hud { Rc createUniformBuffer(); - void synchronize(); void updateUniformBuffer(); void beginRenderPass(bool initFbo); void endRenderPass(); diff --git a/src/dxvk/hud/dxvk_hud_text.cpp b/src/dxvk/hud/dxvk_hud_text.cpp index 44b8e0ab..e44a9433 100644 --- a/src/dxvk/hud/dxvk_hud_text.cpp +++ b/src/dxvk/hud/dxvk_hud_text.cpp @@ -68,8 +68,11 @@ namespace dxvk::hud { const std::string& text) { const size_t vertexIndex = m_vertexIndex; + auto vertexSlice = m_vertexBuffer->allocPhysicalSlice(); + context->invalidateBuffer(m_vertexBuffer, vertexSlice); + HudTextVertex* vertexData = reinterpret_cast( - m_vertexBuffer->mapPtr(vertexIndex * sizeof(HudTextVertex))); + vertexSlice.mapPtr(vertexIndex * sizeof(HudTextVertex))); const float sizeFactor = size / static_cast(g_hudFont.size);