1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-02-20 19:54:19 +01:00

[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.
This commit is contained in:
Philip Rebohle 2018-02-08 12:48:54 +01:00
parent 59be5b72e8
commit 807dd72656
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
3 changed files with 11 additions and 21 deletions

View File

@ -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<uint64_t>::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);
}

View File

@ -68,7 +68,6 @@ namespace dxvk::hud {
HudTextRenderer m_textRenderer;
VkExtent2D m_surfaceSize = { 0, 0 };
Rc<DxvkFence> m_syncFence;
Rc<DxvkBuffer> m_uniformBuffer;
Rc<DxvkImage> m_renderTarget;
Rc<DxvkImageView> m_renderTargetView;
@ -81,7 +80,6 @@ namespace dxvk::hud {
Rc<DxvkBuffer> createUniformBuffer();
void synchronize();
void updateUniformBuffer();
void beginRenderPass(bool initFbo);
void endRenderPass();

View File

@ -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<HudTextVertex*>(
m_vertexBuffer->mapPtr(vertexIndex * sizeof(HudTextVertex)));
vertexSlice.mapPtr(vertexIndex * sizeof(HudTextVertex)));
const float sizeFactor = size / static_cast<float>(g_hudFont.size);