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 <tommek@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
This commit is contained in:
Tomek Ponitka 2020-07-17 09:45:26 +00:00 committed by Commit Bot service account
parent 73652263df
commit 7f4980e7d2
1 changed files with 12 additions and 1 deletions

View File

@ -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);