d3d12: Add a context state tracking structure
Reviewed-by: Bill Kristiansen <billkris@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17688>
This commit is contained in:
parent
6a8070bcef
commit
6bc5df76d3
|
@ -27,6 +27,7 @@
|
|||
#include "d3d12_query.h"
|
||||
#include "d3d12_residency.h"
|
||||
#include "d3d12_resource.h"
|
||||
#include "d3d12_resource_state.h"
|
||||
#include "d3d12_screen.h"
|
||||
#include "d3d12_surface.h"
|
||||
|
||||
|
@ -212,13 +213,12 @@ d3d12_end_batch(struct d3d12_context *ctx, struct d3d12_batch *batch)
|
|||
|
||||
d3d12_process_batch_residency(screen, batch);
|
||||
|
||||
d3d12_context_state_resolve_submission(ctx, batch);
|
||||
|
||||
ID3D12CommandList* cmdlists[] = { ctx->cmdlist };
|
||||
screen->cmdqueue->ExecuteCommandLists(1, cmdlists);
|
||||
batch->fence = d3d12_create_fence(screen);
|
||||
|
||||
/* TODO clean up resource state based on destroyed resources */
|
||||
util_dynarray_clear(&ctx->recently_destroyed_bos);
|
||||
|
||||
mtx_unlock(&screen->submit_mutex);
|
||||
}
|
||||
|
||||
|
|
|
@ -100,6 +100,7 @@ d3d12_context_destroy(struct pipe_context *pctx)
|
|||
d3d12_root_signature_cache_destroy(ctx);
|
||||
d3d12_cmd_signature_cache_destroy(ctx);
|
||||
d3d12_compute_transform_cache_destroy(ctx);
|
||||
d3d12_context_state_table_destroy(ctx);
|
||||
pipe_resource_reference(&ctx->pstipple.texture, nullptr);
|
||||
pipe_sampler_view_reference(&ctx->pstipple.sampler_view, nullptr);
|
||||
util_dynarray_fini(&ctx->recently_destroyed_bos);
|
||||
|
@ -2591,6 +2592,7 @@ d3d12_context_create(struct pipe_screen *pscreen, void *priv, unsigned flags)
|
|||
d3d12_gs_variant_cache_init(ctx);
|
||||
d3d12_tcs_variant_cache_init(ctx);
|
||||
d3d12_compute_transform_cache_init(ctx);
|
||||
d3d12_context_state_table_init(ctx);
|
||||
|
||||
util_dl_library *d3d12_mod = util_dl_open(UTIL_DL_PREFIX "d3d12" UTIL_DL_EXT);
|
||||
if (!d3d12_mod) {
|
||||
|
|
|
@ -175,6 +175,7 @@ struct d3d12_context {
|
|||
struct hash_table *gs_variant_cache;
|
||||
struct hash_table *tcs_variant_cache;
|
||||
struct hash_table *compute_transform_cache;
|
||||
struct hash_table_u64 *bo_state_table;
|
||||
|
||||
struct d3d12_batch batches[4];
|
||||
unsigned current_batch_idx;
|
||||
|
|
|
@ -21,6 +21,7 @@
|
|||
* IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "d3d12_context.h"
|
||||
#include "d3d12_resource_state.h"
|
||||
|
||||
#include <assert.h>
|
||||
|
@ -180,3 +181,45 @@ d3d12_resource_state_copy(d3d12_resource_state *dest, d3d12_resource_state *src)
|
|||
dest->subresource_states[i] = src->subresource_states[i];
|
||||
}
|
||||
}
|
||||
|
||||
struct d3d12_context_state_table_entry
|
||||
{
|
||||
struct d3d12_desired_resource_state desired;
|
||||
struct d3d12_resource_state batch_begin, batch_end;
|
||||
};
|
||||
|
||||
static void
|
||||
destroy_context_state_table_entry(d3d12_context_state_table_entry *entry)
|
||||
{
|
||||
d3d12_desired_resource_state_cleanup(&entry->desired);
|
||||
d3d12_resource_state_cleanup(&entry->batch_begin);
|
||||
d3d12_resource_state_cleanup(&entry->batch_end);
|
||||
free(entry);
|
||||
}
|
||||
|
||||
void
|
||||
d3d12_context_state_table_init(struct d3d12_context *ctx)
|
||||
{
|
||||
ctx->bo_state_table = _mesa_hash_table_u64_create(nullptr);
|
||||
}
|
||||
|
||||
void
|
||||
d3d12_context_state_table_destroy(struct d3d12_context *ctx)
|
||||
{
|
||||
hash_table_foreach(ctx->bo_state_table->table, entry)
|
||||
destroy_context_state_table_entry((d3d12_context_state_table_entry *)entry->data);
|
||||
_mesa_hash_table_u64_destroy(ctx->bo_state_table);
|
||||
}
|
||||
|
||||
void
|
||||
d3d12_context_state_resolve_submission(struct d3d12_context *ctx, struct d3d12_batch *batch)
|
||||
{
|
||||
util_dynarray_foreach(&ctx->recently_destroyed_bos, uint64_t, id) {
|
||||
void *data = _mesa_hash_table_u64_search(ctx->bo_state_table, *id);
|
||||
if (data)
|
||||
destroy_context_state_table_entry((d3d12_context_state_table_entry *)data);
|
||||
_mesa_hash_table_u64_remove(ctx->bo_state_table, *id);
|
||||
}
|
||||
|
||||
util_dynarray_clear(&ctx->recently_destroyed_bos);
|
||||
}
|
||||
|
|
|
@ -29,6 +29,10 @@
|
|||
|
||||
#include "d3d12_common.h"
|
||||
|
||||
#include "util/hash_table.h"
|
||||
|
||||
struct d3d12_context;
|
||||
|
||||
const D3D12_RESOURCE_STATES RESOURCE_STATE_ALL_WRITE_BITS =
|
||||
D3D12_RESOURCE_STATE_RENDER_TARGET | D3D12_RESOURCE_STATE_UNORDERED_ACCESS | D3D12_RESOURCE_STATE_DEPTH_WRITE |
|
||||
D3D12_RESOURCE_STATE_STREAM_OUT | D3D12_RESOURCE_STATE_COPY_DEST | D3D12_RESOURCE_STATE_RESOLVE_DEST |
|
||||
|
@ -119,4 +123,13 @@ d3d12_resource_state_if_promoted(D3D12_RESOURCE_STATES desired_state,
|
|||
void
|
||||
d3d12_resource_state_copy(d3d12_resource_state *dest, d3d12_resource_state *src);
|
||||
|
||||
void
|
||||
d3d12_context_state_table_init(struct d3d12_context *ctx);
|
||||
|
||||
void
|
||||
d3d12_context_state_table_destroy(struct d3d12_context *ctx);
|
||||
|
||||
void
|
||||
d3d12_context_state_resolve_submission(struct d3d12_context *ctx, struct d3d12_batch *batch);
|
||||
|
||||
#endif // D3D12_RESOURCE_STATE_H
|
||||
|
|
Loading…
Reference in New Issue