From 96827b125f3a91ad9423a3f51d312518b9cdd425 Mon Sep 17 00:00:00 2001 From: Jim Van Verth Date: Mon, 29 Jul 2019 09:20:30 -0400 Subject: [PATCH] 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 Reviewed-by: Greg Daniel --- src/gpu/mtl/GrMtlGpu.mm | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/gpu/mtl/GrMtlGpu.mm b/src/gpu/mtl/GrMtlGpu.mm index 1ca829a921..04cecd9db8 100644 --- a/src/gpu/mtl/GrMtlGpu.mm +++ b/src/gpu/mtl/GrMtlGpu.mm @@ -252,15 +252,13 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, int left, int top, int width, return true; } - sk_sp transferBuffer = GrMtlBuffer::Make(this, combinedBufferSize, - GrGpuBufferType::kXferCpuToGpu, - kStream_GrAccessPattern); + size_t bufferOffset; + id transferBuffer = this->resourceProvider().getDynamicBuffer(combinedBufferSize, + &bufferOffset); if (!transferBuffer) { return false; } - - char* buffer = (char*) transferBuffer->map(); - size_t bufferOffset = transferBuffer->offset(); + char* buffer = (char*) transferBuffer.contents + bufferOffset; currentWidth = width; 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 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]; const char* src = (const char*)texels[currentMipLevel].fPixels; SkRectMemcpy(dst, trimRowBytes, src, rowBytes, trimRowBytes, currentHeight); - [blitCmdEncoder copyFromBuffer: transferBuffer->mtlBuffer() + [blitCmdEncoder copyFromBuffer: transferBuffer sourceOffset: bufferOffset + individualMipOffsets[currentMipLevel] sourceBytesPerRow: trimRowBytes sourceBytesPerImage: trimRowBytes*currentHeight @@ -293,7 +291,9 @@ bool GrMtlGpu::uploadToTexture(GrMtlTexture* tex, int left, int top, int width, currentHeight = SkTMax(1, currentHeight/2); layerHeight = currentHeight; } - transferBuffer->unmap(); +#ifdef SK_BUILD_FOR_MAC + [transferBuffer didModifyRange: NSMakeRange(bufferOffset, combinedBufferSize)]; +#endif if (mipLevelCount < (int) tex->mtlTexture().mipmapLevelCount) { tex->texturePriv().markMipMapsDirty();