d3d12: Track a global resource state for non-simultaneous-access resources
authorJesse Natalie <jenatali@microsoft.com>
Wed, 20 Jul 2022 14:45:59 +0000 (07:45 -0700)
committerMarge Bot <emma+marge@anholt.net>
Fri, 22 Jul 2022 14:42:56 +0000 (14:42 +0000)
Reviewed-by: Bill Kristiansen <billkris@microsoft.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17688>

src/gallium/drivers/d3d12/d3d12_bufmgr.cpp
src/gallium/drivers/d3d12/d3d12_bufmgr.h
src/gallium/drivers/d3d12/d3d12_resource_state.cpp

index 332400b..2f5110e 100644 (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)
index ce2001b..a84df2c 100644 (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
index 541176b..44d451b 100644 (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);
       }