Commit b7d6949b by Mohan Maiya Committed by Commit Bot

Vulkan: Enable persistently mapped buffer objects

The VMA allocator has a handy feature where during memory allocation we can request persistently mapped memory. This saves IOCTL overhead for apps that update buffers frequently. Bug: angleproject:2162 Change-Id: I870d880033beec343efae6de06f1c5935de4c2c1 Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2155131Reviewed-by: 's avatarTobin Ehlis <tobine@google.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org> Commit-Queue: Tobin Ehlis <tobine@google.com>
parent fe60973b
......@@ -251,6 +251,13 @@ struct FeaturesVk : FeatureSetBase
"Fill new allocations with non-zero values to flush out errors.", &members,
"http://anglebug.com/4384"};
// Persistently map buffer memory until destroy, saves on map/unmap IOCTL overhead
// for buffers that are updated frequently.
Feature persistentlyMappedBuffers = {
"persistently_mapped_buffers", FeatureCategory::VulkanFeatures,
"Persistently map buffer memory to reduce map/unmap IOCTL overhead.", &members,
"http://anglebug.com/2162"};
// Android needs to pre-rotate surfaces that are not oriented per the native device's
// orientation (e.g. a landscape application on a Pixel phone). This feature works for
// full-screen applications. http://anglebug.com/3502
......
......@@ -1679,6 +1679,8 @@ void RendererVk::initFeatures(DisplayVk *displayVk, const ExtensionNameList &dev
// that can cause OOM and timeouts.
ANGLE_FEATURE_CONDITION(&mFeatures, allocateNonZeroMemory, false);
ANGLE_FEATURE_CONDITION(&mFeatures, persistentlyMappedBuffers, true);
ANGLE_FEATURE_CONDITION(
&mFeatures, supportsExternalMemoryHost,
ExtensionFound(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME, deviceExtensionNames));
......
......@@ -1699,8 +1699,9 @@ angle::Result BufferHelper::init(ContextVk *contextVk,
VkMemoryPropertyFlags preferredFlags =
(memoryPropertyFlags & (~VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
mAllocation.createBufferAndMemory(renderer->getAllocator(), createInfo, requiredFlags,
preferredFlags, &mBuffer, &mMemoryPropertyFlags);
mAllocation.createBufferAndMemory(
renderer->getAllocator(), createInfo, requiredFlags, preferredFlags,
renderer->getFeatures().persistentlyMappedBuffers.enabled, &mBuffer, &mMemoryPropertyFlags);
mCurrentQueueFamilyIndex = contextVk->getRenderer()->getQueueFamilyIndex();
......
......@@ -62,6 +62,7 @@ VkResult CreateBuffer(VmaAllocator allocator,
const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags,
bool persistentlyMappedBuffers,
uint32_t *pMemoryTypeIndexOut,
VkBuffer *pBuffer,
VmaAllocation *pAllocation)
......@@ -70,7 +71,8 @@ VkResult CreateBuffer(VmaAllocator allocator,
VmaAllocationCreateInfo allocationCreateInfo = {};
allocationCreateInfo.requiredFlags = requiredFlags;
allocationCreateInfo.preferredFlags = preferredFlags;
VmaAllocationInfo allocationInfo = {};
allocationCreateInfo.flags = (persistentlyMappedBuffers) ? VMA_ALLOCATION_CREATE_MAPPED_BIT : 0;
VmaAllocationInfo allocationInfo = {};
result = vmaCreateBuffer(allocator, pBufferCreateInfo, &allocationCreateInfo, pBuffer,
pAllocation, &allocationInfo);
......
......@@ -30,6 +30,7 @@ VkResult CreateBuffer(VmaAllocator allocator,
const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags,
bool persistentlyMappedBuffers,
uint32_t *pMemoryTypeIndexOut,
VkBuffer *pBuffer,
VmaAllocation *pAllocation);
......
......@@ -408,9 +408,10 @@ angle::Result StagingBuffer::init(Context *context, VkDeviceSize size, StagingUs
VkMemoryPropertyFlags requiredFlags =
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
mAllocation.createBufferAndMemory(context->getRenderer()->getAllocator(), &createInfo,
requiredFlags, preferredFlags, &mBuffer,
&memoryPropertyOutFlags);
mAllocation.createBufferAndMemory(
context->getRenderer()->getAllocator(), &createInfo, requiredFlags, preferredFlags,
context->getRenderer()->getFeatures().persistentlyMappedBuffers.enabled, &mBuffer,
&memoryPropertyOutFlags);
mSize = static_cast<size_t>(size);
return angle::Result::Continue;
......
......@@ -466,6 +466,7 @@ class Allocation final : public WrappedObject<Allocation, VmaAllocation>
const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags,
bool persistentlyMappedBuffers,
Buffer *buffer,
VkMemoryPropertyFlags *pMemPropertyOut);
VkResult map(VmaAllocator allocator, uint8_t **mapPointer) const;
......@@ -1329,6 +1330,7 @@ ANGLE_INLINE VkResult Allocation::createBufferAndMemory(VmaAllocator allocator,
const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags,
bool persistentlyMappedBuffers,
Buffer *buffer,
VkMemoryPropertyFlags *pMemPropertyOut)
{
......@@ -1336,8 +1338,9 @@ ANGLE_INLINE VkResult Allocation::createBufferAndMemory(VmaAllocator allocator,
VkResult result;
uint32_t memoryTypeIndex;
VkBuffer bufferHandle;
result = vma::CreateBuffer(allocator, pBufferCreateInfo, requiredFlags, preferredFlags,
&memoryTypeIndex, &bufferHandle, &mHandle);
result =
vma::CreateBuffer(allocator, pBufferCreateInfo, requiredFlags, preferredFlags,
persistentlyMappedBuffers, &memoryTypeIndex, &bufferHandle, &mHandle);
vma::GetMemoryTypeProperties(allocator, memoryTypeIndex, pMemPropertyOut);
buffer->setHandle(bufferHandle);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment