d3d12: Fix winsys displaytarget leak in d3d12_resource
Reviewed-by: Giancarlo Devich <gdevich@microsoft.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18328>
This commit is contained in:
@@ -66,6 +66,21 @@ d3d12_resource_destroy(struct pipe_screen *pscreen,
|
|||||||
struct pipe_resource *presource)
|
struct pipe_resource *presource)
|
||||||
{
|
{
|
||||||
struct d3d12_resource *resource = d3d12_resource(presource);
|
struct d3d12_resource *resource = d3d12_resource(presource);
|
||||||
|
|
||||||
|
// When instanciating a planar d3d12_resource, the same resource->dt pointer
|
||||||
|
// is copied to all their planes linked list resources
|
||||||
|
// Different instances of objects like d3d12_surface, can be pointing
|
||||||
|
// to different planes of the same overall (ie. NV12) planar d3d12_resource
|
||||||
|
// sharing the same dt, so keep a refcount when destroying them
|
||||||
|
// and only destroy it on the last plane being destroyed
|
||||||
|
if (resource->dt_refcount > 0)
|
||||||
|
resource->dt_refcount--;
|
||||||
|
if ((resource->dt_refcount == 0) && resource->dt)
|
||||||
|
{
|
||||||
|
struct d3d12_screen *screen = d3d12_screen(pscreen);
|
||||||
|
screen->winsys->displaytarget_destroy(screen->winsys, resource->dt);
|
||||||
|
}
|
||||||
|
|
||||||
threaded_resource_deinit(presource);
|
threaded_resource_deinit(presource);
|
||||||
if (can_map_directly(presource))
|
if (can_map_directly(presource))
|
||||||
util_range_destroy(&resource->valid_buffer_range);
|
util_range_destroy(&resource->valid_buffer_range);
|
||||||
@@ -291,6 +306,7 @@ init_texture(struct d3d12_screen *screen,
|
|||||||
templ->height0,
|
templ->height0,
|
||||||
64, NULL,
|
64, NULL,
|
||||||
&res->dt_stride);
|
&res->dt_stride);
|
||||||
|
res->dt_refcount = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
res->bo = d3d12_bo_wrap_res(screen, d3d12_res, init_residency);
|
res->bo = d3d12_bo_wrap_res(screen, d3d12_res, init_residency);
|
||||||
@@ -314,6 +330,7 @@ convert_planar_resource(struct d3d12_resource *res)
|
|||||||
if (!plane_res) {
|
if (!plane_res) {
|
||||||
plane_res = CALLOC_STRUCT(d3d12_resource);
|
plane_res = CALLOC_STRUCT(d3d12_resource);
|
||||||
*plane_res = *res;
|
*plane_res = *res;
|
||||||
|
plane_res->dt_refcount = num_planes;
|
||||||
d3d12_bo_reference(plane_res->bo);
|
d3d12_bo_reference(plane_res->bo);
|
||||||
pipe_reference_init(&plane_res->base.b.reference, 1);
|
pipe_reference_init(&plane_res->base.b.reference, 1);
|
||||||
threaded_resource_init(&plane_res->base.b, false);
|
threaded_resource_init(&plane_res->base.b, false);
|
||||||
|
@@ -49,6 +49,7 @@ struct d3d12_resource {
|
|||||||
struct pipe_resource* first_plane;
|
struct pipe_resource* first_plane;
|
||||||
unsigned mip_levels;
|
unsigned mip_levels;
|
||||||
struct sw_displaytarget *dt;
|
struct sw_displaytarget *dt;
|
||||||
|
unsigned dt_refcount; /* For planar resources sharing the dt pointer */
|
||||||
unsigned dt_stride;
|
unsigned dt_stride;
|
||||||
struct util_range valid_buffer_range;
|
struct util_range valid_buffer_range;
|
||||||
uint32_t bind_counts[PIPE_SHADER_TYPES][D3D12_RESOURCE_BINDING_TYPES];
|
uint32_t bind_counts[PIPE_SHADER_TYPES][D3D12_RESOURCE_BINDING_TYPES];
|
||||||
|
Reference in New Issue
Block a user