diff --git a/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp b/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp index a5dbf7d20ed..80994e0f4a7 100644 --- a/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp +++ b/src/gallium/drivers/d3d12/d3d12_bufmgr.cpp @@ -108,6 +108,7 @@ d3d12_bo_wrap_res(struct d3d12_screen *screen, ID3D12Resource *res, enum pipe_fo pipe_reference_init(&bo->reference, 1); bo->res = res; bo->trans_state = create_trans_state(res, format); + bo->unique_id = p_atomic_inc_return(&screen->resource_id_generator); bo->residency_status = residency; bo->last_used_timestamp = 0; @@ -167,7 +168,7 @@ d3d12_bo_new(struct d3d12_screen *screen, uint64_t size, const pb_desc *pb_desc) } struct d3d12_bo * -d3d12_bo_wrap_buffer(struct pb_buffer *buf) +d3d12_bo_wrap_buffer(struct d3d12_screen *screen, struct pb_buffer *buf) { struct d3d12_bo *bo; @@ -178,6 +179,7 @@ d3d12_bo_wrap_buffer(struct pb_buffer *buf) pipe_reference_init(&bo->reference, 1); bo->buffer = buf; bo->trans_state = NULL; /* State from base BO will be used */ + bo->unique_id = p_atomic_inc_return(&screen->resource_id_generator); return bo; } diff --git a/src/gallium/drivers/d3d12/d3d12_bufmgr.h b/src/gallium/drivers/d3d12/d3d12_bufmgr.h index 7529dd4fb7e..12120c2f90c 100644 --- a/src/gallium/drivers/d3d12/d3d12_bufmgr.h +++ b/src/gallium/drivers/d3d12/d3d12_bufmgr.h @@ -47,6 +47,12 @@ struct d3d12_bo { struct pb_buffer *buffer; struct TransitionableResourceState *trans_state; + /* Used as a key in per-context resource state maps, + * to avoid needing to lock them for single-threaded lookups to + * protect against resource destruction. + */ + uint64_t unique_id; + struct list_head residency_list_entry; uint64_t estimated_size; int64_t last_used_timestamp; @@ -111,7 +117,7 @@ struct d3d12_bo * d3d12_bo_wrap_res(struct d3d12_screen *screen, ID3D12Resource *res, enum pipe_format format, enum d3d12_residency_status residency); struct d3d12_bo * -d3d12_bo_wrap_buffer(struct pb_buffer *buf); +d3d12_bo_wrap_buffer(struct d3d12_screen *screen, struct pb_buffer *buf); void d3d12_debug_describe_bo(char* buf, struct d3d12_bo* ptr); diff --git a/src/gallium/drivers/d3d12/d3d12_resource.cpp b/src/gallium/drivers/d3d12/d3d12_resource.cpp index 560360cbb28..8ccf5eb86be 100644 --- a/src/gallium/drivers/d3d12/d3d12_resource.cpp +++ b/src/gallium/drivers/d3d12/d3d12_resource.cpp @@ -159,7 +159,7 @@ init_buffer(struct d3d12_screen *screen, buf = bufmgr->create_buffer(bufmgr, templ->width0, &buf_desc); if (!buf) return false; - res->bo = d3d12_bo_wrap_buffer(buf); + res->bo = d3d12_bo_wrap_buffer(screen, buf); return true; } diff --git a/src/gallium/drivers/d3d12/d3d12_screen.h b/src/gallium/drivers/d3d12/d3d12_screen.h index 6c96aefe807..500dc08d4c0 100644 --- a/src/gallium/drivers/d3d12/d3d12_screen.h +++ b/src/gallium/drivers/d3d12/d3d12_screen.h @@ -93,6 +93,7 @@ struct d3d12_screen { struct d3d12_descriptor_handle null_rtv; volatile uint32_t ctx_count; + volatile uint64_t resource_id_generator; /* capabilities */ D3D_FEATURE_LEVEL max_feature_level;