d3d11videosink: Fix rendering on keyed mutex enabled handle

As of the commit 69b2e1565c,
keyed mutex will be handled by the memory object.

Fixes: https://gitlab.freedesktop.org/gstreamer/gstreamer/-/issues/3468
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6600>
This commit is contained in:
Seungha Yang 2024-04-10 22:01:18 +09:00 committed by GStreamer Marge Bot
parent c4e0d19f13
commit d002acdd0c
3 changed files with 18 additions and 29 deletions

View file

@ -346,6 +346,8 @@ gst_d3d11_video_sink_class_init (GstD3D11VideoSinkClass * klass)
* - DXGI_FORMAT_R10G10B10A2_UNORM
*
* Since: 1.20
*
* Deprecated, Use appsink to access GStreamer produced D3D11 texture
*/
g_object_class_install_property (gobject_class, PROP_DRAW_ON_SHARED_TEXTURE,
g_param_spec_boolean ("draw-on-shared-texture",
@ -573,6 +575,8 @@ gst_d3d11_video_sink_class_init (GstD3D11VideoSinkClass * klass)
* #d3d11videosink::begin-draw signal handler.
*
* Since: 1.20
*
* Deprecated, Use appsink to access GStreamer produced D3D11 texture
*/
gst_d3d11_video_sink_signals[SIGNAL_BEGIN_DRAW] =
g_signal_new ("begin-draw", G_TYPE_FROM_CLASS (klass), G_SIGNAL_RUN_LAST,
@ -597,6 +601,11 @@ gst_d3d11_video_sink_class_init (GstD3D11VideoSinkClass * klass)
* @acquire_key and @release_key will be ignored.
*
* Since: 1.20
*
* As of 1.24, @acquire_key and @release_key must be zero. Other values are
* not supported.
*
* Deprecated, Use appsink to access GStreamer produced D3D11 texture
*/
gst_d3d11_video_sink_signals[SIGNAL_DRAW] =
g_signal_new ("draw", G_TYPE_FROM_CLASS (klass),
@ -1844,6 +1853,11 @@ gst_d3d11_video_sink_draw_action (GstD3D11VideoSink * self,
return FALSE;
}
if (acquire_key != 0 || release_key != 0) {
GST_ERROR_OBJECT (self, "Non zero mutex key value is not supported");
return FALSE;
}
GstD3D11CSLockGuard lk (&self->lock);
if (!self->drawing || !self->prepared_buffer) {
GST_WARNING_OBJECT (self, "Nothing to draw");

View file

@ -66,9 +66,9 @@ typedef struct
guint texture_misc_flags;
guint64 acquire_key;
guint64 release_key;
gboolean use_keyed_mutex;
GstBuffer *render_target;
IDXGIKeyedMutex *keyed_mutex;
} GstD3D11WindowSharedHandleData;
struct _GstD3D11Window

View file

@ -211,7 +211,6 @@ gst_d3d11_window_dummy_open_shared_handle (GstD3D11Window * window,
GstMemory *mem;
GstD3D11Memory *dmem;
D3D11_TEXTURE2D_DESC desc;
gboolean use_keyed_mutex = FALSE;
device_handle = gst_d3d11_device_get_device_handle (device);
@ -234,17 +233,10 @@ gst_d3d11_window_dummy_open_shared_handle (GstD3D11Window * window,
return FALSE;
texture->GetDesc (&desc);
use_keyed_mutex = (desc.MiscFlags & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX) ==
data->use_keyed_mutex =
(desc.MiscFlags & D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX) ==
D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX;
if (use_keyed_mutex) {
hr = texture->QueryInterface (IID_PPV_ARGS (&keyed_mutex));
if (!gst_d3d11_result (hr, device)) {
GST_ERROR_OBJECT (window, "Keyed mutex is unavailable");
return FALSE;
}
}
mem = gst_d3d11_allocator_alloc_wrapped (nullptr,
device, texture.Get (), desc.Width * desc.Height * 4, nullptr, nullptr);
if (!mem) {
@ -260,23 +252,12 @@ gst_d3d11_window_dummy_open_shared_handle (GstD3D11Window * window,
return FALSE;
}
if (keyed_mutex) {
hr = keyed_mutex->AcquireSync (data->acquire_key, INFINITE);
if (!gst_d3d11_result (hr, device)) {
GST_ERROR_OBJECT (window, "Couldn't acquire sync");
gst_memory_unref (mem);
return FALSE;
}
}
/* Everything is prepared now */
gst_d3d11_window_dummy_on_resize (window, desc.Width, desc.Height);
/* Move owned resources */
data->render_target = gst_buffer_new ();
gst_buffer_append_memory (data->render_target, mem);
if (keyed_mutex)
data->keyed_mutex = keyed_mutex.Detach ();
return TRUE;
}
@ -287,15 +268,9 @@ gst_d3d11_window_dummy_release_shared_handle (GstD3D11Window * window,
{
GstD3D11WindowDummy *self = GST_D3D11_WINDOW_DUMMY (window);
GstD3D11Device *device = window->device;
HRESULT hr;
/* TODO: cache owned resource for the later reuse? */
if (data->keyed_mutex) {
hr = data->keyed_mutex->ReleaseSync (data->release_key);
gst_d3d11_result (hr, device);
GST_D3D11_CLEAR_COM (data->keyed_mutex);
} else {
if (!data->use_keyed_mutex) {
/* If keyed mutex is not used, let's handle sync manually by using
* fence. Issued GPU commands might not be finished yet */