From 69d7a20fa61c42104ade7cf12b9e7c8f618a8d07 Mon Sep 17 00:00:00 2001 From: Karmjit Mahil Date: Tue, 28 Apr 2026 13:16:53 +0100 Subject: [PATCH] freedreno: Add heap_memory_percent driconf support Note: instead of using the common heuristic, the old behavior is maintained. Signed-off-by: Karmjit Mahil --- .../drivers/freedreno/driinfo_freedreno.h | 1 + .../drivers/freedreno/freedreno_screen.c | 35 ++++++++++--------- .../drivers/freedreno/freedreno_screen.h | 3 +- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src/gallium/drivers/freedreno/driinfo_freedreno.h b/src/gallium/drivers/freedreno/driinfo_freedreno.h index 1920b3e59e3..4b0dcff4386 100644 --- a/src/gallium/drivers/freedreno/driinfo_freedreno.h +++ b/src/gallium/drivers/freedreno/driinfo_freedreno.h @@ -1,6 +1,7 @@ // freedreno specific driconf options DRI_CONF_SECTION_MISCELLANEOUS + DRI_CONF_HEAP_MEMORY_PERCENT(0) DRI_CONF_DISABLE_CONSERVATIVE_LRZ(false) DRI_CONF_DISABLE_EXPLICIT_SYNC_HEURISTIC(false) DRI_CONF_SECTION_END diff --git a/src/gallium/drivers/freedreno/freedreno_screen.c b/src/gallium/drivers/freedreno/freedreno_screen.c index 4b128d437f1..8c85c33bade 100644 --- a/src/gallium/drivers/freedreno/freedreno_screen.c +++ b/src/gallium/drivers/freedreno/freedreno_screen.c @@ -12,6 +12,7 @@ #include "util/format/u_format.h" #include "util/format/u_format_s3tc.h" +#include "util/os_misc.h" #include "util/u_debug.h" #include "util/u_inlines.h" #include "util/u_memory.h" @@ -25,7 +26,6 @@ #include #include #include "drm-uapi/drm_fourcc.h" -#include #include "freedreno_fence.h" #include "freedreno_perfetto.h" @@ -186,18 +186,21 @@ fd_screen_destroy(struct pipe_screen *pscreen) static uint64_t get_memory_size(struct fd_screen *screen) { - uint64_t system_memory; + float percent = screen->driconf.heap_memory_percent; + uint64_t va_size = 0; - if (!os_get_total_physical_memory(&system_memory)) - return 0; - if (fd_device_version(screen->dev) >= FD_VERSION_VA_SIZE) { - uint64_t va_size; - if (!fd_pipe_get_param(screen->pipe, FD_VA_SIZE, &va_size)) { - system_memory = MIN2(system_memory / 2, va_size); - } - } + if (fd_device_version(screen->dev) >= FD_VERSION_VA_SIZE) + fd_pipe_get_param(screen->pipe, FD_VA_SIZE, &va_size); - return system_memory; + if (percent == OS_GPU_HEAP_SIZE_HEURISTIC) + percent = va_size ? 0.5f : 1.0f; + + uint64_t memory = os_get_gpu_heap_size(percent, NULL); + + if (va_size) + memory = MIN2(memory, va_size); + + return memory; } static void @@ -351,11 +354,11 @@ fd_init_compute_caps(struct fd_screen *screen) caps->max_threads_per_block = options->max_workgroup_invocations; - caps->max_global_size = screen->ram_size; + caps->max_global_size = os_get_gpu_heap_size(1.0f, NULL); caps->max_local_size = screen->info->cs_shared_mem_size; - caps->max_mem_alloc_size = screen->ram_size; + caps->max_mem_alloc_size = caps->max_global_size; caps->max_clock_frequency = screen->max_freq / 1000000; @@ -1000,6 +1003,8 @@ fd_screen_create(int fd, driParseConfigFiles(config->options, config->options_info, 0, "msm", NULL, fd_dev_name(screen->dev_id), NULL, 0, NULL, 0); + screen->driconf.heap_memory_percent = + driQueryOptionf(config->options, "heap_memory_percent"); screen->driconf.conservative_lrz = !driQueryOptionb(config->options, "disable_conservative_lrz"); screen->driconf.enable_throttling = @@ -1009,10 +1014,6 @@ fd_screen_create(int fd, if (driQueryOptionb(config->options, "disable_explicit_sync_heuristic")) fd_device_disable_explicit_sync_heuristic(dev); - struct sysinfo si; - sysinfo(&si); - screen->ram_size = si.totalram; - DBG("Pipe Info:"); DBG(" GPU-id: %s", fd_dev_name(screen->dev_id)); DBG(" Chip-id: 0x%016"PRIx64, screen->chip_id); diff --git a/src/gallium/drivers/freedreno/freedreno_screen.h b/src/gallium/drivers/freedreno/freedreno_screen.h index 137fea1c5b8..91c98f4b9bf 100644 --- a/src/gallium/drivers/freedreno/freedreno_screen.h +++ b/src/gallium/drivers/freedreno/freedreno_screen.h @@ -69,7 +69,6 @@ struct fd_screen { uint32_t gpu_id; /* 220, 305, etc */ uint64_t chip_id; /* coreid:8 majorrev:8 minorrev:8 patch:8 */ uint32_t max_freq; - uint32_t ram_size; uint32_t max_rts; /* max # of render targets */ uint32_t priority_mask; unsigned prio_low, prio_norm, prio_high; /* remap low/norm/high priority to kernel priority */ @@ -93,6 +92,8 @@ struct fd_screen { /* If "dual_color_blend_by_location" workaround is enabled */ bool dual_color_blend_by_location; + + float heap_memory_percent; } driconf; struct fd_dev_info dev_info;