Mesa (main): d3d12: Notify contexts about deletion of bos

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Fri Jul 22 14:58:07 UTC 2022


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

Author: Jesse Natalie <jenatali at microsoft.com>
Date:   Tue Jul 19 15:42:04 2022 -0700

d3d12: Notify contexts about deletion of bos

Reviewed-by: Bill Kristiansen <billkris at microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17688>

---

 src/gallium/drivers/d3d12/d3d12_batch.cpp   |  3 +++
 src/gallium/drivers/d3d12/d3d12_bufmgr.cpp  | 26 ++++++++++++++++++--------
 src/gallium/drivers/d3d12/d3d12_context.cpp |  1 +
 src/gallium/drivers/d3d12/d3d12_context.h   |  2 ++
 4 files changed, 24 insertions(+), 8 deletions(-)

diff --git a/src/gallium/drivers/d3d12/d3d12_batch.cpp b/src/gallium/drivers/d3d12/d3d12_batch.cpp
index 93fa816e363..f511e3c4cdf 100644
--- a/src/gallium/drivers/d3d12/d3d12_batch.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_batch.cpp
@@ -216,6 +216,9 @@ d3d12_end_batch(struct d3d12_context *ctx, struct d3d12_batch *batch)
    screen->cmdqueue->ExecuteCommandLists(1, cmdlists);
    batch->fence = d3d12_create_fence(screen);
 
+   /* TODO clean up resource state based on destroyed resources */
+   util_dynarray_clear(&ctx->recently_destroyed_bos);
+
    mtx_unlock(&screen->submit_mutex);
 }
 
diff --git a/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp b/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp
index 993906375b9..68df8e90fd6 100644
--- a/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp
@@ -22,6 +22,7 @@
  */
 
 #include "d3d12_bufmgr.h"
+#include "d3d12_context.h"
 #include "d3d12_format.h"
 #include "d3d12_screen.h"
 
@@ -182,6 +183,7 @@ d3d12_bo_wrap_buffer(struct d3d12_screen *screen, struct pb_buffer *buf)
    bo->buffer = buf;
    bo->trans_state = NULL; /* State from base BO will be used */
    bo->unique_id = p_atomic_inc_return(&screen->resource_id_generator);
+   bo->residency_status = d3d12_evicted;
 
    return bo;
 }
@@ -197,17 +199,25 @@ d3d12_bo_unreference(struct d3d12_bo *bo)
    if (pipe_reference_described(&bo->reference, NULL,
                                 (debug_reference_descriptor)
                                 d3d12_debug_describe_bo)) {
-      if (bo->buffer) {
+      if (bo->buffer)
          pb_reference(&bo->buffer, NULL);
-      } else {
-         mtx_lock(&bo->screen->submit_mutex);
-         if (bo->residency_status != d3d12_evicted) {
-            list_del(&bo->residency_list_entry);
-         }
-         mtx_unlock(&bo->screen->submit_mutex);
+
+      mtx_lock(&bo->screen->submit_mutex);
+
+      if (bo->residency_status != d3d12_evicted)
+         list_del(&bo->residency_list_entry);
+
+      /* MSVC's offsetof fails when the name is ambiguous between struct and function */
+      typedef struct d3d12_context d3d12_context_type;
+      list_for_each_entry(d3d12_context_type, ctx, &bo->screen->context_list, context_list_entry)
+         util_dynarray_append(&ctx->recently_destroyed_bos, uint64_t, bo->unique_id);
+
+      mtx_unlock(&bo->screen->submit_mutex);
+
+      if (bo->trans_state)
          delete bo->trans_state;
+      if (bo->res)
          bo->res->Release();
-      }
       FREE(bo);
    }
 }
diff --git a/src/gallium/drivers/d3d12/d3d12_context.cpp b/src/gallium/drivers/d3d12/d3d12_context.cpp
index 78fc5ef0c21..4d0724856ca 100644
--- a/src/gallium/drivers/d3d12/d3d12_context.cpp
+++ b/src/gallium/drivers/d3d12/d3d12_context.cpp
@@ -102,6 +102,7 @@ d3d12_context_destroy(struct pipe_context *pctx)
    d3d12_compute_transform_cache_destroy(ctx);
    pipe_resource_reference(&ctx->pstipple.texture, nullptr);
    pipe_sampler_view_reference(&ctx->pstipple.sampler_view, nullptr);
+   util_dynarray_fini(&ctx->recently_destroyed_bos);
    FREE(ctx->pstipple.sampler_cso);
 
    u_suballocator_destroy(&ctx->query_allocator);
diff --git a/src/gallium/drivers/d3d12/d3d12_context.h b/src/gallium/drivers/d3d12/d3d12_context.h
index 3c366f9d16d..e77b593567d 100644
--- a/src/gallium/drivers/d3d12/d3d12_context.h
+++ b/src/gallium/drivers/d3d12/d3d12_context.h
@@ -179,6 +179,8 @@ struct d3d12_context {
    struct d3d12_batch batches[4];
    unsigned current_batch_idx;
 
+   struct util_dynarray recently_destroyed_bos;
+
    struct pipe_constant_buffer cbufs[PIPE_SHADER_TYPES][PIPE_MAX_CONSTANT_BUFFERS];
    struct pipe_framebuffer_state fb;
    struct pipe_vertex_buffer vbs[PIPE_MAX_ATTRIBS];



More information about the mesa-commit mailing list