mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-08 09:08:10 +02:00
util: Add heap_memory_percent driconf option
Also adds helper function to be used by drivers. Signed-off-by: Karmjit Mahil <karmjit.mahil@igalia.com> Reviewed-by: Iago Toral Quiroga <itoral@igalia.com>
This commit is contained in:
parent
38cf44a733
commit
fbdd9bec92
3 changed files with 53 additions and 0 deletions
|
|
@ -541,6 +541,10 @@
|
|||
DRI_CONF_OPT_B(no_fp16, def, \
|
||||
"Disable 16-bit float support")
|
||||
|
||||
#define DRI_CONF_HEAP_MEMORY_PERCENT(def) \
|
||||
DRI_CONF_OPT_F(heap_memory_percent, def, 0.0, 1.0, \
|
||||
"Percentage of total system memory to report as gpu heap memory (0 = driver default)")
|
||||
|
||||
#define DRI_CONF_VK_ZERO_VRAM(def) \
|
||||
DRI_CONF_OPT_B(vk_zero_vram, def, \
|
||||
"Initialize to zero all VRAM allocations")
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
#include "ralloc.h"
|
||||
#include "simple_mtx.h"
|
||||
#include "u_debug.h"
|
||||
#include "u_math.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -39,6 +39,7 @@
|
|||
#include <stddef.h>
|
||||
|
||||
#include "util/detect.h"
|
||||
#include "util/u_math.h"
|
||||
|
||||
|
||||
#if DETECT_OS_POSIX
|
||||
|
|
@ -158,6 +159,53 @@ os_unset_option(const char *name)
|
|||
bool
|
||||
os_get_total_physical_memory(uint64_t *size);
|
||||
|
||||
#define OS_GPU_HEAP_SIZE_HEURISTIC (0.0f)
|
||||
|
||||
/*
|
||||
* Calculate the gpu heap size based on a percentage of @memory.
|
||||
* If @percent is OS_GPU_HEAP_SIZE_HEURISTIC:
|
||||
* Use a heuristic.
|
||||
*/
|
||||
static inline uint64_t
|
||||
os_gpu_heap_size_calculate(uint64_t memory, float percent, float *percent_out)
|
||||
{
|
||||
if (percent == OS_GPU_HEAP_SIZE_HEURISTIC) {
|
||||
/* We don't want to burn too much ram with the GPU on devices with a small
|
||||
* amount of memory.
|
||||
*/
|
||||
if (memory <= 1ull * 1024ull * 1024ull * 1024ull)
|
||||
percent = 0.25f;
|
||||
else if (memory <= 4ull * 1024ull * 1024ull * 1024ull)
|
||||
percent = 0.5f;
|
||||
else
|
||||
percent = 0.75f;
|
||||
}
|
||||
|
||||
if (percent_out)
|
||||
*percent_out = percent;
|
||||
|
||||
return ROUND_DOWN_TO((uint64_t)(memory * percent), 1 << 20);
|
||||
}
|
||||
|
||||
/*
|
||||
* Calculate the gpu heap size based on a percentage of the system memory.
|
||||
* If @percent is OS_GPU_HEAP_SIZE_HEURISTIC:
|
||||
* Use a heuristic.
|
||||
*
|
||||
* @percent_out is preserved on failure.
|
||||
*/
|
||||
static inline uint64_t
|
||||
os_get_gpu_heap_size(float percent, float *percent_out)
|
||||
{
|
||||
uint64_t memory;
|
||||
|
||||
const bool success = os_get_total_physical_memory(&memory);
|
||||
if (!success)
|
||||
return 0;
|
||||
|
||||
return os_gpu_heap_size_calculate(memory, percent, percent_out);
|
||||
}
|
||||
|
||||
/*
|
||||
* Amount of physical memory available to a process
|
||||
*/
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue