From 0e1ef96992dc1e82ce6f0578048805f4c2b15cb2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=80=9A=E6=B4=B2?= Date: Thu, 19 Jun 2025 15:54:26 +0800 Subject: [PATCH] GPU (Linux): detect shared vram usage of AMD GPU --- src/detection/gpu/gpu_drm.c | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/detection/gpu/gpu_drm.c b/src/detection/gpu/gpu_drm.c index 72c69acd8..f03d393ae 100644 --- a/src/detection/gpu/gpu_drm.c +++ b/src/detection/gpu/gpu_drm.c @@ -50,12 +50,20 @@ const char* ffDrmDetectRadeon(const FFGPUOptions* options, FFGPUResult* gpu, con if (ioctl(fd, DRM_IOCTL_RADEON_GEM_INFO, &gemInfo) >= 0 && gemInfo.vram_visible > 0) { gpu->dedicated.total = gemInfo.vram_visible; + gpu->shared.total = gemInfo.gart_size; + uint64_t memSize; if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &(struct drm_radeon_info) { .request = RADEON_INFO_VRAM_USAGE, // uint64_t .value = (uintptr_t) &memSize, }) >= 0) gpu->dedicated.used = memSize; + + if (ioctl(fd, DRM_IOCTL_RADEON_INFO, &(struct drm_radeon_info) { + .request = RADEON_INFO_GTT_USAGE, // uint64_t + .value = (uintptr_t) &memSize, + }) >= 0) + gpu->shared.used = memSize; } } @@ -126,16 +134,13 @@ const char* ffDrmDetectAmdgpu(const FFGPUOptions* options, FFGPUResult* gpu, con struct amdgpu_heap_info heapInfo; if (ffamdgpu_query_heap_info(handle, AMDGPU_GEM_DOMAIN_VRAM, 0, &heapInfo) >= 0) { - if (gpu->type == FF_GPU_TYPE_DISCRETE) - { - gpu->dedicated.total = heapInfo.heap_size; - gpu->dedicated.used = heapInfo.heap_usage; - } - else - { - gpu->shared.total = heapInfo.heap_size; - gpu->shared.used = heapInfo.heap_usage; - } + gpu->dedicated.total = heapInfo.heap_size; + gpu->dedicated.used = heapInfo.heap_usage; + } + if (ffamdgpu_query_heap_info(handle, AMDGPU_GEM_DOMAIN_GTT, 0, &heapInfo) >= 0) + { + gpu->shared.total = heapInfo.heap_size; + gpu->shared.used = heapInfo.heap_usage; } }