radv,gallium: Add driconf option to reduce advertised VRAM size.
authorBas Nieuwenhuizen <bas@basnieuwenhuizen.nl>
Tue, 8 Sep 2020 00:02:09 +0000 (02:02 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 8 Sep 2020 23:59:35 +0000 (23:59 +0000)
To help debugging games that actually do active memory budget
management.

Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/6641>

src/amd/vulkan/radv_device.c
src/gallium/auxiliary/pipe-loader/driinfo_gallium.h
src/gallium/frontends/dri/dri_query_renderer.c
src/util/driconf.h

index ff62890..747238e 100644 (file)
@@ -128,15 +128,25 @@ radv_get_device_uuid(struct radeon_info *info, void *uuid)
 }
 
 static uint64_t
+radv_get_adjusted_vram_size(struct radv_physical_device *device)
+{
+       int ov = driQueryOptioni(&device->instance->dri_options,
+                                "override_vram_size");
+       if (ov >= 0)
+               return MIN2(device->rad_info.vram_size, (uint64_t)ov << 20);
+       return device->rad_info.vram_size;
+}
+
+static uint64_t
 radv_get_visible_vram_size(struct radv_physical_device *device)
 {
-       return MIN2(device->rad_info.vram_size, device->rad_info.vram_vis_size);
+       return MIN2(radv_get_adjusted_vram_size(device) , device->rad_info.vram_vis_size);
 }
 
 static uint64_t
 radv_get_vram_size(struct radv_physical_device *device)
 {
-       return device->rad_info.vram_size - radv_get_visible_vram_size(device);
+       return radv_get_adjusted_vram_size(device) - device->rad_info.vram_vis_size;
 }
 
 static void
@@ -609,6 +619,7 @@ DRI_CONF_BEGIN
        DRI_CONF_SECTION_END
 
        DRI_CONF_SECTION_DEBUG
+               DRI_CONF_OVERRIDE_VRAM_SIZE()
                DRI_CONF_VK_WSI_FORCE_BGRA8_UNORM_FIRST("false")
        DRI_CONF_SECTION_END
 DRI_CONF_END;
@@ -2195,7 +2206,7 @@ radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice,
                                                             RADEON_ALLOCATED_VRAM);
 
                        heap_budget = vram_size -
-                               device->ws->query_value(device->ws, RADEON_VRAM_USAGE) +
+                               MIN2(vram_size, device->ws->query_value(device->ws, RADEON_VRAM_USAGE)) +
                                heap_usage;
 
                        memoryBudget->heapBudget[heap_index] = heap_budget;
@@ -2205,7 +2216,7 @@ radv_get_memory_budget_properties(VkPhysicalDevice physicalDevice,
                                                             RADEON_ALLOCATED_VRAM_VIS);
 
                        heap_budget = visible_vram_size -
-                               device->ws->query_value(device->ws, RADEON_VRAM_VIS_USAGE) +
+                               MIN2(visible_vram_size, device->ws->query_value(device->ws, RADEON_VRAM_VIS_USAGE)) +
                                heap_usage;
 
                        memoryBudget->heapBudget[heap_index] = heap_budget;
index 25ade27..9246f24 100644 (file)
@@ -35,6 +35,7 @@ DRI_CONF_SECTION_DEBUG
    DRI_CONF_ALLOW_DRAW_OUT_OF_ORDER("false")
    DRI_CONF_FORCE_COMPAT_PROFILE("false")
    DRI_CONF_FORCE_GL_VENDOR()
+   DRI_CONF_OVERRIDE_VRAM_SIZE()
 DRI_CONF_SECTION_END
 
 DRI_CONF_SECTION_MISCELLANEOUS
index 9a78fa3..e84c955 100644 (file)
@@ -6,6 +6,7 @@
 #include "utils.h"
 #include "dri_screen.h"
 #include "dri_query_renderer.h"
+#include "pipe-loader/pipe_loader.h"
 
 static int
 dri2_query_renderer_integer(__DRIscreen *_screen, int param,
@@ -30,11 +31,15 @@ dri2_query_renderer_integer(__DRIscreen *_screen, int param,
                                                       PIPE_CAP_ACCELERATED);
       return 0;
 
-   case __DRI2_RENDERER_VIDEO_MEMORY:
+   case __DRI2_RENDERER_VIDEO_MEMORY: {
+      int ov = driQueryOptioni(&screen->dev->option_cache, "override_vram_size");
       value[0] =
          (unsigned int)screen->base.screen->get_param(screen->base.screen,
                                                       PIPE_CAP_VIDEO_MEMORY);
+      if (ov >= 0)
+         value[0] = MIN2(ov, value[0]);
       return 0;
+   }
 
    case __DRI2_RENDERER_UNIFIED_MEMORY_ARCHITECTURE:
       value[0] =
index d7c7344..7559aa7 100644 (file)
@@ -222,6 +222,11 @@ DRI_CONF_OPT_BEGIN_B(force_compat_profile, def) \
         DRI_CONF_DESC("Force an OpenGL compatibility context") \
 DRI_CONF_OPT_END
 
+#define DRI_CONF_OVERRIDE_VRAM_SIZE() \
+DRI_CONF_OPT_BEGIN_V(override_vram_size, int, -1, "-1:2147483647") \
+        DRI_CONF_DESC("Override the VRAM size advertised to the application in MiB (-1 = default)") \
+DRI_CONF_OPT_END
+
 /**
  * \brief Image quality-related options
  */