d3d12: Use native device handle if possible

Various abstraction objects such as command queue/list/allocator
can be constructed without GstD3D12Device

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6395>
This commit is contained in:
Seungha Yang 2024-03-16 20:04:43 +09:00 committed by GStreamer Marge Bot
parent 331522210f
commit 393fb4733c
18 changed files with 62 additions and 55 deletions

View file

@ -111,17 +111,17 @@ gst_d3d12_command_allocator_pool_finalize (GObject * object)
}
GstD3D12CommandAllocatorPool *
gst_d3d12_command_allocator_pool_new (GstD3D12Device * device,
gst_d3d12_command_allocator_pool_new (ID3D12Device * device,
D3D12_COMMAND_LIST_TYPE type)
{
g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), nullptr);
g_return_val_if_fail (device, nullptr);
auto self = (GstD3D12CommandAllocatorPool *)
g_object_new (GST_TYPE_D3D12_COMMAND_ALLOCATOR_POOL, nullptr);
gst_object_ref_sink (self);
auto priv = self->priv;
priv->device = gst_d3d12_device_get_device_handle (device);
priv->device = device;
priv->cmd_type = type;
return self;

View file

@ -31,7 +31,7 @@ G_DECLARE_FINAL_TYPE (GstD3D12CommandAllocatorPool,
typedef struct _GstD3D12CommandAllocator GstD3D12CommandAllocator;
GstD3D12CommandAllocatorPool * gst_d3d12_command_allocator_pool_new (GstD3D12Device * device,
GstD3D12CommandAllocatorPool * gst_d3d12_command_allocator_pool_new (ID3D12Device * device,
D3D12_COMMAND_LIST_TYPE type);
gboolean gst_d3d12_command_allocator_pool_acquire (GstD3D12CommandAllocatorPool * pool,

View file

@ -101,14 +101,14 @@ gst_d3d12_command_list_pool_finalize (GObject * object)
}
GstD3D12CommandListPool *
gst_d3d12_command_list_pool_new (GstD3D12Device * device,
gst_d3d12_command_list_pool_new (ID3D12Device * device,
D3D12_COMMAND_LIST_TYPE type)
{
g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), nullptr);
g_return_val_if_fail (device, nullptr);
if (type != D3D12_COMMAND_LIST_TYPE_DIRECT &&
type != D3D12_COMMAND_LIST_TYPE_COPY) {
GST_ERROR_OBJECT (device, "Not supported command list type");
GST_ERROR ("Not supported command list type");
return nullptr;
}
@ -117,7 +117,7 @@ gst_d3d12_command_list_pool_new (GstD3D12Device * device,
gst_object_ref_sink (self);
auto priv = self->priv;
priv->device = gst_d3d12_device_get_device_handle (device);;
priv->device = device;
priv->cmd_type = type;
return self;

View file

@ -31,7 +31,7 @@ G_DECLARE_FINAL_TYPE (GstD3D12CommandListPool,
typedef struct _GstD3D12CommandList GstD3D12CommandList;
GstD3D12CommandListPool * gst_d3d12_command_list_pool_new (GstD3D12Device * device,
GstD3D12CommandListPool * gst_d3d12_command_list_pool_new (ID3D12Device * device,
D3D12_COMMAND_LIST_TYPE type);
gboolean gst_d3d12_command_list_pool_acquire (GstD3D12CommandListPool * pool,

View file

@ -124,9 +124,6 @@ gst_d3d12_command_queue_class_init (GstD3D12CommandQueueClass * klass)
auto object_class = G_OBJECT_CLASS (klass);
object_class->finalize = gst_d3d12_command_queue_finalize;
GST_DEBUG_CATEGORY_INIT (gst_d3d12_command_queue_debug,
"d3d12commandqueue", 0, "d3d12commandqueue");
}
static void
@ -146,26 +143,28 @@ gst_d3d12_command_queue_finalize (GObject * object)
}
GstD3D12CommandQueue *
gst_d3d12_command_queue_new (GstD3D12Device * device,
gst_d3d12_command_queue_new (ID3D12Device * device,
const D3D12_COMMAND_QUEUE_DESC * desc, guint queue_size)
{
g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), nullptr);
g_return_val_if_fail (device, nullptr);
g_return_val_if_fail (desc, nullptr);
auto device_handle = gst_d3d12_device_get_device_handle (device);
GST_D3D12_CALL_ONCE_BEGIN {
GST_DEBUG_CATEGORY_INIT (gst_d3d12_command_queue_debug,
"d3d12commandqueue", 0, "d3d12commandqueue");
} GST_D3D12_CALL_ONCE_END;
ComPtr < ID3D12CommandQueue > cq;
auto hr = device_handle->CreateCommandQueue (desc, IID_PPV_ARGS (&cq));
if (!gst_d3d12_result (hr, device)) {
GST_ERROR_OBJECT (device, "Couldn't create command queue");
auto hr = device->CreateCommandQueue (desc, IID_PPV_ARGS (&cq));
if (FAILED (hr)) {
GST_ERROR ("Couldn't create command queue, hr: 0x%x", (guint) hr);
return nullptr;
}
ComPtr < ID3D12Fence > fence;
hr = device_handle->CreateFence (0,
D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS (&fence));
if (!gst_d3d12_result (hr, device)) {
GST_ERROR_OBJECT (device, "Couldn't create fence");
hr = device->CreateFence (0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS (&fence));
if (FAILED (hr)) {
GST_ERROR ("Couldn't create fence, hr: 0x%x", (guint) hr);
return nullptr;
}
@ -174,7 +173,7 @@ gst_d3d12_command_queue_new (GstD3D12Device * device,
gst_object_ref_sink (self);
auto priv = self->priv;
priv->device = gst_d3d12_device_get_device_handle (device);
priv->device = device;
priv->cq = cq;
priv->fence = fence;
priv->queue_size = queue_size;

View file

@ -29,7 +29,7 @@ G_BEGIN_DECLS
G_DECLARE_FINAL_TYPE (GstD3D12CommandQueue,
gst_d3d12_command_queue, GST, D3D12_COMMAND_QUEUE, GstObject);
GstD3D12CommandQueue * gst_d3d12_command_queue_new (GstD3D12Device * device,
GstD3D12CommandQueue * gst_d3d12_command_queue_new (ID3D12Device * device,
const D3D12_COMMAND_QUEUE_DESC * desc,
guint queue_size);

View file

@ -227,20 +227,23 @@ static const D3D12_ROOT_SIGNATURE_FLAGS g_rs_flags =
D3D12_ROOT_SIGNATURE_FLAG_DENY_AMPLIFICATION_SHADER_ROOT_ACCESS |
D3D12_ROOT_SIGNATURE_FLAG_DENY_MESH_SHADER_ROOT_ACCESS;
/* *INDENT-OFF* */
struct PadContext
{
PadContext (GstD3D12Device * dev)
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
device = (GstD3D12Device *) gst_object_ref (dev);
ca_pool = gst_d3d12_command_allocator_pool_new (device,
auto device_handle = gst_d3d12_device_get_device_handle (device);
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
D3D12_COMMAND_LIST_TYPE_DIRECT);
gst_video_info_init (&info);
}
PadContext () = delete;
~PadContext () {
~PadContext ()
{
gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT,
fence_val, event_handle);
@ -261,6 +264,7 @@ struct PadContext
HANDLE event_handle;
guint64 fence_val = 0;
};
/* *INDENT-ON* */
struct GstD3D12CompositorPadPrivate
{
@ -315,13 +319,15 @@ struct VertexData
} texture;
};
/* *INDENT-OFF* */
struct BackgroundRender
{
BackgroundRender (GstD3D12Device * dev, const GstVideoInfo & info)
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
device = (GstD3D12Device *) gst_object_ref (dev);
ca_pool = gst_d3d12_command_allocator_pool_new (device,
auto device_handle = gst_d3d12_device_get_device_handle (device);
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
D3D12_COMMAND_LIST_TYPE_DIRECT);
D3D12_VERSIONED_ROOT_SIGNATURE_DESC rs_desc = { };
@ -342,7 +348,6 @@ struct BackgroundRender
return;
}
auto device_handle = gst_d3d12_device_get_device_handle (device);
hr = device_handle->CreateRootSignature (0, rs_blob->GetBufferPointer (),
rs_blob->GetBufferSize (), IID_PPV_ARGS (&rs));
if (!gst_d3d12_result (hr, device)) {
@ -491,7 +496,8 @@ struct BackgroundRender
}
BackgroundRender () = delete;
~BackgroundRender () {
~BackgroundRender ()
{
gst_d3d12_device_fence_wait (device, D3D12_COMMAND_LIST_TYPE_DIRECT,
fence_val, event_handle);
@ -518,6 +524,7 @@ struct BackgroundRender
HANDLE event_handle;
guint64 fence_val = 0;
};
/* *INDENT-ON* */
struct ClearColor
{

View file

@ -82,7 +82,8 @@ struct ConvertContext
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
device = (GstD3D12Device *) gst_object_ref (dev);
ca_pool = gst_d3d12_command_allocator_pool_new (device,
auto device_handle = gst_d3d12_device_get_device_handle (device);
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
D3D12_COMMAND_LIST_TYPE_DIRECT);
}

View file

@ -720,8 +720,7 @@ gst_d3d12_converter_setup_resource (GstD3D12Converter * self,
srv_heap_desc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_SHADER_VISIBLE;
priv->srv_heap_pool = gst_d3d12_descriptor_pool_new (self->device,
&srv_heap_desc);
priv->srv_heap_pool = gst_d3d12_descriptor_pool_new (device, &srv_heap_desc);
priv->upload_data = new ConverterUploadData ();
auto upload_data = priv->upload_data;

View file

@ -442,13 +442,13 @@ gst_d3d12_decoder_open (GstD3D12Decoder * decoder, GstElement * element)
D3D12_COMMAND_QUEUE_DESC desc = { };
desc.Type = D3D12_COMMAND_LIST_TYPE_VIDEO_DECODE;
desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
cmd->queue = gst_d3d12_command_queue_new (decoder->device, &desc, 4);
cmd->queue = gst_d3d12_command_queue_new (cmd->device.Get (), &desc, 4);
if (!cmd->queue) {
GST_ERROR_OBJECT (element, "Couldn't create command queue");
return FALSE;
}
cmd->ca_pool = gst_d3d12_command_allocator_pool_new (decoder->device,
cmd->ca_pool = gst_d3d12_command_allocator_pool_new (cmd->device.Get (),
D3D12_COMMAND_LIST_TYPE_VIDEO_DECODE);
priv->cmd = std::move (cmd);

View file

@ -100,10 +100,10 @@ gst_d3d12_descriptor_pool_finalize (GObject * object)
}
GstD3D12DescriptorPool *
gst_d3d12_descriptor_pool_new (GstD3D12Device * device,
gst_d3d12_descriptor_pool_new (ID3D12Device * device,
const D3D12_DESCRIPTOR_HEAP_DESC * desc)
{
g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), nullptr);
g_return_val_if_fail (device, nullptr);
g_return_val_if_fail (desc, nullptr);
auto self = (GstD3D12DescriptorPool *)
@ -111,7 +111,7 @@ gst_d3d12_descriptor_pool_new (GstD3D12Device * device,
gst_object_ref_sink (self);
auto priv = self->priv;
priv->device = gst_d3d12_device_get_device_handle (device);
priv->device = device;
priv->heap_desc = *desc;
return self;

View file

@ -31,7 +31,7 @@ G_DECLARE_FINAL_TYPE (GstD3D12DescriptorPool,
typedef struct _GstD3D12Descriptor GstD3D12Descriptor;
GstD3D12DescriptorPool * gst_d3d12_descriptor_pool_new (GstD3D12Device * device,
GstD3D12DescriptorPool * gst_d3d12_descriptor_pool_new (ID3D12Device * device,
const D3D12_DESCRIPTOR_HEAP_DESC * desc);
gboolean gst_d3d12_descriptor_pool_acquire (GstD3D12DescriptorPool * pool,

View file

@ -782,36 +782,37 @@ gst_d3d12_device_new_internal (const GstD3D12DeviceConstructData * data)
priv->info_queue = info_queue;
}
D3D12_COMMAND_QUEUE_DESC queue_desc = { };
queue_desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
queue_desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
priv->direct_queue = gst_d3d12_command_queue_new (self, &queue_desc, 0);
priv->direct_queue = gst_d3d12_command_queue_new (device.Get (),
&queue_desc, 0);
if (!priv->direct_queue)
goto error;
priv->direct_cl_pool = gst_d3d12_command_list_pool_new (self,
priv->direct_cl_pool = gst_d3d12_command_list_pool_new (device.Get (),
D3D12_COMMAND_LIST_TYPE_DIRECT);
if (!priv->direct_cl_pool)
goto error;
priv->direct_ca_pool = gst_d3d12_command_allocator_pool_new (self,
priv->direct_ca_pool = gst_d3d12_command_allocator_pool_new (device.Get (),
D3D12_COMMAND_LIST_TYPE_DIRECT);
if (!priv->direct_ca_pool)
goto error;
queue_desc.Type = D3D12_COMMAND_LIST_TYPE_COPY;
priv->copy_queue = gst_d3d12_command_queue_new (self, &queue_desc, 0);
priv->copy_queue = gst_d3d12_command_queue_new (device.Get (),
&queue_desc, 0);
if (!priv->copy_queue)
goto error;
priv->copy_cl_pool = gst_d3d12_command_list_pool_new (self,
priv->copy_cl_pool = gst_d3d12_command_list_pool_new (device.Get (),
D3D12_COMMAND_LIST_TYPE_COPY);
if (!priv->copy_cl_pool)
goto error;
priv->copy_ca_pool = gst_d3d12_command_allocator_pool_new (self,
priv->copy_ca_pool = gst_d3d12_command_allocator_pool_new (device.Get (),
D3D12_COMMAND_LIST_TYPE_COPY);
if (!priv->copy_ca_pool)
goto error;

View file

@ -1025,7 +1025,7 @@ gst_d3d12_dxgi_capture_open (GstD3D12DxgiCapture * self,
return FALSE;
}
priv->ca_pool = gst_d3d12_command_allocator_pool_new (self->device,
priv->ca_pool = gst_d3d12_command_allocator_pool_new (device,
D3D12_COMMAND_LIST_TYPE_DIRECT);
priv->device = (GstD3D12Device *) gst_object_ref (self->device);

View file

@ -304,14 +304,13 @@ gst_d3d12_encoder_open (GstVideoEncoder * encoder)
queue_desc.Type = D3D12_COMMAND_LIST_TYPE_VIDEO_ENCODE;
auto cmd = std::make_unique < EncoderCmdData > ();
cmd->queue = gst_d3d12_command_queue_new (self->device,
&queue_desc, ASYNC_DEPTH);
cmd->queue = gst_d3d12_command_queue_new (device, &queue_desc, ASYNC_DEPTH);
if (!cmd->queue) {
GST_ERROR_OBJECT (self, "Couldn't create command queue");
return FALSE;
}
cmd->ca_pool = gst_d3d12_command_allocator_pool_new (self->device,
cmd->ca_pool = gst_d3d12_command_allocator_pool_new (device,
D3D12_COMMAND_LIST_TYPE_VIDEO_ENCODE);
cmd->video_device = video_device;

View file

@ -539,9 +539,8 @@ gst_d3d12_overlay_compositor_setup_shader (GstD3D12OverlayCompositor * self)
priv->idv.SizeInBytes = sizeof (indices);
priv->idv.Format = DXGI_FORMAT_R16_UINT;
priv->index_buf = index_buf;
priv->srv_heap_pool = gst_d3d12_descriptor_pool_new (self->device,
&heap_desc);
priv->ca_pool = gst_d3d12_command_allocator_pool_new (self->device,
priv->srv_heap_pool = gst_d3d12_descriptor_pool_new (device, &heap_desc);
priv->ca_pool = gst_d3d12_command_allocator_pool_new (device,
D3D12_COMMAND_LIST_TYPE_DIRECT);
priv->viewport.TopLeftX = 0;

View file

@ -232,7 +232,8 @@ struct RenderContext
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
device = (GstD3D12Device *) gst_object_ref (dev);
ca_pool = gst_d3d12_command_allocator_pool_new (device,
auto device_handle = gst_d3d12_device_get_device_handle (device);
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
D3D12_COMMAND_LIST_TYPE_DIRECT);
}

View file

@ -89,14 +89,15 @@ struct DeviceContext
queue_desc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
queue_desc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
queue = gst_d3d12_command_queue_new (device,
auto device_handle = gst_d3d12_device_get_device_handle (device);
queue = gst_d3d12_command_queue_new (device_handle,
&queue_desc, BACK_BUFFER_COUNT * 2);
if (!queue) {
GST_ERROR_OBJECT (device, "Couldn't create command queue");
return;
}
ca_pool = gst_d3d12_command_allocator_pool_new (device,
ca_pool = gst_d3d12_command_allocator_pool_new (device_handle,
D3D12_COMMAND_LIST_TYPE_DIRECT);
if (!ca_pool) {
GST_ERROR_OBJECT (device, "Couldn't create command allocator pool");