diff options
author | Android Build Coastguard Worker <android-build-coastguard-worker@google.com> | 2023-02-27 18:59:31 +0000 |
---|---|---|
committer | Gerrit Code Review <noreply-gerritcodereview@google.com> | 2023-02-27 18:59:31 +0000 |
commit | 7e5588ac5c56e6e0d1545605f715fb9a5ab3ee99 (patch) | |
tree | b52867d6c1cf19843eadcd46e2b52bf0be4946bf | |
parent | 8133c6efd20000bb16f2e30410709f0b88f8159a (diff) | |
parent | 97dee1d451df943c79e7ad1f94e9847593165790 (diff) | |
download | qemu-snap-temp-L66500000958831100.tar.gz |
Merge "Use dedicated allocations if the driver requires them." into snap-temp-L66500000958831100snap-temp-L66500000958831100
-rw-r--r-- | android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.cpp | 84 | ||||
-rw-r--r-- | android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.h | 4 |
2 files changed, 75 insertions, 13 deletions
diff --git a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.cpp b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.cpp index 7a3a229678..71d455e040 100644 --- a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.cpp +++ b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.cpp @@ -1061,23 +1061,40 @@ void teardownGlobalVkEmulation() { bool allocExternalMemory(VulkanDispatch* vk, VkEmulation::ExternalMemoryInfo* info, bool actuallyExternal, - Optional<uint64_t> deviceAlignment) { + Optional<uint64_t> deviceAlignment, + Optional<VkImage> dedicatedImage, + Optional<VkBuffer> dedicatedBuffer) { VkExportMemoryAllocateInfo exportAi = { - VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO, 0, + VK_STRUCTURE_TYPE_EXPORT_MEMORY_ALLOCATE_INFO, + 0, VK_EXT_MEMORY_HANDLE_TYPE_BIT, }; + bool dedicated = dedicatedImage || dedicatedBuffer; + + VkMemoryDedicatedAllocateInfoKHR dedicated_memory_info = { + VK_STRUCTURE_TYPE_MEMORY_DEDICATED_ALLOCATE_INFO_KHR, + NULL, + dedicatedImage ? dedicatedImage.value() : VK_NULL_HANDLE, + dedicatedBuffer? dedicatedBuffer.value(): VK_NULL_HANDLE, + }; - VkExportMemoryAllocateInfo* exportAiPtr = nullptr; + void* pNext = nullptr; - if (sVkEmulation->deviceInfo.supportsExternalMemory && - actuallyExternal) { - exportAiPtr = &exportAi; + if (sVkEmulation->deviceInfo.supportsExternalMemory && actuallyExternal) { + pNext = &exportAi; + if (dedicated) { + exportAi.pNext = &dedicated_memory_info; + } + } else if (dedicated) { + pNext = &dedicated_memory_info; } - info->actualSize = (info->size + 2 * kPageSize - 1) / kPageSize * kPageSize; + info->actualSize = dedicated ? info->size + : (info->size + 2 * kPageSize - 1) / + kPageSize * kPageSize; VkMemoryAllocateInfo allocInfo = { VK_STRUCTURE_TYPE_MEMORY_ALLOCATE_INFO, - exportAiPtr, + pNext, info->actualSize, info->typeIndex, }; @@ -1549,8 +1566,25 @@ bool setupVkColorBuffer(uint32_t colorBufferHandle, return false; } - vk->vkGetImageMemoryRequirements(sVkEmulation->device, res.image, - &res.memReqs); + bool use_dedicated = false; + if (vk->vkGetImageMemoryRequirements2KHR) { + VkMemoryDedicatedRequirements dedicated_reqs{ + VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS, nullptr}; + VkMemoryRequirements2 reqs{VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, + &dedicated_reqs}; + + VkImageMemoryRequirementsInfo2 info{ + VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, + nullptr, + res.image + }; + vk->vkGetImageMemoryRequirements2KHR(sVkEmulation->device, &info, &reqs); + use_dedicated = dedicated_reqs.prefersDedicatedAllocation; + res.memReqs = reqs.memoryRequirements; + } else { + vk->vkGetImageMemoryRequirements(sVkEmulation->device, res.image, + &res.memReqs); + } // Currently we only care about two memory properties: DEVICE_LOCAL // and HOST_VISIBLE; other memory properties specified in @@ -1580,8 +1614,11 @@ bool setupVkColorBuffer(uint32_t colorBufferHandle, bool isHostVisible = memoryProperty & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT; Optional<uint64_t> deviceAlignment = isHostVisible ? Optional(res.memReqs.alignment) : kNullopt; - bool allocRes = allocExternalMemory( - vk, &res.memory, true /*actuallyExternal*/, deviceAlignment); + bool allocRes = + allocExternalMemory(vk, &res.memory, true /*actuallyExternal*/, + deviceAlignment, + use_dedicated? + Optional<VkImage>(res.image): android::base::kNullopt); if (!allocRes) { LOG(VERBOSE) << "Failed to allocate ColorBuffer with Vulkan backing."; @@ -2225,8 +2262,27 @@ bool setupVkBuffer(uint32_t bufferHandle, return false; } + + bool use_dedicated = false; + if (vk->vkGetImageMemoryRequirements2KHR) { + VkMemoryDedicatedRequirements dedicated_reqs{ + VK_STRUCTURE_TYPE_MEMORY_DEDICATED_REQUIREMENTS, nullptr}; + VkMemoryRequirements2 reqs{VK_STRUCTURE_TYPE_MEMORY_REQUIREMENTS_2, + &dedicated_reqs}; + + VkBufferMemoryRequirementsInfo2 info{ + VK_STRUCTURE_TYPE_IMAGE_MEMORY_REQUIREMENTS_INFO_2, + nullptr, + res.buffer + }; + vk->vkGetBufferMemoryRequirements2KHR(sVkEmulation->device, &info, &reqs); + use_dedicated = dedicated_reqs.prefersDedicatedAllocation; + res.memReqs = reqs.memoryRequirements; + } else { vk->vkGetBufferMemoryRequirements(sVkEmulation->device, res.buffer, &res.memReqs); + } + // Currently we only care about two memory properties: DEVICE_LOCAL // and HOST_VISIBLE; other memory properties specified in @@ -2257,7 +2313,9 @@ bool setupVkBuffer(uint32_t bufferHandle, Optional<uint64_t> deviceAlignment = isHostVisible ? Optional(res.memReqs.alignment) : kNullopt; bool allocRes = allocExternalMemory( - vk, &res.memory, true /* actuallyExternal */, deviceAlignment); + vk, &res.memory, true /* actuallyExternal */, deviceAlignment, + android::base::kNullopt, + use_dedicated? Optional(res.buffer): android::base::kNullopt); if (!allocRes) { LOG(VERBOSE) << "Failed to allocate ColorBuffer with Vulkan backing."; diff --git a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.h b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.h index c1ba4a4904..266fa1dd2d 100644 --- a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.h +++ b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.h @@ -337,6 +337,10 @@ bool allocExternalMemory(VulkanDispatch* vk, VkEmulation::ExternalMemoryInfo* info, bool actuallyExternal = true, android::base::Optional<uint64_t> deviceAlignment = + android::base::kNullopt, + android::base::Optional<VkImage> dedicatedImage = + android::base::kNullopt, + android::base::Optional<VkBuffer> dedicatedBuffer = android::base::kNullopt); void freeExternalMemoryLocked(VulkanDispatch* vk, VkEmulation::ExternalMemoryInfo* info); |