VkCommonOperations: Accept non-cached staging memory
Came across this limitation while playing with memory types. I don't see
a reason other than performance that we can't use non-cached types for
staging memory. Instead, we can try looking for cached ones, and if we
fail then look again.
Bug: b/249823013
Test: Verified a memory type like this boots the emulator
Change-Id: I6fcf86cd27191c722685f7dbfd31a023088dd471
diff --git a/stream-servers/vulkan/VkCommonOperations.cpp b/stream-servers/vulkan/VkCommonOperations.cpp
index 70929f7..9a9fc6a 100644
--- a/stream-servers/vulkan/VkCommonOperations.cpp
+++ b/stream-servers/vulkan/VkCommonOperations.cpp
@@ -140,7 +140,7 @@
bool foundSuitableStagingMemoryType = false;
uint32_t stagingMemoryTypeIndex = 0;
- for (uint32_t i = 0; i < VK_MAX_MEMORY_TYPES; ++i) {
+ for (uint32_t i = 0; i < memProps->memoryTypeCount; ++i) {
const auto& typeInfo = memProps->memoryTypes[i];
bool hostVisible = typeInfo.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
bool hostCached = typeInfo.propertyFlags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT;
@@ -152,6 +152,21 @@
}
}
+ // If the previous loop failed, try to accept a type that is not HOST_CACHED.
+ if (!foundSuitableStagingMemoryType) {
+ for (uint32_t i = 0; i < memProps->memoryTypeCount; ++i) {
+ const auto& typeInfo = memProps->memoryTypes[i];
+ bool hostVisible = typeInfo.propertyFlags & VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT;
+ bool allowedInBuffer = (1 << i) & memReqs.memoryTypeBits;
+ if (hostVisible && allowedInBuffer) {
+ VK_COMMON_ERROR("Warning: using non-cached HOST_VISIBLE type for staging memory");
+ foundSuitableStagingMemoryType = true;
+ stagingMemoryTypeIndex = i;
+ break;
+ }
+ }
+ }
+
vk->vkDestroyBuffer(device, testBuffer, nullptr);
if (!foundSuitableStagingMemoryType) {