rhi: metal: Reduce staging copy size for full-width texture uploads

Pick-to: 6.6 6.5
Task-number: QTBUG-120565
Change-Id: I3f11796e0cfd7261885cec04695665b2266082f8
Reviewed-by: Andy Nichols <andy.nichols@qt.io>
(cherry picked from commit a1371783ac3b04df5b5275de49179a26a7c5112b)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
Laszlo Agocs 2024-04-30 12:04:35 +02:00 committed by Qt Cherry-pick Bot
parent 191459da49
commit aa6d59deee

View File

@ -2581,7 +2581,6 @@ void QRhiMetal::enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEnc
int w = img.width(); int w = img.width();
int h = img.height(); int h = img.height();
int bpl = img.bytesPerLine(); int bpl = img.bytesPerLine();
int srcOffset = 0;
if (!subresDesc.sourceSize().isEmpty() || !subresDesc.sourceTopLeft().isNull()) { if (!subresDesc.sourceSize().isEmpty() || !subresDesc.sourceTopLeft().isNull()) {
const int sx = subresDesc.sourceTopLeft().x(); const int sx = subresDesc.sourceTopLeft().x();
@ -2590,10 +2589,12 @@ void QRhiMetal::enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEnc
w = subresDesc.sourceSize().width(); w = subresDesc.sourceSize().width();
h = subresDesc.sourceSize().height(); h = subresDesc.sourceSize().height();
} }
if (img.depth() == 32) { if (w == img.width()) {
memcpy(reinterpret_cast<char *>(mp) + *curOfs, img.constBits(), size_t(fullImageSizeBytes)); const int bpc = qMax(1, img.depth() / 8);
srcOffset = sy * bpl + sx * 4; Q_ASSERT(h * img.bytesPerLine() <= fullImageSizeBytes);
// bpl remains set to the original image's row stride memcpy(reinterpret_cast<char *>(mp) + *curOfs,
img.constBits() + sy * img.bytesPerLine() + sx * bpc,
h * img.bytesPerLine());
} else { } else {
img = img.copy(sx, sy, w, h); img = img.copy(sx, sy, w, h);
bpl = img.bytesPerLine(); bpl = img.bytesPerLine();
@ -2605,7 +2606,7 @@ void QRhiMetal::enqueueSubresUpload(QMetalTexture *texD, void *mp, void *blitEnc
} }
[blitEnc copyFromBuffer: texD->d->stagingBuf[currentFrameSlot] [blitEnc copyFromBuffer: texD->d->stagingBuf[currentFrameSlot]
sourceOffset: NSUInteger(*curOfs + srcOffset) sourceOffset: NSUInteger(*curOfs)
sourceBytesPerRow: NSUInteger(bpl) sourceBytesPerRow: NSUInteger(bpl)
sourceBytesPerImage: 0 sourceBytesPerImage: 0
sourceSize: MTLSizeMake(NSUInteger(w), NSUInteger(h), 1) sourceSize: MTLSizeMake(NSUInteger(w), NSUInteger(h), 1)