diff options
author | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-10-09 13:34:37 +0200 |
---|---|---|
committer | Laszlo Agocs <laszlo.agocs@qt.io> | 2020-10-11 10:58:37 +0200 |
commit | 2ac2809ec36af238b3755f176ef45427c1d32467 (patch) | |
tree | 1567c3bba1db68c7e249d5a345f14f42ccc45804 /src/gui/rhi/qrhid3d11.cpp | |
parent | cd0b5bba9a1a76e03d4b9b5105c4d16d1e1dfd1e (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/qrhid3d11.cpp')
-rw-r--r-- | src/gui/rhi/qrhid3d11.cpp | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/gui/rhi/qrhid3d11.cpp b/src/gui/rhi/qrhid3d11.cpp index 4d00f11c84..7d8339252b 100644 --- a/src/gui/rhi/qrhid3d11.cpp +++ b/src/gui/rhi/qrhid3d11.cpp @@ -2692,6 +2692,31 @@ QRhiBuffer::NativeBuffer QD3D11Buffer::nativeBuffer() return { { &buffer }, 1 }; } +char *QD3D11Buffer::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, since dynBuf is left untouched and out of sync, 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)); + D3D11_MAPPED_SUBRESOURCE mp; + QRHI_RES_RHI(QRhiD3D11); + HRESULT hr = rhiD->context->Map(buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp); + if (FAILED(hr)) { + qWarning("Failed to map buffer: %s", qPrintable(comErrorMessage(hr))); + return nullptr; + } + return static_cast<char *>(mp.pData); +} + +void QD3D11Buffer::endFullDynamicUniformBufferUpdateForCurrentFrame() +{ + QRHI_RES_RHI(QRhiD3D11); + rhiD->context->Unmap(buffer, 0); +} + ID3D11UnorderedAccessView *QD3D11Buffer::unorderedAccessView() { if (uav) |