From 7f4980e7d265d3f2e984dd316dccdb28a9dd86bf Mon Sep 17 00:00:00 2001 From: Tomek Ponitka Date: Fri, 17 Jul 2020 09:45:26 +0000 Subject: [PATCH] Optimizing WriteTexture offset on Vulkan Added an additional alignment on the staging buffer offset in WriteTexture on Vulkan to match VkPhysicalDeviceLimits::optimalBufferCopyOffsetAlignment. We now allocate some additional memory in the staging buffer for that purpose. Bug: dawn:483 Change-Id: Ic5b95aa57f6c241e0ab9f9853b4c3152e52e5630 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/24982 Commit-Queue: Tomek Ponitka Reviewed-by: Corentin Wallez Reviewed-by: Austin Eng --- src/dawn_native/vulkan/QueueVk.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/dawn_native/vulkan/QueueVk.cpp b/src/dawn_native/vulkan/QueueVk.cpp index d5f95787af..99a05909a8 100644 --- a/src/dawn_native/vulkan/QueueVk.cpp +++ b/src/dawn_native/vulkan/QueueVk.cpp @@ -41,9 +41,15 @@ namespace dawn_native { namespace vulkan { uint32_t newDataSize = ComputeRequiredBytesInCopy( textureFormat, *writeSize, optimallyAlignedBytesPerRow, alignedRowsPerImage); + uint64_t optimalOffsetAlignment = + ToBackend(device) + ->GetDeviceInfo() + .properties.limits.optimalBufferCopyOffsetAlignment; + UploadHandle uploadHandle; DAWN_TRY_ASSIGN(uploadHandle, device->GetDynamicUploader()->Allocate( - newDataSize, device->GetPendingCommandSerial())); + newDataSize + optimalOffsetAlignment - 1, + device->GetPendingCommandSerial())); ASSERT(uploadHandle.mappedBuffer != nullptr); // TODO(tommek@google.com): Add an optimization to do a single memcpy if the data @@ -58,6 +64,11 @@ namespace dawn_native { namespace vulkan { dataRowsPerImageInBlock = writeSize->height / textureFormat.blockHeight; } + uint64_t additionalOffset = + Align(uploadHandle.startOffset, optimalOffsetAlignment) - uploadHandle.startOffset; + uploadHandle.startOffset += additionalOffset; + dstPointer += additionalOffset; + ASSERT(dataRowsPerImageInBlock >= alignedRowsPerImageInBlock); uint64_t imageAdditionalStride = dataLayout->bytesPerRow * (dataRowsPerImageInBlock - alignedRowsPerImageInBlock);