mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +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:
parent
59be5b72e8
commit
807dd72656
@ -29,9 +29,8 @@ namespace dxvk::hud {
|
|||||||
|
|
||||||
m_hudFps.update();
|
m_hudFps.update();
|
||||||
|
|
||||||
this->synchronize();
|
|
||||||
this->updateUniformBuffer();
|
|
||||||
this->beginRenderPass(recreateFbo);
|
this->beginRenderPass(recreateFbo);
|
||||||
|
this->updateUniformBuffer();
|
||||||
this->renderText();
|
this->renderText();
|
||||||
this->endRenderPass();
|
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() {
|
void Hud::updateUniformBuffer() {
|
||||||
HudUniformData uniformData;
|
HudUniformData uniformData;
|
||||||
uniformData.surfaceSize = m_surfaceSize;
|
uniformData.surfaceSize = m_surfaceSize;
|
||||||
|
|
||||||
std::memcpy(m_uniformBuffer->mapPtr(0),
|
auto slice = m_uniformBuffer->allocPhysicalSlice();
|
||||||
&uniformData, sizeof(uniformData));
|
m_context->invalidateBuffer(m_uniformBuffer, slice);
|
||||||
|
std::memcpy(slice.mapPtr(0), &uniformData, sizeof(uniformData));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -139,8 +127,9 @@ namespace dxvk::hud {
|
|||||||
|
|
||||||
|
|
||||||
void Hud::endRenderPass() {
|
void Hud::endRenderPass() {
|
||||||
m_syncFence = m_device->submitCommandList(
|
m_device->submitCommandList(
|
||||||
m_context->endRecording(), nullptr, nullptr);
|
m_context->endRecording(),
|
||||||
|
nullptr, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,7 +68,6 @@ namespace dxvk::hud {
|
|||||||
HudTextRenderer m_textRenderer;
|
HudTextRenderer m_textRenderer;
|
||||||
VkExtent2D m_surfaceSize = { 0, 0 };
|
VkExtent2D m_surfaceSize = { 0, 0 };
|
||||||
|
|
||||||
Rc<DxvkFence> m_syncFence;
|
|
||||||
Rc<DxvkBuffer> m_uniformBuffer;
|
Rc<DxvkBuffer> m_uniformBuffer;
|
||||||
Rc<DxvkImage> m_renderTarget;
|
Rc<DxvkImage> m_renderTarget;
|
||||||
Rc<DxvkImageView> m_renderTargetView;
|
Rc<DxvkImageView> m_renderTargetView;
|
||||||
@ -81,7 +80,6 @@ namespace dxvk::hud {
|
|||||||
|
|
||||||
Rc<DxvkBuffer> createUniformBuffer();
|
Rc<DxvkBuffer> createUniformBuffer();
|
||||||
|
|
||||||
void synchronize();
|
|
||||||
void updateUniformBuffer();
|
void updateUniformBuffer();
|
||||||
void beginRenderPass(bool initFbo);
|
void beginRenderPass(bool initFbo);
|
||||||
void endRenderPass();
|
void endRenderPass();
|
||||||
|
@ -68,8 +68,11 @@ namespace dxvk::hud {
|
|||||||
const std::string& text) {
|
const std::string& text) {
|
||||||
const size_t vertexIndex = m_vertexIndex;
|
const size_t vertexIndex = m_vertexIndex;
|
||||||
|
|
||||||
|
auto vertexSlice = m_vertexBuffer->allocPhysicalSlice();
|
||||||
|
context->invalidateBuffer(m_vertexBuffer, vertexSlice);
|
||||||
|
|
||||||
HudTextVertex* vertexData = reinterpret_cast<HudTextVertex*>(
|
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);
|
const float sizeFactor = size / static_cast<float>(g_hudFont.size);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user