Vulkan: Use optimalBufferCopyOffsetAlignment

optimalBufferCopyOffsetAlignment is the optimal buffer offset alignment
in bytes for vkCmdCopyBufferToImage2KHR, vkCmdCopyBufferToImage,
vkCmdCopyImageToBuffer2KHR, and vkCmdCopyImageToBuffer. The per texel
alignment requirements are enforced, but applications should use the
optimal alignment for optimal performance and power use.

To improve efficiency, this CL updates ContextVk::mStagingBuffer's
alignment to the max of:
- minMemoryMapAlignment
- nonCoherentAtomSize
- optimalBufferCopyOffsetAlignment

On ARM, this is not expected to have any affect, since all three values
are 0x40, but other platforms may see a benefit.

Bug: angleproject:4297
Change-Id: I9185da111e09c5d782eb1dedb10369727cb9bf51
Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/3256007
Commit-Queue: Tim Van Patten <timvp@google.com>
Reviewed-by: Shahbaz Youssefi <syoussefi@chromium.org>
Reviewed-by: Charlie Lao <cclao@google.com>
This commit is contained in:
Tim Van Patten 2021-11-01 20:25:17 -06:00 коммит произвёл Angle LUCI CQ
Родитель 0e20c68092
Коммит 53371cc0a7
2 изменённых файлов: 15 добавлений и 7 удалений

Просмотреть файл

@ -781,6 +781,17 @@ angle::Result ContextVk::initialize()
VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT;
size_t stagingBufferAlignment =
static_cast<size_t>(mRenderer->getPhysicalDeviceProperties().limits.minMemoryMapAlignment);
ASSERT(gl::isPow2(mRenderer->getPhysicalDeviceProperties().limits.nonCoherentAtomSize));
ASSERT(gl::isPow2(
mRenderer->getPhysicalDeviceProperties().limits.optimalBufferCopyOffsetAlignment));
stagingBufferAlignment = static_cast<size_t>(std::max(
stagingBufferAlignment,
static_cast<size_t>(
mRenderer->getPhysicalDeviceProperties().limits.optimalBufferCopyOffsetAlignment)));
stagingBufferAlignment = static_cast<size_t>(std::max(
stagingBufferAlignment,
static_cast<size_t>(mRenderer->getPhysicalDeviceProperties().limits.nonCoherentAtomSize)));
constexpr size_t kStagingBufferSize = 1024u * 1024u; // 1M
mStagingBuffer.init(mRenderer, kStagingBufferUsageFlags, stagingBufferAlignment,
kStagingBufferSize, true, vk::DynamicBufferPolicy::SporadicTextureUpload);

Просмотреть файл

@ -5765,8 +5765,7 @@ angle::Result ImageHelper::reformatStagedBufferUpdates(ContextVk *contextVk,
VkBuffer dstBufferHandle = VK_NULL_HANDLE;
VkDeviceSize dstBufferOffset = 0;
GLuint dstBufferSize = dstDataDepthPitch * copy.imageExtent.depth;
ANGLE_TRY(mStagingBuffer.allocateWithAlignment(
contextVk, dstBufferSize, mStagingBuffer.getAlignment(), &dstData,
ANGLE_TRY(mStagingBuffer.allocate(contextVk, dstBufferSize, &dstData,
&dstBufferHandle, &dstBufferOffset, nullptr));
BufferHelper *dstBuffer = mStagingBuffer.getCurrentBuffer();
@ -7002,10 +7001,8 @@ angle::Result ImageHelper::copyImageDataToBuffer(ContextVk *contextVk,
// Allocate staging buffer data from context
VkBuffer bufferHandle;
size_t alignment = mStagingBuffer.getAlignment();
ANGLE_TRY(mStagingBuffer.allocateWithAlignment(contextVk, *bufferSize, alignment, outDataPtr,
&bufferHandle, &(*bufferOffsetsOut)[0],
nullptr));
ANGLE_TRY(mStagingBuffer.allocate(contextVk, *bufferSize, outDataPtr, &bufferHandle,
&(*bufferOffsetsOut)[0], nullptr));
*bufferOut = mStagingBuffer.getCurrentBuffer();
LevelIndex sourceLevelVk = toVkLevel(sourceLevelGL);