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;
|
||||
}
|
||||
|
||||
sk_sp<GrMtlBuffer> transferBuffer = GrMtlBuffer::Make(this, combinedBufferSize,
|
||||
GrGpuBufferType::kXferCpuToGpu,
|
||||
kStream_GrAccessPattern);
|
||||
size_t bufferOffset;
|
||||
id<MTLBuffer> 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();
|
||||
|
Loading…
Reference in New Issue
Block a user