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 ...@@ -251,6 +251,13 @@ struct FeaturesVk : FeatureSetBase
"Fill new allocations with non-zero values to flush out errors.", &members, "Fill new allocations with non-zero values to flush out errors.", &members,
"http://anglebug.com/4384"}; "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 // 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 // orientation (e.g. a landscape application on a Pixel phone). This feature works for
// full-screen applications. http://anglebug.com/3502 // full-screen applications. http://anglebug.com/3502
......
...@@ -1679,6 +1679,8 @@ void RendererVk::initFeatures(DisplayVk *displayVk, const ExtensionNameList &dev ...@@ -1679,6 +1679,8 @@ void RendererVk::initFeatures(DisplayVk *displayVk, const ExtensionNameList &dev
// that can cause OOM and timeouts. // that can cause OOM and timeouts.
ANGLE_FEATURE_CONDITION(&mFeatures, allocateNonZeroMemory, false); ANGLE_FEATURE_CONDITION(&mFeatures, allocateNonZeroMemory, false);
ANGLE_FEATURE_CONDITION(&mFeatures, persistentlyMappedBuffers, true);
ANGLE_FEATURE_CONDITION( ANGLE_FEATURE_CONDITION(
&mFeatures, supportsExternalMemoryHost, &mFeatures, supportsExternalMemoryHost,
ExtensionFound(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME, deviceExtensionNames)); ExtensionFound(VK_EXT_EXTERNAL_MEMORY_HOST_EXTENSION_NAME, deviceExtensionNames));
......
...@@ -1699,8 +1699,9 @@ angle::Result BufferHelper::init(ContextVk *contextVk, ...@@ -1699,8 +1699,9 @@ angle::Result BufferHelper::init(ContextVk *contextVk,
VkMemoryPropertyFlags preferredFlags = VkMemoryPropertyFlags preferredFlags =
(memoryPropertyFlags & (~VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT)); (memoryPropertyFlags & (~VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT));
mAllocation.createBufferAndMemory(renderer->getAllocator(), createInfo, requiredFlags, mAllocation.createBufferAndMemory(
preferredFlags, &mBuffer, &mMemoryPropertyFlags); renderer->getAllocator(), createInfo, requiredFlags, preferredFlags,
renderer->getFeatures().persistentlyMappedBuffers.enabled, &mBuffer, &mMemoryPropertyFlags);
mCurrentQueueFamilyIndex = contextVk->getRenderer()->getQueueFamilyIndex(); mCurrentQueueFamilyIndex = contextVk->getRenderer()->getQueueFamilyIndex();
......
...@@ -62,6 +62,7 @@ VkResult CreateBuffer(VmaAllocator allocator, ...@@ -62,6 +62,7 @@ VkResult CreateBuffer(VmaAllocator allocator,
const VkBufferCreateInfo *pBufferCreateInfo, const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags, VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags, VkMemoryPropertyFlags preferredFlags,
bool persistentlyMappedBuffers,
uint32_t *pMemoryTypeIndexOut, uint32_t *pMemoryTypeIndexOut,
VkBuffer *pBuffer, VkBuffer *pBuffer,
VmaAllocation *pAllocation) VmaAllocation *pAllocation)
...@@ -70,7 +71,8 @@ VkResult CreateBuffer(VmaAllocator allocator, ...@@ -70,7 +71,8 @@ VkResult CreateBuffer(VmaAllocator allocator,
VmaAllocationCreateInfo allocationCreateInfo = {}; VmaAllocationCreateInfo allocationCreateInfo = {};
allocationCreateInfo.requiredFlags = requiredFlags; allocationCreateInfo.requiredFlags = requiredFlags;
allocationCreateInfo.preferredFlags = preferredFlags; allocationCreateInfo.preferredFlags = preferredFlags;
VmaAllocationInfo allocationInfo = {}; allocationCreateInfo.flags = (persistentlyMappedBuffers) ? VMA_ALLOCATION_CREATE_MAPPED_BIT : 0;
VmaAllocationInfo allocationInfo = {};
result = vmaCreateBuffer(allocator, pBufferCreateInfo, &allocationCreateInfo, pBuffer, result = vmaCreateBuffer(allocator, pBufferCreateInfo, &allocationCreateInfo, pBuffer,
pAllocation, &allocationInfo); pAllocation, &allocationInfo);
......
...@@ -30,6 +30,7 @@ VkResult CreateBuffer(VmaAllocator allocator, ...@@ -30,6 +30,7 @@ VkResult CreateBuffer(VmaAllocator allocator,
const VkBufferCreateInfo *pBufferCreateInfo, const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags, VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags, VkMemoryPropertyFlags preferredFlags,
bool persistentlyMappedBuffers,
uint32_t *pMemoryTypeIndexOut, uint32_t *pMemoryTypeIndexOut,
VkBuffer *pBuffer, VkBuffer *pBuffer,
VmaAllocation *pAllocation); VmaAllocation *pAllocation);
......
...@@ -408,9 +408,10 @@ angle::Result StagingBuffer::init(Context *context, VkDeviceSize size, StagingUs ...@@ -408,9 +408,10 @@ angle::Result StagingBuffer::init(Context *context, VkDeviceSize size, StagingUs
VkMemoryPropertyFlags requiredFlags = VkMemoryPropertyFlags requiredFlags =
VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | VK_MEMORY_PROPERTY_HOST_COHERENT_BIT;
mAllocation.createBufferAndMemory(context->getRenderer()->getAllocator(), &createInfo, mAllocation.createBufferAndMemory(
requiredFlags, preferredFlags, &mBuffer, context->getRenderer()->getAllocator(), &createInfo, requiredFlags, preferredFlags,
&memoryPropertyOutFlags); context->getRenderer()->getFeatures().persistentlyMappedBuffers.enabled, &mBuffer,
&memoryPropertyOutFlags);
mSize = static_cast<size_t>(size); mSize = static_cast<size_t>(size);
return angle::Result::Continue; return angle::Result::Continue;
......
...@@ -466,6 +466,7 @@ class Allocation final : public WrappedObject<Allocation, VmaAllocation> ...@@ -466,6 +466,7 @@ class Allocation final : public WrappedObject<Allocation, VmaAllocation>
const VkBufferCreateInfo *pBufferCreateInfo, const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags, VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags, VkMemoryPropertyFlags preferredFlags,
bool persistentlyMappedBuffers,
Buffer *buffer, Buffer *buffer,
VkMemoryPropertyFlags *pMemPropertyOut); VkMemoryPropertyFlags *pMemPropertyOut);
VkResult map(VmaAllocator allocator, uint8_t **mapPointer) const; VkResult map(VmaAllocator allocator, uint8_t **mapPointer) const;
...@@ -1329,6 +1330,7 @@ ANGLE_INLINE VkResult Allocation::createBufferAndMemory(VmaAllocator allocator, ...@@ -1329,6 +1330,7 @@ ANGLE_INLINE VkResult Allocation::createBufferAndMemory(VmaAllocator allocator,
const VkBufferCreateInfo *pBufferCreateInfo, const VkBufferCreateInfo *pBufferCreateInfo,
VkMemoryPropertyFlags requiredFlags, VkMemoryPropertyFlags requiredFlags,
VkMemoryPropertyFlags preferredFlags, VkMemoryPropertyFlags preferredFlags,
bool persistentlyMappedBuffers,
Buffer *buffer, Buffer *buffer,
VkMemoryPropertyFlags *pMemPropertyOut) VkMemoryPropertyFlags *pMemPropertyOut)
{ {
...@@ -1336,8 +1338,9 @@ ANGLE_INLINE VkResult Allocation::createBufferAndMemory(VmaAllocator allocator, ...@@ -1336,8 +1338,9 @@ ANGLE_INLINE VkResult Allocation::createBufferAndMemory(VmaAllocator allocator,
VkResult result; VkResult result;
uint32_t memoryTypeIndex; uint32_t memoryTypeIndex;
VkBuffer bufferHandle; VkBuffer bufferHandle;
result = vma::CreateBuffer(allocator, pBufferCreateInfo, requiredFlags, preferredFlags, result =
&memoryTypeIndex, &bufferHandle, &mHandle); vma::CreateBuffer(allocator, pBufferCreateInfo, requiredFlags, preferredFlags,
persistentlyMappedBuffers, &memoryTypeIndex, &bufferHandle, &mHandle);
vma::GetMemoryTypeProperties(allocator, memoryTypeIndex, pMemPropertyOut); vma::GetMemoryTypeProperties(allocator, memoryTypeIndex, pMemPropertyOut);
buffer->setHandle(bufferHandle); 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