d3d12: Move core part to gst-libs

Move buffer pool, converter, and device abstraction layer to
public library

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/6494>
This commit is contained in:
Seungha Yang 2024-03-31 21:55:51 +09:00 committed by GStreamer Marge Bot
parent 7829315305
commit 7d0e90b7bc
61 changed files with 1972 additions and 405 deletions

View file

@ -1,6 +1,7 @@
subprojects/gst-plugins-bad/ext/qt6d3d11
subprojects/gst-plugins-bad/gst-libs/gst/cuda
subprojects/gst-plugins-bad/gst-libs/gst/d3d11
subprojects/gst-plugins-bad/gst-libs/gst/d3d12
subprojects/gst-plugins-bad/gst-libs/gst/dxva
subprojects/gst-plugins-bad/gst-libs/gst/va
subprojects/gst-plugins-bad/gst-libs/gst/winrt

View file

@ -1,5 +1,5 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
* Copyright (C) 2024 GStreamer developers
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
@ -20,16 +20,12 @@
#pragma once
#include <gst/gst.h>
#include "gstd3d12_fwd.h"
#include "gstd3d12bufferpool.h"
#include "gstd3d12commandallocatorpool.h"
#include "gstd3d12commandlistpool.h"
#include "gstd3d12commandqueue.h"
#include "gstd3d12converter.h"
#include "gstd3d12descriptorpool.h"
#include "gstd3d12device.h"
#include "gstd3d12fencedatapool.h"
#include "gstd3d12format.h"
#include "gstd3d12memory.h"
#include "gstd3d12utils.h"
#include "gstd3d12compat.h"
#ifndef GST_D3D12_API
# ifdef BUILDING_GST_D3D12
# define GST_D3D12_API GST_API_EXPORT /* from config.h */
# else
# define GST_D3D12_API GST_API_IMPORT
# endif
#endif

View file

@ -0,0 +1,71 @@
/* GStreamer
* Copyright (C) 2024 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <gst/d3d12/gstd3d12.h>
#include <gst/d3d12/gstd3d12device-private.h>
#include <gst/d3d12/gstd3d12format-private.h>
#include <gst/d3d12/gstd3d12converter-private.h>
#include <gst/d3d12/gstd3d12compat.h>
/*
* Preferred sorting order in a tier
* - number of components
* - depth
* - subsampling
* - supports both SRV and RTV
* - prefer smaller number of planes
* - prefer non-complex formats
* - prefer YUV formats over RGB ones
* - prefer I420 over YV12
* - format name
*/
/* DXGI (semi) native formats */
#define GST_D3D12_TIER_0_FORMATS \
"RGBA64_LE, RGB10A2_LE, Y410, VUYA, RGBA, BGRA, RBGA, P016_LE, P012_LE, " \
"P010_10LE, RGBx, BGRx, NV12"
/* both SRV and RTV are supported */
#define GST_D3D12_TIER_1_FORMATS \
"AYUV64, GBRA_12LE, GBRA_10LE, AYUV, ABGR, ARGB, GBRA, Y444_16LE, " \
"GBR_16LE, Y444_12LE, GBR_12LE, I422_12LE, I420_12LE, Y444_10LE, GBR_10LE, " \
"I422_10LE, I420_10LE, Y444, BGRP, GBR, RGBP, xBGR, xRGB, Y42B, NV21, " \
"I420, YV12, GRAY16_LE, GRAY8"
#define GST_D3D12_COMMON_FORMATS \
GST_D3D12_TIER_0_FORMATS ", " \
GST_D3D12_TIER_1_FORMATS
#define GST_D3D12_ALL_FORMATS \
"{ " GST_D3D12_COMMON_FORMATS " }"
#ifdef __cplusplus
#include <mutex>
#define GST_D3D12_CALL_ONCE_BEGIN \
static std::once_flag __once_flag; \
std::call_once (__once_flag, [&]()
#define GST_D3D12_CALL_ONCE_END )
#endif /* __cplusplus */

View file

@ -0,0 +1,39 @@
/* GStreamer
* Copyright (C) 2024 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#ifndef GST_USE_UNSTABLE_API
#pragma message ("The d3d12 library from gst-plugins-bad is unstable API and may change in future.")
#pragma message ("You can define GST_USE_UNSTABLE_API to avoid this warning.")
#endif
#include <gst/gst.h>
#include <gst/d3d12/gstd3d12_fwd.h>
#include <gst/d3d12/gstd3d12bufferpool.h>
#include <gst/d3d12/gstd3d12commandallocatorpool.h>
#include <gst/d3d12/gstd3d12commandqueue.h>
#include <gst/d3d12/gstd3d12converter.h>
#include <gst/d3d12/gstd3d12descriptorpool.h>
#include <gst/d3d12/gstd3d12device.h>
#include <gst/d3d12/gstd3d12fencedatapool.h>
#include <gst/d3d12/gstd3d12format.h>
#include <gst/d3d12/gstd3d12memory.h>
#include <gst/d3d12/gstd3d12utils.h>

View file

@ -20,14 +20,23 @@
#pragma once
#include <gst/gst.h>
#include <gst/d3d12/d3d12-prelude.h>
#ifndef INITGUID
#include <initguid.h>
#endif
#include <directx/d3d12.h>
#include <directx/d3d12video.h>
#include <dxguids/dxguids.h>
#if defined(BUILDING_GST_D3D12) || defined(GST_D3D12_USE_DIRECTX_HEADERS)
#include <directx/d3d12.h>
#include <directx/d3d12video.h>
#ifdef __cplusplus
#include <dxguids/dxguids.h>
#endif /* __cplusplus */
#else
#include <d3d12.h>
#include <d3d12video.h>
#endif
#include <dxgi1_6.h>
G_BEGIN_DECLS
@ -55,10 +64,27 @@ typedef struct _GstD3D12BufferPool GstD3D12BufferPool;
typedef struct _GstD3D12BufferPoolClass GstD3D12BufferPoolClass;
typedef struct _GstD3D12BufferPoolPrivate GstD3D12BufferPoolPrivate;
typedef struct _GstD3D12CommandAllocatorPool GstD3D12CommandAllocatorPool;
typedef struct _GstD3D12CommandAllocatorPoolClass GstD3D12CommandAllocatorPoolClass;
typedef struct _GstD3D12CommandAllocatorPoolPrivate GstD3D12CommandAllocatorPoolPrivate;
typedef struct _GstD3D12CommandAllocator GstD3D12CommandAllocator;
typedef struct _GstD3D12CommandQueue GstD3D12CommandQueue;
typedef struct _GstD3D12CommandQueueClass GstD3D12CommandQueueClass;
typedef struct _GstD3D12CommandQueuePrivate GstD3D12CommandQueuePrivate;
typedef struct _GstD3D12Converter GstD3D12Converter;
typedef struct _GstD3D12ConverterClass GstD3D12ConverterClass;
typedef struct _GstD3D12ConverterPrivate GstD3D12ConverterPrivate;
typedef struct _GstD3D12DescriptorPool GstD3D12DescriptorPool;
typedef struct _GstD3D12DescriptorPoolClass GstD3D12DescriptorPoolClass;
typedef struct _GstD3D12DescriptorPoolPrivate GstD3D12DescriptorPoolPrivate;
typedef struct _GstD3D12Descriptor GstD3D12Descriptor;
typedef struct _GstD3D12FenceDataPool GstD3D12FenceDataPool;
typedef struct _GstD3D12FenceDataPoolClass GstD3D12FenceDataPoolClass;
typedef struct _GstD3D12FenceDataPoolPrivate GstD3D12FenceDataPoolPrivate;
typedef struct _GstD3D12FenceData GstD3D12FenceData;
G_END_DECLS

View file

@ -371,6 +371,15 @@ gst_d3d12_buffer_pool_stop (GstBufferPool * pool)
return GST_BUFFER_POOL_CLASS (parent_class)->stop (pool);
}
/**
* gst_d3d12_buffer_pool_new:
* @device: a #GstD3D12Device to use
*
* Returns: (transfer full): a #GstBufferPool that allocates buffers with
* #GstD3D12Memory
*
* Since: 1.26
*/
GstBufferPool *
gst_d3d12_buffer_pool_new (GstD3D12Device * device)
{
@ -385,6 +394,16 @@ gst_d3d12_buffer_pool_new (GstD3D12Device * device)
return GST_BUFFER_POOL_CAST (self);
}
/**
* gst_buffer_pool_config_get_d3d12_allocation_params:
* @config: a buffer pool config
*
* Returns: (transfer full) (nullable): the currently configured
* #GstD3D12AllocationParams on @config or %NULL if @config doesn't contain
* #GstD3D12AllocationParams
*
* Since: 1.26
*/
GstD3D12AllocationParams *
gst_buffer_pool_config_get_d3d12_allocation_params (GstStructure * config)
{
@ -398,6 +417,15 @@ gst_buffer_pool_config_get_d3d12_allocation_params (GstStructure * config)
return ret;
}
/**
* gst_buffer_pool_config_set_d3d12_allocation_params:
* @config: a buffer pool config
* @params: (transfer none): a #GstD3D12AllocationParams
*
* Sets @params on @config
*
* Since: 1.26
*/
void
gst_buffer_pool_config_set_d3d12_allocation_params (GstStructure * config,
GstD3D12AllocationParams * params)

View file

@ -21,35 +21,57 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include "gstd3d12memory.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
#define GST_TYPE_D3D12_BUFFER_POOL (gst_d3d12_buffer_pool_get_type())
#define GST_D3D12_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), GST_TYPE_D3D12_BUFFER_POOL, GstD3D12BufferPool))
#define GST_IS_D3D12_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_TYPE_D3D12_BUFFER_POOL))
#define GST_TYPE_D3D12_BUFFER_POOL (gst_d3d12_buffer_pool_get_type ())
#define GST_D3D12_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_D3D12_BUFFER_POOL, GstD3D12BufferPool))
#define GST_D3D12_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_D3D12_BUFFER_POOL, GstD3D12BufferPoolClass))
#define GST_IS_D3D12_BUFFER_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_D3D12_BUFFER_POOL))
#define GST_IS_D3D12_BUFFER_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_D3D12_BUFFER_POOL))
#define GST_D3D12_BUFFER_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_D3D12_BUFFER_POOL, GstD3D12BufferPoolClass))
#define GST_D3D12_BUFFER_POOL_CAST(obj) ((GstD3D12BufferPool*)(obj))
/**
* GstD3D12BufferPool:
*
* Opaque GstD3D12BufferPool struct
*
* Since: 1.26
*/
struct _GstD3D12BufferPool
{
GstBufferPool parent;
GstD3D12Device *device;
/*< private >*/
GstD3D12BufferPoolPrivate *priv;
};
/**
* GstD3D12BufferPoolClass:
*
* Opaque GstD3D12BufferPoolClass struct
*
* Since: 1.26
*/
struct _GstD3D12BufferPoolClass
{
GstBufferPoolClass parent_class;
};
GST_D3D12_API
GType gst_d3d12_buffer_pool_get_type (void);
GST_D3D12_API
GstBufferPool * gst_d3d12_buffer_pool_new (GstD3D12Device * device);
GST_D3D12_API
GstD3D12AllocationParams * gst_buffer_pool_config_get_d3d12_allocation_params (GstStructure * config);
GST_D3D12_API
void gst_buffer_pool_config_set_d3d12_allocation_params (GstStructure * config,
GstD3D12AllocationParams * params);

View file

