From b72ec453bd6fc451db5c8583a3245ae1fc36ee40 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Tue, 19 Jul 2022 15:07:42 -0700 Subject: [PATCH] d3d12: Add a list of contexts alive for the current screen When a resource is destroyed, we'll need to let the contexts know. This is guarded by the submit mutex, because we'll already be holding that for at least one place where we want to iterate this list, and it's low-frequency enough that re-using it is simpler than adding more locks and creating confusing lock ordering. Reviewed-by: Bill Kristiansen Part-of: --- src/gallium/drivers/d3d12/d3d12_context.cpp | 9 +++++++++ src/gallium/drivers/d3d12/d3d12_context.h | 1 + src/gallium/drivers/d3d12/d3d12_screen.cpp | 2 ++ src/gallium/drivers/d3d12/d3d12_screen.h | 2 ++ 4 files changed, 14 insertions(+) diff --git a/src/gallium/drivers/d3d12/d3d12_context.cpp b/src/gallium/drivers/d3d12/d3d12_context.cpp index d60c44d..78fc5ef 100644 --- a/src/gallium/drivers/d3d12/d3d12_context.cpp +++ b/src/gallium/drivers/d3d12/d3d12_context.cpp @@ -71,6 +71,11 @@ d3d12_context_destroy(struct pipe_context *pctx) { struct d3d12_context *ctx = d3d12_context(pctx); + struct d3d12_screen *screen = d3d12_screen(pctx->screen); + mtx_lock(&screen->submit_mutex); + list_del(&ctx->context_list_entry); + mtx_unlock(&screen->submit_mutex); + #ifdef _WIN32 if (ctx->dxil_validator) dxil_destroy_validator(ctx->dxil_validator); @@ -2631,6 +2636,10 @@ d3d12_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) return NULL; } + mtx_lock(&screen->submit_mutex); + list_addtail(&ctx->context_list_entry, &screen->context_list); + mtx_unlock(&screen->submit_mutex); + if (flags & PIPE_CONTEXT_PREFER_THREADED) return threaded_context_create(&ctx->base, &screen->transfer_pool, diff --git a/src/gallium/drivers/d3d12/d3d12_context.h b/src/gallium/drivers/d3d12/d3d12_context.h index c769991..3c366f9 100644 --- a/src/gallium/drivers/d3d12/d3d12_context.h +++ b/src/gallium/drivers/d3d12/d3d12_context.h @@ -162,6 +162,7 @@ struct d3d12_context { struct pipe_context base; struct slab_child_pool transfer_pool; struct slab_child_pool transfer_pool_unsync; + struct list_head context_list_entry; struct threaded_context *threaded_context; struct primconvert_context *primconvert; struct blitter_context *blitter; diff --git a/src/gallium/drivers/d3d12/d3d12_screen.cpp b/src/gallium/drivers/d3d12/d3d12_screen.cpp index 11dc0c3..3306610 100644 --- a/src/gallium/drivers/d3d12/d3d12_screen.cpp +++ b/src/gallium/drivers/d3d12/d3d12_screen.cpp @@ -1149,6 +1149,8 @@ d3d12_init_screen_base(struct d3d12_screen *screen, struct sw_winsys *winsys, LU mtx_init(&screen->descriptor_pool_mutex, mtx_plain); mtx_init(&screen->submit_mutex, mtx_plain); + list_inithead(&screen->context_list); + screen->base.get_vendor = d3d12_get_vendor; screen->base.get_device_vendor = d3d12_get_device_vendor; screen->base.get_param = d3d12_get_param; diff --git a/src/gallium/drivers/d3d12/d3d12_screen.h b/src/gallium/drivers/d3d12/d3d12_screen.h index 500dc08..54cb32d 100644 --- a/src/gallium/drivers/d3d12/d3d12_screen.h +++ b/src/gallium/drivers/d3d12/d3d12_screen.h @@ -77,6 +77,8 @@ struct d3d12_screen { ID3D12Fence *residency_fence; uint64_t residency_fence_value; + struct list_head context_list; + struct slab_parent_pool transfer_pool; struct pb_manager *bufmgr; struct pb_manager *cache_bufmgr; -- 2.7.4