d3d12: Simplify fence data setup

Adding COM and GstMiniObject specific methods to skip passing
free function pointer

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5895>
This commit is contained in:
Seungha Yang 2024-01-09 20:18:38 +09:00 committed by GStreamer Marge Bot
parent 2c3f3c0cb6
commit e1ecd1de2f
13 changed files with 78 additions and 78 deletions

View file

@ -58,5 +58,7 @@ typedef struct _GstD3D12Converter GstD3D12Converter;
typedef struct _GstD3D12ConverterClass GstD3D12ConverterClass;
typedef struct _GstD3D12ConverterPrivate GstD3D12ConverterPrivate;
typedef struct _GstD3D12FenceData GstD3D12FenceData;
G_END_DECLS

View file

@ -1110,8 +1110,7 @@ gst_d3d12_compositor_preprare_func (GstVideoAggregatorPad * pad,
GstD3D12FenceData *fence_data;
gst_d3d12_fence_data_pool_acquire (self->priv->fence_data_pool, &fence_data);
gst_d3d12_fence_data_add_notify (fence_data, gst_ca,
(GDestroyNotify) gst_d3d12_command_allocator_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data, gst_ca);
ComPtr < ID3D12CommandAllocator > ca;
gst_d3d12_command_allocator_get_handle (gst_ca, &ca);
@ -1203,7 +1202,7 @@ gst_d3d12_compositor_pad_clean_frame (GstVideoAggregatorPad * pad,
if (priv->ctx && priv->ctx->fence_data) {
gst_d3d12_device_set_fence_notify (priv->ctx->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->ctx->fence_val,
priv->ctx->fence_data, (GDestroyNotify) gst_d3d12_fence_data_unref);
priv->ctx->fence_data);
priv->ctx->fence_data = nullptr;
}
}
@ -2173,13 +2172,6 @@ gst_d3d12_compositor_decide_allocation (GstAggregator * agg, GstQuery * query)
return TRUE;
}
static void
resource_free_func (ID3D12Resource * resource)
{
if (resource)
resource->Release ();
}
static gboolean
gst_d3d12_compositor_draw_background (GstD3D12Compositor * self)
{
@ -2218,8 +2210,7 @@ gst_d3d12_compositor_draw_background (GstD3D12Compositor * self)
GstD3D12FenceData *fence_data;
gst_d3d12_fence_data_pool_acquire (priv->fence_data_pool, &fence_data);
gst_d3d12_fence_data_add_notify (fence_data, gst_ca,
(GDestroyNotify) gst_d3d12_command_allocator_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data, gst_ca);
ComPtr < ID3D12CommandAllocator > ca;
gst_d3d12_command_allocator_get_handle (gst_ca, &ca);
@ -2318,14 +2309,12 @@ gst_d3d12_compositor_draw_background (GstD3D12Compositor * self)
bg_render->fence_val);
if (bg_render->vertex_index_upload) {
gst_d3d12_fence_data_add_notify (fence_data,
bg_render->vertex_index_upload.Detach (),
(GDestroyNotify) resource_free_func);
gst_d3d12_fence_data_add_notify_com (fence_data,
bg_render->vertex_index_upload.Detach ());
}
gst_d3d12_device_set_fence_notify (self->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->bg_render->fence_val,
fence_data, (GDestroyNotify) gst_d3d12_fence_data_unref);
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->bg_render->fence_val, fence_data);
return TRUE;
}

View file

