sg: Use the new buffer update shortcut for geometry with d3d11 and gl

If we know the (dynamic) vertex QRhiBuffer is backed by a single native
buffer object, we could use the
begin/EndFullDynamicBufferUpdateForCurrentFrame mechanism to update the
contents since the entire buffer contents is changing, saving a memcpy
in practice (and no need to enqueue a resource update via the standard
QRhi mechanism)

However, with OpenGL glMapBufferRange has "interesting" behavior
patterns on some platforms (like unexpectedly trippling the CPU load for
no apparent reason on some systems), and anyway all we want in the end
with GL is a glBufferSubData. So instead of the mapBuffer-like existing
begin/end functions, use a newly introduced helper function in
QRhiBuffer that, specifically for OpenGL, boils down to doing a
glBufferSubData, whereas it is equivalent to begin+memcpy+end everywhere
else.

Not applicable for backends for modern APIs.

The logic is based on querying resourceLimit(FramesInFlight) == 1. This
is convenient to avoid having to write backend type checks, although it
relies on undocumented internal knowledge (as FramesInFlight==1 may not
strictly imply and give guarantees on how a Dynamic QRhiBuffer is
implemented internally)

Task-number: QTBUG-125087
Pick-to: 6.8
Change-Id: I317f9ff4bc03fadb6808b61cb053461b30ef1db7
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
This commit is contained in:
Laszlo Agocs 2024-07-04 11:34:34 +02:00
parent d02f3adadc
commit 1f29bc32df
1 changed files with 5 additions and 4 deletions

View File

@ -1083,12 +1083,13 @@ void Renderer::unmap(Buffer *buffer, bool isIndexBuf)
}
if (buffer->buf) {
if (buffer->buf->type() != QRhiBuffer::Dynamic) {
m_resourceUpdates->uploadStaticBuffer(buffer->buf,
0, buffer->size, buffer->data);
m_resourceUpdates->uploadStaticBuffer(buffer->buf, 0, buffer->size, buffer->data);
buffer->nonDynamicChangeCount += 1;
} else {
m_resourceUpdates->updateDynamicBuffer(buffer->buf, 0, buffer->size,
buffer->data);
if (m_rhi->resourceLimit(QRhi::FramesInFlight) == 1)
buffer->buf->fullDynamicBufferUpdateForCurrentFrame(buffer->data);
else
m_resourceUpdates->updateDynamicBuffer(buffer->buf, 0, buffer->size, buffer->data);
}
}
if (m_visualizer->mode() == Visualizer::VisualizeNothing)