@ -47,9 +47,9 @@ struct _GstD3D12CommandAllocator : public GstMiniObject
GDestroyNotify notify = nullptr;
};
struct GstD3D12CommandAllocatorPoolPrivate
struct _GstD3D12CommandAllocatorPoolPrivate
{
~GstD3D12CommandAllocatorPoolPrivate ()
~_GstD3D12CommandAllocatorPoolPrivate ()
{
while (!cmd_pool.empty ()) {
auto cmd = cmd_pool.front ();
@ -66,13 +66,6 @@ struct GstD3D12CommandAllocatorPoolPrivate
};
/* *INDENT-ON* */
struct _GstD3D12CommandAllocatorPool
{
GstObject parent;
GstD3D12CommandAllocatorPoolPrivate *priv;
};
GST_DEFINE_MINI_OBJECT_TYPE (GstD3D12CommandAllocator,
gst_d3d12_command_allocator);
@ -110,6 +103,15 @@ gst_d3d12_command_allocator_pool_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/**
* gst_d3d12_command_allocator_pool_new:
* @device: a #GstD3D12Device
* @type: D3D12_COMMAND_LIST_TYPE
*
* Returns: (transfer full): a new #GstD3D12CommandAllocatorPool instance
*
* Since: 1.26
*/
GstD3D12CommandAllocatorPool *
gst_d3d12_command_allocator_pool_new (ID3D12Device * device,
D3D12_COMMAND_LIST_TYPE type)
@ -175,6 +177,17 @@ gst_d3d12_command_allocator_new (ID3D12CommandAllocator * ca,
return cmd;
}
/**
* gst_d3d12_command_allocator_pool_acquire:
* @pool: a #GstD3D12CommandAllocatorPool
* @cmd: (out) (transfer full): a pointer to #GstD3D12CommandAllocator
*
* Acquire #GstD3D12CommandAllocator object
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_command_allocator_pool_acquire (GstD3D12CommandAllocatorPool * pool,
GstD3D12CommandAllocator ** cmd)
@ -220,32 +233,60 @@ gst_d3d12_command_allocator_pool_acquire (GstD3D12CommandAllocatorPool * pool,
return TRUE;
}
/**
* gst_d3d12_command_allocator_ref:
* @cmd: a #GstD3D12CommandAllocator
*
* Increments the refcount of @cmd
*
* Returns: (transfer full): a #GstD3D12CommandAllocator
*
* Since: 1.26
*/
GstD3D12CommandAllocator *
gst_d3d12_command_allocator_ref (GstD3D12CommandAllocator * cmd)
{
return (GstD3D12CommandAllocator *) gst_mini_object_ref (cmd);
}
/**
* gst_d3d12_command_allocator_unref:
* @cmd: a #GstD3D12CommandAllocator
*
* Decrements the refcount of @cmd
*
* Since: 1.26
*/
void
gst_d3d12_command_allocator_unref (GstD3D12CommandAllocator * cmd)
{
gst_mini_object_unref (cmd);
}
/**
* gst_clear_d3d12_command_allocator:
* @cmd: a pointer to #GstD3D12CommandAllocator
*
* Clears a reference to a #GstD3D12CommandAllocator
*
* Since: 1.26
*/
void
gst_clear_d3d12_command_allocator (GstD3D12CommandAllocator ** cmd)
{
gst_clear_mini_object (cmd);
}
D3D12_COMMAND_LIST_TYPE
gst_d3d12_command_allocator_get_command_type (GstD3D12CommandAllocator * cmd)
{
g_return_val_if_fail (cmd, D3D12_COMMAND_LIST_TYPE_NONE);
return cmd->type;
}
/**
* gst_d3d12_command_allocator_get_handle:
* @cmd: a #GstD3D12CommandAllocator
*
* Gets ID3D12CommandAllocator handle.
*
* Returns: (transfer none): ID3D12CommandAllocator handle
*
* Since: 1.26
*/
ID3D12CommandAllocator *
gst_d3d12_command_allocator_get_handle (GstD3D12CommandAllocator * cmd)
{
@ -254,6 +295,16 @@ gst_d3d12_command_allocator_get_handle (GstD3D12CommandAllocator * cmd)
return cmd->ca.Get ();
}
/**
* gst_d3d12_command_allocator_set_user_data:
* @cmd: a #GstD3D12CommandAllocator
* @user_data: private data
* @notify: a #GDestroyNotify
*
* Sets @user_data on the @cmd
*
* Since: 1.26
*/
void
gst_d3d12_command_allocator_set_user_data (GstD3D12CommandAllocator * cmd,
gpointer user_data, GDestroyNotify notify)
@ -267,6 +318,16 @@ gst_d3d12_command_allocator_set_user_data (GstD3D12CommandAllocator * cmd,
cmd->notify = notify;
}
/**
* gst_d3d12_command_allocator_get_user_data:
* @cmd: a #GstD3D12CommandAllocator
*
* Gets private data configured via gst_d3d12_command_allocator_set_user_data()
*
* Returns: (transfer none): previously set user_data
*
* Since: 1.26
*/
gpointer
gst_d3d12_command_allocator_get_user_data (GstD3D12CommandAllocator * cmd)
{

View file

@ -21,38 +21,81 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
#define GST_TYPE_D3D12_COMMAND_ALLOCATOR_POOL (gst_d3d12_command_allocator_pool_get_type())
G_DECLARE_FINAL_TYPE (GstD3D12CommandAllocatorPool,
gst_d3d12_command_allocator_pool, GST, D3D12_COMMAND_ALLOCATOR_POOL, GstObject);
#define GST_TYPE_D3D12_COMMAND_ALLOCATOR_POOL (gst_d3d12_command_allocator_pool_get_type ())
#define GST_D3D12_COMMAND_ALLOCATOR_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_D3D12_COMMAND_ALLOCATOR_POOL, GstD3D12CommandAllocatorPool))
#define GST_D3D12_COMMAND_ALLOCATOR_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_D3D12_COMMAND_ALLOCATOR_POOL, GstD3D12CommandAllocatorPoolClass))
#define GST_IS_D3D12_COMMAND_ALLOCATOR_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_D3D12_COMMAND_ALLOCATOR_POOL))
#define GST_IS_D3D12_COMMAND_ALLOCATOR_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_D3D12_COMMAND_ALLOCATOR_POOL))
#define GST_D3D12_COMMAND_ALLOCATOR_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_D3D12_COMMAND_ALLOCATOR_POOL, GstD3D12CommandAllocatorPoolClass))
#define GST_D3D12_COMMAND_ALLOCATOR_POOL_CAST(obj) ((GstD3D12CommandAllocatorPool*)(obj))
typedef struct _GstD3D12CommandAllocator GstD3D12CommandAllocator;
/**
* GstD3D12CommandAllocatorPool:
*
* Opaque GstD3D12CommandAllocatorPool struct
*
* Since: 1.26
*/
struct _GstD3D12CommandAllocatorPool
{
GstObject parent;
GType gst_d3d12_command_allocator_get_type (void);
/*< private >*/
GstD3D12CommandAllocatorPoolPrivate *priv;
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstD3D12CommandAllocatorPoolClass:
*
* Opaque GstD3D12CommandAllocatorPoolClass struct
*
* Since: 1.26
*/
struct _GstD3D12CommandAllocatorPoolClass
{
GstObjectClass parent_class;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
GST_D3D12_API
GType gst_d3d12_command_allocator_pool_get_type (void);
GST_D3D12_API
GType gst_d3d12_command_allocator_get_type (void);
GST_D3D12_API
GstD3D12CommandAllocatorPool * gst_d3d12_command_allocator_pool_new (ID3D12Device * device,
D3D12_COMMAND_LIST_TYPE type);
GST_D3D12_API
gboolean gst_d3d12_command_allocator_pool_acquire (GstD3D12CommandAllocatorPool * pool,
GstD3D12CommandAllocator ** cmd);
GST_D3D12_API
GstD3D12CommandAllocator * gst_d3d12_command_allocator_ref (GstD3D12CommandAllocator * cmd);
GST_D3D12_API
void gst_d3d12_command_allocator_unref (GstD3D12CommandAllocator * cmd);
GST_D3D12_API
void gst_clear_d3d12_command_allocator (GstD3D12CommandAllocator ** cmd);
D3D12_COMMAND_LIST_TYPE gst_d3d12_command_allocator_get_command_type (GstD3D12CommandAllocator * cmd);
GST_D3D12_API
ID3D12CommandAllocator * gst_d3d12_command_allocator_get_handle (GstD3D12CommandAllocator * cmd);
GST_D3D12_API
void gst_d3d12_command_allocator_set_user_data (GstD3D12CommandAllocator * cmd,
gpointer user_data,
GDestroyNotify notify);
GST_D3D12_API
gpointer gst_d3d12_command_allocator_get_user_data (GstD3D12CommandAllocator * cmd);
G_END_DECLS

View file

@ -22,6 +22,7 @@
#endif
#include "gstd3d12.h"
#include "gstd3d12commandlistpool.h"
#include <wrl.h>
#include <queue>
#include <mutex>
@ -249,14 +250,6 @@ gst_clear_d3d12_command_list (GstD3D12CommandList ** cmd)
gst_clear_mini_object (cmd);
}
D3D12_COMMAND_LIST_TYPE
gst_d3d12_command_list_get_command_type (GstD3D12CommandList * cmd)
{
g_return_val_if_fail (cmd, D3D12_COMMAND_LIST_TYPE_NONE);
return cmd->type;
}
ID3D12CommandList *
gst_d3d12_command_list_get_handle (GstD3D12CommandList * cmd)
{

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
@ -46,8 +46,6 @@ void gst_d3d12_command_list_unref (GstD3D12CommandList * cm
void gst_clear_d3d12_command_list (GstD3D12CommandList ** cmd);
D3D12_COMMAND_LIST_TYPE gst_d3d12_command_list_get_command_type (GstD3D12CommandList * cmd);
ID3D12CommandList * gst_d3d12_command_list_get_handle (GstD3D12CommandList * cmd);
G_END_DECLS

View file

@ -60,14 +60,14 @@ struct gc_cmp {
}
};
struct GstD3D12CommandQueuePrivate
struct _GstD3D12CommandQueuePrivate
{
GstD3D12CommandQueuePrivate ()
_GstD3D12CommandQueuePrivate ()
{
event_handle = CreateEventEx (nullptr, nullptr, 0, EVENT_ALL_ACCESS);
}
~GstD3D12CommandQueuePrivate ()
~_GstD3D12CommandQueuePrivate ()
{
{
std::lock_guard <std::mutex> lk (lock);
@ -106,13 +106,6 @@ struct GstD3D12CommandQueuePrivate
};
/* *INDENT-ON* */
struct _GstD3D12CommandQueue
{
GstObject parent;
GstD3D12CommandQueuePrivate *priv;
};
static void gst_d3d12_command_queue_finalize (GObject * object);
#define gst_d3d12_command_queue_parent_class parent_class
@ -142,6 +135,19 @@ gst_d3d12_command_queue_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/**
* gst_d3d12_command_queue_new:
* @device: a #GstD3D12Device
* @desc: a D3D12_COMMAND_QUEUE_DESC
* @fence_flags: a D3D12_FENCE_FLAGS
* @queue_size: command queue size, Sets zero for unlimited queue size
*
* Creates GstD3D12CommandQueue with given parameters.
*
* Returns: (transfer full): a new #GstD3D12CommandQueue instance
*
* Since: 1.26
*/
GstD3D12CommandQueue *
gst_d3d12_command_queue_new (ID3D12Device * device,
const D3D12_COMMAND_QUEUE_DESC * desc, D3D12_FENCE_FLAGS fence_flags,
@ -182,6 +188,16 @@ gst_d3d12_command_queue_new (ID3D12Device * device,
return self;
}
/**
* gst_d3d12_command_queue_get_handle:
* @queue: a #GstD3D12CommandQueue
*
* Gets command queue handle
*
* Return: (transfer none): ID3D12CommandQueue handle
*
* Since: 1.26
*/
ID3D12CommandQueue *
gst_d3d12_command_queue_get_handle (GstD3D12CommandQueue * queue)
{
@ -190,6 +206,16 @@ gst_d3d12_command_queue_get_handle (GstD3D12CommandQueue * queue)
return queue->priv->cq.Get ();
}
/**
* gst_d3d12_command_queue_get_fence_handle:
* @queue: a #GstD3D12CommandQueue
*
* Gets fence handle handle
*
* Return: (transfer none): ID3D12Fence handle
*
* Since: 1.26
*/
ID3D12Fence *
gst_d3d12_command_queue_get_fence_handle (GstD3D12CommandQueue * queue)
{
@ -198,6 +224,20 @@ gst_d3d12_command_queue_get_fence_handle (GstD3D12CommandQueue * queue)
return queue->priv->fence.Get ();
}
/**
* gst_d3d12_command_queue_execute_command_lists:
* @queue: a #GstD3D12CommandQueue
* @num_command_lists: command list size
* @command_lists: array of ID3D12CommandList
* @fence_value: (out) (optional): fence value of submitted command
*
* Executes command list and signals queue. If @num_command_lists is zero,
* Only fence signal is executed with fence value increment.
*
* Return: HRESULT code
*
* Since: 1.26
*/
HRESULT
gst_d3d12_command_queue_execute_command_lists (GstD3D12CommandQueue * queue,
guint num_command_lists, ID3D12CommandList ** command_lists,
@ -236,6 +276,18 @@ gst_d3d12_command_queue_execute_command_lists (GstD3D12CommandQueue * queue,
return hr;
}
/**
* gst_d3d12_command_queue_execute_wait:
* @queue: a #GstD3D12CommandQueue
* @fence: a ID3D12Fence
* @fence_value: fence value to wait
*
* Exectues ID3D12CommandQueue::Wait() operation
*
* Return: %TRUE if successful
*
* Since: 1.26
*/
HRESULT
gst_d3d12_command_queue_execute_wait (GstD3D12CommandQueue * queue,
ID3D12Fence * fence, guint64 fence_value)
@ -248,6 +300,16 @@ gst_d3d12_command_queue_execute_wait (GstD3D12CommandQueue * queue,
return priv->cq->Wait (fence, fence_value);
}
/**
* gst_d3d12_command_queue_get_completed_value:
* @queue: a #GstD3D12CommandQueue
*
* Gets completed fence value
*
* Returns: Completed fence value
*
* Since: 1.26
*/
guint64
gst_d3d12_command_queue_get_completed_value (GstD3D12CommandQueue * queue)
{
@ -256,6 +318,20 @@ gst_d3d12_command_queue_get_completed_value (GstD3D12CommandQueue * queue)
return queue->priv->fence->GetCompletedValue ();
}
/**
* gst_d3d12_command_queue_fence_wait:
* @queue: a #GstD3D12CommandQueue
* @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
* is completed. If @fence_value is %G_MAXUINT64, this method will block
* calling thread until all pending GPU operations are completed
*
* Returns: HRESULT code
*
* Since: 1.26
*/
HRESULT
gst_d3d12_command_queue_fence_wait (GstD3D12CommandQueue * queue,
guint64 fence_value, HANDLE event_handle)
@ -362,6 +438,26 @@ gst_d3d12_command_queue_gc_thread (GstD3D12CommandQueue * self)
return nullptr;
}
/**
* gst_d3d12_command_queue_set_notify:
* @queue: a #GstD3D12CommandQueue
* @fence_value: target fence value
* @fence_data: user data
* @notify: a #GDestroyNotify
*
* Schedules oneshot @notify callback.
*
* This method is designed for garbage collection task.
* Users can construct a storage which holds graphics command associated
* resources (e.g., command allocator, descriptors, and textures) and pass
* the storage with destructor, in order to keep resources alive during
* command execution.
*
* GstD3D12CommandQueue launches internal worker thread to monitor fence value
* and once it reaches the scheduled value, @notify will be called with @fence_data
*
* Since: 1.26
*/
void
gst_d3d12_command_queue_set_notify (GstD3D12CommandQueue * queue,
guint64 fence_value, gpointer fence_data, GDestroyNotify notify)
@ -384,6 +480,16 @@ gst_d3d12_command_queue_set_notify (GstD3D12CommandQueue * queue,
priv->cond.notify_one ();
}
/**
* gst_d3d12_command_queue_drain:
* @queue: a #GstD3D12CommandQueue
*
* Waits for all scheduled GPU commands to be finished
*
* Returns: HRESULT code
*
* Since: 1.26
*/
HRESULT
gst_d3d12_command_queue_drain (GstD3D12CommandQueue * queue)
{

View file

@ -21,44 +21,90 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
#define GST_TYPE_D3D12_COMMAND_QUEUE (gst_d3d12_command_queue_get_type())
G_DECLARE_FINAL_TYPE (GstD3D12CommandQueue,
gst_d3d12_command_queue, GST, D3D12_COMMAND_QUEUE, GstObject);
#define GST_TYPE_D3D12_COMMAND_QUEUE (gst_d3d12_command_queue_get_type ())
#define GST_D3D12_COMMAND_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_D3D12_COMMAND_QUEUE, GstD3D12CommandQueue))
#define GST_D3D12_COMMAND_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_D3D12_COMMAND_QUEUE, GstD3D12CommandQueueClass))
#define GST_IS_D3D12_COMMAND_QUEUE(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_D3D12_COMMAND_QUEUE))
#define GST_IS_D3D12_COMMAND_QUEUE_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_D3D12_COMMAND_QUEUE))
#define GST_D3D12_COMMAND_QUEUE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_D3D12_COMMAND_QUEUE, GstD3D12CommandQueueClass))
#define GST_D3D12_COMMAND_QUEUE_CAST(obj) ((GstD3D12CommandQueue*)(obj))
/**
* GstD3D12CommandQueue:
*
* Opaque GstD3D12CommandQueue struct
*
* Since: 1.26
*/
struct _GstD3D12CommandQueue
{
GstObject parent;
/*< private >*/
GstD3D12CommandQueuePrivate *priv;
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstD3D12CommandQueueClass:
*
* Opaque GstD3D12CommandQueueClass struct
*
* Since: 1.26
*/
struct _GstD3D12CommandQueueClass
{
GstObjectClass parent_class;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
GST_D3D12_API
GType gst_d3d12_command_queue_get_type (void);
GST_D3D12_API
GstD3D12CommandQueue * gst_d3d12_command_queue_new (ID3D12Device * device,
const D3D12_COMMAND_QUEUE_DESC * desc,
D3D12_FENCE_FLAGS fence_flags,
guint queue_size);
GST_D3D12_API
ID3D12CommandQueue * gst_d3d12_command_queue_get_handle (GstD3D12CommandQueue * queue);
GST_D3D12_API
ID3D12Fence * gst_d3d12_command_queue_get_fence_handle (GstD3D12CommandQueue * queue);
GST_D3D12_API
HRESULT gst_d3d12_command_queue_execute_command_lists (GstD3D12CommandQueue * queue,
guint num_command_lists,
ID3D12CommandList ** command_lists,
guint64 * fence_value);
GST_D3D12_API
HRESULT gst_d3d12_command_queue_execute_wait (GstD3D12CommandQueue * queue,
ID3D12Fence * fence,
guint64 fence_value);
GST_D3D12_API
guint64 gst_d3d12_command_queue_get_completed_value (GstD3D12CommandQueue * queue);
GST_D3D12_API
HRESULT gst_d3d12_command_queue_fence_wait (GstD3D12CommandQueue * queue,
guint64 fence_value,
HANDLE event_handle);
GST_D3D12_API
void gst_d3d12_command_queue_set_notify (GstD3D12CommandQueue * queue,
guint64 fence_value,
gpointer fence_data,
GDestroyNotify notify);
GST_D3D12_API
HRESULT gst_d3d12_command_queue_drain (GstD3D12CommandQueue * queue);
G_END_DECLS

View file

@ -19,9 +19,6 @@
#pragma once
#include <gst/gst.h>
#include "gstd3d12_fwd.h"
#ifdef __cplusplus
template <typename T>
D3D12_CPU_DESCRIPTOR_HANDLE

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include <gst/d3d12/gstd3d12_fwd.h>
#include <vector>
#include <wrl.h>
#include <memory>

View file

@ -0,0 +1,41 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
GST_D3D12_API
gboolean gst_d3d12_converter_apply_transform (GstD3D12Converter * converter,
GstVideoOrientationMethod orientation,
gfloat viewport_width,
gfloat viewport_height,
gfloat fov,
gboolean ortho,
gfloat rotation_x,
gfloat rotation_y,
gfloat rotation_z,
gfloat scale_x,
gfloat scale_y);
G_END_DECLS

View file

@ -22,7 +22,9 @@
#endif
#include "gstd3d12.h"
#include "gstd3d12-private.h"
#include "gstd3d12converter-builder.h"
#include "gstd3d12converter-private.h"
#include <directx/d3dx12.h>
#include <wrl.h>
#include <string.h>
@ -1588,6 +1590,22 @@ gst_d3d12_converter_calculate_border_color (GstD3D12Converter * self)
}
}
/**
* gst_d3d12_converter_new:
* @device: a #GstD3D12Device
* @in_info: a #GstVideoInfo
* @out_info: a #GstVideoInfo
* @blend_desc: (nullable): D3D12_BLEND_DESC
* @blend_factor: (nullable): blend factor value
* @config: (nullable): converter config
*
* Creates a new converter instance
*
* Returns: (transfer full) (nullable): a new #GstD3D12Converter instance
* or %NULL if conversion is not supported
*
* Since: 1.26
*/
GstD3D12Converter *
gst_d3d12_converter_new (GstD3D12Device * device, const GstVideoInfo * in_info,
const GstVideoInfo * out_info, const D3D12_BLEND_DESC * blend_desc,
@ -2204,6 +2222,22 @@ gst_d3d12_converter_check_needs_upload (GstD3D12Converter * self,
return FALSE;
}
/**
* gst_d3d12_converter_convert_buffer:
* @converter: a #GstD3D12Converter
* @in_buf: a #GstBuffer
* @out_buf: a #GstBuffer
* @fence_data: a #GstD3D12FenceData
* @cl: a ID3D12GraphicsCommandList
*
* Records command list for conversion operation. converter will attach
* conversion command associated resources such as command allocator
* to @fence_data.
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_converter_convert_buffer (GstD3D12Converter * converter,
GstBuffer * in_buf, GstBuffer * out_buf, GstD3D12FenceData * fence_data,
@ -2244,6 +2278,19 @@ gst_d3d12_converter_convert_buffer (GstD3D12Converter * converter,
return ret;
}
/**
* gst_d3d12_converter_update_blend_state:
* @converter: a #GstD3D12Converter
* @blend_desc: (nullable): D3D12_BLEND_DESC
* @blend_factor: (nullable): blend factor values
*
* Updates pipeline state object with new @blend_desc. If @blend_desc is %NULL,
* pipeline state object will be updated with default blend state
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_converter_update_blend_state (GstD3D12Converter * converter,
const D3D12_BLEND_DESC * blend_desc, const gfloat blend_factor[4])

View file

@ -21,24 +21,25 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include "gstd3d12fencedatapool.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
#define GST_TYPE_D3D12_CONVERTER (gst_d3d12_converter_get_type())
#define GST_D3D12_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj),GST_TYPE_D3D12_CONVERTER,GstD3D12Converter))
#define GST_D3D12_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass),GST_TYPE_D3D12_CONVERTER,GstD3D12ConverterClass))
#define GST_D3D12_CONVERTER_GET_CLASS(obj) (GST_D3D12_CONVERTER_CLASS(G_OBJECT_GET_CLASS(obj)))
#define GST_IS_D3D12_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE((obj),GST_TYPE_D3D12_CONVERTER))
#define GST_IS_D3D12_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass),GST_TYPE_D3D12_CONVERTER))
#define GST_D3D12_CONVERTER_CAST(obj) ((GstD3D12Converter*)(obj))
#define GST_TYPE_D3D12_CONVERTER (gst_d3d12_converter_get_type ())
#define GST_D3D12_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_D3D12_CONVERTER, GstD3D12Converter))
#define GST_D3D12_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_D3D12_CONVERTER, GstD3D12ConverterClass))
#define GST_IS_D3D12_CONVERTER(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_D3D12_CONVERTER))
#define GST_IS_D3D12_CONVERTER_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_D3D12_CONVERTER))
#define GST_D3D12_CONVERTER_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_D3D12_CONVERTER, GstD3D12ConverterClass))
#define GST_D3D12_CONVERTER_CAST(obj) ((GstD3D12Converter*)(obj))
/**
* GST_D3D12_CONVERTER_OPT_GAMMA_MODE:
*
* #GstVideoGammaMode, set the gamma mode.
* Default is #GST_VIDEO_GAMMA_MODE_NONE
*
* Since: 1.26
*/
#define GST_D3D12_CONVERTER_OPT_GAMMA_MODE "GstD3D12Converter.gamma-mode"
@ -47,24 +48,29 @@ G_BEGIN_DECLS
*
* #GstVideoPrimariesMode, set the primaries conversion mode.
* Default is #GST_VIDEO_PRIMARIES_MODE_NONE.
*
* Since: 1.26
*/
#define GST_D3D12_CONVERTER_OPT_PRIMARIES_MODE "GstD3D12Converter.primaries-mode"
/**
* GST_D3D12_CONVERTER_OPT_SAMPLER_FILTER:
*
* #D3D12_FILTER, set sampler filter.
*
* Supported values are:
* @D3D12_FILTER_MIN_MAG_MIP_POINT
* @D3D12_FILTER_MIN_LINEAR_MAG_MIP_POINT
* @D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT
* @D3D12_FILTER_ANISOTROPIC
*
* Default is #D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT.
*/
/**
* GST_D3D12_CONVERTER_OPT_SAMPLER_FILTER:
*
* #D3D12_FILTER, set sampler filter.
*
* Supported values are:
* @D3D12_FILTER_MIN_MAG_MIP_POINT
* @D3D12_FILTER_MIN_LINEAR_MAG_MIP_POINT
* @D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT
* @D3D12_FILTER_ANISOTROPIC
*
* Default is #D3D12_FILTER_MIN_MAG_LINEAR_MIP_POINT.
*
* Since: 1.26
*/
#define GST_D3D12_CONVERTER_OPT_SAMPLER_FILTER "GstD3D12Converter.sampler-filter"
GST_D3D12_API
GType gst_d3d12_converter_sampler_filter_get_type (void);
#define GST_TYPE_D3D12_CONVERTER_SAMPLER_FILTER (gst_d3d12_converter_sampler_filter_get_type())
@ -75,6 +81,8 @@ GType gst_d3d12_converter_sampler_filter_get_type (void);
* @GST_D3D12_CONVERTER_ALPHA_MODE_STRAIGHT: Straight alpha
*
* Alpha mode. Enum values are idnetical to DXGI_ALPHA_MODE
*
* Since: 1.26
*/
typedef enum
{
@ -83,6 +91,7 @@ typedef enum
GST_D3D12_CONVERTER_ALPHA_MODE_STRAIGHT = 2,
} GstD3D12ConverterAlphaMode;
GST_D3D12_API
GType gst_d3d12_converter_alpha_mode_get_type (void);
#define GST_TYPE_D3D12_CONVERTER_ALPHA_MODE (gst_d3d12_converter_alpha_mode_get_type())
@ -91,6 +100,8 @@ GType gst_d3d12_converter_alpha_mode_get_type (void);
*
* Set the source alpha mode.
* Default is #GST_D3D12_CONVERTER_ALPHA_MODE_UNSPECIFIED.
*
* Since: 1.26
*/
#define GST_D3D12_CONVERTER_OPT_SRC_ALPHA_MODE "GstD3D12Converter.src-alpha-mode"
@ -99,6 +110,8 @@ GType gst_d3d12_converter_alpha_mode_get_type (void);
*
* Set the source alpha mode.
* Default is #GST_D3D12_CONVERTER_ALPHA_MODE_UNSPECIFIED.
*
* Since: 1.26
*/
#define GST_D3D12_CONVERTER_OPT_DEST_ALPHA_MODE "GstD3D12Converter.dest-alpha-mode"
@ -106,6 +119,8 @@ GType gst_d3d12_converter_alpha_mode_get_type (void);
* GstD3D12Converter:
*
* Opaque GstD3D12Converter struct
*
* Since: 1.26
*/
struct _GstD3D12Converter
{
@ -122,6 +137,8 @@ struct _GstD3D12Converter
* GstD3D12ConverterClass:
*
* Opaque GstD3D12ConverterClass struct
*
* Since: 1.26
*/
struct _GstD3D12ConverterClass
{
@ -131,8 +148,10 @@ struct _GstD3D12ConverterClass
gpointer _gst_reserved[GST_PADDING];
};
GST_D3D12_API
GType gst_d3d12_converter_get_type (void);
GST_D3D12_API
GstD3D12Converter * gst_d3d12_converter_new (GstD3D12Device * device,
const GstVideoInfo * in_info,
const GstVideoInfo * out_info,
@ -140,26 +159,16 @@ GstD3D12Converter * gst_d3d12_converter_new (GstD3D12Device * device,
const gfloat blend_factor[4],
GstStructure * config);
GST_D3D12_API
gboolean gst_d3d12_converter_convert_buffer (GstD3D12Converter * converter,
GstBuffer * in_buf,
GstBuffer * out_buf,
GstD3D12FenceData * fence_data,
ID3D12GraphicsCommandList * command_list);
GST_D3D12_API
gboolean gst_d3d12_converter_update_blend_state (GstD3D12Converter * converter,
const D3D12_BLEND_DESC * blend_desc,
const gfloat blend_factor[4]);
gboolean gst_d3d12_converter_apply_transform (GstD3D12Converter * converter,
GstVideoOrientationMethod orientation,
gfloat viewport_width,
gfloat viewport_height,
gfloat fov,
gboolean ortho,
gfloat rotation_x,
gfloat rotation_y,
gfloat rotation_z,
gfloat scale_x,
gfloat scale_y);
G_END_DECLS

View file

@ -38,9 +38,9 @@ struct _GstD3D12Descriptor : public GstMiniObject
ComPtr < ID3D12DescriptorHeap > heap;
};
struct GstD3D12DescriptorPoolPrivate
struct _GstD3D12DescriptorPoolPrivate
{
~GstD3D12DescriptorPoolPrivate ()
~_GstD3D12DescriptorPoolPrivate ()
{
while (!heap_pool.empty ()) {
auto desc = heap_pool.front ();
@ -57,13 +57,6 @@ struct GstD3D12DescriptorPoolPrivate
};
/* *INDENT-ON* */
struct _GstD3D12DescriptorPool
{
GstObject parent;
GstD3D12DescriptorPoolPrivate *priv;
};
GST_DEFINE_MINI_OBJECT_TYPE (GstD3D12Descriptor, gst_d3d12_descriptor);
static void gst_d3d12_descriptor_pool_finalize (GObject * object);
@ -99,6 +92,15 @@ gst_d3d12_descriptor_pool_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/**
* gst_d3d12_descriptor_pool_new:
* @device: a #GstD3D12Device
* @type: D3D12_DESCRIPTOR_HEAP_DESC
*
* Returns: (transfer full): a new #GstD3D12DescriptorPool instance
*
* Since: 1.26
*/
GstD3D12DescriptorPool *
gst_d3d12_descriptor_pool_new (ID3D12Device * device,
const D3D12_DESCRIPTOR_HEAP_DESC * desc)
@ -162,6 +164,17 @@ gst_d3d12_descriptor_new (ID3D12DescriptorHeap * heap)
return desc;
}
/**
* gst_d3d12_descriptor_pool_acquire:
* @pool: a #GstD3D12DescriptorPool
* @cmd: (out) (transfer full): a pointer to GstD3D12Descriptor
*
* Acquire #GstD3D12Descriptor object
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_descriptor_pool_acquire (GstD3D12DescriptorPool * pool,
GstD3D12Descriptor ** desc)
@ -205,24 +218,60 @@ gst_d3d12_descriptor_pool_acquire (GstD3D12DescriptorPool * pool,
return TRUE;
}
/**
* gst_d3d12_descriptor_ref:
* @desc: a #GstD3D12Descriptor
*
* Increments the refcount of @desc
*
* Returns: (transfer full): a #GstD3D12Descriptor
*
* Since: 1.26
*/
GstD3D12Descriptor *
gst_d3d12_descriptor_ref (GstD3D12Descriptor * desc)
{
return (GstD3D12Descriptor *) gst_mini_object_ref (desc);
}
/**
* gst_d3d12_descriptor_unref:
* @desc: a #GstD3D12Descriptor
*
* Decrements the refcount of @desc
*
* Since: 1.26
*/
void
gst_d3d12_descriptor_unref (GstD3D12Descriptor * desc)
{
gst_mini_object_unref (desc);
}
/**
* gst_clear_d3d12_descriptor:
* @desc: a pointer to #GstD3D12Descriptor
*
* Clears a reference to a #GstD3D12Descriptor
*
* Since: 1.26
*/
void
gst_clear_d3d12_descriptor (GstD3D12Descriptor ** desc)
{
gst_clear_mini_object (desc);
}
/**
* gst_d3d12_descriptor_get_handle:
* @desc: a #GstD3D12Descriptor
*
* Gets ID3D12DescriptorHeap handle.
*
* Returns: (transfer none): ID3D12DescriptorHeap handle
*
* Since: 1.26
*/
ID3D12DescriptorHeap *
gst_d3d12_descriptor_get_handle (GstD3D12Descriptor * desc)
{

View file

@ -21,30 +21,73 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
#define GST_TYPE_D3D12_DESCRIPTOR_POOL (gst_d3d12_descriptor_pool_get_type())
G_DECLARE_FINAL_TYPE (GstD3D12DescriptorPool,
gst_d3d12_descriptor_pool, GST, D3D12_DESCRIPTOR_POOL, GstObject);
#define GST_TYPE_D3D12_DESCRIPTOR_POOL (gst_d3d12_descriptor_pool_get_type ())
#define GST_D3D12_DESCRIPTOR_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_D3D12_DESCRIPTOR_POOL, GstD3D12DescriptorPool))
#define GST_D3D12_DESCRIPTOR_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_D3D12_DESCRIPTOR_POOL, GstD3D12DescriptorPoolClass))
#define GST_IS_D3D12_DESCRIPTOR_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_D3D12_DESCRIPTOR_POOL))
#define GST_IS_D3D12_DESCRIPTOR_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_D3D12_DESCRIPTOR_POOL))
#define GST_D3D12_DESCRIPTOR_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_D3D12_DESCRIPTOR_POOL, GstD3D12DescriptorPoolClass))
#define GST_D3D12_DESCRIPTOR_POOL_CAST(obj) ((GstD3D12DescriptorPool*)(obj))
typedef struct _GstD3D12Descriptor GstD3D12Descriptor;
/**
* GstD3D12DescriptorPool:
*
* Opaque GstD3D12DescriptorPool struct
*
* Since: 1.26
*/
struct _GstD3D12DescriptorPool
{
GstObject parent;
GType gst_d3d12_descriptor_get_type (void);
/*< private >*/
GstD3D12DescriptorPoolPrivate *priv;
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstD3D12DescriptorPoolClass:
*
* Opaque GstD3D12DescriptorPoolClass struct
*
* Since: 1.26
*/
struct _GstD3D12DescriptorPoolClass
{
GstObjectClass parent_class;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
GST_D3D12_API
GType gst_d3d12_descriptor_pool_get_type (void);
GST_D3D12_API
GType gst_d3d12_descriptor_get_type (void);
GST_D3D12_API
GstD3D12DescriptorPool * gst_d3d12_descriptor_pool_new (ID3D12Device * device,
const D3D12_DESCRIPTOR_HEAP_DESC * desc);
GST_D3D12_API
gboolean gst_d3d12_descriptor_pool_acquire (GstD3D12DescriptorPool * pool,
GstD3D12Descriptor ** desc);
GST_D3D12_API
GstD3D12Descriptor * gst_d3d12_descriptor_ref (GstD3D12Descriptor * desc);
GST_D3D12_API
void gst_d3d12_descriptor_unref (GstD3D12Descriptor * desc);
GST_D3D12_API
void gst_clear_d3d12_descriptor (GstD3D12Descriptor ** desc);
GST_D3D12_API
ID3D12DescriptorHeap * gst_d3d12_descriptor_get_handle (GstD3D12Descriptor * desc);
G_END_DECLS

View file

@ -0,0 +1,56 @@
/* GStreamer
* Copyright (C) 2024 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
struct GstD3D12CopyTextureRegionArgs
{
D3D12_TEXTURE_COPY_LOCATION dst;
guint dst_x;
guint dst_y;
guint dst_z;
D3D12_TEXTURE_COPY_LOCATION src;
const D3D12_BOX * src_box;
};
GST_D3D12_API
gboolean gst_d3d12_device_copy_texture_region (GstD3D12Device * device,
guint num_args,
const GstD3D12CopyTextureRegionArgs * args,
D3D12_COMMAND_LIST_TYPE command_type,
guint64 * fence_value);
GST_D3D12_API
void gst_d3d12_device_clear_yuv_texture (GstD3D12Device * device,
GstMemory * mem);
GST_D3D12_API
void gst_d3d12_device_d3d12_debug (GstD3D12Device * device,
const gchar * file,
const gchar * function,
gint line);
G_END_DECLS

View file

@ -23,6 +23,7 @@
#include "gstd3d12.h"
#include "gstd3d12-private.h"
#include "gstd3d12commandlistpool.h"
#include <directx/d3dx12.h>
#include <wrl.h>
#include <vector>
@ -773,6 +774,15 @@ error:
return nullptr;
}
/**
* gst_d3d12_device_new:
* @adapter_index: DXGI adapter index
*
* Returns: (transfer full) (nullable): a new #GstD3D12Device for @adapter_index
* or %NULL when failed to create D3D12 device with given adapter index.
*
* Since: 1.26
*/
GstD3D12Device *
gst_d3d12_device_new (guint adapter_index)
{
@ -784,6 +794,15 @@ gst_d3d12_device_new (guint adapter_index)
return manager->GetDevice (&data);
}
/**
* gst_d3d12_device_new_for_adapter_luid:
* @adapter_luid: an int64 representation of the DXGI adapter LUID
*
* Returns: (transfer full) (nullable): a new #GstD3D12Device for @adapter_luid
* or %NULL when failed to create D3D12 device with given adapter luid.
*
* Since: 1.26
*/
GstD3D12Device *
gst_d3d12_device_new_for_adapter_luid (gint64 adapter_luid)
{
@ -795,6 +814,16 @@ gst_d3d12_device_new_for_adapter_luid (gint64 adapter_luid)
return manager->GetDevice (&data);
}
/**
* gst_d3d12_device_get_device_handle:
* @device: a #GstD3D12Device
*
* Gets ID3D12Device handle
*
* Returns: (transfer none): ID3D12Device handle
*
* Since: 1.26
*/
ID3D12Device *
gst_d3d12_device_get_device_handle (GstD3D12Device * device)
{
@ -803,6 +832,16 @@ gst_d3d12_device_get_device_handle (GstD3D12Device * device)
return device->priv->inner->device.Get ();
}
/**
* gst_d3d12_device_get_adapter_handle:
* @device: a #GstD3D12Device
*
* Gets IDXGIAdapter1 handle
*
* Returns: (transfer none): IDXGIAdapter1 handle
*
* Since: 1.26
*/
IDXGIAdapter1 *
gst_d3d12_device_get_adapter_handle (GstD3D12Device * device)
{
@ -811,6 +850,16 @@ gst_d3d12_device_get_adapter_handle (GstD3D12Device * device)
return device->priv->inner->adapter.Get ();
}
/**
* gst_d3d12_device_get_factory_handle:
* @device: a #GstD3D12Device
*
* Gets IDXGIFactory2 handle
*
* Returns: (transfer none): IDXGIFactory2 handle
*
* Since: 1.26
*/
IDXGIFactory2 *
gst_d3d12_device_get_factory_handle (GstD3D12Device * device)
{
@ -819,6 +868,19 @@ gst_d3d12_device_get_factory_handle (GstD3D12Device * device)
return device->priv->inner->factory.Get ();
}
/**
* gst_d3d12_device_get_format:
* @device: a #GstD3D12Device
* @format: a #GstVideoFormat
* @device_format: (out caller-allocates): a #GstD3D11Format
*
* Converts @format to #GstD3D12Format if the @format is supported
* by device
*
* Returns: %TRUE if @format is supported by @device
*
* Since: 1.26
*/
gboolean
gst_d3d12_device_get_format (GstD3D12Device * device,
GstVideoFormat format, GstD3D12Format * device_format)
@ -831,12 +893,22 @@ gst_d3d12_device_get_format (GstD3D12Device * device,
if (target == priv->format_table.end ())
return FALSE;
if (device_format)
*device_format = target->second;
*device_format = target->second;
return TRUE;
}
/**
* gst_d3d12_device_get_command_queue:
* @device: a #GstD3D12Device
* @queue_type: a D3D12_COMMAND_LIST_TYPE
*
* Gets #GstD3D12CommandQueue corresponding to @queue_type
*
* Returns: (transfer none): a #GstD3D12CommandQueue
*
* Since: 1.26
*/
GstD3D12CommandQueue *
gst_d3d12_device_get_command_queue (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type)
@ -859,6 +931,21 @@ gst_d3d12_device_get_command_queue (GstD3D12Device * device,
return nullptr;
}
/**
* gst_d3d12_device_execute_command_lists:
* @device: a #GstD3D12Device
* @queue_type: a D3D12_COMMAND_LIST_TYPE
* @num_command_lists: command list size
* @command_lists: array of ID3D12CommandList
* @fence_value: (out) (optional): fence value of submitted command
*
* Exectues gst_d3d12_command_queue_execute_command_lists ()
* using a #GstD3D12CommandQueue corresponding to @queue_type
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_device_execute_command_lists (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type, guint num_command_lists,
@ -887,6 +974,18 @@ gst_d3d12_device_execute_command_lists (GstD3D12Device * device,
return gst_d3d12_result (hr, device);
}
/**
* gst_d3d12_device_get_completed_value:
* @device: a #GstD3D12Device
* @queue_type: a D3D12_COMMAND_LIST_TYPE
*
* Exectues gst_d3d12_command_queue_get_completed_value ()
* using a #GstD3D12CommandQueue corresponding to @queue_type
*
* Returns: Completed fence value
*
* Since: 1.26
*/
guint64
gst_d3d12_device_get_completed_value (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type)
@ -911,6 +1010,21 @@ gst_d3d12_device_get_completed_value (GstD3D12Device * device,
return gst_d3d12_command_queue_get_completed_value (queue);
}
/**
* gst_d3d12_device_get_completed_value:
* @device: a #GstD3D12Device
* @queue_type: a D3D12_COMMAND_LIST_TYPE
* @fence_value: target fence value
* @fence_data: user data
* @notify: a #GDestroyNotify
*
* Exectues gst_d3d12_command_queue_set_notify ()
* using a #GstD3D12CommandQueue corresponding to @queue_type
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_device_set_fence_notify (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type, guint64 fence_value,
@ -940,6 +1054,20 @@ gst_d3d12_device_set_fence_notify (GstD3D12Device * device,
return TRUE;
}
/**
* gst_d3d12_device_fence_wait:
* @device: a #GstD3D12Device
* @queue_type: a D3D12_COMMAND_LIST_TYPE
* @fence_value: target fence value
* @handle: (nullable) (transfer none): event handle used for fence wait
*
* Exectues gst_d3d12_command_queue_fence_wait ()
* using a #GstD3D12CommandQueue corresponding to @queue_type
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_device_fence_wait (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type, guint64 fence_value,
@ -1200,6 +1328,17 @@ gst_d3d12_device_clear_yuv_texture (GstD3D12Device * device, GstMemory * mem)
}
}
/**
* gst_d3d12_device_is_equal:
* @device1: (transfer none) (nullable): a #GstD3D12Device
* @device2: (transfer none) (nullable): a #GstD3D12Device
*
* Checks if the given devices represent the same device
*
* Returns: %TRUE if both devices are valid and equal
*
* Since: 1.26
*/
gboolean
gst_d3d12_device_is_equal (GstD3D12Device * device1, GstD3D12Device * device2)
{

View file

@ -21,8 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include "gstd3d12commandqueue.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
@ -36,6 +35,13 @@ G_BEGIN_DECLS
#define GST_D3D12_DEVICE_HANDLE_CONTEXT_TYPE "gst.d3d12.device.handle"
/**
* GstD3D12Device:
*
* Opaque GstD3D12Device struct
*
* Since: 1.26
*/
struct _GstD3D12Device
{
GstObject parent;
@ -45,6 +51,13 @@ struct _GstD3D12Device
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstD3D12DeviceClass:
*
* Opaque GstD3D12DeviceClass struct
*
* Since: 1.26
*/
struct _GstD3D12DeviceClass
{
GstObjectClass parent_class;
@ -53,65 +66,57 @@ struct _GstD3D12DeviceClass
gpointer _gst_reserved[GST_PADDING];
};
typedef struct _GstD3D12CopyTextureRegionArgs
{
D3D12_TEXTURE_COPY_LOCATION dst;
guint dst_x;
guint dst_y;
guint dst_z;
D3D12_TEXTURE_COPY_LOCATION src;
const D3D12_BOX * src_box;
} GstD3D12CopyTextureRegionArgs;
GST_D3D12_API
GType gst_d3d12_device_get_type (void);
GST_D3D12_API
GstD3D12Device * gst_d3d12_device_new (guint adapter_index);
GST_D3D12_API
GstD3D12Device * gst_d3d12_device_new_for_adapter_luid (gint64 adapter_luid);
GST_D3D12_API
ID3D12Device * gst_d3d12_device_get_device_handle (GstD3D12Device * device);
GST_D3D12_API
IDXGIAdapter1 * gst_d3d12_device_get_adapter_handle (GstD3D12Device * device);
GST_D3D12_API
IDXGIFactory2 * gst_d3d12_device_get_factory_handle (GstD3D12Device * device);
GST_D3D12_API
gboolean gst_d3d12_device_get_format (GstD3D12Device * device,
GstVideoFormat format,
GstD3D12Format * device_format);
GST_D3D12_API
GstD3D12CommandQueue * gst_d3d12_device_get_command_queue (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type);
GST_D3D12_API
gboolean gst_d3d12_device_execute_command_lists (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type,
guint num_command_lists,
ID3D12CommandList ** command_lists,
guint64 * fence_value);
GST_D3D12_API
guint64 gst_d3d12_device_get_completed_value (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type);
GST_D3D12_API
gboolean gst_d3d12_device_set_fence_notify (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type,
guint64 fence_value,
GstD3D12FenceData * fence_data);
GST_D3D12_API
gboolean gst_d3d12_device_fence_wait (GstD3D12Device * device,
D3D12_COMMAND_LIST_TYPE queue_type,
guint64 fence_value,
HANDLE event_handle);
gboolean gst_d3d12_device_copy_texture_region (GstD3D12Device * device,
guint num_args,
const GstD3D12CopyTextureRegionArgs * args,
D3D12_COMMAND_LIST_TYPE command_type,
guint64 * fence_value);
void gst_d3d12_device_d3d12_debug (GstD3D12Device * device,
const gchar * file,
const gchar * function,
gint line);
GST_D3D12_API
gboolean gst_d3d12_device_is_equal (GstD3D12Device * device1,
GstD3D12Device * device2);

View file

@ -66,9 +66,9 @@ struct _GstD3D12FenceData : public GstMiniObject
GST_DEFINE_MINI_OBJECT_TYPE (GstD3D12FenceData, gst_d3d12_fence_data);
struct GstD3D12FenceDataPoolPrivate
struct _GstD3D12FenceDataPoolPrivate
{
~GstD3D12FenceDataPoolPrivate ()
~_GstD3D12FenceDataPoolPrivate ()
{
while (!data_pool.empty ()) {
auto data = data_pool.front ();
@ -82,13 +82,6 @@ struct GstD3D12FenceDataPoolPrivate
};
/* *INDENT-ON* */
struct _GstD3D12FenceDataPool
{
GstObject parent;
GstD3D12FenceDataPoolPrivate *priv;
};
static void gst_d3d12_fence_data_pool_finalize (GObject * object);
#define gst_d3d12_fence_data_pool_parent_class parent_class
@ -122,6 +115,15 @@ gst_d3d12_fence_data_pool_finalize (GObject * object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
/**
* gst_d3d12_fence_data_pool_new:
*
* Creates #GstD3D12FenceDataPool instance
*
* Returns: (transfer full): a #GstD3D12FenceDataPool instance
*
* Since: 1.26
*/
GstD3D12FenceDataPool *
gst_d3d12_fence_data_pool_new (void)
{
@ -177,6 +179,17 @@ gst_d3d12_fence_data_new (void)
return data;
}
/**
* gst_d3d12_fence_data_pool_acquire:
* @pool: a #GstD3D12FenceDataPool
* @data: (out) (transfer full): a pointer to #GstD3D12FenceData
*
* Acquire #GstD3D12CommandAllocator object
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_fence_data_pool_acquire (GstD3D12FenceDataPool * pool,
GstD3D12FenceData ** data)
@ -219,6 +232,16 @@ gst_d3d12_fence_data_add_notify_internal (GstD3D12FenceData * data,
gst_queue_array_push_tail_struct (data->queue, &notify_data);
}
/**
* gst_d3d12_fence_data_add_notify:
* @data: a #GstD3D12FenceData
* @user_data: private data
* @notify: a #GDestroyNotify
*
* Sets notify callback
*
* Since: 1.26
*/
void
gst_d3d12_fence_data_add_notify (GstD3D12FenceData * data, gpointer user_data,
GDestroyNotify notify)
@ -235,6 +258,15 @@ com_free_func (IUnknown * unknown)
unknown->Release ();
}
/**
* gst_d3d12_fence_data_add_notify_com:
* @data: a #GstD3D12FenceData
* @unknown: (transfer full): IUnknown COM pointer
*
* Schedules IUnknown::Release() notify for @unknown
*
* Since: 1.26
*/
void
gst_d3d12_fence_data_add_notify_com (GstD3D12FenceData * data, gpointer unknown)
{
@ -244,6 +276,15 @@ gst_d3d12_fence_data_add_notify_com (GstD3D12FenceData * data, gpointer unknown)
unknown, (GDestroyNotify) com_free_func);
}
/**
* gst_d3d12_fence_data_add_notify_mini_object:
* @data: a #GstD3D12FenceData
* @object: (transfer full): #GstMiniObject
*
* Schedules gst_mini_object_unref() notify for @object
*
* Since: 1.26
*/
void
gst_d3d12_fence_data_add_notify_mini_object (GstD3D12FenceData * data,
gpointer object)
@ -254,18 +295,44 @@ gst_d3d12_fence_data_add_notify_mini_object (GstD3D12FenceData * data,
object, (GDestroyNotify) gst_mini_object_unref);
}
/**
* gst_d3d12_fence_data_ref:
* @data: a #GstD3D12FenceData
*
* Increments the refcount of @data
*
* Returns: (transfer full): a #GstD3D12FenceData
*
* Since: 1.26
*/
GstD3D12FenceData *
gst_d3d12_fence_data_ref (GstD3D12FenceData * data)
{
return (GstD3D12FenceData *) gst_mini_object_ref (data);
}
/**
* gst_d3d12_fence_data_unref:
* @cmd: a #GstD3D12FenceData
*
* Decrements the refcount of @data
*
* Since: 1.26
*/
void
gst_d3d12_fence_data_unref (GstD3D12FenceData * data)
{
gst_mini_object_unref (data);
}
/**
* gst_clear_d3d12_fence_data:
* @data: a pointer to #GstD3D12FenceData
*
* Clears a reference to a #GstD3D12FenceData
*
* Since: 1.26
*/
void
gst_clear_d3d12_fence_data (GstD3D12FenceData ** data)
{

View file

@ -21,35 +21,82 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
#define GST_TYPE_D3D12_FENCE_DATA_POOL (gst_d3d12_fence_data_pool_get_type())
G_DECLARE_FINAL_TYPE (GstD3D12FenceDataPool,
gst_d3d12_fence_data_pool, GST, D3D12_FENCE_DATA_POOL, GstObject);
#define GST_TYPE_D3D12_FENCE_DATA_POOL (gst_d3d12_fence_data_pool_get_type ())
#define GST_D3D12_FENCE_DATA_POOL(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_D3D12_FENCE_DATA_POOL, GstD3D12FenceDataPool))
#define GST_D3D12_FENCE_DATA_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GST_TYPE_D3D12_FENCE_DATA_POOL, GstD3D12FenceDataPoolClass))
#define GST_IS_D3D12_FENCE_DATA_POOL(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GST_TYPE_D3D12_FENCE_DATA_POOL))
#define GST_IS_D3D12_FENCE_DATA_POOL_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GST_TYPE_D3D12_FENCE_DATA_POOL))
#define GST_D3D12_FENCE_DATA_POOL_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GST_TYPE_D3D12_FENCE_DATA_POOL, GstD3D12FenceDataPoolClass))
#define GST_D3D12_FENCE_DATA_POOL_CAST(obj) ((GstD3D12FenceDataPool*)(obj))
GType gst_d3d12_fence_data_get_type (void);
/**
* GstD3D12FenceDataPool:
*
* Opaque GstD3D12FenceDataPool struct
*
* Since: 1.26
*/
struct _GstD3D12FenceDataPool
{
GstObject parent;
/*< private >*/
GstD3D12FenceDataPoolPrivate *priv;
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstD3D12FenceDataPoolClass:
*
* Opaque GstD3D12FenceDataPoolClass struct
*
* Since: 1.26
*/
struct _GstD3D12FenceDataPoolClass
{
GstObjectClass parent_class;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
};
GST_D3D12_API
GType gst_d3d12_fence_data_pool_get_type (void);
GST_D3D12_API
GType gst_d3d12_fence_data_get_type (void);
GST_D3D12_API
GstD3D12FenceDataPool * gst_d3d12_fence_data_pool_new (void);
GST_D3D12_API
gboolean gst_d3d12_fence_data_pool_acquire (GstD3D12FenceDataPool * pool,
GstD3D12FenceData ** data);
GST_D3D12_API
void gst_d3d12_fence_data_add_notify (GstD3D12FenceData * data,
gpointer user_data,
GDestroyNotify notify);
GST_D3D12_API
void gst_d3d12_fence_data_add_notify_com (GstD3D12FenceData * data,
gpointer unknown);
GST_D3D12_API
void gst_d3d12_fence_data_add_notify_mini_object (GstD3D12FenceData * data,
gpointer object);
GST_D3D12_API
GstD3D12FenceData * gst_d3d12_fence_data_ref (GstD3D12FenceData * data);
GST_D3D12_API
void gst_d3d12_fence_data_unref (GstD3D12FenceData * data);
GST_D3D12_API
void gst_clear_d3d12_fence_data (GstD3D12FenceData ** data);
G_END_DECLS

View file

@ -20,40 +20,45 @@
#pragma once
#include <gst/gst.h>
#include "gstd3d12device.h"
#include "gstd3d12format.h"
#include <gst/video/video.h>
#include <gst/d3d12/gstd3d12_fwd.h>
#include <gst/d3d12/gstd3d12format.h>
/*
* Preferred sorting order in a tier
* - number of components
* - depth
* - subsampling
* - supports both SRV and RTV
* - prefer smaller number of planes
* - prefer non-complex formats
* - prefer YUV formats over RGB ones
* - prefer I420 over YV12
* - format name
*/
G_BEGIN_DECLS
/* DXGI (semi) native formats */
#define GST_D3D12_TIER_0_FORMATS \
"RGBA64_LE, RGB10A2_LE, Y410, VUYA, RGBA, BGRA, RBGA, P016_LE, P012_LE, " \
"P010_10LE, RGBx, BGRx, NV12"
struct GstD3D12ColorMatrix
{
gdouble matrix[3][3];
gdouble offset[3];
gdouble min[3];
gdouble max[3];
};
/* both SRV and RTV are supported */
#define GST_D3D12_TIER_1_FORMATS \
"AYUV64, GBRA_12LE, GBRA_10LE, AYUV, ABGR, ARGB, GBRA, Y444_16LE, " \
"GBR_16LE, Y444_12LE, GBR_12LE, I422_12LE, I420_12LE, Y444_10LE, GBR_10LE, " \
"I422_10LE, I420_10LE, Y444, BGRP, GBR, RGBP, xBGR, xRGB, Y42B, NV21, " \
"I420, YV12, GRAY16_LE, GRAY8"
GST_D3D12_API
void gst_d3d12_color_matrix_init (GstD3D12ColorMatrix * matrix);
#define GST_D3D12_COMMON_FORMATS \
GST_D3D12_TIER_0_FORMATS ", " \
GST_D3D12_TIER_1_FORMATS
GST_D3D12_API
gchar * gst_d3d12_dump_color_matrix (GstD3D12ColorMatrix * matrix);
#define GST_D3D12_ALL_FORMATS \
"{ " GST_D3D12_COMMON_FORMATS " }"
GST_D3D12_API
gboolean gst_d3d12_color_range_adjust_matrix_unorm (const GstVideoInfo * in_info,
const GstVideoInfo * out_info,
GstD3D12ColorMatrix * matrix);
GST_D3D12_API
gboolean gst_d3d12_yuv_to_rgb_matrix_unorm (const GstVideoInfo * in_yuv_info,
const GstVideoInfo * out_rgb_info,
GstD3D12ColorMatrix * matrix);
GST_D3D12_API
gboolean gst_d3d12_rgb_to_yuv_matrix_unorm (const GstVideoInfo * in_rgb_info,
const GstVideoInfo * out_yuv_info,
GstD3D12ColorMatrix * matrix);
GST_D3D12_API
gboolean gst_d3d12_color_primaries_matrix_unorm (const GstVideoColorPrimariesInfo * in_info,
const GstVideoColorPrimariesInfo * out_info,
GstD3D12ColorMatrix * matrix);
#define MAKE_FORMAT_MAP_YUV(g,d,r0,r1,r2,r3) \
{ GST_VIDEO_FORMAT_ ##g, DXGI_FORMAT_ ##d, \
@ -189,5 +194,9 @@ static const GstD3D12Format g_gst_d3d12_default_format_map[] = {
#define GST_D3D12_N_FORMATS G_N_ELEMENTS(g_gst_d3d12_default_format_map)
void gst_d3d12_device_clear_yuv_texture (GstD3D12Device * device,
GstMemory * mem);
GST_D3D12_API
guint gst_d3d12_dxgi_format_get_resource_format (DXGI_FORMAT format,
DXGI_FORMAT resource_format[GST_VIDEO_MAX_PLANES]);
G_END_DECLS

View file

@ -25,8 +25,20 @@
#include "gstd3d12-private.h"
#include <string.h>
GST_DEBUG_CATEGORY_EXTERN (gst_d3d12_format_debug);
#define GST_CAT_DEFAULT gst_d3d12_format_debug
#ifndef GST_DISABLE_GST_DEBUG
#define GST_CAT_DEFAULT ensure_debug_category()
static GstDebugCategory *
ensure_debug_category (void)
{
static GstDebugCategory *cat = nullptr;
GST_D3D12_CALL_ONCE_BEGIN {
cat = _gst_debug_category_new ("d3d12format", 0, "d3d12format");
} GST_D3D12_CALL_ONCE_END;
return cat;
}
#endif
GstVideoFormat
gst_d3d12_dxgi_format_to_gst (DXGI_FORMAT format)
@ -59,8 +71,8 @@ gst_d3d12_dxgi_format_to_gst (DXGI_FORMAT format)
return GST_VIDEO_FORMAT_UNKNOWN;
}
gboolean
gst_d3d12_dxgi_format_to_resource_formats (DXGI_FORMAT format,
guint
gst_d3d12_dxgi_format_get_resource_format (DXGI_FORMAT format,
DXGI_FORMAT resource_format[GST_VIDEO_MAX_PLANES])
{
g_return_val_if_fail (resource_format != nullptr, FALSE);
@ -68,43 +80,29 @@ gst_d3d12_dxgi_format_to_resource_formats (DXGI_FORMAT format,
for (guint i = 0; i < GST_VIDEO_MAX_PLANES; i++)
resource_format[i] = DXGI_FORMAT_UNKNOWN;
switch (format) {
case DXGI_FORMAT_B8G8R8A8_UNORM:
case DXGI_FORMAT_R8G8B8A8_UNORM:
case DXGI_FORMAT_R10G10B10A2_UNORM:
case DXGI_FORMAT_R8_UNORM:
case DXGI_FORMAT_R8G8_UNORM:
case DXGI_FORMAT_R16_UNORM:
case DXGI_FORMAT_R16G16_UNORM:
case DXGI_FORMAT_G8R8_G8B8_UNORM:
case DXGI_FORMAT_R8G8_B8G8_UNORM:
case DXGI_FORMAT_R16G16B16A16_UNORM:
resource_format[0] = format;
break;
case DXGI_FORMAT_AYUV:
case DXGI_FORMAT_YUY2:
resource_format[0] = DXGI_FORMAT_R8G8B8A8_UNORM;
break;
case DXGI_FORMAT_NV12:
resource_format[0] = DXGI_FORMAT_R8_UNORM;
resource_format[1] = DXGI_FORMAT_R8G8_UNORM;
break;
case DXGI_FORMAT_P010:
case DXGI_FORMAT_P016:
resource_format[0] = DXGI_FORMAT_R16_UNORM;
resource_format[1] = DXGI_FORMAT_R16G16_UNORM;
break;
case DXGI_FORMAT_Y210:
resource_format[0] = DXGI_FORMAT_R16G16B16A16_UNORM;
break;
case DXGI_FORMAT_Y410:
resource_format[0] = DXGI_FORMAT_R10G10B10A2_UNORM;
break;
default:
return FALSE;
if (format == DXGI_FORMAT_UNKNOWN)
return 0;
for (guint i = 0; i < GST_D3D12_N_FORMATS; i++) {
const GstD3D12Format *fmt = &g_gst_d3d12_default_format_map[i];
if (fmt->dxgi_format == format) {
guint n_planes = 0;
for (n_planes = 0; n_planes < GST_VIDEO_MAX_PLANES; n_planes++) {
if (fmt->resource_format[n_planes] == DXGI_FORMAT_UNKNOWN)
break;
resource_format[n_planes] = fmt->resource_format[n_planes];
}
return n_planes;
}
}
return TRUE;
resource_format[0] = format;
return 1;
}
char *

View file

@ -0,0 +1,55 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
struct _GstD3D12Format
{
GstVideoFormat format;
/* direct mapping to dxgi format if applicable */
DXGI_FORMAT dxgi_format;
/* formats for texture processing */
DXGI_FORMAT resource_format[GST_VIDEO_MAX_PLANES];
/* extra format used for unordered access view (unused) */
DXGI_FORMAT uav_format[GST_VIDEO_MAX_PLANES];
/* D3D12_FORMAT_SUPPORT1 flags */
guint format_support1[GST_VIDEO_MAX_PLANES];
/* D3D12_FORMAT_SUPPORT2 flags (unused) */
guint format_support2[GST_VIDEO_MAX_PLANES];
/*< private >*/
guint padding[GST_PADDING_LARGE];
};
GST_D3D12_API
GstVideoFormat gst_d3d12_dxgi_format_to_gst (DXGI_FORMAT format);
G_END_DECLS

View file

@ -39,8 +39,20 @@
using namespace Microsoft::WRL;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY_EXTERN (gst_d3d12_allocator_debug);
#define GST_CAT_DEFAULT gst_d3d12_allocator_debug
#ifndef GST_DISABLE_GST_DEBUG
#define GST_CAT_DEFAULT ensure_debug_category()
static GstDebugCategory *
ensure_debug_category (void)
{
static GstDebugCategory *cat = nullptr;
GST_D3D12_CALL_ONCE_BEGIN {
cat = _gst_debug_category_new ("d3d12allocator", 0, "d3d12allocator");
} GST_D3D12_CALL_ONCE_END;
return cat;
}
#endif
static GstD3D12Allocator *_d3d12_memory_allocator = nullptr;
@ -75,6 +87,23 @@ G_DEFINE_BOXED_TYPE_WITH_CODE (GstD3D12AllocationParams,
(GBoxedFreeFunc) gst_d3d12_allocation_params_free,
gst_d3d12_allocation_params_init (g_define_type_id));
/**
* gst_d3d12_allocation_params_new:
* @device: a #GstD3D12Device
* @info: a #GstVideoInfo
* @flags: a #GstD3D12AllocationFlags
* @resource_flags: D3D12_RESOURCE_FLAGS value used for creating texture
* @heap_flags: D3D12_HEAP_FLAGS value used for creating texture
*
* Create #GstD3D12AllocationParams object which is used by #GstD3D12BufferPool
* and #GstD3D12Allocator in order to allocate new ID3D12Resource
* object with given configuration
*
* Returns: (transfer full) (nullable): a #GstD3D12AllocationParams
* or %NULL if given configuration is not supported
*
* Since: 1.26
*/
GstD3D12AllocationParams *
gst_d3d12_allocation_params_new (GstD3D12Device * device,
const GstVideoInfo * info, GstD3D12AllocationFlags flags,
@ -106,6 +135,14 @@ gst_d3d12_allocation_params_new (GstD3D12Device * device,
return ret;
}
/**
* gst_d3d12_allocation_params_copy:
* @src: a #GstD3D12AllocationParams
*
* Returns: (transfer full): a copy of @src
*
* Since: 1.26
*/
GstD3D12AllocationParams *
gst_d3d12_allocation_params_copy (GstD3D12AllocationParams * src)
{
@ -119,12 +156,31 @@ gst_d3d12_allocation_params_copy (GstD3D12AllocationParams * src)
return dst;
}
/**
* gst_d3d12_allocation_params_free:
* @params: a #GstD3D12AllocationParams
*
* Free @params
*
* Since: 1.26
*/
void
gst_d3d12_allocation_params_free (GstD3D12AllocationParams * params)
{
g_free (params);
}
/**
* gst_d3d12_allocation_params_alignment:
* @params: a #GstD3D12AllocationParams
* @align: a #GstVideoAlignment
*
* Adjust alignment
*
* Returns: %TRUE if alignment could be applied
*
* Since: 1.26
*/
gboolean
gst_d3d12_allocation_params_alignment (GstD3D12AllocationParams * params,
const GstVideoAlignment * align)
@ -154,6 +210,17 @@ gst_d3d12_allocation_params_alignment (GstD3D12AllocationParams * params,
return TRUE;
}
/**
* gst_d3d12_allocation_params_set_resource_flags:
* @params: a #GstD3D12AllocationParams
* @resource_flags: D3D12_RESOURCE_FLAGS
*
* Set @resource_flags
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_allocation_params_set_resource_flags (GstD3D12AllocationParams *
params, D3D12_RESOURCE_FLAGS resource_flags)
@ -165,6 +232,17 @@ gst_d3d12_allocation_params_set_resource_flags (GstD3D12AllocationParams *
return TRUE;
}
/**
* gst_d3d12_allocation_params_unset_resource_flags:
* @params: a #GstD3D12AllocationParams
* @resource_flags: D3D12_RESOURCE_FLAGS
*
* Unset @resource_flags
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_allocation_params_unset_resource_flags (GstD3D12AllocationParams *
params, D3D12_RESOURCE_FLAGS resource_flags)
@ -176,6 +254,17 @@ gst_d3d12_allocation_params_unset_resource_flags (GstD3D12AllocationParams *
return TRUE;
}
/**
* gst_d3d12_allocation_params_set_heap_flags:
* @params: a #GstD3D12AllocationParams
* @heap_flags: D3D12_HEAP_FLAGS
*
* Set @heap_flags
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_allocation_params_set_heap_flags (GstD3D12AllocationParams *
params, D3D12_HEAP_FLAGS heap_flags)
@ -187,6 +276,15 @@ gst_d3d12_allocation_params_set_heap_flags (GstD3D12AllocationParams *
return TRUE;
}
/**
* gst_d3d12_allocation_params_set_array_size:
* @params: a #GstD3D12AllocationParams
* @size: a texture array size
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_allocation_params_set_array_size (GstD3D12AllocationParams * params,
guint size)
@ -495,6 +593,14 @@ gst_d3d12_memory_share (GstMemory * mem, gssize offset, gssize size)
return nullptr;
}
/**
* gst_is_d3d12_memory:
* @mem: a #GstMemory
*
* Returns: %TRUE if @mem is allocated by #GstD3D12Allocator
*
* Since: 1.26
*/
gboolean
gst_is_d3d12_memory (GstMemory * mem)
{
@ -503,6 +609,16 @@ gst_is_d3d12_memory (GstMemory * mem)
GST_IS_D3D12_POOL_ALLOCATOR (mem->allocator));
}
/**
* gst_d3d12_memory_sync:
* @mem: a #GstD3D12Memory
*
* Wait for pending GPU operation
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_memory_sync (GstD3D12Memory * mem)
{
@ -515,6 +631,15 @@ gst_d3d12_memory_sync (GstD3D12Memory * mem)
return TRUE;
}
/**
* gst_d3d12_memory_init_once:
*
* Initializes the Direct3D12 Texture allocator. It is safe to call
* this function multiple times. This must be called before any other
* GstD3D12Memory operation.
*
* Since: 1.26
*/
void
gst_d3d12_memory_init_once (void)
{
@ -529,6 +654,14 @@ gst_d3d12_memory_init_once (void)
} GST_D3D12_CALL_ONCE_END;
}
/**
* gst_d3d12_memory_get_resource_handle:
* @mem: a #GstD3D12Memory
*
* Returns: (transfer none) (nullable): ID3D12Resource handle
*
* Since: 1.26
*/
ID3D12Resource *
gst_d3d12_memory_get_resource_handle (GstD3D12Memory * mem)
{
@ -537,6 +670,16 @@ gst_d3d12_memory_get_resource_handle (GstD3D12Memory * mem)
return mem->priv->resource.Get ();
}
/**
* gst_d3d12_memory_get_subresource_index:
* @mem: a #GstD3D12Memory
* @plane: a plane index
* @index: (out): subresource index of @plane
*
* Returns: %TRUE if returned @index is valid
*
* Since: 1.26
*/
gboolean
gst_d3d12_memory_get_subresource_index (GstD3D12Memory * mem, guint plane,
guint * index)
@ -555,6 +698,14 @@ gst_d3d12_memory_get_subresource_index (GstD3D12Memory * mem, guint plane,
return TRUE;
}
/**
* gst_d3d12_memory_get_plane_count:
* @mem: a #GstD3D12Memory
*
* Returns: the number of planes of resource
*
* Since: 1.26
*/
guint
gst_d3d12_memory_get_plane_count (GstD3D12Memory * mem)
{
@ -563,6 +714,16 @@ gst_d3d12_memory_get_plane_count (GstD3D12Memory * mem)
return mem->priv->num_subresources;
}
/**
* gst_d3d12_memory_get_plane_rectangle:
* @mem: a #GstD3D12Memory
* @plane: a plane index
* @rect: (out): a rectangle of @plane
*
* Returns: %TRUE if returned @rect is valid
*
* Since: 1.26
*/
gboolean
gst_d3d12_memory_get_plane_rectangle (GstD3D12Memory * mem, guint plane,
D3D12_RECT * rect)
@ -578,6 +739,19 @@ gst_d3d12_memory_get_plane_rectangle (GstD3D12Memory * mem, guint plane,
return TRUE;
}
/**
* gst_d3d12_memory_get_shader_resource_view_heap:
* @mem: a #GstD3D12Memory
*
* Gets shader invisible shader resource view descriptor heap.
* Caller needs to copy returned descriptor heap to another shader visible
* descriptor heap in order for resource to be used in shader.
*
* Returns: (transfer none) (nullable): ID3D12DescriptorHeap handle or %NULL
* if the resource was allocated without shader resource view enabled
*
* Since: 1.26
*/
ID3D12DescriptorHeap *
gst_d3d12_memory_get_shader_resource_view_heap (GstD3D12Memory * mem)
{
@ -629,6 +803,17 @@ gst_d3d12_memory_get_shader_resource_view_heap (GstD3D12Memory * mem)
return priv->srv_heap.Get ();
}
/**
* gst_d3d12_memory_get_render_target_view_heap:
* @mem: a #GstD3D12Memory
*
* Gets render target view descriptor heap
*
* Returns: (transfer none) (nullable): ID3D12DescriptorHeap handle or %NULL
* if the resource was allocated without render target view enabled
*
* Since: 1.26
*/
ID3D12DescriptorHeap *
gst_d3d12_memory_get_render_target_view_heap (GstD3D12Memory * mem)
{
@ -681,6 +866,19 @@ gst_d3d12_memory_get_render_target_view_heap (GstD3D12Memory * mem)
return priv->rtv_heap.Get ();
}
/**
* gst_d3d12_memory_get_nt_handle:
* @mem: a #GstD3D12Memory
* @handle: (out) (transfer none) a sharable NT handle
*
* Gets NT handle created via ID3D12Device::CreateSharedHandle().
* Returned NT handle is owned by @mem, thus caller should not close
* the @handle
*
* Returns: %TRUE if successful
*
* Since: 1.26
*/
gboolean
gst_d3d12_memory_get_nt_handle (GstD3D12Memory * mem, HANDLE * handle)
{
@ -704,6 +902,17 @@ gst_d3d12_memory_get_nt_handle (GstD3D12Memory * mem, HANDLE * handle)
return TRUE;
}
/**
* gst_d3d12_memory_set_token_data:
* @mem: a #GstD3D12Memory
* @token: an user token
* @data: an user data
* @notify: a #GDestroyNotify
*
* Sets an opaque user data on a #GstD3D12Memory
*
* Since: 1.26
*/
void
gst_d3d12_memory_set_token_data (GstD3D12Memory * mem, gint64 token,
gpointer data, GDestroyNotify notify)
@ -721,6 +930,17 @@ gst_d3d12_memory_set_token_data (GstD3D12Memory * mem, gint64 token,
}
}
/**
* gst_d3d12_memory_get_token_data:
* @mem: a #GstD3D12Memory
* @token: an user token
*
* Gets back user data pointer stored via gst_d3d12_memory_set_token_data()
*
* Returns: (transfer none) (nullable): user data pointer or %NULL
*
* Since: 1.26
*/
gpointer
gst_d3d12_memory_get_token_data (GstD3D12Memory * mem, gint64 token)
{
@ -735,6 +955,17 @@ gst_d3d12_memory_get_token_data (GstD3D12Memory * mem, gint64 token)
return ret;
}
/**
* gst_d3d12_memory_set_external_fence:
* @mem: a #GstD3D12Memory
* @fence: (allow-none): a ID3D12Fence
* @fence_val: fence value
*
* Sets external fence handle to @mem. Later memory map operation will wait
* for @fence if needed
*
* Since: 1.26
*/
void
gst_d3d12_memory_set_external_fence (GstD3D12Memory * mem, ID3D12Fence * fence,
guint64 fence_val)
@ -808,6 +1039,23 @@ gst_d3d12_allocator_free (GstAllocator * allocator, GstMemory * mem)
g_free (dmem);
}
/**
* gst_d3d12_allocator_alloc_wrapped:
* @allocator: (allow-none): a #GstD3D12Allocator
* @device: a #GstD3D12Device
* @resource: a ID3D12Resource
* @array_slice: array slice index of the first plane
* @user_data: (allow-none): an user data
* @notify: a #GDestroyNotify
*
* Allocates memory object with @resource. The refcount of @resource
* will be increased by one.
*
* Returns: (transfer full) (nullable): a newly allocated #GstD3D12Memory
* with given @resource if successful, otherwise %NULL.
*
* Since: 1.26
*/
GstMemory *
gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * allocator,
GstD3D12Device * device, ID3D12Resource * resource, guint array_slice,
@ -843,7 +1091,7 @@ gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * allocator,
priv->desc = desc;
priv->num_subresources = num_subresources;
priv->resource = resource;
gst_d3d12_dxgi_format_to_resource_formats (priv->desc.Format,
gst_d3d12_dxgi_format_get_resource_format (priv->desc.Format,
priv->resource_formats);
priv->srv_inc_size =
device_handle->GetDescriptorHandleIncrementSize
@ -955,6 +1203,22 @@ gst_d3d12_allocator_alloc_internal (GstD3D12Allocator * self,
return mem;
}
/**
* gst_d3d12_allocator_alloc:
* @allocator: (allow-none): a #GstD3D12Allocator
* @device: a #GstD3D12Device
* @heap_prop: a D3D12_HEAP_PROPERTIES
* @heap_flags: a D3D12_HEAP_FLAGS
* @desc: a D3D12_RESOURCE_DESC
* @initial_state: initial resource state
* @optimized_clear_value: (allow-none): optimized clear value
*
* Returns: (transfer full) (nullable): a newly allocated #GstD3D12Memory
* with given parameters.
*
* Since: 1.26
*/
GstMemory *
gst_d3d12_allocator_alloc (GstD3D12Allocator * allocator,
GstD3D12Device * device, const D3D12_HEAP_PROPERTIES * heap_props,
@ -976,6 +1240,22 @@ gst_d3d12_allocator_alloc (GstD3D12Allocator * allocator,
heap_flags, desc, initial_state, optimized_clear_value);
}
/**
* gst_d3d12_allocator_set_active:
* @allocator: a #GstD3D12Allocator
* @active: the new active state
*
* Controls the active state of @allocator. Default #GstD3D12Allocator is
* stateless and therefore active state is ignored, but subclass implementation
* (e.g., #GstD3D12PoolAllocator) will require explicit active state control
* for its internal resource management.
*
* This method is conceptually identical to gst_buffer_pool_set_active method.
*
* Returns: %TRUE if active state of @allocator was successfully updated.
*
* Since: 1.26
*/
gboolean
gst_d3d12_allocator_set_active (GstD3D12Allocator * allocator, gboolean active)
{
@ -1325,6 +1605,19 @@ gst_d3d12_pool_allocator_acquire_memory_internal (GstD3D12PoolAllocator * self,
return ret;
}
/**
* gst_d3d12_pool_allocator_new:
* @device: a #GstD3D12Device
* @heap_prop: a D3D12_HEAP_PROPERTIES
* @heap_flags: a D3D12_HEAP_FLAGS
* @desc: a D3D12_RESOURCE_DESC
* @initial_state: initial resource state
* @optimized_clear_value: (allow-none) optimized clear value
*
* Returns: (transfer full) (nullable): a new #GstD3D12PoolAllocator instance
*
* Since: 1.26
*/
GstD3D12PoolAllocator *
gst_d3d12_pool_allocator_new (GstD3D12Device * device,
const D3D12_HEAP_PROPERTIES * heap_props, D3D12_HEAP_FLAGS heap_flags,
@ -1358,6 +1651,19 @@ gst_d3d12_pool_allocator_new (GstD3D12Device * device,
return self;
}
/**
* gst_d3d12_pool_allocator_acquire_memory:
* @allocator: a #GstD3D12PoolAllocator
* @memory: (out) (transfer full): a #GstMemory
*
* Acquires a #GstMemory from @allocator. @memory should point to a memory
* location that can hold a pointer to the new #GstMemory.
*
* Returns: a #GstFlowReturn such as %GST_FLOW_FLUSHING when the allocator is
* inactive.
*
* Since: 1.26
*/
GstFlowReturn
gst_d3d12_pool_allocator_acquire_memory (GstD3D12PoolAllocator * allocator,
GstMemory ** memory)

View file

@ -21,14 +21,12 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
#include "gstd3d12format.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
#define GST_TYPE_D3D12_ALLOCATION_PARAMS (gst_d3d12_allocation_params_get_type())
#define GST_TYPE_D3D12_MEMORY (gst_d3d12_memory_get_type())
#define GST_D3D12_MEMORY_CAST(obj) ((GstD3D12Memory *)obj)
#define GST_TYPE_D3D12_ALLOCATOR (gst_d3d12_allocator_get_type())
@ -51,6 +49,8 @@ G_BEGIN_DECLS
* GST_D3D12_MEMORY_NAME:
*
* The name of the Direct3D12 memory
*
* Since: 1.26
*/
#define GST_D3D12_MEMORY_NAME "D3D12Memory"
@ -58,6 +58,8 @@ G_BEGIN_DECLS
* GST_CAPS_FEATURE_MEMORY_D3D12_MEMORY:
*
* Name of the caps feature for indicating the use of #GstD3D12Memory
*
* Since: 1.26
*/
#define GST_CAPS_FEATURE_MEMORY_D3D12_MEMORY "memory:D3D12Memory"
@ -65,6 +67,8 @@ G_BEGIN_DECLS
* GST_MAP_D3D12:
*
* Flag indicating that we should map the D3D12 resource instead of to system memory.
*
* Since: 1.26
*/
#define GST_MAP_D3D12 (GST_MAP_FLAG_LAST << 1)
@ -72,6 +76,8 @@ G_BEGIN_DECLS
* GST_MAP_READ_D3D12:
*
* GstMapFlags value alias for GST_MAP_READ | GST_MAP_D3D12
*
* Since: 1.26
*/
#define GST_MAP_READ_D3D12 ((GstMapFlags) (GST_MAP_READ | GST_MAP_D3D12))
@ -79,6 +85,8 @@ G_BEGIN_DECLS
* GST_MAP_WRITE_D3D12:
*
* GstMapFlags value alias for GST_MAP_WRITE | GST_MAP_D3D12
*
* Since: 1.26
*/
#define GST_MAP_WRITE_D3D12 ((GstMapFlags) (GST_MAP_WRITE | GST_MAP_D3D12))
@ -86,6 +94,8 @@ G_BEGIN_DECLS
* GstD3D12MemoryTransfer:
*
* Pending memory transfer operation
*
* Since: 1.26
*/
typedef enum
{
@ -93,43 +103,64 @@ typedef enum
GST_D3D12_MEMORY_TRANSFER_NEED_UPLOAD = (GST_MEMORY_FLAG_LAST << 1)
} GstD3D12MemoryTransfer;
/**
* GstD3D12AllocationFlags:
* @GST_D3D12_ALLOCATION_FLAG_DEFAULT: Default allocation behavior
*
* Since: 1.26
*/
typedef enum
{
GST_D3D12_ALLOCATION_FLAG_DEFAULT = 0,
} GstD3D12AllocationFlags;
GST_D3D12_API
GType gst_d3d12_allocation_params_get_type (void);
GST_D3D12_API
GstD3D12AllocationParams * gst_d3d12_allocation_params_new (GstD3D12Device * device,
const GstVideoInfo * info,
GstD3D12AllocationFlags flags,
D3D12_RESOURCE_FLAGS resource_flags,
D3D12_HEAP_FLAGS heap_flags);
GST_D3D12_API
GstD3D12AllocationParams * gst_d3d12_allocation_params_copy (GstD3D12AllocationParams * src);
GST_D3D12_API
void gst_d3d12_allocation_params_free (GstD3D12AllocationParams * params);
GST_D3D12_API
gboolean gst_d3d12_allocation_params_alignment (GstD3D12AllocationParams * parms,
const GstVideoAlignment * align);
GST_D3D12_API
gboolean gst_d3d12_allocation_params_set_resource_flags (GstD3D12AllocationParams * params,
D3D12_RESOURCE_FLAGS resource_flags);
GST_D3D12_API
gboolean gst_d3d12_allocation_params_unset_resource_flags (GstD3D12AllocationParams * params,
D3D12_RESOURCE_FLAGS resource_flags);
GST_D3D12_API
gboolean gst_d3d12_allocation_params_set_heap_flags (GstD3D12AllocationParams * params,
D3D12_HEAP_FLAGS heap_flags);
GST_D3D12_API
gboolean gst_d3d12_allocation_params_set_array_size (GstD3D12AllocationParams * params,
guint size);
/**
* GstD3D12Memory:
*
* Opaque GstD3D12Memory struct
*
* Since: 1.26
*/
struct _GstD3D12Memory
{
GstMemory mem;
/*< public >*/
GstD3D12Device *device;
guint64 fence_value;
@ -138,45 +169,66 @@ struct _GstD3D12Memory
gpointer _gst_reserved[GST_PADDING];
};
GST_D3D12_API
GType gst_d3d12_memory_get_type (void);
GST_D3D12_API
void gst_d3d12_memory_init_once (void);
GST_D3D12_API
gboolean gst_is_d3d12_memory (GstMemory * mem);
GST_D3D12_API
gboolean gst_d3d12_memory_sync (GstD3D12Memory * mem);
GST_D3D12_API
ID3D12Resource * gst_d3d12_memory_get_resource_handle (GstD3D12Memory * mem);
GST_D3D12_API
gboolean gst_d3d12_memory_get_subresource_index (GstD3D12Memory * mem,
guint plane,
guint * index);
GST_D3D12_API
guint gst_d3d12_memory_get_plane_count (GstD3D12Memory * mem);
GST_D3D12_API
gboolean gst_d3d12_memory_get_plane_rectangle (GstD3D12Memory * mem,
guint plane,
D3D12_RECT * rect);
GST_D3D12_API
ID3D12DescriptorHeap * gst_d3d12_memory_get_shader_resource_view_heap (GstD3D12Memory * mem);
GST_D3D12_API
ID3D12DescriptorHeap * gst_d3d12_memory_get_render_target_view_heap (GstD3D12Memory * mem);
GST_D3D12_API
gboolean gst_d3d12_memory_get_nt_handle (GstD3D12Memory * mem,
HANDLE * handle);
GST_D3D12_API
void gst_d3d12_memory_set_token_data (GstD3D12Memory * mem,
gint64 token,
gpointer data,
GDestroyNotify notify);
GST_D3D12_API
gpointer gst_d3d12_memory_get_token_data (GstD3D12Memory * mem,
gint64 token);
GST_D3D12_API
void gst_d3d12_memory_set_external_fence (GstD3D12Memory * mem,
ID3D12Fence * fence,
guint64 fence_val);
/**
* GstD3D12Allocator:
*
* Opaque GstD3D12Allocator struct
*
* Since: 1.26
*/
struct _GstD3D12Allocator
{
GstAllocator allocator;
@ -187,6 +239,13 @@ struct _GstD3D12Allocator
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstD3D12AllocatorClass:
*
* Opaque GstD3D12AllocatorClass struct
*
* Since: 1.26
*/
struct _GstD3D12AllocatorClass
{
GstAllocatorClass allocator_class;
@ -198,8 +257,10 @@ struct _GstD3D12AllocatorClass
gpointer _gst_reserved[GST_PADDING_LARGE];
};
GST_D3D12_API
GType gst_d3d12_allocator_get_type (void);
GST_D3D12_API
GstMemory * gst_d3d12_allocator_alloc (GstD3D12Allocator * allocator,
GstD3D12Device * device,
const D3D12_HEAP_PROPERTIES * heap_props,
@ -208,6 +269,7 @@ GstMemory * gst_d3d12_allocator_alloc (GstD3D12Allocator * allocator,
D3D12_RESOURCE_STATES initial_state,
const D3D12_CLEAR_VALUE * optimized_clear_value);
GST_D3D12_API
GstMemory * gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * allocator,
GstD3D12Device * device,
ID3D12Resource * resource,
@ -215,9 +277,17 @@ GstMemory * gst_d3d12_allocator_alloc_wrapped (GstD3D12Allocator * allocator,
gpointer user_data,
GDestroyNotify notify);
GST_D3D12_API
gboolean gst_d3d12_allocator_set_active (GstD3D12Allocator * allocator,
gboolean active);
/**
* GstD3D12PoolAllocator:
*
* Opaque GstD3D12PoolAllocator struct
*
* Since: 1.26
*/
struct _GstD3D12PoolAllocator
{
GstD3D12Allocator allocator;
@ -231,6 +301,13 @@ struct _GstD3D12PoolAllocator
gpointer _gst_reserved[GST_PADDING];
};
/**
* GstD3D12PoolAllocatorClass:
*
* Opaque GstD3D12PoolAllocatorClass struct
*
* Since: 1.26
*/
struct _GstD3D12PoolAllocatorClass
{
GstD3D12AllocatorClass allocator_class;
@ -239,8 +316,10 @@ struct _GstD3D12PoolAllocatorClass
gpointer _gst_reserved[GST_PADDING];
};
GST_D3D12_API
GType gst_d3d12_pool_allocator_get_type (void);
GST_D3D12_API
GstD3D12PoolAllocator * gst_d3d12_pool_allocator_new (GstD3D12Device * device,
const D3D12_HEAP_PROPERTIES * heap_props,
D3D12_HEAP_FLAGS heap_flags,
@ -248,6 +327,7 @@ GstD3D12PoolAllocator * gst_d3d12_pool_allocator_new (GstD3D12Device * device,
D3D12_RESOURCE_STATES initial_state,
const D3D12_CLEAR_VALUE * optimized_clear_value);
GST_D3D12_API
GstFlowReturn gst_d3d12_pool_allocator_acquire_memory (GstD3D12PoolAllocator * allocator,
GstMemory ** memory);

View file

@ -22,6 +22,7 @@
#endif
#include "gstd3d12.h"
#include "gstd3d12-private.h"
#include <mutex>
#include <atomic>
@ -30,8 +31,21 @@ static std::recursive_mutex context_lock_;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY_STATIC (GST_CAT_CONTEXT);
GST_DEBUG_CATEGORY_EXTERN (gst_d3d12_utils_debug);
#define GST_CAT_DEFAULT gst_d3d12_utils_debug
#ifndef GST_DISABLE_GST_DEBUG
#define GST_CAT_DEFAULT ensure_debug_category()
static GstDebugCategory *
ensure_debug_category (void)
{
static GstDebugCategory *cat = nullptr;
GST_D3D12_CALL_ONCE_BEGIN {
cat = _gst_debug_category_new ("d3d12allocator", 0, "d3d12allocator");
} GST_D3D12_CALL_ONCE_END;
return cat;
}
#endif
static void
init_context_debug (void)
@ -41,6 +55,24 @@ init_context_debug (void)
} GST_D3D12_CALL_ONCE_END;
}
/**
* gst_d3d12_handle_set_context:
* @element: a #GstElement
* @context: a #GstContext
* @adapter_index: a DXGI adapter index
* @device: (inout) (transfer full): location of a #GstD3D12Device
*
* Helper function for implementing #GstElementClass.set_context() in
* D3D12 capable elements.
*
* Retrieve's the #GstD3D12Device in @context and places the result in @device.
* @device is accepted if @adapter_index is equal to -1 (accept any device)
* or equal to that of @device
*
* Returns: whether the @device could be set successfully
*
* Since: 1.26
*/
gboolean
gst_d3d12_handle_set_context (GstElement * element, GstContext * context,
gint adapter_index, GstD3D12Device ** device)
@ -85,6 +117,23 @@ gst_d3d12_handle_set_context (GstElement * element, GstContext * context,
return FALSE;
}
/**
* gst_d3d12_handle_set_context_for_adapter_luid:
* @element: a #GstElement
* @context: a #GstContext
* @adapter_luid: an int64 representation of DXGI adapter LUID
* @device: (inout) (transfer full): location of a #GstD3D12Device
*
* Helper function for implementing #GstElementClass.set_context() in
* D3D12 capable elements.
*
* Retrieve's the #GstD3D12Device in @context and places the result in @device.
* @device is accepted only when @adapter_index is equal to that of @device
*
* Returns: whether the @device could be set successfully
*
* Since: 1.26
*/
gboolean
gst_d3d12_handle_set_context_for_adapter_luid (GstElement * element,
GstContext * context, gint64 adapter_luid, GstD3D12Device ** device)
@ -160,6 +209,17 @@ context_set_d3d12_device (GstContext * context, GstD3D12Device * device)
g_free (desc);
}
/**
* gst_d3d12_handle_context_query:
* @element: a #GstElement
* @query: a #GstQuery of type %GST_QUERY_CONTEXT
* @device: (transfer none) (nullable): a #GstD3D12Device
*
* Returns: Whether the @query was successfully responded to from the passed
* @device.
*
* Since: 1.26
*/
gboolean
gst_d3d12_handle_context_query (GstElement * element, GstQuery * query,
GstD3D12Device * device)
@ -277,6 +337,23 @@ run_d3d12_context_query (GstElement * element, GstD3D12Device ** device)
gst_query_unref (query);
}
/**
* gst_d3d12_ensure_element_data:
* @element: the #GstElement running the query
* @adapter: preferred DXGI adapter index, pass adapter >=0 when
* the adapter explicitly required. Otherwise, set -1.
* @device: (inout): the resulting #GstD3D12Device
*
* Perform the steps necessary for retrieving a #GstD3D12Device
* from the surrounding elements or from the application using the #GstContext mechanism.
*
* If the contents of @device is not %NULL, then no #GstContext query is
* necessary for #GstD3D12Device retrieval is performed.
*
* Returns: whether a #GstD3D12Device exists in @device
*
* Since: 1.26
*/
gboolean
gst_d3d12_ensure_element_data (GstElement * element, gint adapter_index,
GstD3D12Device ** device)
@ -328,6 +405,23 @@ gst_d3d12_ensure_element_data (GstElement * element, gint adapter_index,
return TRUE;
}
/**
* gst_d3d12_ensure_element_data_for_adapter_luid:
* @element: a #GstElement
* @context: a #GstContext
* @adapter_luid: an int64 representation of DXGI adapter LUID
* @device: (inout) (transfer full): location of a #GstD3D12Device
*
* Helper function for implementing #GstElementClass.set_context() in
* D3D12 capable elements.
*
* Retrieve's the #GstD3D12Device in @context and places the result in @device.
* @device is accepted only when @adapter_index is equal to that of @device
*
* Returns: whether the @device could be set successfully
*
* Since: 1.26
*/
gboolean
gst_d3d12_ensure_element_data_for_adapter_luid (GstElement * element,
gint64 adapter_luid, GstD3D12Device ** device)
@ -375,6 +469,16 @@ gst_d3d12_ensure_element_data_for_adapter_luid (GstElement * element,
return TRUE;
}
/**
* gst_d3d12_luid_to_int64:
* @luid: A pointer to LUID struct
*
* Converts @luid to a 64-bit signed integer.
* See also Int64FromLuid method defined in
* windows.devices.display.core.interop.h Windows SDK header
*
* Since: 1.26
*/
gint64
gst_d3d12_luid_to_int64 (const LUID * luid)
{
@ -388,6 +492,16 @@ gst_d3d12_luid_to_int64 (const LUID * luid)
return val.QuadPart;
}
/**
* gst_d3d12_context_new:
* @device: (transfer none): a #GstD3D12Device
*
* Creates a new #GstContext object with @device
*
* Returns: a #GstContext object
*
* Since: 1.26
*/
GstContext *
gst_d3d12_context_new (GstD3D12Device * device)
{
@ -401,6 +515,15 @@ gst_d3d12_context_new (GstD3D12Device * device)
return context;
}
/**
* gst_d3d12_create_user_token:
*
* Creates new user token value
*
* Returns: user token value
*
* Since: 1.26
*/
gint64
gst_d3d12_create_user_token (void)
{
@ -411,6 +534,21 @@ gst_d3d12_create_user_token (void)
return user_token.fetch_add (1);
}
/**
* _gst_d3d12_result:
* @result: HRESULT D3D12 API return code
* @device: (nullable): Associated #GstD3D12Device
* @cat: a #GstDebugCategory
* @file: the file that checking the result code
* @function: the function that checking the result code
* @line: the line that checking the result code
*
* Prints debug message if @result code indicates the operation was failed.
*
* Returns: %TRUE if D3D12 API call result is SUCCESS
*
* Since: 1.26
*/
gboolean
_gst_d3d12_result (HRESULT hr, GstD3D12Device * device, GstDebugCategory * cat,
const gchar * file, const gchar * function, gint line, GstDebugLevel level)

View file

@ -20,38 +20,47 @@
#pragma once
#include <gst/gst.h>
#include "gstd3d12_fwd.h"
#include <gst/d3d12/gstd3d12_fwd.h>
G_BEGIN_DECLS
GST_D3D12_API
gboolean gst_d3d12_handle_set_context (GstElement * element,
GstContext * context,
gint adapter_index,
GstD3D12Device ** device);
GST_D3D12_API
gboolean gst_d3d12_handle_set_context_for_adapter_luid (GstElement * element,
GstContext * context,
gint64 adapter_luid,
GstD3D12Device ** device);
GST_D3D12_API
gboolean gst_d3d12_handle_context_query (GstElement * element,
GstQuery * query,
GstD3D12Device * device);
GST_D3D12_API
gboolean gst_d3d12_ensure_element_data (GstElement * element,
gint adapter_index,
GstD3D12Device ** device);
GST_D3D12_API
gboolean gst_d3d12_ensure_element_data_for_adapter_luid (GstElement * element,
gint64 adapter_luid,
GstD3D12Device ** device);
GST_D3D12_API
gint64 gst_d3d12_luid_to_int64 (const LUID * luid);
GST_D3D12_API
GstContext * gst_d3d12_context_new (GstD3D12Device * device);
GST_D3D12_API
gint64 gst_d3d12_create_user_token (void);
GST_D3D12_API
gboolean _gst_d3d12_result (HRESULT hr,
GstD3D12Device * device,
GstDebugCategory * cat,
@ -66,6 +75,8 @@ gboolean _gst_d3d12_result (HRESULT hr,
* @device: (nullable): Associated #GstD3D12Device
*
* Returns: %TRUE if D3D12 API call result is SUCCESS
*
* Since: 1.26
*/
#ifndef GST_DISABLE_GST_DEBUG
#define gst_d3d12_result(result,device) \
@ -77,10 +88,3 @@ gboolean _gst_d3d12_result (HRESULT hr,
G_END_DECLS
#include <mutex>
#define GST_D3D12_CALL_ONCE_BEGIN \
static std::once_flag __once_flag; \
std::call_once (__once_flag, [&]()
#define GST_D3D12_CALL_ONCE_END )

View file

@ -0,0 +1,152 @@
d3d12_sources = [
'gstd3d12bufferpool.cpp',
'gstd3d12commandallocatorpool.cpp',
'gstd3d12commandlistpool.cpp',
'gstd3d12commandqueue.cpp',
'gstd3d12converter-builder.cpp',
'gstd3d12converter.cpp',
'gstd3d12descriptorpool.cpp',
'gstd3d12device.cpp',
'gstd3d12fencedatapool.cpp',
'gstd3d12format.cpp',
'gstd3d12memory.cpp',
'gstd3d12utils.cpp',
]
d3d12_headers = [
'd3d12-prelude.h',
'gstd3d12_fwd.h',
'gstd3d12.h',
'gstd3d12bufferpool.h',
'gstd3d12commandallocatorpool.h',
'gstd3d12commandqueue.h',
'gstd3d12converter.h',
'gstd3d12descriptorpool.h',
'gstd3d12device.h',
'gstd3d12fencedatapool.h',
'gstd3d12format.h',
'gstd3d12memory.h',
'gstd3d12utils.h',
]
extra_args = [
'-DGST_USE_UNSTABLE_API',
'-DBUILDING_GST_D3D12',
'-DG_LOG_DOMAIN="GStreamer-D3D12"',
]
extra_deps = []
# Disable this warning error. Otherwise d3dx12.h will break build
if cc.get_argument_syntax() == 'msvc'
extra_args += cc.get_supported_arguments([
'/wd4062', # 'identifier' : unreferenced local variable
])
else
extra_args += cc.get_supported_arguments([
'-Wno-misleading-indentation',
# MinGW 32bits compiler seems to be complaining about redundant-decls
# when ComPtr is in use. Let's just disable the warning
'-Wno-redundant-decls',
])
endif
gstd3d12_dep = dependency('', required : false)
d3d12_option = get_option('d3d12')
if host_system != 'windows' or d3d12_option.disabled()
subdir_done()
endif
d3d12_lib = cc.find_library('d3d12', required : d3d12_option)
dxgi_lib = cc.find_library('dxgi', required : d3d12_option)
dx_headers_dep = dependency('DirectX-Headers',
version: '>= 1.611',
allow_fallback: true,
required: d3d12_option)
if not d3d12_lib.found() or not dxgi_lib.found() or not dx_headers_dep.found() \
or not gstd3dshader_dep.found()
if d3d12_option.enabled()
error('The d3d12 was enabled explicitly, but required dependencies were not found.')
endif
subdir_done()
endif
sdk_headers = [
'dxgi1_6.h',
]
have_d3d12_headers = true
foreach h: sdk_headers
if not cc.has_header(h)
have_d3d12_headers = false
endif
endforeach
if not have_d3d12_headers
if d3d12_option.enabled()
error('The d3d12 was enabled explicitly, but required dependencies were not found.')
endif
subdir_done()
endif
have_dx_math = cxx.compiles('''
#include <windows.h>
#include <DirectXMath.h>
using namespace DirectX;
int main(int argc, char ** argv) {
XMMATRIX matrix;
XMFLOAT4X4 dump;
matrix = XMMatrixIdentity ();
XMStoreFloat4x4 (&dump, matrix);
return 0;
}
''',
name: 'DirectXMath support in Windows SDK')
if not have_dx_math
directxmath_dep = dependency('directxmath',
allow_fallback: true,
required: d3d12_option)
if not directxmath_dep.found()
subdir_done()
endif
extra_deps += [directxmath_dep]
endif
# https://learn.microsoft.com/en-us/windows/win32/dxmath/pg-xnamath-internals#windows-sse-versus-sse2
# x86 with Windows 7 or older may not support SSE2
if host_machine.cpu_family() != 'x86'
extra_args += ['-DHAVE_DIRECTX_MATH_SIMD']
endif
pkg_name = 'gstreamer-d3d12-' + api_version
gstd3d12 = library('gstd3d12-' + api_version,
d3d12_sources + hlsl_precompiled,
c_args : gst_plugins_bad_args + extra_args,
cpp_args: gst_plugins_bad_args + extra_args,
include_directories : [configinc, libsinc],
dependencies : [gstbase_dep, gstvideo_dep, gstd3dshader_dep, d3d12_lib,
dxgi_lib, dx_headers_dep] + extra_deps,
version : libversion,
install : true,
)
pkgconfig.generate(gstd3d12,
libraries : [gstbase_dep, gstvideo_dep, d3d12_lib, dxgi_lib],
variables : pkgconfig_variables,
subdirs : pkgconfig_subdirs,
name : pkg_name,
description : 'GStreamer Direct3D12 library',
)
library_def = {'lib': gstd3d12}
gst_libraries += [[pkg_name, library_def]]
install_headers(d3d12_headers, subdir : 'gstreamer-1.0/gst/d3d12')
gstd3d12_dep = declare_dependency(link_with : gstd3d12,
include_directories : [libsinc],
dependencies : [gstbase_dep, gstvideo_dep, d3d12_lib, dxgi_lib])
meson.override_dependency(pkg_name, gstd3d12_dep)

View file

@ -7,6 +7,7 @@ subdir('codecparsers')
subdir('codecs')
subdir('d3dshader')
subdir('d3d11')
subdir('d3d12')
# cuda can depend on d3d11
subdir('cuda')
subdir('dxva')

View file

@ -37,8 +37,6 @@
#endif
#include "gstd3d12av1dec.h"
#include "gstd3d12device.h"
#include "gstd3d12utils.h"
#include <gst/dxva/gstdxvaav1decoder.h>
GST_DEBUG_CATEGORY_STATIC (gst_d3d12_av1_dec_debug);

View file

@ -22,7 +22,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/base/gstbasetransform.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -22,7 +22,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/video/gstvideoaggregator.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -21,8 +21,8 @@
#include <config.h>
#endif
#include <directx/d3dx12.h>
#include "gstd3d12decoder.h"
#include <directx/d3dx12.h>
#include <gst/base/gstqueuearray.h>
#include <wrl.h>
#include <string.h>
@ -37,8 +37,20 @@
#include <algorithm>
#include <atomic>
GST_DEBUG_CATEGORY_EXTERN (gst_d3d12_decoder_debug);
#define GST_CAT_DEFAULT gst_d3d12_decoder_debug
#ifndef GST_DISABLE_GST_DEBUG
#define GST_CAT_DEFAULT ensure_debug_category()
static GstDebugCategory *
ensure_debug_category (void)
{
static GstDebugCategory *cat = nullptr;
GST_D3D12_CALL_ONCE_BEGIN {
cat = _gst_debug_category_new ("d3d12decoder", 0, "d3d12decoder");
} GST_D3D12_CALL_ONCE_END;
return cat;
}
#endif /* GST_DISABLE_GST_DEBUG */
struct DecoderFormat
{

View file

@ -23,7 +23,7 @@
#include <gst/video/video.h>
#include <gst/codecs/gstcodecpicture.h>
#include <gst/dxva/gstdxva.h>
#include "gstd3d12.h"
#include "gstd3d12pluginutils.h"
G_BEGIN_DECLS

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include "gstd3d12pluginutils.h"
G_BEGIN_DECLS

View file

@ -23,7 +23,6 @@
#include "gstd3d12encoder.h"
#include "gstd3d12encoderbufferpool.h"
#include "gstd3d12pluginutils.h"
#include <gst/base/gstqueuearray.h>
#include <directx/d3dx12.h>
#include <wrl.h>

View file

@ -21,7 +21,8 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
#include "gstd3d12pluginutils.h"
G_BEGIN_DECLS

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -1,86 +0,0 @@
/* GStreamer
* Copyright (C) 2023 Seungha Yang <seungha@centricular.com>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301, USA.
*/
#pragma once
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12_fwd.h"
G_BEGIN_DECLS
struct _GstD3D12Format
{
GstVideoFormat format;
/* direct mapping to dxgi format if applicable */
DXGI_FORMAT dxgi_format;
/* formats for texture processing */
DXGI_FORMAT resource_format[GST_VIDEO_MAX_PLANES];
/* extra format used for unordered access view (unused) */
DXGI_FORMAT uav_format[GST_VIDEO_MAX_PLANES];
/* D3D12_FORMAT_SUPPORT1 flags */
guint format_support1[GST_VIDEO_MAX_PLANES];
/* D3D12_FORMAT_SUPPORT2 flags (unused) */
guint format_support2[GST_VIDEO_MAX_PLANES];
/*< private >*/
guint padding[GST_PADDING_LARGE];
};
typedef struct _GstD3D12ColorMatrix
{
gdouble matrix[3][3];
gdouble offset[3];
gdouble min[3];
gdouble max[3];
} GstD3D12ColorMatrix;
GstVideoFormat gst_d3d12_dxgi_format_to_gst (DXGI_FORMAT format);
gboolean gst_d3d12_dxgi_format_to_resource_formats (DXGI_FORMAT format,
DXGI_FORMAT resource_format[GST_VIDEO_MAX_PLANES]);
void gst_d3d12_color_matrix_init (GstD3D12ColorMatrix * matrix);
gchar * gst_d3d12_dump_color_matrix (GstD3D12ColorMatrix * matrix);
gboolean gst_d3d12_color_range_adjust_matrix_unorm (const GstVideoInfo * in_info,
const GstVideoInfo * out_info,
GstD3D12ColorMatrix * matrix);
gboolean gst_d3d12_yuv_to_rgb_matrix_unorm (const GstVideoInfo * in_yuv_info,
const GstVideoInfo * out_rgb_info,
GstD3D12ColorMatrix * matrix);
gboolean gst_d3d12_rgb_to_yuv_matrix_unorm (const GstVideoInfo * in_rgb_info,
const GstVideoInfo * out_yuv_info,
GstD3D12ColorMatrix * matrix);
gboolean gst_d3d12_color_primaries_matrix_unorm (const GstVideoColorPrimariesInfo * in_info,
const GstVideoColorPrimariesInfo * out_info,
GstD3D12ColorMatrix * matrix);
G_END_DECLS

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include "gstd3d12pluginutils.h"
G_BEGIN_DECLS

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
#include <string>
#include <vector>
#include <windows.h>

View file

@ -22,7 +22,7 @@
#include <gst/gst.h>
#include <gst/base/gstbasesink.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -22,7 +22,7 @@
#include <gst/gst.h>
#include <gst/base/gstbasesrc.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -22,6 +22,7 @@
#endif
#include "gstd3d12overlaycompositor.h"
#include "gstd3d12pluginutils.h"
#include <directx/d3dx12.h>
#include <wrl.h>
#include <memory>

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -20,8 +20,8 @@
#pragma once
#include <gst/gst.h>
#include "gstd3d12.h"
#include "gstd3d12-private.h"
#include <gst/d3d12/gstd3d12.h>
#include <gst/d3d12/gstd3d12-private.h>
G_BEGIN_DECLS

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -20,7 +20,7 @@
#pragma once
#include <gst/gst.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -22,7 +22,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/base/gstbasesrc.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -22,7 +22,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include <gst/base/gstbasesrc.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
G_BEGIN_DECLS

View file

@ -21,7 +21,7 @@
#include <gst/gst.h>
#include <gst/video/video.h>
#include "gstd3d12.h"
#include <gst/d3d12/gstd3d12.h>
#include "gstd3d12pluginutils.h"
G_BEGIN_DECLS

View file

@ -1,24 +1,14 @@
d3d12_sources = [
'gstd3d12av1dec.cpp',
'gstd3d12basefilter.cpp',
'gstd3d12bufferpool.cpp',
'gstd3d12commandallocatorpool.cpp',
'gstd3d12commandlistpool.cpp',
'gstd3d12commandqueue.cpp',
'gstd3d12compositor.cpp',
'gstd3d12converter-builder.cpp',
'gstd3d12converter.cpp',
'gstd3d12convert.cpp',
'gstd3d12decoder.cpp',
'gstd3d12descriptorpool.cpp',
'gstd3d12device.cpp',
'gstd3d12download.cpp',
'gstd3d12dpbstorage.cpp',
'gstd3d12dxgicapture.cpp',
'gstd3d12encoder.cpp',
'gstd3d12encoderbufferpool.cpp',
'gstd3d12fencedatapool.cpp',
'gstd3d12format.cpp',
'gstd3d12h264dec.cpp',
'gstd3d12h264enc.cpp',
'gstd3d12h265dec.cpp',
@ -27,7 +17,6 @@ d3d12_sources = [
'gstd3d12ipcserver.cpp',
'gstd3d12ipcsink.cpp',
'gstd3d12ipcsrc.cpp',
'gstd3d12memory.cpp',
'gstd3d12mpeg2dec.cpp',
'gstd3d12overlaycompositor.cpp',
'gstd3d12pluginutils.cpp',
@ -36,7 +25,6 @@ d3d12_sources = [
'gstd3d12screencapturesrc.cpp',
'gstd3d12testsrc.cpp',
'gstd3d12upload.cpp',
'gstd3d12utils.cpp',
'gstd3d12videosink.cpp',
'gstd3d12vp8dec.cpp',
'gstd3d12vp9dec.cpp',
@ -46,6 +34,7 @@ d3d12_sources = [
extra_args = [
'-DGST_USE_UNSTABLE_API',
'-DGST_D3D12_USE_DIRECTX_HEADERS',
]
# Disable this warning error. Otherwise d3dx12.h will break build
@ -70,18 +59,16 @@ if host_system != 'windows' or d3d12_option.disabled()
subdir_done()
endif
d3d12_lib = cc.find_library('d3d12', required : d3d12_option)
d3d11_lib = cc.find_library('d3d11', required : d3d12_option)
d2d_dep = cc.find_library('d2d1', required: d3d12_option)
dxgi_lib = cc.find_library('dxgi', required : d3d12_option)
d2d_lib = cc.find_library('d2d1', required: d3d12_option)
dwmapi_lib = cc.find_library('dwmapi', required: d3d12_wgc_option)
dx_headers_dep = dependency('DirectX-Headers',
version: '>= 1.611',
allow_fallback: true,
required: d3d12_option)
if not gstdxva_dep.found() or not d3d12_lib.found() or not dxgi_lib.found() \
or not dx_headers_dep.found() or not gstd3dshader_dep.found() or not d2d_dep.found()
if not gstdxva_dep.found() or not gstd3d12_dep.found() or not gstd3dshader_dep.found() \
or not dx_headers_dep.found() or not d2d_lib.found() or not d3d11_lib.found()
if d3d12_option.enabled()
error('The d3d12 was enabled explicitly, but required dependencies were not found.')
endif
@ -139,7 +126,6 @@ if not have_dx_math
endif
d3d12_headers = [
'dxgi1_6.h',
'd3d11.h',
'd3d11on12.h',
'd2d1.h',
@ -177,8 +163,8 @@ gstd3d12 = library('gstd3d12',
cpp_args: gst_plugins_bad_args + extra_args,
include_directories : [configinc],
dependencies : [gstbase_dep, gstvideo_dep, gstcodecs_dep, gmodule_dep,
gstdxva_dep, d3d12_lib, d3d11_lib, d2d_dep, dxgi_lib,
gstd3dshader_dep, dx_headers_dep] + extra_deps,
gstdxva_dep, gstd3dshader_dep, gstd3d12_dep, d3d11_lib,
d2d_lib, dx_headers_dep] + extra_deps,
install : true,
install_dir : plugins_install_dir,
)

View file

@ -28,8 +28,8 @@
#endif
#include <gst/gst.h>
#include "gstd3d12.h"
#include "gstd3d12-private.h"
#include <gst/d3d12/gstd3d12.h>
#include "gstd3d12pluginutils.h"
#include "gstd3d12convert.h"
#include "gstd3d12download.h"
#include "gstd3d12upload.h"
@ -51,19 +51,12 @@
#include <windows.h>
#include <versionhelpers.h>
#include <wrl.h>
#include <glib/gi18n-lib.h>
/* *INDENT-OFF* */
using namespace Microsoft::WRL;
/* *INDENT-ON* */
GST_DEBUG_CATEGORY (gst_d3d12_debug);
GST_DEBUG_CATEGORY (gst_d3d12_allocator_debug);
GST_DEBUG_CATEGORY (gst_d3d12_decoder_debug);
GST_DEBUG_CATEGORY (gst_d3d12_format_debug);
GST_DEBUG_CATEGORY (gst_d3d12_utils_debug);
#define GST_CAT_DEFAULT gst_d3d12_debug
static void
plugin_deinit (gpointer data)
{
@ -73,22 +66,12 @@ plugin_deinit (gpointer data)
static gboolean
plugin_init (GstPlugin * plugin)
{
GST_DEBUG_CATEGORY_INIT (gst_d3d12_debug, "d3d12", 0, "d3d12");
if (!IsWindows8OrGreater ()) {
GST_WARNING ("Not supported OS");
gst_plugin_add_status_warning (plugin,
N_("This plugin requires at least Windows 8 or newer."));
return TRUE;
}
GST_DEBUG_CATEGORY_INIT (gst_d3d12_allocator_debug, "d3d12allocator", 0,
"d3d12allocator");
GST_DEBUG_CATEGORY_INIT (gst_d3d12_decoder_debug, "d3d12decoder", 0,
"d3d12decoder");
GST_DEBUG_CATEGORY_INIT (gst_d3d12_format_debug, "d3d12format", 0,
"d3d12format");
GST_DEBUG_CATEGORY_INIT (gst_d3d12_utils_debug,
"d3d12utils", 0, "d3d12utils");
/* Enumerate devices to register decoders per device and to get the highest
* feature level */
/* AMD seems to be supporting up to 12 cards, and 8 for NVIDIA */