d3d12: Update allocation params signalling

Sync up with d3d11 implementation

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/5812>
This commit is contained in:
Seungha Yang 2023-12-14 20:22:35 +09:00
parent e5194d4c45
commit 818c95e8c3
5 changed files with 112 additions and 79 deletions

View file

@ -23,6 +23,7 @@
#include "gstd3d12device.h"
#include "gstd3d12bufferpool.h"
#include "gstd3d12memory-private.h"
#include "gstd3d12utils.h"
#include <directx/d3dx12.h>
@ -123,12 +124,12 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
GstCaps *caps = nullptr;
guint min_buffers, max_buffers;
gboolean ret = TRUE;
guint align = 0;
D3D12_RESOURCE_DESC *desc;
D3D12_RESOURCE_DESC desc[GST_VIDEO_MAX_PLANES];
D3D12_HEAP_PROPERTIES heap_props =
CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT);
guint plane_index = 0;
gsize mem_size = 0;
gsize total_offset = 0;
if (!gst_buffer_pool_config_get_params (config, &caps, nullptr, &min_buffers,
&max_buffers)) {
@ -165,54 +166,40 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
}
desc = priv->d3d12_params->desc;
switch (desc[0].Format) {
const auto params = priv->d3d12_params;
memset (desc, 0, sizeof (desc));
if (params->d3d12_format.dxgi_format != DXGI_FORMAT_UNKNOWN) {
desc[0] = CD3DX12_RESOURCE_DESC::Tex2D (params->d3d12_format.dxgi_format,
params->aligned_info.width, params->aligned_info.height,
params->array_size, 1, 1, 0, params->resource_flags);
switch (params->d3d12_format.dxgi_format) {
case DXGI_FORMAT_NV12:
case DXGI_FORMAT_P010:
case DXGI_FORMAT_P016:
align = 2;
desc[0].Width = GST_ROUND_UP_2 (desc[0].Width);
desc[0].Height = GST_ROUND_UP_2 (desc[0].Height);
break;
case DXGI_FORMAT_Y210:
case DXGI_FORMAT_Y216:
desc[0].Width = GST_ROUND_UP_2 (desc[0].Width);
break;
default:
break;
}
/* resolution of semi-planar formats must be multiple of 2 */
if (align != 0 && (desc[0].Width % align || desc[0].Height % align)) {
gint width, height;
GstVideoAlignment video_align;
GST_WARNING_OBJECT (self, "Resolution %" G_GUINT64_FORMAT
"x%d is not mutiple of %d, fixing", desc[0].Width, desc[0].Height,
align);
width = GST_ROUND_UP_N ((guint) desc[0].Width, align);
height = GST_ROUND_UP_N ((guint) desc[0].Height, align);
gst_video_alignment_reset (&video_align);
video_align.padding_right = width - desc[0].Width;
video_align.padding_bottom = height - desc[0].Height;
gst_d3d12_allocation_params_alignment (priv->d3d12_params, &video_align);
}
if ((priv->d3d12_params->flags & GST_D3D12_ALLOCATION_FLAG_TEXTURE_ARRAY)) {
guint max_array_size = 0;
} else {
for (guint i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
if (desc[i].Format == DXGI_FORMAT_UNKNOWN)
if (params->d3d12_format.resource_format[i] == DXGI_FORMAT_UNKNOWN)
break;
if (desc[i].DepthOrArraySize > max_array_size)
max_array_size = desc[i].DepthOrArraySize;
desc[i] =
CD3DX12_RESOURCE_DESC::Tex2D (params->d3d12_format.resource_format[i],
params->aligned_info.width, params->aligned_info.height,
params->array_size, 1, 1, 0, params->resource_flags);
}
}
if (max_buffers == 0 || max_buffers > max_array_size) {
GST_WARNING_OBJECT (self,
"Array pool is requested but allowed pool size %d > ArraySize %d",
max_buffers, max_array_size);
max_buffers = max_array_size;
}
}
if (params->array_size > 1)
max_buffers = params->array_size;
for (guint i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
GstD3D12Allocator *alloc;
@ -221,8 +208,8 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
GstMemory *mem = nullptr;
GstD3D12Memory *dmem;
gint stride = 0;
gsize offset = 0;
guint plane_count = 0;
gsize offset;
if (desc[i].Format == DXGI_FORMAT_UNKNOWN)
break;
@ -261,9 +248,10 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
return FALSE;
}
total_offset += offset;
g_assert (plane_index < GST_VIDEO_MAX_PLANES);
priv->stride[plane_index] = stride;
priv->offset[plane_index] = offset;
priv->offset[plane_index] = total_offset;
plane_index++;
}

