vulkan: in addition to size, keep type index consistent bug: https://bugs.fuchsia.dev/p/fuchsia/issues/detail?id=48401 We were getting VK_ERROR_DEVICE_LOST on NV because an external memory was created with a different type index than its import allocation. Change-Id: Ie5a994f2a8db9c635d097372015bf191c2ddbee2
diff --git a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.cpp b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.cpp index 03de52b..ece1bc8 100644 --- a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.cpp +++ b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.cpp
@@ -1197,7 +1197,7 @@ return 0; } -bool setupVkColorBuffer(uint32_t colorBufferHandle, bool vulkanOnly, bool* exported, VkDeviceSize* allocSize) { +bool setupVkColorBuffer(uint32_t colorBufferHandle, bool vulkanOnly, bool* exported, VkDeviceSize* allocSize, uint32_t* typeIndex) { if (!isColorBufferVulkanCompatible(colorBufferHandle)) return false; auto vk = sVkEmulation->dvk; @@ -1222,6 +1222,9 @@ // Update the allocation size to what the host driver wanted, or we // might get VK_ERROR_OUT_OF_DEVICE_MEMORY and a host crash if (allocSize) *allocSize = infoPtr->memory.size; + // Update the type index to what the host driver wanted, or we might + // get VK_ERROR_DEVICE_LOST + if (typeIndex) *typeIndex = infoPtr->memory.typeIndex; return true; } @@ -1339,6 +1342,7 @@ if (exported) *exported = res.glExported; if (allocSize) *allocSize = res.memory.size; + if (typeIndex) *typeIndex = res.memory.typeIndex; sVkEmulation->colorBuffers[colorBufferHandle] = res;
diff --git a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.h b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.h index ca978d0..2458826 100644 --- a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.h +++ b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkCommonOperations.h
@@ -301,7 +301,7 @@ bool isColorBufferVulkanCompatible(uint32_t colorBufferHandle); -bool setupVkColorBuffer(uint32_t colorBufferHandle, bool vulkanOnly = false, bool* exported = nullptr, VkDeviceSize* allocSize = nullptr); +bool setupVkColorBuffer(uint32_t colorBufferHandle, bool vulkanOnly = false, bool* exported = nullptr, VkDeviceSize* allocSize = nullptr, uint32_t* typeIndex = nullptr); bool teardownVkColorBuffer(uint32_t colorBufferHandle); VkEmulation::ColorBufferInfo getColorBufferInfo(uint32_t colorBufferHandle); bool updateColorBufferFromVkImage(uint32_t colorBufferHandle);
diff --git a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkDecoderGlobalState.cpp b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkDecoderGlobalState.cpp index 4deadf0..c9f41a2 100644 --- a/android/android-emugl/host/libs/libOpenglRender/vulkan/VkDecoderGlobalState.cpp +++ b/android/android-emugl/host/libs/libOpenglRender/vulkan/VkDecoderGlobalState.cpp
@@ -2515,8 +2515,10 @@ importCbInfoPtr->colorBuffer, false /* not vulkan only */, nullptr, - // Modify the allocation size to suit the resulting image memory size. - &localAllocInfo.allocationSize); + // Modify the allocation size and type index + // to suit the resulting image memory size. + &localAllocInfo.allocationSize, + &localAllocInfo.memoryTypeIndex); if (m_emu->instanceSupportsExternalMemoryCapabilities) { VK_EXT_MEMORY_HANDLE cbExtMemoryHandle =