summaryrefslogtreecommitdiffstats
path: root/src/amd/vulkan/winsys
diff options
context:
space:
mode:
authorSamuel Pitoiset <[email protected]>2019-01-09 14:40:00 +0100
committerSamuel Pitoiset <[email protected]>2019-01-15 11:18:37 +0100
commit7bef19201822ab2aebfd244142ff3a23535019a7 (patch)
tree68f8db1182d8f7a089cceca5802477d7dc989e12 /src/amd/vulkan/winsys
parent9784400a6b800ae9d08aa8de4d5262c0214fb339 (diff)
radv: add support for VK_EXT_memory_budget
A simple Vulkan extension that allows apps to query size and usage of all exposed memory heaps. The different usage values are not really accurate because they are per drm-fd, but they should be close enough. Signed-off-by: Samuel Pitoiset <[email protected]> Reviewed-by: Alex Smith <[email protected]> Reviewed-by: Bas Nieuwenhuizen <[email protected]>
Diffstat (limited to 'src/amd/vulkan/winsys')
-rw-r--r--src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c38
-rw-r--r--src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c6
-rw-r--r--src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h4
3 files changed, 47 insertions, 1 deletions
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c
index a9bd55eac8f..7194d5a3236 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c
@@ -249,6 +249,7 @@ radv_amdgpu_winsys_bo_virtual_bind(struct radeon_winsys_bo *_parent,
static void radv_amdgpu_winsys_bo_destroy(struct radeon_winsys_bo *_bo)
{
struct radv_amdgpu_winsys_bo *bo = radv_amdgpu_winsys_bo(_bo);
+ struct radv_amdgpu_winsys *ws = bo->ws;
if (p_atomic_dec_return(&bo->ref_count))
return;
@@ -269,6 +270,17 @@ static void radv_amdgpu_winsys_bo_destroy(struct radeon_winsys_bo *_bo)
0, AMDGPU_VA_OP_UNMAP);
amdgpu_bo_free(bo->bo);
}
+
+ if (bo->initial_domain & RADEON_DOMAIN_VRAM)
+ p_atomic_add(&ws->allocated_vram,
+ -align64(bo->size, ws->info.gart_page_size));
+ if (bo->base.vram_cpu_access)
+ p_atomic_add(&ws->allocated_vram_vis,
+ -align64(bo->size, ws->info.gart_page_size));
+ if (bo->initial_domain & RADEON_DOMAIN_GTT)
+ p_atomic_add(&ws->allocated_gtt,
+ -align64(bo->size, ws->info.gart_page_size));
+
amdgpu_va_range_free(bo->va_handle);
FREE(bo);
}
@@ -344,8 +356,10 @@ radv_amdgpu_winsys_bo_create(struct radeon_winsys *_ws,
if (initial_domain & RADEON_DOMAIN_GTT)
request.preferred_heap |= AMDGPU_GEM_DOMAIN_GTT;
- if (flags & RADEON_FLAG_CPU_ACCESS)
+ if (flags & RADEON_FLAG_CPU_ACCESS) {
+ bo->base.vram_cpu_access = initial_domain & RADEON_DOMAIN_VRAM;
request.flags |= AMDGPU_GEM_CREATE_CPU_ACCESS_REQUIRED;
+ }
if (flags & RADEON_FLAG_NO_CPU_ACCESS)
request.flags |= AMDGPU_GEM_CREATE_NO_CPU_ACCESS;
if (flags & RADEON_FLAG_GTT_WC)
@@ -378,6 +392,17 @@ radv_amdgpu_winsys_bo_create(struct radeon_winsys *_ws,
bo->bo = buf_handle;
bo->initial_domain = initial_domain;
bo->is_shared = false;
+
+ if (initial_domain & RADEON_DOMAIN_VRAM)
+ p_atomic_add(&ws->allocated_vram,
+ align64(bo->size, ws->info.gart_page_size));
+ if (bo->base.vram_cpu_access)
+ p_atomic_add(&ws->allocated_vram_vis,
+ align64(bo->size, ws->info.gart_page_size));
+ if (initial_domain & RADEON_DOMAIN_GTT)
+ p_atomic_add(&ws->allocated_gtt,
+ align64(bo->size, ws->info.gart_page_size));
+
radv_amdgpu_add_buffer_to_global_list(bo);
return (struct radeon_winsys_bo *)bo;
error_va_map:
@@ -474,6 +499,9 @@ radv_amdgpu_winsys_bo_from_ptr(struct radeon_winsys *_ws,
bo->bo = buf_handle;
bo->initial_domain = RADEON_DOMAIN_GTT;
+ p_atomic_add(&ws->allocated_gtt,
+ align64(bo->size, ws->info.gart_page_size));
+
radv_amdgpu_add_buffer_to_global_list(bo);
return (struct radeon_winsys_bo *)bo;
@@ -538,6 +566,14 @@ radv_amdgpu_winsys_bo_from_fd(struct radeon_winsys *_ws,
bo->is_shared = true;
bo->ws = ws;
bo->ref_count = 1;
+
+ if (bo->initial_domain & RADEON_DOMAIN_VRAM)
+ p_atomic_add(&ws->allocated_vram,
+ align64(bo->size, ws->info.gart_page_size));
+ if (bo->initial_domain & RADEON_DOMAIN_GTT)
+ p_atomic_add(&ws->allocated_gtt,
+ align64(bo->size, ws->info.gart_page_size));
+
radv_amdgpu_add_buffer_to_global_list(bo);
return (struct radeon_winsys_bo *)bo;
error_va_map:
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
index 9706c04e8cd..d3a57f6b4f3 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.c
@@ -72,6 +72,12 @@ static uint64_t radv_amdgpu_winsys_query_value(struct radeon_winsys *rws,
uint64_t retval = 0;
switch (value) {
+ case RADEON_ALLOCATED_VRAM:
+ return ws->allocated_vram;
+ case RADEON_ALLOCATED_VRAM_VIS:
+ return ws->allocated_vram_vis;
+ case RADEON_ALLOCATED_GTT:
+ return ws->allocated_gtt;
case RADEON_TIMESTAMP:
amdgpu_query_info(ws->dev, AMDGPU_INFO_TIMESTAMP, 8, &retval);
return retval;
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
index 80a1c6f2926..edec0a1ed78 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_winsys.h
@@ -52,6 +52,10 @@ struct radv_amdgpu_winsys {
pthread_mutex_t global_bo_list_lock;
struct list_head global_bo_list;
+
+ uint64_t allocated_vram;
+ uint64_t allocated_vram_vis;
+ uint64_t allocated_gtt;
};
static inline struct radv_amdgpu_winsys *