View file

@ -564,7 +564,6 @@ gst_d3d12_decoder_prepare_pool (GstD3D12Decoder * self)
/* Tier 1 decoder requires array */
if (priv->support.DecodeTier == D3D12_VIDEO_DECODE_TIER_1) {
priv->use_array_of_texture = FALSE;
alloc_flags = GST_D3D12_ALLOCATION_FLAG_TEXTURE_ARRAY;
} else {
priv->use_array_of_texture = TRUE;
max_buffers = 0;
@ -579,7 +578,7 @@ gst_d3d12_decoder_prepare_pool (GstD3D12Decoder * self)
gst_d3d12_allocation_params_alignment (params, &align);
if (!priv->use_array_of_texture)
params->desc[0].DepthOrArraySize = (UINT16) max_buffers;
gst_d3d12_allocation_params_set_array_size (params, max_buffers);
priv->dpb_pool = gst_d3d12_buffer_pool_new (self->device);
config = gst_buffer_pool_get_config (priv->dpb_pool);
@ -1710,7 +1709,8 @@ gst_d3d12_decoder_decide_allocation (GstD3D12Decoder * decoder,
GST_D3D12_ALLOCATION_FLAG_DEFAULT,
D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
} else {
params->desc[0].Flags |= D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS;
gst_d3d12_allocation_params_set_resource_flags (params,
D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
}
width = GST_VIDEO_INFO_WIDTH (&vinfo);

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 "gstd3d12_fwd.h"
#include "gstd3d12format.h"
#include "gstd3d12memory.h"
G_BEGIN_DECLS
struct _GstD3D12AllocationParams
{
GstVideoInfo info;
GstVideoInfo aligned_info;
GstD3D12Format d3d12_format;
GstD3D12AllocationFlags flags;
D3D12_RESOURCE_FLAGS resource_flags;
guint array_size;
};
G_END_DECLS

View file

@ -23,6 +23,7 @@
#include <directx/d3dx12.h>
#include "gstd3d12memory.h"
#include "gstd3d12memory-private.h"
#include "gstd3d12device.h"
#include "gstd3d12utils.h"
#include "gstd3d12format.h"
@ -97,22 +98,9 @@ gst_d3d12_allocation_params_new (GstD3D12Device * device,
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] =
CD3DX12_RESOURCE_DESC::Tex2D (d3d12_format.resource_format[i],
GST_VIDEO_INFO_COMP_WIDTH (info, i),
GST_VIDEO_INFO_COMP_HEIGHT (info, i), 1, 1, 1, 0, resource_flags);
}
} else {
ret->desc[0] = CD3DX12_RESOURCE_DESC::Tex2D (d3d12_format.dxgi_format,
info->width, info->height, 1, 1, 1, 0, resource_flags);
}
ret->array_size = 1;
ret->flags = flags;
ret->resource_flags = resource_flags;
return ret;
}
@ -162,14 +150,34 @@ gst_d3d12_allocation_params_alignment (GstD3D12AllocationParams * params,
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;
}
gboolean
gst_d3d12_allocation_params_set_resource_flags (GstD3D12AllocationParams *
params, D3D12_RESOURCE_FLAGS resource_flags)
{
g_return_val_if_fail (params, FALSE);
params->resource_flags |= resource_flags;
return TRUE;
}
gboolean
gst_d3d12_allocation_params_set_array_size (GstD3D12AllocationParams * params,
guint size)
{
g_return_val_if_fail (params, FALSE);
g_return_val_if_fail (size > 0, FALSE);
g_return_val_if_fail (size <= G_MAXUINT16, FALSE);
params->array_size = size;
return TRUE;
}
/* *INDENT-OFF* */
struct _GstD3D12MemoryPrivate
{

View file

@ -82,18 +82,8 @@ typedef enum
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,
@ -108,6 +98,12 @@ void gst_d3d12_allocation_params_free (GstD3D12Allocat
gboolean gst_d3d12_allocation_params_alignment (GstD3D12AllocationParams * parms,
const GstVideoAlignment * align);
gboolean gst_d3d12_allocation_params_set_resource_flags (GstD3D12AllocationParams * params,
D3D12_RESOURCE_FLAGS resource_flags);
gboolean gst_d3d12_allocation_params_set_array_size (GstD3D12AllocationParams * params,
guint size);
struct _GstD3D12Memory
{
GstMemory mem;