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 <enga@chromium.org> Reviewed-by: Corentin Wallez <cwallez@chromium.org> Commit-Queue: Jiawei Shao <jiawei.shao@intel.com>
This commit is contained in:
parent
2d8ba5fac6
commit
06ab6e5b13
|
@ -311,6 +311,14 @@ namespace dawn_native { namespace metal {
|
||||||
std::array<CopyInfo, kMaxTextureBufferCopyRegions> copies;
|
std::array<CopyInfo, kMaxTextureBufferCopyRegions> 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,
|
TextureBufferCopySplit ComputeTextureBufferCopySplit(Origin3D origin,
|
||||||
Extent3D copyExtent,
|
Extent3D copyExtent,
|
||||||
Format textureFormat,
|
Format textureFormat,
|
||||||
|
@ -361,7 +369,7 @@ namespace dawn_native { namespace metal {
|
||||||
copy.copies[0].bufferOffset = bufferOffset;
|
copy.copies[0].bufferOffset = bufferOffset;
|
||||||
copy.copies[0].bytesPerRow = rowPitch;
|
copy.copies[0].bytesPerRow = rowPitch;
|
||||||
copy.copies[0].bytesPerImage = bytesPerImage;
|
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 =
|
copy.copies[0].copyExtent =
|
||||||
MTLSizeMake(clampedCopyExtentWidth, clampedCopyExtentHeight, copyExtent.depth);
|
MTLSizeMake(clampedCopyExtentWidth, clampedCopyExtentHeight, copyExtent.depth);
|
||||||
return copy;
|
return copy;
|
||||||
|
@ -374,7 +382,7 @@ namespace dawn_native { namespace metal {
|
||||||
copy.copies[copy.count].bufferOffset = currentOffset;
|
copy.copies[copy.count].bufferOffset = currentOffset;
|
||||||
copy.copies[copy.count].bytesPerRow = rowPitch;
|
copy.copies[copy.count].bytesPerRow = rowPitch;
|
||||||
copy.copies[copy.count].bytesPerImage = bytesPerImage;
|
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(
|
copy.copies[copy.count].copyExtent = MTLSizeMake(
|
||||||
clampedCopyExtentWidth, clampedCopyExtentHeight, copyExtent.depth - 1);
|
clampedCopyExtentWidth, clampedCopyExtentHeight, copyExtent.depth - 1);
|
||||||
|
|
||||||
|
@ -526,32 +534,17 @@ namespace dawn_native { namespace metal {
|
||||||
Texture* srcTexture = ToBackend(copy->source.texture.Get());
|
Texture* srcTexture = ToBackend(copy->source.texture.Get());
|
||||||
Texture* dstTexture = ToBackend(copy->destination.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.EnsureBlit(commandBuffer);
|
||||||
|
|
||||||
[encoders.blit copyFromTexture:srcTexture->GetMTLTexture()
|
[encoders.blit copyFromTexture:srcTexture->GetMTLTexture()
|
||||||
sourceSlice:copy->source.arrayLayer
|
sourceSlice:copy->source.arrayLayer
|
||||||
sourceLevel:copy->source.mipLevel
|
sourceLevel:copy->source.mipLevel
|
||||||
sourceOrigin:srcOrigin
|
sourceOrigin:MakeMTLOrigin(copy->source.origin)
|
||||||
sourceSize:size
|
sourceSize:MakeMTLSize(copy->copySize)
|
||||||
toTexture:dstTexture->GetMTLTexture()
|
toTexture:dstTexture->GetMTLTexture()
|
||||||
destinationSlice:copy->destination.arrayLayer
|
destinationSlice:copy->destination.arrayLayer
|
||||||
destinationLevel:copy->destination.mipLevel
|
destinationLevel:copy->destination.mipLevel
|
||||||
destinationOrigin:dstOrigin];
|
destinationOrigin:MakeMTLOrigin(copy->destination.origin)];
|
||||||
} break;
|
} break;
|
||||||
|
|
||||||
default: { UNREACHABLE(); } break;
|
default: { UNREACHABLE(); } break;
|
||||||
|
|
Loading…
Reference in New Issue