Module: Mesa
Branch: main
Commit: c3c3a8926a461da08a815bc0af8fd9fdbd1dca59
URL:    
http://cgit.freedesktop.org/mesa/mesa/commit/?id=c3c3a8926a461da08a815bc0af8fd9fdbd1dca59

Author: Tatsuyuki Ishi <[email protected]>
Date:   Sun Aug 20 17:29:19 2023 +0900

radv/amdgpu: Separate the concept of residency from use_global_list.

A BO can be always resident by two ways:
1. Through kernel bookkeeping. The BO is created with
   AMDGPU_GEM_CREATE_VM_ALWAYS_VALID and bo->is_local gets set to true.
2. Through the driver global BO list. On every submission, the global
   BO list is added to the CS's BO list.

Until now, use_global_list reflected either 1. or 2. . This commit
changes it to reflect 2. only, and update callsites that checks for
residency to use a new helper.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/26591>

---

 src/amd/vulkan/radv_radeon_winsys.h           | 10 +++++++++-
 src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c |  4 ++--
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/src/amd/vulkan/radv_radeon_winsys.h 
b/src/amd/vulkan/radv_radeon_winsys.h
index 6a05a36955a..7c1ee12b150 100644
--- a/src/amd/vulkan/radv_radeon_winsys.h
+++ b/src/amd/vulkan/radv_radeon_winsys.h
@@ -184,8 +184,10 @@ struct radeon_winsys_ctx;
 
 struct radeon_winsys_bo {
    uint64_t va;
+   /* buffer is created with AMDGPU_GEM_CREATE_VM_ALWAYS_VALID */
    bool is_local;
    bool vram_no_cpu_access;
+   /* buffer is added to the BO list of all submissions */
    bool use_global_list;
    enum radeon_bo_domain initial_domain;
 };
@@ -345,10 +347,16 @@ radv_buffer_get_va(const struct radeon_winsys_bo *bo)
    return bo->va;
 }
 
+static inline bool
+radv_buffer_is_resident(const struct radeon_winsys_bo *bo)
+{
+   return bo->use_global_list || bo->is_local;
+}
+
 static inline void
 radv_cs_add_buffer(struct radeon_winsys *ws, struct radeon_cmdbuf *cs, struct 
radeon_winsys_bo *bo)
 {
-   if (bo->use_global_list)
+   if (radv_buffer_is_resident(bo))
       return;
 
    ws->cs_add_buffer(cs, bo);
diff --git a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c 
b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c
index dc400b3c55f..1a32f9b58d7 100644
--- a/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c
+++ b/src/amd/vulkan/winsys/amdgpu/radv_amdgpu_bo.c
@@ -151,7 +151,7 @@ radv_amdgpu_winsys_bo_virtual_bind(struct radeon_winsys 
*_ws, struct radeon_wins
     * The issue still exists for non-global BO but it will be addressed later, 
once we are 100% it's
     * RADV fault (mostly because the solution looks more complicated).
     */
-   if (bo && bo->base.use_global_list) {
+   if (bo && radv_buffer_is_resident(&bo->base)) {
       bo = NULL;
       bo_offset = 0;
    }
@@ -514,7 +514,7 @@ radv_amdgpu_winsys_bo_create(struct radeon_winsys *_ws, 
uint64_t size, unsigned
 
    bo->bo = buf_handle;
    bo->base.initial_domain = initial_domain;
-   bo->base.use_global_list = bo->base.is_local;
+   bo->base.use_global_list = false;
    bo->priority = priority;
 
    r = amdgpu_bo_export(buf_handle, amdgpu_bo_handle_type_kms, &bo->bo_handle);

Reply via email to