d3d12: Remove unnecessary event handles

null event NT handle to ID3D12Fence::SetEventOnCompletion()
will block the calling CPU thread already, thus it has no point that
creating an event NT handle in order to immediate wait for fence at CPU-side.
Note that passing a valid event NT handle to the fence API might be useful
when we need to wait for the fence value later (or timeout is required),
or want to wait for multiple fences at once via WaitForMultipleObjects().
But it's not a considered use case for now.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/7176>
This commit is contained in:
Seungha Yang 2024-07-16 03:31:33 +09:00 committed by GStreamer Marge Bot
parent 783e1ea327
commit b37bfc02f5
17 changed files with 46 additions and 188 deletions

View file

@ -26,7 +26,6 @@ G_BEGIN_DECLS
GST_D3D12_API GST_D3D12_API
HRESULT gst_d3d12_command_queue_idle_for_swapchain (GstD3D12CommandQueue * queue, HRESULT gst_d3d12_command_queue_idle_for_swapchain (GstD3D12CommandQueue * queue,
guint64 fence_value, guint64 fence_value);
HANDLE event_handle);
G_END_DECLS G_END_DECLS

View file

@ -62,11 +62,6 @@ struct gc_cmp {
struct _GstD3D12CommandQueuePrivate struct _GstD3D12CommandQueuePrivate
{ {
_GstD3D12CommandQueuePrivate ()
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
}
~_GstD3D12CommandQueuePrivate () ~_GstD3D12CommandQueuePrivate ()
{ {
{ {
@ -78,13 +73,8 @@ struct _GstD3D12CommandQueuePrivate
g_clear_pointer (&gc_thread, g_thread_join); g_clear_pointer (&gc_thread, g_thread_join);
auto completed = fence->GetCompletedValue (); auto completed = fence->GetCompletedValue ();
if (fence_val > completed) { if (fence_val > completed)
auto hr = fence->SetEventOnCompletion (completed, event_handle); fence->SetEventOnCompletion (completed, nullptr);
if (SUCCEEDED (hr))
WaitForSingleObjectEx (event_handle, INFINITE, FALSE);
}
CloseHandle (event_handle);
} }
D3D12_COMMAND_QUEUE_DESC desc; D3D12_COMMAND_QUEUE_DESC desc;
@ -92,7 +82,6 @@ struct _GstD3D12CommandQueuePrivate
ComPtr<ID3D12Device> device; ComPtr<ID3D12Device> device;
ComPtr<ID3D12CommandQueue> cq; ComPtr<ID3D12CommandQueue> cq;
ComPtr<ID3D12Fence> fence; ComPtr<ID3D12Fence> fence;
HANDLE event_handle;
guint64 fence_val = 0; guint64 fence_val = 0;
GThread *gc_thread = nullptr; GThread *gc_thread = nullptr;
@ -251,12 +240,11 @@ gst_d3d12_command_queue_execute_command_lists_unlocked (GstD3D12CommandQueue *
if (completed + priv->queue_size < priv->fence_val) { if (completed + priv->queue_size < priv->fence_val) {
hr = priv->fence->SetEventOnCompletion (priv->fence_val - hr = priv->fence->SetEventOnCompletion (priv->fence_val -
priv->queue_size, priv->event_handle); priv->queue_size, nullptr);
if (FAILED (hr)) { if (FAILED (hr)) {
GST_ERROR_OBJECT (queue, "SetEventOnCompletion failed"); GST_ERROR_OBJECT (queue, "SetEventOnCompletion failed");
return hr; return hr;
} }
WaitForSingleObjectEx (priv->event_handle, INFINITE, FALSE);
} }
} }
@ -380,7 +368,6 @@ gst_d3d12_command_queue_get_completed_value (GstD3D12CommandQueue * queue)
* gst_d3d12_command_queue_fence_wait: * gst_d3d12_command_queue_fence_wait:
* @queue: a #GstD3D12CommandQueue * @queue: a #GstD3D12CommandQueue
* @fence_value: fence value to wait * @fence_value: fence value to wait
* @handle: (nullable) (transfer none): event handle used for fence wait
* *
* Blocks calling CPU thread until command corresponding @fence_value * Blocks calling CPU thread until command corresponding @fence_value
* is completed. If @fence_value is %G_MAXUINT64, this method will block * is completed. If @fence_value is %G_MAXUINT64, this method will block
@ -392,7 +379,7 @@ gst_d3d12_command_queue_get_completed_value (GstD3D12CommandQueue * queue)
*/ */
HRESULT HRESULT
gst_d3d12_command_queue_fence_wait (GstD3D12CommandQueue * queue, gst_d3d12_command_queue_fence_wait (GstD3D12CommandQueue * queue,
guint64 fence_value, HANDLE event_handle) guint64 fence_value)
{ {
g_return_val_if_fail (GST_IS_D3D12_COMMAND_QUEUE (queue), E_INVALIDARG); g_return_val_if_fail (GST_IS_D3D12_COMMAND_QUEUE (queue), E_INVALIDARG);
@ -414,24 +401,11 @@ gst_d3d12_command_queue_fence_wait (GstD3D12CommandQueue * queue,
auto completed = priv->fence->GetCompletedValue (); auto completed = priv->fence->GetCompletedValue ();
if (completed < fence_to_wait) { if (completed < fence_to_wait) {
bool close_handle = false; hr = priv->fence->SetEventOnCompletion (fence_to_wait, nullptr);
if (!event_handle) {
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
close_handle = true;
}
hr = priv->fence->SetEventOnCompletion (fence_to_wait, event_handle);
if (FAILED (hr)) { if (FAILED (hr)) {
GST_ERROR_OBJECT (queue, "SetEventOnCompletion failed"); GST_ERROR_OBJECT (queue, "SetEventOnCompletion failed");
if (close_handle)
CloseHandle (event_handle);
return hr; return hr;
} }
WaitForSingleObjectEx (event_handle, INFINITE, FALSE);
if (close_handle)
CloseHandle (event_handle);
} }
return S_OK; return S_OK;
@ -444,8 +418,6 @@ gst_d3d12_command_queue_gc_thread (GstD3D12CommandQueue * self)
GST_INFO_OBJECT (self, "Entering GC thread"); GST_INFO_OBJECT (self, "Entering GC thread");
HANDLE event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
while (true) { while (true) {
GCDataPtr gc_data; GCDataPtr gc_data;
@ -477,12 +449,10 @@ gst_d3d12_command_queue_gc_thread (GstD3D12CommandQueue * self)
if (gc_data) { if (gc_data) {
GST_LOG_OBJECT (self, "Waiting for fence data %" G_GUINT64_FORMAT, GST_LOG_OBJECT (self, "Waiting for fence data %" G_GUINT64_FORMAT,
gc_data->fence_val); gc_data->fence_val);
auto hr = auto hr = priv->fence->SetEventOnCompletion (gc_data->fence_val, nullptr);
priv->fence->SetEventOnCompletion (gc_data->fence_val, event_handle);
if (FAILED (hr)) { if (FAILED (hr)) {
GST_ERROR_OBJECT (self, "SetEventOnCompletion failed"); GST_ERROR_OBJECT (self, "SetEventOnCompletion failed");
} else { } else {
WaitForSingleObjectEx (event_handle, INFINITE, FALSE);
GST_LOG_OBJECT (self, "Waiting done, %" G_GUINT64_FORMAT, GST_LOG_OBJECT (self, "Waiting done, %" G_GUINT64_FORMAT,
gc_data->fence_val); gc_data->fence_val);
} }
@ -491,8 +461,6 @@ gst_d3d12_command_queue_gc_thread (GstD3D12CommandQueue * self)
GST_INFO_OBJECT (self, "Leaving GC thread"); GST_INFO_OBJECT (self, "Leaving GC thread");
CloseHandle (event_handle);
return nullptr; return nullptr;
} }
@ -569,16 +537,11 @@ gst_d3d12_command_queue_drain (GstD3D12CommandQueue * queue)
auto completed = priv->fence->GetCompletedValue (); auto completed = priv->fence->GetCompletedValue ();
if (completed < priv->fence_val) { if (completed < priv->fence_val) {
auto event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS); hr = priv->fence->SetEventOnCompletion (priv->fence_val, nullptr);
hr = priv->fence->SetEventOnCompletion (priv->fence_val, event_handle);
if (FAILED (hr)) { if (FAILED (hr)) {
GST_ERROR_OBJECT (queue, "SetEventOnCompletion failed"); GST_ERROR_OBJECT (queue, "SetEventOnCompletion failed");
CloseHandle (event_handle);
return hr; return hr;
} }
WaitForSingleObjectEx (event_handle, INFINITE, FALSE);
CloseHandle (event_handle);
} }
{ {
@ -597,7 +560,7 @@ gst_d3d12_command_queue_drain (GstD3D12CommandQueue * queue)
HRESULT HRESULT
gst_d3d12_command_queue_idle_for_swapchain (GstD3D12CommandQueue * queue, gst_d3d12_command_queue_idle_for_swapchain (GstD3D12CommandQueue * queue,
guint64 fence_value, HANDLE event_handle) guint64 fence_value)
{ {
g_return_val_if_fail (GST_IS_D3D12_COMMAND_QUEUE (queue), E_INVALIDARG); g_return_val_if_fail (GST_IS_D3D12_COMMAND_QUEUE (queue), E_INVALIDARG);
@ -624,24 +587,11 @@ gst_d3d12_command_queue_idle_for_swapchain (GstD3D12CommandQueue * queue,
auto completed = priv->fence->GetCompletedValue (); auto completed = priv->fence->GetCompletedValue ();
if (completed < fence_to_wait) { if (completed < fence_to_wait) {
bool close_handle = false; hr = priv->fence->SetEventOnCompletion (fence_to_wait, nullptr);
if (!event_handle) {
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
close_handle = true;
}
hr = priv->fence->SetEventOnCompletion (fence_to_wait, event_handle);
if (FAILED (hr)) { if (FAILED (hr)) {
GST_ERROR_OBJECT (queue, "SetEventOnCompletion failed"); GST_ERROR_OBJECT (queue, "SetEventOnCompletion failed");
if (close_handle)
CloseHandle (event_handle);
return hr; return hr;
} }
WaitForSingleObjectEx (event_handle, INFINITE, FALSE);
if (close_handle)
CloseHandle (event_handle);
} }
return S_OK; return S_OK;

View file

@ -104,8 +104,7 @@ guint64 gst_d3d12_command_queue_get_completed_value (GstD3D12Comm
GST_D3D12_API GST_D3D12_API
HRESULT gst_d3d12_command_queue_fence_wait (GstD3D12CommandQueue * queue, HRESULT gst_d3d12_command_queue_fence_wait (GstD3D12CommandQueue * queue,
guint64 fence_value, guint64 fence_value);
HANDLE event_handle);
GST_D3D12_API GST_D3D12_API
void gst_d3d12_command_queue_set_notify (GstD3D12CommandQueue * queue, void gst_d3d12_command_queue_set_notify (GstD3D12CommandQueue * queue,

View file

@ -237,7 +237,7 @@ struct _GstD3D12ConverterPrivate
~_GstD3D12ConverterPrivate () ~_GstD3D12ConverterPrivate ()
{ {
if (fence_val > 0 && cq) if (fence_val > 0 && cq)
gst_d3d12_command_queue_fence_wait (cq, fence_val, nullptr); gst_d3d12_command_queue_fence_wait (cq, fence_val);
gst_clear_object (&srv_heap_pool); gst_clear_object (&srv_heap_pool);
gst_clear_object (&cq); gst_clear_object (&cq);

View file

@ -1696,7 +1696,6 @@ gst_d3d12_device_set_fence_notify (GstD3D12Device * device,
* @device: a #GstD3D12Device * @device: a #GstD3D12Device
* @queue_type: a D3D12_COMMAND_LIST_TYPE * @queue_type: a D3D12_COMMAND_LIST_TYPE
* @fence_value: target fence value * @fence_value: target fence value
* @handle: (nullable) (transfer none): event handle used for fence wait
* *
* Exectues gst_d3d12_command_queue_fence_wait () * Exectues gst_d3d12_command_queue_fence_wait ()
* using a #GstD3D12CommandQueue corresponding to @queue_type * using a #GstD3D12CommandQueue corresponding to @queue_type
@ -1707,8 +1706,7 @@ gst_d3d12_device_set_fence_notify (GstD3D12Device * device,
*/ */
HRESULT HRESULT
gst_d3d12_device_fence_wait (GstD3D12Device * device, gst_d3d12_device_fence_wait (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type, guint64 fence_value, D3D12_COMMAND_LIST_TYPE queue_type, guint64 fence_value)
HANDLE event_handle)
{ {
g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), E_INVALIDARG); g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), E_INVALIDARG);
@ -1727,7 +1725,7 @@ gst_d3d12_device_fence_wait (GstD3D12Device * device,
return E_INVALIDARG; return E_INVALIDARG;
} }
return gst_d3d12_command_queue_fence_wait (queue, fence_value, event_handle); return gst_d3d12_command_queue_fence_wait (queue, fence_value);
} }
gboolean gboolean

View file

@ -118,8 +118,7 @@ gboolean gst_d3d12_device_set_fence_notify (GstD3D12Devic
GST_D3D12_API GST_D3D12_API
HRESULT gst_d3d12_device_fence_wait (GstD3D12Device * device, HRESULT gst_d3d12_device_fence_wait (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type, D3D12_COMMAND_LIST_TYPE queue_type,
guint64 fence_value, guint64 fence_value);
HANDLE event_handle);
GST_D3D12_API GST_D3D12_API
gboolean gst_d3d12_device_is_equal (GstD3D12Device * device1, gboolean gst_d3d12_device_is_equal (GstD3D12Device * device1,

View file

@ -326,15 +326,8 @@ struct D3D11Interop
struct _GstD3D12MemoryPrivate struct _GstD3D12MemoryPrivate
{ {
_GstD3D12MemoryPrivate ()
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
}
~_GstD3D12MemoryPrivate () ~_GstD3D12MemoryPrivate ()
{ {
CloseHandle (event_handle);
if (nt_handle) if (nt_handle)
CloseHandle (nt_handle); CloseHandle (nt_handle);
@ -352,7 +345,6 @@ struct _GstD3D12MemoryPrivate
D3D12_RESOURCE_DESC desc; D3D12_RESOURCE_DESC desc;
HANDLE event_handle = nullptr;
HANDLE nt_handle = nullptr; HANDLE nt_handle = nullptr;
std::map<gint64, std::unique_ptr<GstD3D12MemoryTokenData>> token_map; std::map<gint64, std::unique_ptr<GstD3D12MemoryTokenData>> token_map;
std::vector<std::shared_ptr<D3D11Interop>> shared_texture11; std::vector<std::shared_ptr<D3D11Interop>> shared_texture11;
@ -420,15 +412,13 @@ gst_d3d12_memory_set_fence_unlocked (GstD3D12Memory * dmem,
ID3D12Fence * fence, guint64 fence_val, gboolean wait) ID3D12Fence * fence, guint64 fence_val, gboolean wait)
{ {
auto priv = dmem->priv; auto priv = dmem->priv;
HRESULT hr;
if (priv->fence && priv->fence.Get () != fence && wait) { if (priv->fence && priv->fence.Get () != fence && wait) {
auto completed = priv->fence->GetCompletedValue (); auto completed = priv->fence->GetCompletedValue ();
if (completed < priv->fence_val) { if (completed < priv->fence_val) {
hr = priv->fence->SetEventOnCompletion (priv->fence_val, auto hr = priv->fence->SetEventOnCompletion (priv->fence_val, nullptr);
priv->event_handle); /* For debugging */
if (SUCCEEDED (hr)) gst_d3d12_result (hr, dmem->device);
WaitForSingleObjectEx (priv->event_handle, INFINITE, FALSE);
} }
} }
@ -478,7 +468,7 @@ gst_d3d12_memory_download (GstD3D12Memory * dmem)
} }
gst_d3d12_device_fence_wait (dmem->device, D3D12_COMMAND_LIST_TYPE_COPY, gst_d3d12_device_fence_wait (dmem->device, D3D12_COMMAND_LIST_TYPE_COPY,
fence_val, priv->event_handle); fence_val);
priv->fence = nullptr; priv->fence = nullptr;
priv->fence_val = 0; priv->fence_val = 0;

View file

@ -229,7 +229,6 @@ struct PadContext
{ {
PadContext (GstD3D12Device * dev) PadContext (GstD3D12Device * dev)
{ {
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
device = (GstD3D12Device *) gst_object_ref (dev); device = (GstD3D12Device *) gst_object_ref (dev);
auto device_handle = gst_d3d12_device_get_device_handle (device); auto device_handle = gst_d3d12_device_get_device_handle (device);
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle, ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
@ -242,9 +241,7 @@ struct PadContext
~PadContext () ~PadContext ()
{ {
gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT, gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT,
fence_val, event_handle); fence_val);
CloseHandle (event_handle);
gst_clear_d3d12_fence_data (&fence_data); gst_clear_d3d12_fence_data (&fence_data);
gst_clear_object (&conv); gst_clear_object (&conv);
@ -258,7 +255,6 @@ struct PadContext
GstD3D12FenceData *fence_data = nullptr; GstD3D12FenceData *fence_data = nullptr;
GstD3D12Device *device; GstD3D12Device *device;
GstD3D12Converter *conv = nullptr; GstD3D12Converter *conv = nullptr;
HANDLE event_handle;
guint64 fence_val = 0; guint64 fence_val = 0;
}; };
/* *INDENT-ON* */ /* *INDENT-ON* */
@ -321,7 +317,6 @@ struct BackgroundRender
{ {
BackgroundRender (GstD3D12Device * dev, const GstVideoInfo & info) BackgroundRender (GstD3D12Device * dev, const GstVideoInfo & info)
{ {
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
device = (GstD3D12Device *) gst_object_ref (dev); device = (GstD3D12Device *) gst_object_ref (dev);
auto device_handle = gst_d3d12_device_get_device_handle (device); auto device_handle = gst_d3d12_device_get_device_handle (device);
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle, ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
@ -510,9 +505,7 @@ struct BackgroundRender
~BackgroundRender () ~BackgroundRender ()
{ {
gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT, gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT,
fence_val, event_handle); fence_val);
CloseHandle (event_handle);
gst_clear_object (&ca_pool); gst_clear_object (&ca_pool);
gst_clear_object (&device); gst_clear_object (&device);
@ -532,7 +525,6 @@ struct BackgroundRender
guint rtv_inc_size; guint rtv_inc_size;
bool need_upload = true; bool need_upload = true;
bool is_valid = false; bool is_valid = false;
HANDLE event_handle;
guint64 fence_val = 0; guint64 fence_val = 0;
}; };
/* *INDENT-ON* */ /* *INDENT-ON* */
@ -2378,8 +2370,7 @@ gst_d3d12_compositor_aggregate_frames (GstVideoAggregator * vagg,
GST_LOG_OBJECT (self, "Waiting for previous command, %" G_GUINT64_FORMAT, GST_LOG_OBJECT (self, "Waiting for previous command, %" G_GUINT64_FORMAT,
fence_to_wait); fence_to_wait);
gst_d3d12_device_fence_wait (self->device, gst_d3d12_device_fence_wait (self->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait, D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait);
priv->bg_render->event_handle);
} }
if (!gst_d3d12_compositor_draw_background (self)) { if (!gst_d3d12_compositor_draw_background (self)) {

View file

@ -80,7 +80,6 @@ struct ConvertContext
{ {
ConvertContext (GstD3D12Device * dev) ConvertContext (GstD3D12Device * dev)
{ {
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
device = (GstD3D12Device *) gst_object_ref (dev); device = (GstD3D12Device *) gst_object_ref (dev);
auto device_handle = gst_d3d12_device_get_device_handle (device); auto device_handle = gst_d3d12_device_get_device_handle (device);
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle, ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
@ -90,9 +89,8 @@ struct ConvertContext
~ConvertContext () ~ConvertContext ()
{ {
gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT, gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT,
fence_val, event_handle); fence_val);
CloseHandle (event_handle);
gst_clear_object (&ca_pool); gst_clear_object (&ca_pool);
gst_clear_object (&conv); gst_clear_object (&conv);
gst_clear_object (&device); gst_clear_object (&device);
@ -103,7 +101,6 @@ struct ConvertContext
ComPtr<ID3D12GraphicsCommandList> cl; ComPtr<ID3D12GraphicsCommandList> cl;
std::queue<guint64> scheduled; std::queue<guint64> scheduled;
GstD3D12CommandAllocatorPool *ca_pool; GstD3D12CommandAllocatorPool *ca_pool;
HANDLE event_handle;
guint64 fence_val = 0; guint64 fence_val = 0;
}; };
@ -1984,7 +1981,7 @@ gst_d3d12_convert_transform (GstBaseTransform * trans, GstBuffer * inbuf,
auto fence_to_wait = priv->ctx->scheduled.front (); auto fence_to_wait = priv->ctx->scheduled.front ();
priv->ctx->scheduled.pop (); priv->ctx->scheduled.pop ();
gst_d3d12_device_fence_wait (priv->ctx->device, gst_d3d12_device_fence_wait (priv->ctx->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait, priv->ctx->event_handle); D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait);
} }
GstD3D12CommandAllocator *gst_ca; GstD3D12CommandAllocator *gst_ca;

View file

@ -218,16 +218,6 @@ constexpr UINT64 ASYNC_DEPTH = 4;
struct DecoderCmdData struct DecoderCmdData
{ {
DecoderCmdData ()
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
}
~DecoderCmdData ()
{
CloseHandle (event_handle);
}
ComPtr<ID3D12Device> device; ComPtr<ID3D12Device> device;
ComPtr<ID3D12VideoDevice> video_device; ComPtr<ID3D12VideoDevice> video_device;
ComPtr<ID3D12VideoDecodeCommandList> cl; ComPtr<ID3D12VideoDecodeCommandList> cl;
@ -235,7 +225,6 @@ struct DecoderCmdData
bool need_full_drain = false; bool need_full_drain = false;
/* Fence to wait at command record thread */ /* Fence to wait at command record thread */
HANDLE event_handle;
UINT64 fence_val = 0; UINT64 fence_val = 0;
}; };
@ -333,13 +322,11 @@ struct GstD3D12DecoderPrivate
{ {
GstD3D12DecoderPrivate () GstD3D12DecoderPrivate ()
{ {
copy_event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
fence_data_pool = gst_d3d12_fence_data_pool_new (); fence_data_pool = gst_d3d12_fence_data_pool_new ();
} }
~GstD3D12DecoderPrivate () ~GstD3D12DecoderPrivate ()
{ {
CloseHandle (copy_event_handle);
gst_clear_object (&fence_data_pool); gst_clear_object (&fence_data_pool);
} }
@ -352,8 +339,6 @@ struct GstD3D12DecoderPrivate
std::atomic<bool> flushing; std::atomic<bool> flushing;
std::atomic<GstFlowReturn> last_flow; std::atomic<GstFlowReturn> last_flow;
HANDLE copy_event_handle;
GstD3D12FenceDataPool *fence_data_pool; GstD3D12FenceDataPool *fence_data_pool;
std::vector<D3D12_RESOURCE_BARRIER> pre_barriers; std::vector<D3D12_RESOURCE_BARRIER> pre_barriers;
@ -464,10 +449,8 @@ gst_d3d12_decoder_drain (GstD3D12Decoder * decoder, GstVideoDecoder * videodec)
auto priv = decoder->priv; auto priv = decoder->priv;
GST_DEBUG_OBJECT (decoder, "Draining"); GST_DEBUG_OBJECT (decoder, "Draining");
if (priv->cmd) { if (priv->cmd)
gst_d3d12_command_queue_fence_wait (priv->cmd->queue, priv->cmd->fence_val, gst_d3d12_command_queue_fence_wait (priv->cmd->queue, priv->cmd->fence_val);
priv->cmd->event_handle);
}
GST_VIDEO_DECODER_STREAM_UNLOCK (videodec); GST_VIDEO_DECODER_STREAM_UNLOCK (videodec);
if (priv->output_thread && priv->session) { if (priv->output_thread && priv->session) {
@ -808,7 +791,7 @@ gst_d3d12_decoder_stop (GstD3D12Decoder * decoder)
gst_d3d12_command_queue_drain (priv->cmd->queue); gst_d3d12_command_queue_drain (priv->cmd->queue);
} else { } else {
gst_d3d12_command_queue_fence_wait (priv->cmd->queue, gst_d3d12_command_queue_fence_wait (priv->cmd->queue,
priv->cmd->fence_val, priv->cmd->event_handle); priv->cmd->fence_val);
} }
} }
@ -1471,8 +1454,7 @@ gst_d3d12_decoder_process_output (GstD3D12Decoder * self,
guint8 *map_data; guint8 *map_data;
GstVideoFrame vframe; GstVideoFrame vframe;
gst_d3d12_device_fence_wait (self->device, queue_type, gst_d3d12_device_fence_wait (self->device, queue_type, copy_fence_val);
copy_fence_val, priv->copy_event_handle);
hr = priv->session->staging->Map (0, nullptr, (void **) &map_data); hr = priv->session->staging->Map (0, nullptr, (void **) &map_data);
if (!gst_d3d12_result (hr, self->device)) { if (!gst_d3d12_result (hr, self->device)) {
@ -1538,8 +1520,6 @@ gst_d3d12_decoder_output_loop (GstD3D12Decoder * self)
GST_DEBUG_OBJECT (self, "Entering output thread"); GST_DEBUG_OBJECT (self, "Entering output thread");
auto event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
while (true) { while (true) {
DecoderOutputData output_data; DecoderOutputData output_data;
{ {
@ -1561,7 +1541,7 @@ gst_d3d12_decoder_output_loop (GstD3D12Decoder * self)
g_assert (decoder_pic); g_assert (decoder_pic);
gst_d3d12_command_queue_fence_wait (priv->cmd->queue, gst_d3d12_command_queue_fence_wait (priv->cmd->queue,
decoder_pic->fence_val, event_handle); decoder_pic->fence_val);
if (priv->flushing) { if (priv->flushing) {
GST_DEBUG_OBJECT (self, "Drop framem, we are flushing"); GST_DEBUG_OBJECT (self, "Drop framem, we are flushing");
@ -1587,8 +1567,6 @@ gst_d3d12_decoder_output_loop (GstD3D12Decoder * self)
GST_DEBUG_OBJECT (self, "Leaving output thread"); GST_DEBUG_OBJECT (self, "Leaving output thread");
CloseHandle (event_handle);
return nullptr; return nullptr;
} }

View file

@ -895,7 +895,6 @@ struct GstD3D12DxgiCapturePrivate
{ {
GstD3D12DxgiCapturePrivate () GstD3D12DxgiCapturePrivate ()
{ {
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
fence_data_pool = gst_d3d12_fence_data_pool_new (); fence_data_pool = gst_d3d12_fence_data_pool_new ();
} }
@ -903,7 +902,6 @@ struct GstD3D12DxgiCapturePrivate
{ {
WaitGPU (); WaitGPU ();
ctx = nullptr; ctx = nullptr;
CloseHandle (event_handle);
if (shared_fence_handle) if (shared_fence_handle)
CloseHandle (shared_fence_handle); CloseHandle (shared_fence_handle);
gst_clear_buffer (&mouse_buf); gst_clear_buffer (&mouse_buf);
@ -919,11 +917,8 @@ struct GstD3D12DxgiCapturePrivate
{ {
if (shared_fence) { if (shared_fence) {
auto completed = shared_fence->GetCompletedValue (); auto completed = shared_fence->GetCompletedValue ();
if (completed < fence_val) { if (completed < fence_val)
auto hr = shared_fence->SetEventOnCompletion (fence_val, event_handle); shared_fence->SetEventOnCompletion (fence_val, nullptr);
if (SUCCEEDED (hr))
WaitForSingleObject (event_handle, INFINITE);
}
} }
} }
@ -948,7 +943,6 @@ struct GstD3D12DxgiCapturePrivate
guint cached_width = 0; guint cached_width = 0;
guint cached_height = 0; guint cached_height = 0;
HANDLE event_handle;
guint64 fence_val = 0; guint64 fence_val = 0;
guint64 mouse_token = 0; guint64 mouse_token = 0;

View file

@ -88,17 +88,11 @@ struct EncoderSessionData
struct EncoderCmdData struct EncoderCmdData
{ {
EncoderCmdData ()
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
}
~EncoderCmdData () ~EncoderCmdData ()
{ {
if (queue) if (queue)
gst_d3d12_command_queue_fence_wait (queue, G_MAXUINT64, event_handle); gst_d3d12_command_queue_fence_wait (queue, G_MAXUINT64);
CloseHandle (event_handle);
gst_clear_object (&ca_pool); gst_clear_object (&ca_pool);
gst_clear_object (&queue); gst_clear_object (&queue);
} }
@ -107,7 +101,6 @@ struct EncoderCmdData
ComPtr<ID3D12VideoEncodeCommandList2> cl; ComPtr<ID3D12VideoEncodeCommandList2> cl;
GstD3D12CommandQueue *queue = nullptr; GstD3D12CommandQueue *queue = nullptr;
GstD3D12CommandAllocatorPool *ca_pool = nullptr; GstD3D12CommandAllocatorPool *ca_pool = nullptr;
HANDLE event_handle;
guint64 fence_val = 0; guint64 fence_val = 0;
}; };
@ -353,8 +346,7 @@ gst_d3d12_encoder_drain (GstD3D12Encoder * self, gboolean locked)
if (priv->cmd) { if (priv->cmd) {
GST_DEBUG_OBJECT (self, "Waiting for command finish %" G_GUINT64_FORMAT, GST_DEBUG_OBJECT (self, "Waiting for command finish %" G_GUINT64_FORMAT,
priv->cmd->fence_val); priv->cmd->fence_val);
gst_d3d12_command_queue_fence_wait (priv->cmd->queue, priv->cmd->fence_val, gst_d3d12_command_queue_fence_wait (priv->cmd->queue, priv->cmd->fence_val);
priv->cmd->event_handle);
} }
if (priv->session && priv->output_thread) { if (priv->session && priv->output_thread) {
@ -1145,8 +1137,6 @@ gst_d3d12_encoder_output_loop (GstD3D12Encoder * self)
GST_DEBUG_OBJECT (self, "Entering output thread"); GST_DEBUG_OBJECT (self, "Entering output thread");
HANDLE event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
while (true) { while (true) {
EncoderOutputData output_data; EncoderOutputData output_data;
{ {
@ -1167,8 +1157,8 @@ gst_d3d12_encoder_output_loop (GstD3D12Encoder * self)
GST_LOG_OBJECT (self, "Processing output %" G_GUINT64_FORMAT, GST_LOG_OBJECT (self, "Processing output %" G_GUINT64_FORMAT,
output_data.fence_val); output_data.fence_val);
gst_d3d12_command_queue_fence_wait (priv->cmd->queue, output_data.fence_val, gst_d3d12_command_queue_fence_wait (priv->cmd->queue,
event_handle); output_data.fence_val);
if (priv->flushing) { if (priv->flushing) {
GST_DEBUG_OBJECT (self, "We are flushing"); GST_DEBUG_OBJECT (self, "We are flushing");
@ -1218,8 +1208,6 @@ gst_d3d12_encoder_output_loop (GstD3D12Encoder * self)
GST_DEBUG_OBJECT (self, "Leaving output thread"); GST_DEBUG_OBJECT (self, "Leaving output thread");
CloseHandle (event_handle);
return nullptr; return nullptr;
} }

View file

@ -226,7 +226,6 @@ struct RenderContext
{ {
RenderContext (GstD3D12Device * dev) RenderContext (GstD3D12Device * dev)
{ {
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
device = (GstD3D12Device *) gst_object_ref (dev); device = (GstD3D12Device *) gst_object_ref (dev);
auto device_handle = gst_d3d12_device_get_device_handle (device); auto device_handle = gst_d3d12_device_get_device_handle (device);
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle, ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
@ -236,9 +235,7 @@ struct RenderContext
~RenderContext () ~RenderContext ()
{ {
gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT, gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT,
fence_val, event_handle); fence_val);
CloseHandle (event_handle);
{ {
GstD3D12Device11on12LockGuard lk (device); GstD3D12Device11on12LockGuard lk (device);
@ -290,7 +287,6 @@ struct RenderContext
StaticColor static_color[2]; StaticColor static_color[2];
std::vector < std::shared_ptr < GstD3D12TestSrcQuad >> quad; std::vector < std::shared_ptr < GstD3D12TestSrcQuad >> quad;
GstD3D12TestSrcPattern pattern; GstD3D12TestSrcPattern pattern;
HANDLE event_handle;
guint64 fence_val = 0; guint64 fence_val = 0;
}; };
@ -2183,7 +2179,7 @@ gst_d3d12_test_src_create (GstBaseSrc * bsrc, guint64 offset,
auto fence_to_wait = priv->ctx->scheduled.front (); auto fence_to_wait = priv->ctx->scheduled.front ();
priv->ctx->scheduled.pop (); priv->ctx->scheduled.pop ();
gst_d3d12_device_fence_wait (self->device, gst_d3d12_device_fence_wait (self->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait, priv->ctx->event_handle); D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait);
} }
GstD3D12CommandAllocator *gst_ca; GstD3D12CommandAllocator *gst_ca;

View file

@ -69,7 +69,6 @@ struct SwapChainResource
GstD3D12OverlayCompositor *comp = nullptr; GstD3D12OverlayCompositor *comp = nullptr;
GstD3D12Device *device = nullptr; GstD3D12Device *device = nullptr;
GstD3D12CommandAllocatorPool *ca_pool = nullptr; GstD3D12CommandAllocatorPool *ca_pool = nullptr;
HANDLE event_handle = nullptr;
UINT64 fence_val = 0; UINT64 fence_val = 0;
std::queue<UINT64> prev_fence_val; std::queue<UINT64> prev_fence_val;
DXGI_FORMAT render_format = DXGI_FORMAT_UNKNOWN; DXGI_FORMAT render_format = DXGI_FORMAT_UNKNOWN;

View file

@ -49,7 +49,6 @@ SwapChainBuffer::~SwapChainBuffer ()
SwapChainResource::SwapChainResource (GstD3D12Device * dev) SwapChainResource::SwapChainResource (GstD3D12Device * dev)
{ {
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
device = (GstD3D12Device *) gst_object_ref (dev); device = (GstD3D12Device *) gst_object_ref (dev);
auto device_handle = gst_d3d12_device_get_device_handle (device); auto device_handle = gst_d3d12_device_get_device_handle (device);
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle, ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
@ -80,8 +79,6 @@ SwapChainResource::~SwapChainResource ()
gst_clear_object (&conv); gst_clear_object (&conv);
gst_clear_object (&ca_pool); gst_clear_object (&ca_pool);
gst_clear_object (&device); gst_clear_object (&device);
CloseHandle (event_handle);
} }
void void
@ -90,7 +87,7 @@ SwapChainResource::clear_resource ()
if (!buffers.empty ()) { if (!buffers.empty ()) {
auto cq = gst_d3d12_device_get_command_queue (device, auto cq = gst_d3d12_device_get_command_queue (device,
D3D12_COMMAND_LIST_TYPE_DIRECT); D3D12_COMMAND_LIST_TYPE_DIRECT);
gst_d3d12_command_queue_idle_for_swapchain (cq, fence_val, event_handle); gst_d3d12_command_queue_idle_for_swapchain (cq, fence_val);
prev_fence_val = { }; prev_fence_val = { };
} }
@ -234,8 +231,7 @@ SwapChain::~SwapChain()
if (!resource_->buffers.empty ()) { if (!resource_->buffers.empty ()) {
auto cq = gst_d3d12_device_get_command_queue (resource_->device, auto cq = gst_d3d12_device_get_command_queue (resource_->device,
D3D12_COMMAND_LIST_TYPE_DIRECT); D3D12_COMMAND_LIST_TYPE_DIRECT);
gst_d3d12_command_queue_idle_for_swapchain (cq, resource_->fence_val, gst_d3d12_command_queue_idle_for_swapchain (cq, resource_->fence_val);
resource_->event_handle);
} }
resource_ = nullptr; resource_ = nullptr;
@ -269,8 +265,7 @@ SwapChain::setup_swapchain (GstD3D12Window * window, GstD3D12Device * device,
std::lock_guard <std::recursive_mutex> lk (lock_); std::lock_guard <std::recursive_mutex> lk (lock_);
if (!gst_d3d12_device_is_equal (device, resource_->device)) { if (!gst_d3d12_device_is_equal (device, resource_->device)) {
gst_d3d12_device_fence_wait (resource_->device, gst_d3d12_device_fence_wait (resource_->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, resource_->fence_val, D3D12_COMMAND_LIST_TYPE_DIRECT, resource_->fence_val);
resource_->event_handle);
resource_ = std::make_unique <SwapChainResource> (device); resource_ = std::make_unique <SwapChainResource> (device);
} }
@ -615,8 +610,7 @@ SwapChain::before_rendering ()
D3D12_COMMAND_LIST_TYPE_DIRECT); D3D12_COMMAND_LIST_TYPE_DIRECT);
if (completed < fence_val_to_wait) { if (completed < fence_val_to_wait) {
gst_d3d12_device_fence_wait (resource_->device, gst_d3d12_device_fence_wait (resource_->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, fence_val_to_wait, D3D12_COMMAND_LIST_TYPE_DIRECT, fence_val_to_wait);
resource->event_handle);
} }
} }
} }

View file

@ -42,7 +42,6 @@ struct GstDWriteD3D12RenderPrivate
GstDWriteD3D12RenderPrivate () GstDWriteD3D12RenderPrivate ()
{ {
fence_data_pool = gst_d3d12_fence_data_pool_new (); fence_data_pool = gst_d3d12_fence_data_pool_new ();
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
} }
~GstDWriteD3D12RenderPrivate () ~GstDWriteD3D12RenderPrivate ()
@ -52,14 +51,13 @@ struct GstDWriteD3D12RenderPrivate
d2d_factory = nullptr; d2d_factory = nullptr;
ClearResource (); ClearResource ();
gst_clear_object (&fence_data_pool); gst_clear_object (&fence_data_pool);
CloseHandle (event_handle);
} }
void ClearResource () void ClearResource ()
{ {
if (device) { if (device) {
gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT, gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT,
fence_val, event_handle); fence_val);
} }
gst_clear_object (&ca_pool); gst_clear_object (&ca_pool);
@ -109,7 +107,6 @@ struct GstDWriteD3D12RenderPrivate
GstD3D12Converter *blend_conv = nullptr; GstD3D12Converter *blend_conv = nullptr;
GstD3D12Converter *post_conv = nullptr; GstD3D12Converter *post_conv = nullptr;
HANDLE event_handle;
guint64 fence_val = 0; guint64 fence_val = 0;
ComPtr<ID3D12GraphicsCommandList> cl; ComPtr<ID3D12GraphicsCommandList> cl;
@ -331,7 +328,7 @@ gst_dwrite_d3d12_render_draw_layout (GstDWriteRender * render,
auto fence_to_wait = priv->scheduled.front (); auto fence_to_wait = priv->scheduled.front ();
priv->scheduled.pop (); priv->scheduled.pop ();
gst_d3d12_device_fence_wait (priv->device, gst_d3d12_device_fence_wait (priv->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait, priv->event_handle); D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait);
} }
GstBuffer *layout_buf = nullptr; GstBuffer *layout_buf = nullptr;
@ -404,7 +401,7 @@ gst_dwrite_d3d12_render_blend (GstDWriteRender * render, GstBuffer * layout_buf,
auto fence_to_wait = priv->scheduled.front (); auto fence_to_wait = priv->scheduled.front ();
priv->scheduled.pop (); priv->scheduled.pop ();
gst_d3d12_device_fence_wait (priv->device, gst_d3d12_device_fence_wait (priv->device,
D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait, priv->event_handle); D3D12_COMMAND_LIST_TYPE_DIRECT, fence_to_wait);
} }
GstD3D12Frame out_frame; GstD3D12Frame out_frame;

View file

@ -71,30 +71,20 @@ enum
/* *INDENT-OFF* */ /* *INDENT-OFF* */
struct GstWebView2SrcPrivate struct GstWebView2SrcPrivate
{ {
GstWebView2SrcPrivate ()
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
}
~GstWebView2SrcPrivate () ~GstWebView2SrcPrivate ()
{ {
ClearResource (); ClearResource ();
gst_clear_object (&object); gst_clear_object (&object);
gst_clear_object (&device12); gst_clear_object (&device12);
gst_clear_object (&device); gst_clear_object (&device);
CloseHandle (event_handle);
} }
void ClearResource () void ClearResource ()
{ {
if (fence12) { if (fence12) {
auto completed = fence12->GetCompletedValue (); auto completed = fence12->GetCompletedValue ();
if (completed < fence_val) { if (completed < fence_val)
auto hr = fence12->SetEventOnCompletion (fence_val, event_handle); fence12->SetEventOnCompletion (fence_val, nullptr);
if (SUCCEEDED (hr))
WaitForSingleObject (event_handle, INFINITE);
}
} }
staging = nullptr; staging = nullptr;
@ -124,7 +114,6 @@ struct GstWebView2SrcPrivate
ComPtr<ID3D12Fence> fence12; ComPtr<ID3D12Fence> fence12;
gboolean can_d3d12_copy; gboolean can_d3d12_copy;
UINT64 fence_val = 0; UINT64 fence_val = 0;
HANDLE event_handle;
/* properties */ /* properties */
gint adapter_index = DEFAULT_ADAPTER; gint adapter_index = DEFAULT_ADAPTER;