diff --git a/src/amd/vulkan/radv_device.c b/src/amd/vulkan/radv_device.c index ff62890217b..747238e2cf9 100644 --- a/src/amd/vulkan/radv_device.c +++ b/src/amd/vulkan/radv_device.c @@ -127,16 +127,26 @@ radv_get_device_uuid(struct radeon_info *info, void *uuid) ac_compute_device_uuid(info, uuid, VK_UUID_SIZE); } +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; diff --git a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h index 25ade275d64..9246f24da0a 100644 --- a/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h +++ b/src/gallium/auxiliary/pipe-loader/driinfo_gallium.h @@ -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 diff --git a/src/gallium/frontends/dri/dri_query_renderer.c b/src/gallium/frontends/dri/dri_query_renderer.c index 9a78fa38da6..e84c955334d 100644 --- a/src/gallium/frontends/dri/dri_query_renderer.c +++ b/src/gallium/frontends/dri/dri_query_renderer.c @@ -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] = diff --git a/src/util/driconf.h b/src/util/driconf.h index d7c734464cc..7559aa7aa1e 100644 --- a/src/util/driconf.h +++ b/src/util/driconf.h @@ -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 */