Use raw MTLBuffer for texture uploads.
There's a fair bit of overhead to setting up a GrMtlBuffer (adding it to the resource cache, etc.) that isn't necessary in this case when using a temporary buffer. Overall it gives about 10% improvement in uploadToTexture(). Change-Id: I99449c9001098c90743cba8d614007db307156d3 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/230131 Commit-Queue: Jim Van Verth <jvanverth@google.com> Reviewed-by: Greg Daniel <egdaniel@google.com>
This commit is contained in:
parent
3da607ec72
commit
96827b125f
@ -252,15 +252,13 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, int left, int top, int width,
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
sk_sp<GrMtlBuffer> transferBuffer = GrMtlBuffer::Make(this, combinedBufferSize,
|
size_t bufferOffset;
|
||||||
GrGpuBufferType::kXferCpuToGpu,
|
id<MTLBuffer> transferBuffer = this->resourceProvider().getDynamicBuffer(combinedBufferSize,
|
||||||
kStream_GrAccessPattern);
|
&bufferOffset);
|
||||||
if (!transferBuffer) {
|
if (!transferBuffer) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
char* buffer = (char*) transferBuffer.contents + bufferOffset;
|
||||||
char* buffer = (char*) transferBuffer->map();
|
|
||||||
size_t bufferOffset = transferBuffer->offset();
|
|
||||||
|
|
||||||
currentWidth = width;
|
currentWidth = width;
|
||||||
currentHeight = height;
|
currentHeight = height;
|
||||||
@ -274,12 +272,12 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, int left, int top, int width,
|
|||||||
const size_t trimRowBytes = currentWidth * bpp;
|
const size_t trimRowBytes = currentWidth * bpp;
|
||||||
const size_t rowBytes = texels[currentMipLevel].fRowBytes;
|
const size_t rowBytes = texels[currentMipLevel].fRowBytes;
|
||||||
|
|
||||||
// copy data into the buffer, skipping the trailing bytes
|
// copy data into the buffer, skipping any trailing bytes
|
||||||
char* dst = buffer + individualMipOffsets[currentMipLevel];
|
char* dst = buffer + individualMipOffsets[currentMipLevel];
|
||||||
const char* src = (const char*)texels[currentMipLevel].fPixels;
|
const char* src = (const char*)texels[currentMipLevel].fPixels;
|
||||||
SkRectMemcpy(dst, trimRowBytes, src, rowBytes, trimRowBytes, currentHeight);
|
SkRectMemcpy(dst, trimRowBytes, src, rowBytes, trimRowBytes, currentHeight);
|
||||||
|
|
||||||
[blitCmdEncoder copyFromBuffer: transferBuffer->mtlBuffer()
|
[blitCmdEncoder copyFromBuffer: transferBuffer
|
||||||
sourceOffset: bufferOffset + individualMipOffsets[currentMipLevel]
|
sourceOffset: bufferOffset + individualMipOffsets[currentMipLevel]
|
||||||
sourceBytesPerRow: trimRowBytes
|
sourceBytesPerRow: trimRowBytes
|
||||||
sourceBytesPerImage: trimRowBytes*currentHeight
|
sourceBytesPerImage: trimRowBytes*currentHeight
|
||||||
@ -293,7 +291,9 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, int left, int top, int width,
|
|||||||
currentHeight = SkTMax(1, currentHeight/2);
|
currentHeight = SkTMax(1, currentHeight/2);
|
||||||
layerHeight = currentHeight;
|
layerHeight = currentHeight;
|
||||||
}
|
}
|
||||||
transferBuffer->unmap();
|
#ifdef SK_BUILD_FOR_MAC
|
||||||
|
[transferBuffer didModifyRange: NSMakeRange(bufferOffset, combinedBufferSize)];
|
||||||
|
#endif
|
||||||
|
|
||||||
if (mipLevelCount < (int) tex->mtlTexture().mipmapLevelCount) {
|
if (mipLevelCount < (int) tex->mtlTexture().mipmapLevelCount) {
|
||||||
tex->texturePriv().markMipMapsDirty();
|
tex->texturePriv().markMipMapsDirty();
|
||||||
|
Loading…
Reference in New Issue
Block a user