Commit 6281e30d by Hyunchang Kim Committed by Commit Bot

Vulkan: Add flush condition for the device memory updated by CPU

Memory created using HOST_COHERENT_BIT does not need to be explicitly flushed. Bug: angleproject:2162 Change-Id: Idc2001e2254de616d7e7067410d225d0b521f29f Reviewed-on: https://chromium-review.googlesource.com/c/angle/angle/+/2131881 Commit-Queue: Mohan Maiya <m.maiya@samsung.com> Reviewed-by: 's avatarJamie Madill <jmadill@chromium.org>
parent d30da072
......@@ -86,7 +86,8 @@ angle::Result FindAndAllocateCompatibleMemory(vk::Context *context,
{
// Can map the memory.
ANGLE_TRY(vk::InitMappableDeviceMemory(context, deviceMemoryOut,
memoryRequirements.size, kNonZeroInitValue));
memoryRequirements.size, kNonZeroInitValue,
*memoryPropertyFlagsOut));
}
}
......@@ -433,7 +434,8 @@ void StagingBuffer::collectGarbage(RendererVk *renderer, Serial serial)
angle::Result InitMappableDeviceMemory(Context *context,
DeviceMemory *deviceMemory,
VkDeviceSize size,
int value)
int value,
VkMemoryPropertyFlags memoryPropertyFlags)
{
VkDevice device = context->getDevice();
......@@ -441,11 +443,15 @@ angle::Result InitMappableDeviceMemory(Context *context,
ANGLE_VK_TRY(context, deviceMemory->map(device, 0, VK_WHOLE_SIZE, 0, &mapPointer));
memset(mapPointer, value, static_cast<size_t>(size));
VkMappedMemoryRange mappedRange = {};
mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
mappedRange.memory = deviceMemory->getHandle();
mappedRange.size = VK_WHOLE_SIZE;
ANGLE_VK_TRY(context, vkFlushMappedMemoryRanges(device, 1, &mappedRange));
// if the memory type is not host coherent, we perform an explicit flush
if ((memoryPropertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == 0)
{
VkMappedMemoryRange mappedRange = {};
mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE;
mappedRange.memory = deviceMemory->getHandle();
mappedRange.size = VK_WHOLE_SIZE;
ANGLE_VK_TRY(context, vkFlushMappedMemoryRanges(device, 1, &mappedRange));
}
deviceMemory->unmap(device);
......
......@@ -328,7 +328,8 @@ class StagingBuffer final : angle::NonCopyable
angle::Result InitMappableDeviceMemory(vk::Context *context,
vk::DeviceMemory *deviceMemory,
VkDeviceSize size,
int value);
int value,
VkMemoryPropertyFlags memoryPropertyFlags);
angle::Result AllocateBufferMemory(Context *context,
VkMemoryPropertyFlags requestedMemoryPropertyFlags,
......
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