From 70e7cb444e4ef118b8bd06152cdc07fb92cb6100 Mon Sep 17 00:00:00 2001 From: Jesse Natalie Date: Wed, 20 Jul 2022 07:45:59 -0700 Subject: [PATCH] d3d12: Track a global resource state for non-simultaneous-access resources Reviewed-by: Bill Kristiansen Part-of: --- src/gallium/drivers/d3d12/d3d12_bufmgr.cpp | 28 ++++++------------- src/gallium/drivers/d3d12/d3d12_bufmgr.h | 2 ++ .../drivers/d3d12/d3d12_resource_state.cpp | 2 ++ 3 files changed, 13 insertions(+), 19 deletions(-) diff --git a/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp b/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp index 332400bcedc..2f5110e37d1 100644 --- a/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp +++ b/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp @@ -52,23 +52,6 @@ d3d12_bufmgr(struct pb_manager *mgr) return (struct d3d12_bufmgr *)mgr; } -static struct TransitionableResourceState * -create_trans_state(ID3D12Resource *res) -{ - D3D12_RESOURCE_DESC desc = GetDesc(res); - - // Calculate the total number of subresources - unsigned arraySize = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? - 1 : desc.DepthOrArraySize; - unsigned total_subresources = desc.MipLevels * - arraySize * - d3d12_non_opaque_plane_count(desc.Format); - - return new TransitionableResourceState(res, - total_subresources, - d3d12_resource_supports_simultaneous_access(&desc)); -} - static void describe_direct_bo(char *buf, struct d3d12_bo *ptr) { @@ -104,15 +87,21 @@ d3d12_bo_wrap_res(struct d3d12_screen *screen, ID3D12Resource *res, enum d3d12_r if (!bo) return NULL; + D3D12_RESOURCE_DESC desc = GetDesc(res); + unsigned array_size = desc.Dimension == D3D12_RESOURCE_DIMENSION_TEXTURE3D ? 1 : desc.DepthOrArraySize; + unsigned total_subresources = desc.MipLevels * array_size * d3d12_non_opaque_plane_count(desc.Format); + bool supports_simultaneous_access = d3d12_resource_supports_simultaneous_access(&desc); + pipe_reference_init(&bo->reference, 1); bo->screen = screen; bo->res = res; - bo->trans_state = create_trans_state(res); + bo->trans_state = new TransitionableResourceState(res, total_subresources, supports_simultaneous_access); bo->unique_id = p_atomic_inc_return(&screen->resource_id_generator); + if (!supports_simultaneous_access) + d3d12_resource_state_init(&bo->global_state, total_subresources, false); bo->residency_status = residency; bo->last_used_timestamp = 0; - D3D12_RESOURCE_DESC desc = GetDesc(res); screen->dev->GetCopyableFootprints(&desc, 0, bo->trans_state->NumSubresources(), 0, nullptr, nullptr, nullptr, &bo->estimated_size); if (residency != d3d12_evicted) { mtx_lock(&screen->submit_mutex); @@ -212,6 +201,7 @@ d3d12_bo_unreference(struct d3d12_bo *bo) mtx_unlock(&bo->screen->submit_mutex); + d3d12_resource_state_cleanup(&bo->global_state); if (bo->trans_state) delete bo->trans_state; if (bo->res) diff --git a/src/gallium/drivers/d3d12/d3d12_bufmgr.h b/src/gallium/drivers/d3d12/d3d12_bufmgr.h index ce2001b195b..a84df2cd255 100644 --- a/src/gallium/drivers/d3d12/d3d12_bufmgr.h +++ b/src/gallium/drivers/d3d12/d3d12_bufmgr.h @@ -29,6 +29,7 @@ #include "util/list.h" #include "d3d12_common.h" +#include "d3d12_resource_state.h" struct d3d12_bufmgr; struct d3d12_screen; @@ -47,6 +48,7 @@ struct d3d12_bo { ID3D12Resource *res; struct pb_buffer *buffer; struct TransitionableResourceState *trans_state; + struct d3d12_resource_state global_state; /* Used as a key in per-context resource state maps, * to avoid needing to lock them for single-threaded lookups to diff --git a/src/gallium/drivers/d3d12/d3d12_resource_state.cpp b/src/gallium/drivers/d3d12/d3d12_resource_state.cpp index 541176b1838..44d451b42f7 100644 --- a/src/gallium/drivers/d3d12/d3d12_resource_state.cpp +++ b/src/gallium/drivers/d3d12/d3d12_resource_state.cpp @@ -269,7 +269,9 @@ d3d12_context_state_resolve_submission(struct d3d12_context *ctx, struct d3d12_b d3d12_bo *bo = (d3d12_bo *)bo_entry->key; d3d12_context_state_table_entry *bo_state = find_or_create_state_entry(ctx->bo_state_table, bo); if (!bo_state->batch_end.supports_simultaneous_access) { + assert(bo->res && bo->global_state.subresource_states); d3d12_resource_state_copy(&bo_state->batch_begin, &bo_state->batch_end); + d3d12_resource_state_copy(&bo->global_state, &bo_state->batch_end); } else { d3d12_reset_resource_state(&bo_state->batch_end); }