rhi: gl: d3d: Do not use QByteArray where there is no point

The real benefit in practice is getting rid of profilers going wild
about QByteArray::begin() and similar. The actual perf. gain is
fairly small.

Change-Id: I25e4c762f303b41f0aaf914bc62751f3265d3cf8
Reviewed-by: Paul Olav Tvete <paul.tvete@qt.io>
This commit is contained in:
Laszlo Agocs 2020-09-25 12:51:47 +02:00
parent cc5287a0a9
commit 89f7389494
4 changed files with 17 additions and 14 deletions

View File

@ -1418,7 +1418,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
if (u.type == QRhiResourceUpdateBatchPrivate::BufferOp::DynamicUpdate) {
QD3D11Buffer *bufD = QRHI_RES(QD3D11Buffer, u.buf);
Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic);
memcpy(bufD->dynBuf.data() + u.offset, u.data.constData(), size_t(u.dataSize));
memcpy(bufD->dynBuf + u.offset, u.data.constData(), size_t(u.dataSize));
bufD->hasPendingDynamicUpdates = true;
} else if (u.type == QRhiResourceUpdateBatchPrivate::BufferOp::StaticUpload) {
QD3D11Buffer *bufD = QRHI_RES(QD3D11Buffer, u.buf);
@ -1445,7 +1445,7 @@ void QRhiD3D11::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
QD3D11Buffer *bufD = QRHI_RES(QD3D11Buffer, u.buf);
if (bufD->m_type == QRhiBuffer::Dynamic) {
u.result->data.resize(u.readSize);
memcpy(u.result->data.data(), bufD->dynBuf.constData() + u.offset, size_t(u.readSize));
memcpy(u.result->data.data(), bufD->dynBuf + u.offset, size_t(u.readSize));
} else {
BufferReadback readback;
readback.result = u.result;
@ -2155,7 +2155,7 @@ void QRhiD3D11::updateShaderResourceBindings(QD3D11ShaderResourceBindings *srbD,
void QRhiD3D11::executeBufferHostWrites(QD3D11Buffer *bufD)
{
if (!bufD->hasPendingDynamicUpdates)
if (!bufD->hasPendingDynamicUpdates || bufD->m_size < 1)
return;
Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic);
@ -2163,7 +2163,7 @@ void QRhiD3D11::executeBufferHostWrites(QD3D11Buffer *bufD)
D3D11_MAPPED_SUBRESOURCE mp;
HRESULT hr = context->Map(bufD->buffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &mp);
if (SUCCEEDED(hr)) {
memcpy(mp.pData, bufD->dynBuf.constData(), size_t(bufD->dynBuf.size()));
memcpy(mp.pData, bufD->dynBuf, size_t(bufD->m_size));
context->Unmap(bufD->buffer, 0);
} else {
qWarning("Failed to map buffer: %s", qPrintable(comErrorMessage(hr)));
@ -2600,11 +2600,12 @@ void QD3D11Buffer::destroy()
if (!buffer)
return;
dynBuf.clear();
buffer->Release();
buffer = nullptr;
delete[] dynBuf;
dynBuf = nullptr;
if (uav) {
uav->Release();
uav = nullptr;
@ -2664,7 +2665,7 @@ bool QD3D11Buffer::create()
}
if (m_type == Dynamic) {
dynBuf.resize(m_size);
dynBuf = new char[nonZeroSize];
hasPendingDynamicUpdates = false;
}

View File

@ -69,7 +69,7 @@ struct QD3D11Buffer : public QRhiBuffer
ID3D11UnorderedAccessView *unorderedAccessView();
ID3D11Buffer *buffer = nullptr;
QByteArray dynBuf;
char *dynBuf = nullptr;
bool hasPendingDynamicUpdates = false;
ID3D11UnorderedAccessView *uav = nullptr;
uint generation = 0;

View File

@ -1697,7 +1697,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, u.buf);
Q_ASSERT(bufD->m_type == QRhiBuffer::Dynamic);
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), size_t(u.dataSize));
memcpy(bufD->ubuf + u.offset, u.data.constData(), size_t(u.dataSize));
} else {
trackedBufferBarrier(cbD, bufD, QGles2Buffer::AccessUpdate);
QGles2CommandBuffer::Command cmd;
@ -1714,7 +1714,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
Q_ASSERT(bufD->m_type != QRhiBuffer::Dynamic);
Q_ASSERT(u.offset + u.dataSize <= bufD->m_size);
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
memcpy(bufD->ubuf.data() + u.offset, u.data.constData(), size_t(u.dataSize));
memcpy(bufD->ubuf + u.offset, u.data.constData(), size_t(u.dataSize));
} else {
trackedBufferBarrier(cbD, bufD, QGles2Buffer::AccessUpdate);
QGles2CommandBuffer::Command cmd;
@ -1730,7 +1730,7 @@ void QRhiGles2::enqueueResourceUpdates(QRhiCommandBuffer *cb, QRhiResourceUpdate
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, u.buf);
if (bufD->m_usage.testFlag(QRhiBuffer::UniformBuffer)) {
u.result->data.resize(u.readSize);
memcpy(u.result->data.data(), bufD->ubuf.constData() + u.offset, size_t(u.readSize));
memcpy(u.result->data.data(), bufD->ubuf + u.offset, size_t(u.readSize));
if (u.result->completed)
u.result->completed();
} else {
@ -2836,7 +2836,7 @@ void QRhiGles2::bindShaderResources(QRhiGraphicsPipeline *maybeGraphicsPs, QRhiC
}
}
QGles2Buffer *bufD = QRHI_RES(QGles2Buffer, b->u.ubuf.buf);
const QByteArray bufView = QByteArray::fromRawData(bufD->ubuf.constData() + viewOffset,
const QByteArray bufView = QByteArray::fromRawData(bufD->ubuf + viewOffset,
b->u.ubuf.maybeSize ? b->u.ubuf.maybeSize : bufD->m_size);
QGles2UniformDescriptionVector &uniforms(maybeGraphicsPs ? QRHI_RES(QGles2GraphicsPipeline, maybeGraphicsPs)->uniforms
: QRHI_RES(QGles2ComputePipeline, maybeComputePs)->uniforms);
@ -3706,6 +3706,8 @@ void QGles2Buffer::destroy()
e.buffer.buffer = buffer;
buffer = 0;
delete[] ubuf;
ubuf = nullptr;
QRHI_RES_RHI(QRhiGles2);
rhiD->releaseQueue.append(e);
@ -3729,7 +3731,7 @@ bool QGles2Buffer::create()
qWarning("Uniform buffer: multiple usages specified, this is not supported by the OpenGL backend");
return false;
}
ubuf.resize(nonZeroSize);
ubuf = new char[nonZeroSize];
QRHI_PROF_F(newBuffer(this, uint(nonZeroSize), 0, 1));
return true;
}

View File

@ -68,7 +68,7 @@ struct QGles2Buffer : public QRhiBuffer
GLuint buffer = 0;
GLenum targetForDataOps;
QByteArray ubuf;
char *ubuf = nullptr;
enum Access {
AccessNone,
AccessVertex,