Module: Mesa Branch: main Commit: 2c00c069fee756526f62eb11d6d339002336f604 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=2c00c069fee756526f62eb11d6d339002336f604
Author: Giancarlo Devich <[email protected]> Date: Fri Feb 24 16:19:16 2023 -0800 d3d12: Assign up to 16 simultaneously active contexts unique IDs Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/21528> --- src/gallium/drivers/d3d12/d3d12_context.cpp | 6 ++++++ src/gallium/drivers/d3d12/d3d12_context.h | 4 ++++ src/gallium/drivers/d3d12/d3d12_screen.cpp | 6 ++++++ src/gallium/drivers/d3d12/d3d12_screen.h | 2 ++ 4 files changed, 18 insertions(+) diff --git a/src/gallium/drivers/d3d12/d3d12_context.cpp b/src/gallium/drivers/d3d12/d3d12_context.cpp index 933c2956a94..d3a0330cb5f 100644 --- a/src/gallium/drivers/d3d12/d3d12_context.cpp +++ b/src/gallium/drivers/d3d12/d3d12_context.cpp @@ -69,6 +69,8 @@ d3d12_context_destroy(struct pipe_context *pctx) struct d3d12_screen *screen = d3d12_screen(pctx->screen); mtx_lock(&screen->submit_mutex); list_del(&ctx->context_list_entry); + if (ctx->id != D3D12_CONTEXT_NO_ID) + screen->context_id_list[screen->context_id_count++] = ctx->id; mtx_unlock(&screen->submit_mutex); #ifdef _WIN32 @@ -2589,6 +2591,10 @@ d3d12_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags) mtx_lock(&screen->submit_mutex); list_addtail(&ctx->context_list_entry, &screen->context_list); + if (screen->context_id_count > 0) + ctx->id = screen->context_id_list[--screen->context_id_count]; + else + ctx->id = D3D12_CONTEXT_NO_ID; mtx_unlock(&screen->submit_mutex); if (flags & PIPE_CONTEXT_PREFER_THREADED) diff --git a/src/gallium/drivers/d3d12/d3d12_context.h b/src/gallium/drivers/d3d12/d3d12_context.h index 27ff9ba80d9..7258b0c4eaf 100644 --- a/src/gallium/drivers/d3d12/d3d12_context.h +++ b/src/gallium/drivers/d3d12/d3d12_context.h @@ -158,8 +158,12 @@ struct dxil_validator; class ResourceStateManager; #endif +#define D3D12_CONTEXT_NO_ID 0xffffffff + struct d3d12_context { struct pipe_context base; + + unsigned id; struct slab_child_pool transfer_pool; struct slab_child_pool transfer_pool_unsync; struct list_head context_list_entry; diff --git a/src/gallium/drivers/d3d12/d3d12_screen.cpp b/src/gallium/drivers/d3d12/d3d12_screen.cpp index d3757c9a65e..c1c128d9f2a 100644 --- a/src/gallium/drivers/d3d12/d3d12_screen.cpp +++ b/src/gallium/drivers/d3d12/d3d12_screen.cpp @@ -1239,6 +1239,12 @@ d3d12_init_screen_base(struct d3d12_screen *screen, struct sw_winsys *winsys, LU mtx_init(&screen->submit_mutex, mtx_plain); list_inithead(&screen->context_list); + screen->context_id_count = 16; + + // Fill the array backwards, because we'll pop off the back to assign ids + for (unsigned i = 0; i < 16; ++i) + screen->context_id_list[i] = 15 - i; + slab_create_parent(&screen->transfer_pool, sizeof(struct d3d12_transfer), 16); screen->base.get_vendor = d3d12_get_vendor; diff --git a/src/gallium/drivers/d3d12/d3d12_screen.h b/src/gallium/drivers/d3d12/d3d12_screen.h index e69100754e0..de68040fb14 100644 --- a/src/gallium/drivers/d3d12/d3d12_screen.h +++ b/src/gallium/drivers/d3d12/d3d12_screen.h @@ -80,6 +80,8 @@ struct d3d12_screen { uint64_t residency_fence_value; struct list_head context_list; + unsigned context_id_list[16]; + unsigned context_id_count; struct slab_parent_pool transfer_pool; struct pb_manager *bufmgr;
