mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-11-22 09:41:07 +00:00
d3d12memory: Add GstD3D12AllocationParams struct
Will be used for buffer pool configuration. And update C++ helper to reduce the number of required arguments Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5345>
This commit is contained in:
parent
73744df6e4
commit
c0572f8749
7 changed files with 171 additions and 21 deletions
|
@ -51,5 +51,7 @@ typedef struct _GstD3D12PoolAllocatorPrivate GstD3D12PoolAllocatorPrivate;
|
|||
|
||||
typedef struct _GstD3D12Format GstD3D12Format;
|
||||
|
||||
typedef struct _GstD3D12AllocationParams GstD3D12AllocationParams;
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
|
|
|
@ -460,7 +460,7 @@ gst_d3d12_decoder_configure (GstD3D12Decoder * decoder,
|
|||
|
||||
gst_d3d12_decoder_reset (decoder);
|
||||
|
||||
if (!gst_d3d12_device_get_device_format (priv->device,
|
||||
if (!gst_d3d12_device_get_format (priv->device,
|
||||
GST_VIDEO_INFO_FORMAT (info), &device_format) ||
|
||||
device_format.dxgi_format == DXGI_FORMAT_UNKNOWN) {
|
||||
GST_ERROR_OBJECT (decoder, "Could not determine dxgi format from %s",
|
||||
|
@ -526,13 +526,7 @@ gst_d3d12_decoder_prepare_allocator (GstD3D12Decoder * self)
|
|||
D3D12_HEAP_PROPERTIES heap_prop =
|
||||
CD3D12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT);
|
||||
D3D12_RESOURCE_DESC desc = CD3D12_RESOURCE_DESC::Tex2D (priv->decoder_format,
|
||||
priv->aligned_width,
|
||||
priv->aligned_height,
|
||||
array_size,
|
||||
1,
|
||||
1,
|
||||
0,
|
||||
resource_flags);
|
||||
priv->aligned_width, priv->aligned_height, resource_flags, array_size);
|
||||
|
||||
priv->allocator = (GstD3D12Allocator *)
|
||||
gst_d3d12_pool_allocator_new (priv->device,
|
||||
|
@ -547,9 +541,7 @@ gst_d3d12_decoder_prepare_allocator (GstD3D12Decoder * self)
|
|||
D3D12_RESOURCE_DESC ref_desc =
|
||||
CD3D12_RESOURCE_DESC::Tex2D (priv->decoder_format,
|
||||
priv->aligned_width,
|
||||
priv->aligned_height,
|
||||
1,
|
||||
1);
|
||||
priv->aligned_height);
|
||||
|
||||
priv->output_allocator = (GstD3D12Allocator *)
|
||||
gst_d3d12_pool_allocator_new (priv->device, &heap_prop,
|
||||
|
@ -974,10 +966,7 @@ gst_d3d12_decoder_ensure_staging_texture (GstD3D12Decoder * self)
|
|||
ID3D12Device *device = gst_d3d12_device_get_device_handle (priv->device);
|
||||
D3D12_RESOURCE_DESC tex_desc =
|
||||
CD3D12_RESOURCE_DESC::Tex2D (priv->decoder_format,
|
||||
priv->aligned_width,
|
||||
priv->aligned_height,
|
||||
1,
|
||||
1);
|
||||
priv->aligned_width, priv->aligned_height);
|
||||
|
||||
device->GetCopyableFootprints (&tex_desc, 0, 2, 0, priv->layout, nullptr,
|
||||
nullptr, &size);
|
||||
|
|
|
@ -713,7 +713,7 @@ gst_d3d12_device_get_factory_handle (GstD3D12Device * device)
|
|||
}
|
||||
|
||||
gboolean
|
||||
gst_d3d12_device_get_device_format (GstD3D12Device * device,
|
||||
gst_d3d12_device_get_format (GstD3D12Device * device,
|
||||
GstVideoFormat format, GstD3D12Format * device_format)
|
||||
{
|
||||
g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), FALSE);
|
||||
|
|
|
@ -64,7 +64,7 @@ IDXGIAdapter1 * gst_d3d12_device_get_adapter_handle (GstD3D12Devic
|
|||
|
||||
IDXGIFactory2 * gst_d3d12_device_get_factory_handle (GstD3D12Device * device);
|
||||
|
||||
gboolean gst_d3d12_device_get_device_format (GstD3D12Device * device,
|
||||
gboolean gst_d3d12_device_get_format (GstD3D12Device * device,
|
||||
GstVideoFormat format,
|
||||
GstD3D12Format * device_format);
|
||||
|
||||
|
|
|
@ -33,14 +33,143 @@
|
|||
#include <atomic>
|
||||
#include <queue>
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
using namespace Microsoft::WRL;
|
||||
/* *INDENT-ON* */
|
||||
|
||||
GST_DEBUG_CATEGORY_EXTERN (gst_d3d12_allocator_debug);
|
||||
#define GST_CAT_DEFAULT gst_d3d12_allocator_debug
|
||||
|
||||
static GstD3D12Allocator *_d3d12_memory_allocator = nullptr;
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
using namespace Microsoft::WRL;
|
||||
static gint
|
||||
gst_d3d12_allocation_params_compare (const GstD3D12AllocationParams * p1,
|
||||
const GstD3D12AllocationParams * p2)
|
||||
{
|
||||
g_return_val_if_fail (p1, -1);
|
||||
g_return_val_if_fail (p2, -1);
|
||||
|
||||
if (p1 == p2)
|
||||
return 0;
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
static void
|
||||
gst_d3d12_allocation_params_init (GType type)
|
||||
{
|
||||
static GstValueTable table = {
|
||||
0, (GstValueCompareFunc) gst_d3d12_allocation_params_compare,
|
||||
nullptr, nullptr
|
||||
};
|
||||
|
||||
table.type = type;
|
||||
gst_value_register (&table);
|
||||
}
|
||||
|
||||
G_DEFINE_BOXED_TYPE_WITH_CODE (GstD3D12AllocationParams,
|
||||
gst_d3d12_allocation_params,
|
||||
(GBoxedCopyFunc) gst_d3d12_allocation_params_copy,
|
||||
(GBoxedFreeFunc) gst_d3d12_allocation_params_free,
|
||||
gst_d3d12_allocation_params_init (g_define_type_id));
|
||||
|
||||
GstD3D12AllocationParams *
|
||||
gst_d3d12_allocation_params_new (GstD3D12Device * device,
|
||||
const GstVideoInfo * info, GstD3D12AllocationFlags flags,
|
||||
D3D12_RESOURCE_FLAGS resource_flags)
|
||||
{
|
||||
GstD3D12AllocationParams *ret;
|
||||
GstD3D12Format d3d12_format;
|
||||
GstVideoFormat format;
|
||||
|
||||
g_return_val_if_fail (GST_IS_D3D12_DEVICE (device), nullptr);
|
||||
g_return_val_if_fail (info, nullptr);
|
||||
|
||||
format = GST_VIDEO_INFO_FORMAT (info);
|
||||
if (!gst_d3d12_device_get_format (device, format, &d3d12_format)) {
|
||||
GST_WARNING_OBJECT (device, "%s is not supported",
|
||||
gst_video_format_to_string (format));
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
ret = g_new0 (GstD3D12AllocationParams, 1);
|
||||
ret->info = *info;
|
||||
ret->aligned_info = *info;
|
||||
ret->d3d12_format = d3d12_format;
|
||||
|
||||
if (d3d12_format.dxgi_format == DXGI_FORMAT_UNKNOWN) {
|
||||
for (guint i = 0; i < GST_VIDEO_INFO_N_PLANES (info); i++) {
|
||||
g_assert (d3d12_format.resource_format[i] != DXGI_FORMAT_UNKNOWN);
|
||||
|
||||
ret->desc[i] =
|
||||
CD3D12_RESOURCE_DESC::Tex2D (d3d12_format.resource_format[i],
|
||||
GST_VIDEO_INFO_COMP_WIDTH (info, i),
|
||||
GST_VIDEO_INFO_COMP_HEIGHT (info, i), resource_flags);
|
||||
}
|
||||
} else {
|
||||
ret->desc[0] = CD3D12_RESOURCE_DESC::Tex2D (d3d12_format.dxgi_format,
|
||||
info->width, info->height, resource_flags);
|
||||
}
|
||||
|
||||
ret->flags = flags;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
GstD3D12AllocationParams *
|
||||
gst_d3d12_allocation_params_copy (GstD3D12AllocationParams * src)
|
||||
{
|
||||
GstD3D12AllocationParams *dst;
|
||||
|
||||
g_return_val_if_fail (src != NULL, NULL);
|
||||
|
||||
dst = g_new0 (GstD3D12AllocationParams, 1);
|
||||
memcpy (dst, src, sizeof (GstD3D12AllocationParams));
|
||||
|
||||
return dst;
|
||||
}
|
||||
|
||||
void
|
||||
gst_d3d12_allocation_params_free (GstD3D12AllocationParams * params)
|
||||
{
|
||||
g_free (params);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gst_d3d12_allocation_params_alignment (GstD3D12AllocationParams * params,
|
||||
const GstVideoAlignment * align)
|
||||
{
|
||||
guint padding_width, padding_height;
|
||||
GstVideoInfo *info;
|
||||
GstVideoInfo new_info;
|
||||
|
||||
g_return_val_if_fail (params, FALSE);
|
||||
g_return_val_if_fail (align, FALSE);
|
||||
|
||||
/* d3d11 does not support stride align. Consider padding only */
|
||||
padding_width = align->padding_left + align->padding_right;
|
||||
padding_height = align->padding_top + align->padding_bottom;
|
||||
|
||||
info = ¶ms->info;
|
||||
|
||||
if (!gst_video_info_set_format (&new_info, GST_VIDEO_INFO_FORMAT (info),
|
||||
GST_VIDEO_INFO_WIDTH (info) + padding_width,
|
||||
GST_VIDEO_INFO_HEIGHT (info) + padding_height)) {
|
||||
GST_WARNING ("Set format failed");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
params->aligned_info = new_info;
|
||||
|
||||
for (guint i = 0; i < GST_VIDEO_INFO_N_PLANES (info); i++) {
|
||||
params->desc[i].Width = GST_VIDEO_INFO_COMP_WIDTH (&new_info, i);
|
||||
params->desc[i].Height = GST_VIDEO_INFO_COMP_HEIGHT (&new_info, i);
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/* *INDENT-OFF* */
|
||||
struct _GstD3D12MemoryPrivate
|
||||
{
|
||||
ComPtr<ID3D12Resource> resource;
|
||||
|
|
|
@ -22,6 +22,7 @@
|
|||
#include <gst/gst.h>
|
||||
#include <gst/video/video.h>
|
||||
#include "gstd3d12_fwd.h"
|
||||
#include "gstd3d12format.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
@ -78,6 +79,35 @@ typedef enum
|
|||
GST_D3D12_MEMORY_TRANSFER_NEED_UPLOAD = (GST_MEMORY_FLAG_LAST << 1)
|
||||
} GstD3D12MemoryTransfer;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GST_D3D12_ALLOCATION_FLAG_DEFAULT = 0,
|
||||
GST_D3D12_ALLOCATION_FLAG_TEXTURE_ARRAY = (1 << 0),
|
||||
} GstD3D12AllocationFlags;
|
||||
|
||||
struct _GstD3D12AllocationParams
|
||||
{
|
||||
D3D12_RESOURCE_DESC desc[GST_VIDEO_MAX_PLANES];
|
||||
GstVideoInfo info;
|
||||
GstVideoInfo aligned_info;
|
||||
GstD3D12Format d3d12_format;
|
||||
GstD3D12AllocationFlags flags;
|
||||
};
|
||||
|
||||
GType gst_d3d12_allocation_params_get_type (void);
|
||||
|
||||
GstD3D12AllocationParams * gst_d3d12_allocation_params_new (GstD3D12Device * device,
|
||||
const GstVideoInfo * info,
|
||||
GstD3D12AllocationFlags flags,
|
||||
D3D12_RESOURCE_FLAGS resource_flags);
|
||||
|
||||
GstD3D12AllocationParams * gst_d3d12_allocation_params_copy (GstD3D12AllocationParams * src);
|
||||
|
||||
void gst_d3d12_allocation_params_free (GstD3D12AllocationParams * params);
|
||||
|
||||
gboolean gst_d3d12_allocation_params_alignment (GstD3D12AllocationParams * parms,
|
||||
const GstVideoAlignment * align);
|
||||
|
||||
struct _GstD3D12Memory
|
||||
{
|
||||
GstMemory mem;
|
||||
|
|
|
@ -143,11 +143,11 @@ struct CD3D12_RESOURCE_DESC : public D3D12_RESOURCE_DESC
|
|||
DXGI_FORMAT format,
|
||||
UINT64 width,
|
||||
UINT height,
|
||||
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
|
||||
UINT16 array_size = 1,
|
||||
UINT16 mip_levels = 0,
|
||||
UINT16 mip_levels = 1,
|
||||
UINT sample_count = 1,
|
||||
UINT sample_quality = 0,
|
||||
D3D12_RESOURCE_FLAGS flags = D3D12_RESOURCE_FLAG_NONE,
|
||||
D3D12_TEXTURE_LAYOUT layout = D3D12_TEXTURE_LAYOUT_UNKNOWN,
|
||||
UINT64 alignment = 0)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue