diff --git a/src/virtio/vulkan/vn_device_memory.c b/src/virtio/vulkan/vn_device_memory.c index a7434c2953b..e277ce68916 100644 --- a/src/virtio/vulkan/vn_device_memory.c +++ b/src/virtio/vulkan/vn_device_memory.c @@ -358,15 +358,6 @@ vn_AllocateMemory(VkDevice device, { struct vn_device *dev = vn_device_from_handle(device); - /* see vn_physical_device_init_memory_properties */ - VkMemoryAllocateInfo local_info; - if (pAllocateInfo->memoryTypeIndex == - dev->physical_device->incoherent_cached) { - local_info = *pAllocateInfo; - local_info.memoryTypeIndex = dev->physical_device->coherent_uncached; - pAllocateInfo = &local_info; - } - const VkImportMemoryFdInfoKHR *import_fd_info = NULL; const VkMemoryDedicatedAllocateInfo *dedicated_info = NULL; vk_foreach_struct_const(pnext, pAllocateInfo->pNext) { diff --git a/src/virtio/vulkan/vn_physical_device.c b/src/virtio/vulkan/vn_physical_device.c index f6a1d29b7ee..e72663201f4 100644 --- a/src/virtio/vulkan/vn_physical_device.c +++ b/src/virtio/vulkan/vn_physical_device.c @@ -720,45 +720,31 @@ vn_physical_device_init_memory_properties( /* Kernel makes every mapping coherent. If a memory type is truly * incoherent, it's better to remove the host-visible flag than silently * making it coherent. However, for app compatibility purpose, when - * coherent-cached memory type is unavailable, we emulate the first cached - * memory type with the first coherent memory type. + * coherent-cached memory type is unavailable, we append the cached bit to + * the first coherent memory type. */ - uint32_t coherent_uncached = VK_MAX_MEMORY_TYPES; - uint32_t incoherent_cached = VK_MAX_MEMORY_TYPES; + bool has_coherent_cached = false; + uint32_t first_coherent = VK_MAX_MEMORY_TYPES; VkPhysicalDeviceMemoryProperties *props = &physical_dev->memory_properties; for (uint32_t i = 0; i < props->memoryTypeCount; i++) { - const VkMemoryPropertyFlags flags = props->memoryTypes[i].propertyFlags; - const bool coherent = flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; - const bool cached = flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT; - if (coherent && cached) { - coherent_uncached = VK_MAX_MEMORY_TYPES; - incoherent_cached = VK_MAX_MEMORY_TYPES; - break; - } else if (coherent && coherent_uncached == VK_MAX_MEMORY_TYPES) { - coherent_uncached = i; - } else if (cached && incoherent_cached == VK_MAX_MEMORY_TYPES) { - incoherent_cached = i; + VkMemoryPropertyFlags *flags = &props->memoryTypes[i].propertyFlags; + const bool coherent = *flags & VK_MEMORY_PROPERTY_HOST_COHERENT_BIT; + const bool cached = *flags & VK_MEMORY_PROPERTY_HOST_CACHED_BIT; + if (coherent) { + if (first_coherent == VK_MAX_MEMORY_TYPES) + first_coherent = i; + if (cached) + has_coherent_cached = true; + } else if (cached) { + *flags &= ~(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | + VK_MEMORY_PROPERTY_HOST_CACHED_BIT); } } - for (uint32_t i = 0; i < props->memoryTypeCount; i++) { - VkMemoryType *type = &props->memoryTypes[i]; - if (i == incoherent_cached) { - /* Only get here if no coherent+cached type is available, and the - * spec guarantees that there is at least one coherent type, so it - * must be coherent+uncached, hence the index is always valid. - */ - assert(coherent_uncached < props->memoryTypeCount); - type->heapIndex = props->memoryTypes[coherent_uncached].heapIndex; - } else if (!(type->propertyFlags & - VK_MEMORY_PROPERTY_HOST_COHERENT_BIT)) { - type->propertyFlags &= ~(VK_MEMORY_PROPERTY_HOST_VISIBLE_BIT | - VK_MEMORY_PROPERTY_HOST_CACHED_BIT); - } + if (!has_coherent_cached) { + props->memoryTypes[first_coherent].propertyFlags |= + VK_MEMORY_PROPERTY_HOST_CACHED_BIT; } - - physical_dev->coherent_uncached = coherent_uncached; - physical_dev->incoherent_cached = incoherent_cached; } static void diff --git a/src/virtio/vulkan/vn_physical_device.h b/src/virtio/vulkan/vn_physical_device.h index 8bd106dc0cb..cc9dbb219d3 100644 --- a/src/virtio/vulkan/vn_physical_device.h +++ b/src/virtio/vulkan/vn_physical_device.h @@ -80,8 +80,6 @@ struct vn_physical_device { bool sparse_binding_disabled; VkPhysicalDeviceMemoryProperties memory_properties; - uint32_t coherent_uncached; - uint32_t incoherent_cached; struct { VkExternalMemoryHandleTypeFlagBits renderer_handle_type;