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, ...@@ -86,7 +86,8 @@ angle::Result FindAndAllocateCompatibleMemory(vk::Context *context,
{ {
// Can map the memory. // Can map the memory.
ANGLE_TRY(vk::InitMappableDeviceMemory(context, deviceMemoryOut, ANGLE_TRY(vk::InitMappableDeviceMemory(context, deviceMemoryOut,
memoryRequirements.size, kNonZeroInitValue)); memoryRequirements.size, kNonZeroInitValue,
*memoryPropertyFlagsOut));
} }
} }
...@@ -433,7 +434,8 @@ void StagingBuffer::collectGarbage(RendererVk *renderer, Serial serial) ...@@ -433,7 +434,8 @@ void StagingBuffer::collectGarbage(RendererVk *renderer, Serial serial)
angle::Result InitMappableDeviceMemory(Context *context, angle::Result InitMappableDeviceMemory(Context *context,
DeviceMemory *deviceMemory, DeviceMemory *deviceMemory,
VkDeviceSize size, VkDeviceSize size,
int value) int value,
VkMemoryPropertyFlags memoryPropertyFlags)
{ {
VkDevice device = context->getDevice(); VkDevice device = context->getDevice();
...@@ -441,11 +443,15 @@ angle::Result InitMappableDeviceMemory(Context *context, ...@@ -441,11 +443,15 @@ angle::Result InitMappableDeviceMemory(Context *context,
ANGLE_VK_TRY(context, deviceMemory->map(device, 0, VK_WHOLE_SIZE, 0, &mapPointer)); ANGLE_VK_TRY(context, deviceMemory->map(device, 0, VK_WHOLE_SIZE, 0, &mapPointer));
memset(mapPointer, value, static_cast<size_t>(size)); memset(mapPointer, value, static_cast<size_t>(size));
VkMappedMemoryRange mappedRange = {}; // if the memory type is not host coherent, we perform an explicit flush
mappedRange.sType = VK_STRUCTURE_TYPE_MAPPED_MEMORY_RANGE; if ((memoryPropertyFlags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT) == 0)
mappedRange.memory = deviceMemory->getHandle(); {
mappedRange.size = VK_WHOLE_SIZE; VkMappedMemoryRange mappedRange = {};
ANGLE_VK_TRY(context, vkFlushMappedMemoryRanges(device, 1, &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); deviceMemory->unmap(device);
......
...@@ -328,7 +328,8 @@ class StagingBuffer final : angle::NonCopyable ...@@ -328,7 +328,8 @@ class StagingBuffer final : angle::NonCopyable
angle::Result InitMappableDeviceMemory(vk::Context *context, angle::Result InitMappableDeviceMemory(vk::Context *context,
vk::DeviceMemory *deviceMemory, vk::DeviceMemory *deviceMemory,
VkDeviceSize size, VkDeviceSize size,
int value); int value,
VkMemoryPropertyFlags memoryPropertyFlags);
angle::Result AllocateBufferMemory(Context *context, angle::Result AllocateBufferMemory(Context *context,
VkMemoryPropertyFlags requestedMemoryPropertyFlags, 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