1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-09-16 08:36:51 +02:00

avutil/hwcontext_d3d12va: added resource and heap flags to DeviceContext

This commit is contained in:
Dmitrii Ovchinnikov
2025-07-23 14:10:06 +02:00
committed by jianhuaw
parent fbbb2996d5
commit 1b97966199
4 changed files with 50 additions and 4 deletions

View File

@@ -2,6 +2,10 @@ The last version increases of all libraries were on 2025-03-28
API changes, most recent first:
2025-09-xx - xxxxxxxxxx - lavu 60.13.100 - hwcontext_d3d12va.h
Add resource_flags and heap_flags to AVD3D12VADeviceContext
Add heap_flags to AVD3D12VAFramesContext
2025-09-xx - xxxxxxxx - lavf 62.5.100 - avformat.h
Add AV_FRAME_FILENAME_FLAGS_IGNORE_TRUNCATION

View File

@@ -301,7 +301,7 @@ static AVBufferRef *d3d12va_pool_alloc(void *opaque, size_t size)
if (!frame)
return NULL;
if (FAILED(ID3D12Device_CreateCommittedResource(device_hwctx->device, &props, D3D12_HEAP_FLAG_NONE, &desc,
if (FAILED(ID3D12Device_CreateCommittedResource(device_hwctx->device, &props, hwctx->heap_flags, &desc,
D3D12_RESOURCE_STATE_COMMON, NULL, &IID_ID3D12Resource, (void **)&frame->texture))) {
av_log(ctx, AV_LOG_ERROR, "Could not create the texture\n");
goto fail;
@@ -345,7 +345,7 @@ static int d3d12va_texture_array_init(AVHWFramesContext *ctx)
.Flags = hwctx->resource_flags,
};
if (FAILED(ID3D12Device_CreateCommittedResource(device_hwctx->device, &props, D3D12_HEAP_FLAG_NONE, &desc,
if (FAILED(ID3D12Device_CreateCommittedResource(device_hwctx->device, &props, hwctx->heap_flags, &desc,
D3D12_RESOURCE_STATE_COMMON, NULL, &IID_ID3D12Resource, (void **)&hwctx->texture_array))) {
av_log(ctx, AV_LOG_ERROR, "Could not create the texture array\n");
return AVERROR(EINVAL);
@@ -355,7 +355,8 @@ static int d3d12va_texture_array_init(AVHWFramesContext *ctx)
static int d3d12va_frames_init(AVHWFramesContext *ctx)
{
AVD3D12VAFramesContext *hwctx = ctx->hwctx;
AVD3D12VAFramesContext *hwctx = ctx->hwctx;
AVD3D12VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
int i;
for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
@@ -367,12 +368,16 @@ static int d3d12va_frames_init(AVHWFramesContext *ctx)
break;
}
}
if (i == FF_ARRAY_ELEMS(supported_formats)) {
av_log(ctx, AV_LOG_ERROR, "Unsupported pixel format: %s\n",
av_get_pix_fmt_name(ctx->sw_format));
return AVERROR(EINVAL);
}
hwctx->resource_flags |= device_hwctx->resource_flags;
hwctx->heap_flags |= device_hwctx->heap_flags;
if (ctx->initial_pool_size > 0 && hwctx->flags & AV_D3D12VA_FRAME_FLAG_TEXTURE_ARRAY) {
int err = d3d12va_texture_array_init(ctx);
if (err < 0)
@@ -754,6 +759,15 @@ static int d3d12va_device_create(AVHWDeviceContext *hwdev, const char *device,
}
}
if (av_dict_get(opts, "UAV", NULL, 0))
ctx->resource_flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
if (av_dict_get(opts, "RTV", NULL, 0))
ctx->resource_flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
if (av_dict_get(opts, "SHARED", NULL, 0))
ctx->heap_flags |= D3D12_HEAP_FLAG_SHARED;
return 0;
}

View File

@@ -75,6 +75,26 @@ typedef struct AVD3D12VADeviceContext {
void (*lock)(void *lock_ctx);
void (*unlock)(void *lock_ctx);
void *lock_ctx;
/**
* Resource flags to be applied to D3D12 resources allocated
* for frames using this device context.
*
* If unset, this will be D3D12_RESOURCE_FLAG_NONE.
*
* It applies globally to all AVD3D12VAFramesContext allocated from this device context.
*/
D3D12_RESOURCE_FLAGS resource_flags;
/**
* Heap flags to be applied to D3D12 resources allocated
* for frames using this device context.
*
* If unset, this will be D3D12_HEAP_FLAG_NONE.
*
* It applies globally to all AVD3D12VAFramesContext allocated from this device context.
*/
D3D12_HEAP_FLAGS heap_flags;
} AVD3D12VADeviceContext;
/**
@@ -164,6 +184,14 @@ typedef struct AVD3D12VAFramesContext {
*/
D3D12_RESOURCE_FLAGS resource_flags;
/**
* Options for working with heaps allocation when creating resources.
* If unset, this will be D3D12_HEAP_FLAG_NONE.
*
* @see https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_heap_flags
*/
D3D12_HEAP_FLAGS heap_flags;
/**
* In texture array mode, the D3D12 uses the same texture array (resource)for all
* pictures.

View File

@@ -79,7 +79,7 @@
*/
#define LIBAVUTIL_VERSION_MAJOR 60
#define LIBAVUTIL_VERSION_MINOR 12
#define LIBAVUTIL_VERSION_MINOR 13
#define LIBAVUTIL_VERSION_MICRO 100
#define LIBAVUTIL_VERSION_INT AV_VERSION_INT(LIBAVUTIL_VERSION_MAJOR, \