@ -2089,8 +2089,7 @@ gst_d3d12_convert_transform (GstBaseTransform * trans, GstBuffer * inbuf,
GstD3D12FenceData *fence_data;
gst_d3d12_fence_data_pool_acquire (priv->fence_data_pool, &fence_data);
gst_d3d12_fence_data_add_notify (fence_data, gst_ca,
(GDestroyNotify) gst_d3d12_command_allocator_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data, gst_ca);
if (!gst_d3d12_converter_convert_buffer (priv->ctx->conv,
inbuf, outbuf, fence_data, priv->ctx->cl.Get ())) {
@ -2118,8 +2117,7 @@ gst_d3d12_convert_transform (GstBaseTransform * trans, GstBuffer * inbuf,
gst_d3d12_buffer_after_write (outbuf, priv->ctx->fence_val);
gst_d3d12_device_set_fence_notify (priv->ctx->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->ctx->fence_val, fence_data,
(GDestroyNotify) gst_d3d12_fence_data_unref);
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->ctx->fence_val, fence_data);
priv->ctx->scheduled.push (priv->ctx->fence_val);

View file

@ -1810,13 +1810,6 @@ gst_d3d12_converter_update_pso (GstD3D12Converter * self)
return TRUE;
}
static void
pso_free_func (ID3D12PipelineState * pso)
{
if (pso)
pso->Release ();
}
static gboolean
gst_d3d12_converter_execute (GstD3D12Converter * self,
GstBuffer * in_buf, GstBuffer * out_buf, GstD3D12FenceData * fence_data,
@ -1959,8 +1952,7 @@ gst_d3d12_converter_execute (GstD3D12Converter * self,
}
gst_d3d12_descriptor_get_handle (descriptor, &srv_heap);
gst_d3d12_fence_data_add_notify (fence_data, descriptor,
(GDestroyNotify) gst_d3d12_descriptor_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data, descriptor);
auto cpu_handle =
CD3DX12_CPU_DESCRIPTOR_HANDLE
@ -2045,8 +2037,7 @@ gst_d3d12_converter_execute (GstD3D12Converter * self,
cl->DrawIndexedInstanced (6, 1, 0, 0, 0);
pso->AddRef ();
gst_d3d12_fence_data_add_notify (fence_data, pso,
(GDestroyNotify) pso_free_func);
gst_d3d12_fence_data_add_notify_com (fence_data, pso);
auto offset = priv->quad_data[0].num_rtv;
if (priv->quad_data.size () == 2) {
@ -2061,12 +2052,11 @@ gst_d3d12_converter_execute (GstD3D12Converter * self,
cl->DrawIndexedInstanced (6, 1, 0, 0, 0);
pso->AddRef ();
gst_d3d12_fence_data_add_notify (fence_data, pso,
(GDestroyNotify) pso_free_func);
gst_d3d12_fence_data_add_notify_com (fence_data, pso);
}
gst_d3d12_fence_data_add_notify (fence_data,
gst_buffer_ref (in_buf), (GDestroyNotify) gst_buffer_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data,
gst_buffer_ref (in_buf));
if (priv->upload_data) {
gst_d3d12_fence_data_add_notify (fence_data,
priv->upload_data, (GDestroyNotify) converter_upload_data_free);

View file

@ -1247,11 +1247,9 @@ gst_d3d12_decoder_end_picture (GstD3D12Decoder * decoder,
GstD3D12FenceData *fence_data;
gst_d3d12_fence_data_pool_acquire (priv->fence_data_pool, &fence_data);
gst_d3d12_fence_data_add_notify (fence_data,
gst_mini_object_ref (decoder_pic),
(GDestroyNotify) gst_mini_object_unref);
gst_d3d12_fence_data_add_notify (fence_data, gst_ca,
(GDestroyNotify) gst_d3d12_command_allocator_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data,
gst_mini_object_ref (decoder_pic));
gst_d3d12_fence_data_add_notify_mini_object (fence_data, gst_ca);
gst_d3d12_command_queue_set_notify (priv->cmd->queue, priv->cmd->fence_val,
fence_data, (GDestroyNotify) gst_d3d12_fence_data_unref);

View file

@ -891,9 +891,10 @@ gst_d3d12_device_get_completed_value (GstD3D12Device * device,
gboolean
gst_d3d12_device_set_fence_notify (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type, guint64 fence_value,
gpointer fence_data, GDestroyNotify notify)
GstD3D12FenceData * fence_data)
{
g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), FALSE);
g_return_val_if_fail (fence_data, FALSE);
auto priv = device->priv;
GstD3D12CommandQueue *queue;
@ -910,7 +911,8 @@ gst_d3d12_device_set_fence_notify (GstD3D12Device * device,
return FALSE;
}
gst_d3d12_command_queue_set_notify (queue, fence_value, fence_data, notify);
gst_d3d12_command_queue_set_notify (queue, fence_value, fence_data,
(GDestroyNotify) gst_d3d12_fence_data_unref);
return TRUE;
}

View file

@ -101,8 +101,7 @@ guint64 gst_d3d12_device_get_completed_value (GstD3D12Devic
gboolean gst_d3d12_device_set_fence_notify (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type,
guint64 fence_value,
gpointer fence_data,
GDestroyNotify notify);
GstD3D12FenceData * fence_data);
gboolean gst_d3d12_device_fence_wait (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type,

View file

@ -1500,8 +1500,7 @@ gst_d3d12_dxgi_capture_draw_mouse (GstD3D12DxgiCapture * self,
return FALSE;
}
gst_d3d12_fence_data_add_notify (fence_data, gst_ca,
(GDestroyNotify) gst_d3d12_command_allocator_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data, gst_ca);
gst_d3d12_command_allocator_get_handle (gst_ca, &ca);
hr = ca->Reset ();
@ -1634,8 +1633,7 @@ gst_d3d12_dxgi_capture_do_capture (GstD3D12ScreenCapture * capture,
}
gst_d3d12_fence_data_pool_acquire (priv->fence_data_pool, &fence_data);
gst_d3d12_fence_data_add_notify (fence_data, gst_ca,
(GDestroyNotify) gst_d3d12_command_allocator_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data, gst_ca);
gst_d3d12_command_allocator_get_handle (gst_ca, &ca);
@ -1701,8 +1699,7 @@ gst_d3d12_dxgi_capture_do_capture (GstD3D12ScreenCapture * capture,
}
gst_d3d12_device_set_fence_notify (self->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->fence_val, fence_data,
(GDestroyNotify) gst_d3d12_fence_data_unref);
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->fence_val, fence_data);
gst_d3d12_buffer_after_write (buffer, priv->fence_val);
@ -1725,7 +1722,7 @@ gst_d3d12_dxgi_capture_do_capture (GstD3D12ScreenCapture * capture,
gst_d3d12_device_set_fence_notify (self->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->mouse_fence_val,
priv->mouse_fence_data, (GDestroyNotify) gst_d3d12_fence_data_unref);
priv->mouse_fence_data);
priv->mouse_fence_data = nullptr;
gst_d3d12_buffer_after_write (buffer, priv->mouse_fence_val);

View file

@ -207,12 +207,10 @@ gst_d3d12_fence_data_pool_acquire (GstD3D12FenceDataPool * pool,
return TRUE;
}
void
gst_d3d12_fence_data_add_notify (GstD3D12FenceData * data, gpointer user_data,
GDestroyNotify notify)
static inline void
gst_d3d12_fence_data_add_notify_internal (GstD3D12FenceData * data,
gpointer user_data, GDestroyNotify notify)
{
g_return_if_fail (data);
NotifyData notify_data;
notify_data.user_data = user_data;
@ -221,6 +219,41 @@ gst_d3d12_fence_data_add_notify (GstD3D12FenceData * data, gpointer user_data,
gst_queue_array_push_tail_struct (data->queue, &notify_data);
}
void
gst_d3d12_fence_data_add_notify (GstD3D12FenceData * data, gpointer user_data,
GDestroyNotify notify)
{
g_return_if_fail (data);
gst_d3d12_fence_data_add_notify_internal (data, user_data, notify);
}
static void
com_free_func (IUnknown * unknown)
{
if (unknown)
unknown->Release ();
}
void
gst_d3d12_fence_data_add_notify_com (GstD3D12FenceData * data, gpointer unknown)
{
g_return_if_fail (data);
gst_d3d12_fence_data_add_notify_internal (data,
unknown, (GDestroyNotify) com_free_func);
}
void
gst_d3d12_fence_data_add_notify_mini_object (GstD3D12FenceData * data,
gpointer object)
{
g_return_if_fail (data);
gst_d3d12_fence_data_add_notify_internal (data,
object, (GDestroyNotify) gst_mini_object_unref);
}
GstD3D12FenceData *
gst_d3d12_fence_data_ref (GstD3D12FenceData * data)
{

View file

@ -29,8 +29,6 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GstD3D12FenceDataPool,
gst_d3d12_fence_data_pool, GST, D3D12_FENCE_DATA_POOL, GstObject);
typedef struct _GstD3D12FenceData GstD3D12FenceData;
GstD3D12FenceDataPool * gst_d3d12_fence_data_pool_new (void);
gboolean gst_d3d12_fence_data_pool_acquire (GstD3D12FenceDataPool * pool,
@ -40,6 +38,12 @@ void gst_d3d12_fence_data_add_notify (GstD3D12FenceData * dat
gpointer user_data,
GDestroyNotify notify);
void gst_d3d12_fence_data_add_notify_com (GstD3D12FenceData * data,
gpointer unknown);
void gst_d3d12_fence_data_add_notify_mini_object (GstD3D12FenceData * data,
gpointer object);
GstD3D12FenceData * gst_d3d12_fence_data_ref (GstD3D12FenceData * data);
void gst_d3d12_fence_data_unref (GstD3D12FenceData * data);

View file

@ -692,13 +692,6 @@ gst_d3d12_overlay_compositor_update_viewport (GstD3D12OverlayCompositor *
return TRUE;
}
static void
pso_free_func (ID3D12PipelineState * pso)
{
if (pso)
pso->Release ();
}
static gboolean
gst_d3d12_overlay_compositor_execute (GstD3D12OverlayCompositor * self,
GstBuffer * buf, GstD3D12FenceData * fence_data,
@ -764,20 +757,18 @@ gst_d3d12_overlay_compositor_execute (GstD3D12OverlayCompositor * self,
cl->DrawIndexedInstanced (6, 1, 0, 0, 0);
gst_d3d12_fence_data_add_notify (fence_data, gst_mini_object_ref (rect),
(GDestroyNotify) gst_mini_object_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data,
gst_mini_object_ref (rect));
prev_pso = nullptr;
prev_pso = pso;
}
priv->pso->AddRef ();
gst_d3d12_fence_data_add_notify (fence_data, priv->pso.Get (),
(GDestroyNotify) pso_free_func);
gst_d3d12_fence_data_add_notify_com (fence_data, priv->pso.Get ());
priv->pso_premul->AddRef ();
gst_d3d12_fence_data_add_notify (fence_data, priv->pso_premul.Get (),
(GDestroyNotify) pso_free_func);
gst_d3d12_fence_data_add_notify_com (fence_data, priv->pso_premul.Get ());
return TRUE;
}

View file

@ -2158,8 +2158,7 @@ gst_d3d12_test_src_create (GstBaseSrc * bsrc, guint64 offset,
auto cl = priv->ctx->cl;
GstD3D12FenceData *fence_data;
gst_d3d12_fence_data_pool_acquire (priv->fence_data_pool, &fence_data);
gst_d3d12_fence_data_add_notify (fence_data, gst_ca,
(GDestroyNotify) gst_d3d12_command_allocator_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data, gst_ca);
pts = priv->accum_rtime + priv->running_time;
gst_d3d12_test_src_draw_pattern (self, pts, cl.Get ());
@ -2193,8 +2192,7 @@ gst_d3d12_test_src_create (GstBaseSrc * bsrc, guint64 offset,
gst_d3d12_buffer_after_write (convert_buffer, priv->ctx->fence_val);
gst_d3d12_device_set_fence_notify (self->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->ctx->fence_val, fence_data,
(GDestroyNotify) gst_d3d12_fence_data_unref);
D3D12_COMMAND_LIST_TYPE_DIRECT, priv->ctx->fence_val, fence_data);
priv->ctx->scheduled.push (priv->ctx->fence_val);

View file

@ -1484,8 +1484,7 @@ gst_d3d12_window_set_buffer (GstD3D12Window * window, GstBuffer * buffer)
GstD3D12FenceData *fence_data;
gst_d3d12_fence_data_pool_acquire (priv->fence_data_pool, &fence_data);
gst_d3d12_fence_data_add_notify (fence_data, gst_ca,
(GDestroyNotify) gst_d3d12_command_allocator_unref);
gst_d3d12_fence_data_add_notify_mini_object (fence_data, gst_ca);
auto mem = (GstD3D12Memory *) gst_buffer_peek_memory (swapbuf->backbuf, 0);
auto backbuf_texture = gst_d3d12_memory_get_resource_handle (mem);