summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSagar Ghuge <sagar.ghuge@intel.com>2021-08-17 18:23:11 -0700
committerMarge Bot <eric+marge@anholt.net>2021-08-18 17:13:00 +0000
commit57bfd7122f711db4db9100254432e27e877fad09 (patch)
tree704f0f8179ffb6cdd0399b5b7e3a9b1fdda8aee4
parent758662759dcf31c64fd62d5b3d280e2c7791ce63 (diff)
anv: Fix VK_EXT_memory_budget to consider VRAM if available
Instead of calling the OS query, re-run anv_update_meminfo to get the latest from either the kernel memory info API or the OS as appropriate. Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/5173 Signed-off-by: Sagar Ghuge <sagar.ghuge@intel.com> Co-authored-by: Jason Ekstrand <jason@jlekstrand.net> Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12433>
-rw-r--r--src/intel/vulkan/anv_device.c60
1 files changed, 46 insertions, 14 deletions
diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c
index 69a143cd345..ef02557c4f1 100644
--- a/src/intel/vulkan/anv_device.c
+++ b/src/intel/vulkan/anv_device.c
@@ -338,7 +338,7 @@ anv_compute_sys_heap_size(struct anv_physical_device *device,
}
static VkResult MUST_CHECK
-anv_init_meminfo(struct anv_physical_device *device, int fd)
+anv_gather_meminfo(struct anv_physical_device *device, int fd, bool update)
{
char sys_mem_regions[sizeof(struct drm_i915_query_memory_regions) +
sizeof(struct drm_i915_memory_region_info)];
@@ -397,8 +397,14 @@ anv_init_meminfo(struct anv_physical_device *device, int fd)
uint64_t available = MIN2(size, info->unallocated_size);
- region->region = info->region;
- region->size = size;
+ if (update) {
+ assert(region->region.memory_class == info->region.memory_class);
+ assert(region->region.memory_instance == info->region.memory_instance);
+ assert(region->size == size);
+ } else {
+ region->region = info->region;
+ region->size = size;
+ }
region->available = available;
}
@@ -408,6 +414,20 @@ anv_init_meminfo(struct anv_physical_device *device, int fd)
return VK_SUCCESS;
}
+static VkResult MUST_CHECK
+anv_init_meminfo(struct anv_physical_device *device, int fd)
+{
+ return anv_gather_meminfo(device, fd, false);
+}
+
+static void
+anv_update_meminfo(struct anv_physical_device *device, int fd)
+{
+ ASSERTED VkResult result = anv_gather_meminfo(device, fd, true);
+ assert(result == VK_SUCCESS);
+}
+
+
static VkResult
anv_physical_device_init_heaps(struct anv_physical_device *device, int fd)
{
@@ -2786,28 +2806,40 @@ anv_get_memory_budget(VkPhysicalDevice physicalDevice,
VkPhysicalDeviceMemoryBudgetPropertiesEXT *memoryBudget)
{
ANV_FROM_HANDLE(anv_physical_device, device, physicalDevice);
- uint64_t sys_available;
- ASSERTED bool has_available_memory =
- os_get_available_system_memory(&sys_available);
- assert(has_available_memory);
- VkDeviceSize total_heaps_size = 0;
- for (size_t i = 0; i < device->memory.heap_count; i++)
- total_heaps_size += device->memory.heaps[i].size;
+ anv_update_meminfo(device, device->local_fd);
+
+ VkDeviceSize total_sys_heaps_size = 0, total_vram_heaps_size = 0;
+ for (size_t i = 0; i < device->memory.heap_count; i++) {
+ if (device->memory.heaps[i].is_local_mem) {
+ total_vram_heaps_size += device->memory.heaps[i].size;
+ } else {
+ total_sys_heaps_size += device->memory.heaps[i].size;
+ }
+ }
for (size_t i = 0; i < device->memory.heap_count; i++) {
VkDeviceSize heap_size = device->memory.heaps[i].size;
VkDeviceSize heap_used = device->memory.heaps[i].used;
- VkDeviceSize heap_budget;
+ VkDeviceSize heap_budget, total_heaps_size;
+ uint64_t mem_available = 0;
+
+ if (device->memory.heaps[i].is_local_mem) {
+ total_heaps_size = total_vram_heaps_size;
+ mem_available = device->vram.available;
+ } else {
+ total_heaps_size = total_sys_heaps_size;
+ mem_available = device->sys.available;
+ }
double heap_proportion = (double) heap_size / total_heaps_size;
- VkDeviceSize sys_available_prop = sys_available * heap_proportion;
+ VkDeviceSize available_prop = mem_available * heap_proportion;
/*
* Let's not incite the app to starve the system: report at most 90% of
- * available system memory.
+ * the available heap memory.
*/
- uint64_t heap_available = sys_available_prop * 9 / 10;
+ uint64_t heap_available = available_prop * 9 / 10;
heap_budget = MIN2(heap_size, heap_used + heap_available);
/*