mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 03:35:21 +00:00
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:
parent
e5194d4c45
commit
818c95e8c3
5 changed files with 112 additions and 79 deletions
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include "gstd3d12device.h"
|
#include "gstd3d12device.h"
|
||||||
#include "gstd3d12bufferpool.h"
|
#include "gstd3d12bufferpool.h"
|
||||||
|
#include "gstd3d12memory-private.h"
|
||||||
#include "gstd3d12utils.h"
|
#include "gstd3d12utils.h"
|
||||||
#include <directx/d3dx12.h>
|
#include <directx/d3dx12.h>
|
||||||
|
|
||||||
|
@ -123,12 +124,12 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
GstCaps *caps = nullptr;
|
GstCaps *caps = nullptr;
|
||||||
guint min_buffers, max_buffers;
|
guint min_buffers, max_buffers;
|
||||||
gboolean ret = TRUE;
|
gboolean ret = TRUE;
|
||||||
guint align = 0;
|
D3D12_RESOURCE_DESC desc[GST_VIDEO_MAX_PLANES];
|
||||||
D3D12_RESOURCE_DESC *desc;
|
|
||||||
D3D12_HEAP_PROPERTIES heap_props =
|
D3D12_HEAP_PROPERTIES heap_props =
|
||||||
CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT);
|
CD3DX12_HEAP_PROPERTIES (D3D12_HEAP_TYPE_DEFAULT);
|
||||||
guint plane_index = 0;
|
guint plane_index = 0;
|
||||||
gsize mem_size = 0;
|
gsize mem_size = 0;
|
||||||
|
gsize total_offset = 0;
|
||||||
|
|
||||||
if (!gst_buffer_pool_config_get_params (config, &caps, nullptr, &min_buffers,
|
if (!gst_buffer_pool_config_get_params (config, &caps, nullptr, &min_buffers,
|
||||||
&max_buffers)) {
|
&max_buffers)) {
|
||||||
|
@ -165,55 +166,41 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
|
D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
desc = priv->d3d12_params->desc;
|
const auto params = priv->d3d12_params;
|
||||||
switch (desc[0].Format) {
|
memset (desc, 0, sizeof (desc));
|
||||||
case DXGI_FORMAT_NV12:
|
if (params->d3d12_format.dxgi_format != DXGI_FORMAT_UNKNOWN) {
|
||||||
case DXGI_FORMAT_P010:
|
desc[0] = CD3DX12_RESOURCE_DESC::Tex2D (params->d3d12_format.dxgi_format,
|
||||||
case DXGI_FORMAT_P016:
|
params->aligned_info.width, params->aligned_info.height,
|
||||||
align = 2;
|
params->array_size, 1, 1, 0, params->resource_flags);
|
||||||
break;
|
switch (params->d3d12_format.dxgi_format) {
|
||||||
default:
|
case DXGI_FORMAT_NV12:
|
||||||
break;
|
case DXGI_FORMAT_P010:
|
||||||
}
|
case DXGI_FORMAT_P016:
|
||||||
|
desc[0].Width = GST_ROUND_UP_2 (desc[0].Width);
|
||||||
/* resolution of semi-planar formats must be multiple of 2 */
|
desc[0].Height = GST_ROUND_UP_2 (desc[0].Height);
|
||||||
if (align != 0 && (desc[0].Width % align || desc[0].Height % align)) {
|
break;
|
||||||
gint width, height;
|
case DXGI_FORMAT_Y210:
|
||||||
GstVideoAlignment video_align;
|
case DXGI_FORMAT_Y216:
|
||||||
|
desc[0].Width = GST_ROUND_UP_2 (desc[0].Width);
|
||||||
GST_WARNING_OBJECT (self, "Resolution %" G_GUINT64_FORMAT
|
break;
|
||||||
"x%d is not mutiple of %d, fixing", desc[0].Width, desc[0].Height,
|
default:
|
||||||
align);
|
break;
|
||||||
|
}
|
||||||
width = GST_ROUND_UP_N ((guint) desc[0].Width, align);
|
} else {
|
||||||
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;
|
|
||||||
|
|
||||||
for (guint i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
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;
|
break;
|
||||||
|
|
||||||
if (desc[i].DepthOrArraySize > max_array_size)
|
desc[i] =
|
||||||
max_array_size = desc[i].DepthOrArraySize;
|
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++) {
|
for (guint i = 0; i < GST_VIDEO_MAX_PLANES; i++) {
|
||||||
GstD3D12Allocator *alloc;
|
GstD3D12Allocator *alloc;
|
||||||
GstD3D12PoolAllocator *pool_alloc;
|
GstD3D12PoolAllocator *pool_alloc;
|
||||||
|
@ -221,8 +208,8 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
GstMemory *mem = nullptr;
|
GstMemory *mem = nullptr;
|
||||||
GstD3D12Memory *dmem;
|
GstD3D12Memory *dmem;
|
||||||
gint stride = 0;
|
gint stride = 0;
|
||||||
gsize offset = 0;
|
|
||||||
guint plane_count = 0;
|
guint plane_count = 0;
|
||||||
|
gsize offset;
|
||||||
|
|
||||||
if (desc[i].Format == DXGI_FORMAT_UNKNOWN)
|
if (desc[i].Format == DXGI_FORMAT_UNKNOWN)
|
||||||
break;
|
break;
|
||||||
|
@ -261,9 +248,10 @@ gst_d3d12_buffer_pool_set_config (GstBufferPool * pool, GstStructure * config)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
total_offset += offset;
|
||||||
g_assert (plane_index < GST_VIDEO_MAX_PLANES);
|
g_assert (plane_index < GST_VIDEO_MAX_PLANES);
|
||||||
priv->stride[plane_index] = stride;
|
priv->stride[plane_index] = stride;
|
||||||
priv->offset[plane_index] = offset;
|
priv->offset[plane_index] = total_offset;
|
||||||
plane_index++;
|
plane_index++;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -564,7 +564,6 @@ gst_d3d12_decoder_prepare_pool (GstD3D12Decoder * self)
|
||||||
/* Tier 1 decoder requires array */
|
/* Tier 1 decoder requires array */
|
||||||
if (priv->support.DecodeTier == D3D12_VIDEO_DECODE_TIER_1) {
|
if (priv->support.DecodeTier == D3D12_VIDEO_DECODE_TIER_1) {
|
||||||
priv->use_array_of_texture = FALSE;
|
priv->use_array_of_texture = FALSE;
|
||||||
alloc_flags = GST_D3D12_ALLOCATION_FLAG_TEXTURE_ARRAY;
|
|
||||||
} else {
|
} else {
|
||||||
priv->use_array_of_texture = TRUE;
|
priv->use_array_of_texture = TRUE;
|
||||||
max_buffers = 0;
|
max_buffers = 0;
|
||||||
|
@ -579,7 +578,7 @@ gst_d3d12_decoder_prepare_pool (GstD3D12Decoder * self)
|
||||||
gst_d3d12_allocation_params_alignment (params, &align);
|
gst_d3d12_allocation_params_alignment (params, &align);
|
||||||
|
|
||||||
if (!priv->use_array_of_texture)
|
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);
|
priv->dpb_pool = gst_d3d12_buffer_pool_new (self->device);
|
||||||
config = gst_buffer_pool_get_config (priv->dpb_pool);
|
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,
|
GST_D3D12_ALLOCATION_FLAG_DEFAULT,
|
||||||
D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
|
D3D12_RESOURCE_FLAG_ALLOW_SIMULTANEOUS_ACCESS);
|
||||||
} else {
|
} 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);
|
width = GST_VIDEO_INFO_WIDTH (&vinfo);
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <directx/d3dx12.h>
|
#include <directx/d3dx12.h>
|
||||||
#include "gstd3d12memory.h"
|
#include "gstd3d12memory.h"
|
||||||
|
#include "gstd3d12memory-private.h"
|
||||||
#include "gstd3d12device.h"
|
#include "gstd3d12device.h"
|
||||||
#include "gstd3d12utils.h"
|
#include "gstd3d12utils.h"
|
||||||
#include "gstd3d12format.h"
|
#include "gstd3d12format.h"
|
||||||
|
@ -97,22 +98,9 @@ gst_d3d12_allocation_params_new (GstD3D12Device * device,
|
||||||
ret->info = *info;
|
ret->info = *info;
|
||||||
ret->aligned_info = *info;
|
ret->aligned_info = *info;
|
||||||
ret->d3d12_format = d3d12_format;
|
ret->d3d12_format = d3d12_format;
|
||||||
|
ret->array_size = 1;
|
||||||
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->flags = flags;
|
ret->flags = flags;
|
||||||
|
ret->resource_flags = resource_flags;
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -162,14 +150,34 @@ gst_d3d12_allocation_params_alignment (GstD3D12AllocationParams * params,
|
||||||
|
|
||||||
params->aligned_info = new_info;
|
params->aligned_info = new_info;
|
||||||
|
|
||||||
for (guint i = 0; i < GST_VIDEO_INFO_N_PLANES (info); i++) {
|
return TRUE;
|
||||||
params->desc[i].Width = GST_VIDEO_INFO_COMP_WIDTH (&new_info, i);
|
}
|
||||||
params->desc[i].Height = GST_VIDEO_INFO_COMP_HEIGHT (&new_info, i);
|
|
||||||
}
|
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;
|
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* */
|
/* *INDENT-OFF* */
|
||||||
struct _GstD3D12MemoryPrivate
|
struct _GstD3D12MemoryPrivate
|
||||||
{
|
{
|
||||||
|
|
|
@ -82,18 +82,8 @@ typedef enum
|
||||||
typedef enum
|
typedef enum
|
||||||
{
|
{
|
||||||
GST_D3D12_ALLOCATION_FLAG_DEFAULT = 0,
|
GST_D3D12_ALLOCATION_FLAG_DEFAULT = 0,
|
||||||
GST_D3D12_ALLOCATION_FLAG_TEXTURE_ARRAY = (1 << 0),
|
|
||||||
} GstD3D12AllocationFlags;
|
} 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);
|
GType gst_d3d12_allocation_params_get_type (void);
|
||||||
|
|
||||||
GstD3D12AllocationParams * gst_d3d12_allocation_params_new (GstD3D12Device * device,
|
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,
|
gboolean gst_d3d12_allocation_params_alignment (GstD3D12AllocationParams * parms,
|
||||||
const GstVideoAlignment * align);
|
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
|
struct _GstD3D12Memory
|
||||||
{
|
{
|
||||||
GstMemory mem;
|
GstMemory mem;
|
||||||
|
|
Loading…
Reference in a new issue