d3d12: Track a global resource state for non-simultaneous-access resources

Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17688>
This commit is contained in:
Jesse Natalie 2022-07-20 07:45:59 -07:00 committed by Marge Bot
parent 6acab47d7f
commit 70e7cb444e
3 changed files with 13 additions and 19 deletions

View file

@ -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)

View file

@ -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

View file

@ -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);
}