summaryrefslogtreecommitdiffstats
path: root/src/gui/rhi/qrhivulkan.cpp
diff options
context:
space:
mode:
authorLaszlo Agocs <laszlo.agocs@qt.io>2020-10-09 13:34:37 +0200
committerLaszlo Agocs <laszlo.agocs@qt.io>2020-10-11 10:58:37 +0200
commit2ac2809ec36af238b3755f176ef45427c1d32467 (patch)
tree1567c3bba1db68c7e249d5a345f14f42ccc45804 /src/gui/rhi/qrhivulkan.cpp
parentcd0b5bba9a1a76e03d4b9b5105c4d16d1e1dfd1e (diff)
rhi: Add support for full, direct buffer updates
Change-Id: I02c1f8c32c08d39cde9845d20ba8b02541d9d325 Reviewed-by: Andy Nichols <andy.nichols@qt.io>
Diffstat (limited to 'src/gui/rhi/qrhivulkan.cpp')
-rw-r--r--src/gui/rhi/qrhivulkan.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/gui/rhi/qrhivulkan.cpp b/src/gui/rhi/qrhivulkan.cpp
index 4e23f1622c..d0e98fb751 100644
--- a/src/gui/rhi/qrhivulkan.cpp
+++ b/src/gui/rhi/qrhivulkan.cpp
@@ -5373,6 +5373,36 @@ QRhiBuffer::NativeBuffer QVkBuffer::nativeBuffer()
return { { &buffers[0] }, 1 };
}
+char *QVkBuffer::beginFullDynamicUniformBufferUpdateForCurrentFrame()
+{
+ // Shortcut the entire buffer update mechanism and allow the client to do
+ // the host writes directly to the buffer. This will lead to unexpected
+ // results when combined with QRhiResourceUpdateBatch-based updates for the
+ // buffer, but provides a fast path for uniform buffers that have all their
+ // content changed in every frame.
+ Q_ASSERT(m_type == Dynamic && m_usage.testFlag(UniformBuffer));
+ QRHI_RES_RHI(QRhiVulkan);
+ Q_ASSERT(rhiD->inFrame);
+ const int slot = rhiD->currentFrameSlot;
+ void *p = nullptr;
+ VmaAllocation a = toVmaAllocation(allocations[slot]);
+ VkResult err = vmaMapMemory(toVmaAllocator(rhiD->allocator), a, &p);
+ if (err != VK_SUCCESS) {
+ qWarning("Failed to map buffer: %d", err);
+ return nullptr;
+ }
+ return static_cast<char *>(p);
+}
+
+void QVkBuffer::endFullDynamicUniformBufferUpdateForCurrentFrame()
+{
+ QRHI_RES_RHI(QRhiVulkan);
+ const int slot = rhiD->currentFrameSlot;
+ VmaAllocation a = toVmaAllocation(allocations[slot]);
+ vmaUnmapMemory(toVmaAllocator(rhiD->allocator), a);
+ vmaFlushAllocation(toVmaAllocator(rhiD->allocator), a, 0, m_size);
+}
+
QVkRenderBuffer::QVkRenderBuffer(QRhiImplementation *rhi, Type type, const QSize &pixelSize,
int sampleCount, Flags flags,
QRhiTexture::Format backingFormatHint)