From 06ab6e5b1330bea8119cc899c11eecbb50a35d10 Mon Sep 17 00:00:00 2001 From: Jiawei Shao Date: Fri, 12 Jul 2019 07:18:11 +0000 Subject: [PATCH] Metal: Code clean up in copy commands This patch cleans up the code related to both buffer-texture and texture-texture copies on Metal backend by moving the creation of MTLOrigin and MTLSize into helper functions. BUG=dawn:42 Change-Id: Ia3340b9c8b0a5001d775cd391fb8301207b4d2ac Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/8840 Reviewed-by: Austin Eng Reviewed-by: Corentin Wallez Commit-Queue: Jiawei Shao --- src/dawn_native/metal/CommandBufferMTL.mm | 33 +++++++++-------------- 1 file changed, 13 insertions(+), 20 deletions(-) diff --git a/src/dawn_native/metal/CommandBufferMTL.mm b/src/dawn_native/metal/CommandBufferMTL.mm index efb3555e1b..28c0c96487 100644 --- a/src/dawn_native/metal/CommandBufferMTL.mm +++ b/src/dawn_native/metal/CommandBufferMTL.mm @@ -311,6 +311,14 @@ namespace dawn_native { namespace metal { std::array copies; }; + MTLOrigin MakeMTLOrigin(Origin3D origin) { + return MTLOriginMake(origin.x, origin.y, origin.z); + } + + MTLSize MakeMTLSize(Extent3D extent) { + return MTLSizeMake(extent.width, extent.height, extent.depth); + } + TextureBufferCopySplit ComputeTextureBufferCopySplit(Origin3D origin, Extent3D copyExtent, Format textureFormat, @@ -361,7 +369,7 @@ namespace dawn_native { namespace metal { copy.copies[0].bufferOffset = bufferOffset; copy.copies[0].bytesPerRow = rowPitch; copy.copies[0].bytesPerImage = bytesPerImage; - copy.copies[0].textureOrigin = MTLOriginMake(origin.x, origin.y, origin.z); + copy.copies[0].textureOrigin = MakeMTLOrigin(origin); copy.copies[0].copyExtent = MTLSizeMake(clampedCopyExtentWidth, clampedCopyExtentHeight, copyExtent.depth); return copy; @@ -374,7 +382,7 @@ namespace dawn_native { namespace metal { copy.copies[copy.count].bufferOffset = currentOffset; copy.copies[copy.count].bytesPerRow = rowPitch; copy.copies[copy.count].bytesPerImage = bytesPerImage; - copy.copies[copy.count].textureOrigin = MTLOriginMake(origin.x, origin.y, origin.z); + copy.copies[copy.count].textureOrigin = MakeMTLOrigin(origin); copy.copies[copy.count].copyExtent = MTLSizeMake( clampedCopyExtentWidth, clampedCopyExtentHeight, copyExtent.depth - 1); @@ -526,32 +534,17 @@ namespace dawn_native { namespace metal { Texture* srcTexture = ToBackend(copy->source.texture.Get()); Texture* dstTexture = ToBackend(copy->destination.texture.Get()); - MTLOrigin srcOrigin; - srcOrigin.x = copy->source.origin.x; - srcOrigin.y = copy->source.origin.y; - srcOrigin.z = copy->source.origin.z; - - MTLOrigin dstOrigin; - dstOrigin.x = copy->destination.origin.x; - dstOrigin.y = copy->destination.origin.y; - dstOrigin.z = copy->destination.origin.z; - - MTLSize size; - size.width = copy->copySize.width; - size.height = copy->copySize.height; - size.depth = copy->copySize.depth; - encoders.EnsureBlit(commandBuffer); [encoders.blit copyFromTexture:srcTexture->GetMTLTexture() sourceSlice:copy->source.arrayLayer sourceLevel:copy->source.mipLevel - sourceOrigin:srcOrigin - sourceSize:size + sourceOrigin:MakeMTLOrigin(copy->source.origin) + sourceSize:MakeMTLSize(copy->copySize) toTexture:dstTexture->GetMTLTexture() destinationSlice:copy->destination.arrayLayer destinationLevel:copy->destination.mipLevel - destinationOrigin:dstOrigin]; + destinationOrigin:MakeMTLOrigin(copy->destination.origin)]; } break; default: { UNREACHABLE(); } break;