* [FFmpeg-devel] [PATCH v2] avutil/hwcontext_d3d12va: added resource Flags support to command line
@ 2025-06-26 14:11 Dmitrii Ovchinnikov
2025-07-06 16:47 ` [FFmpeg-devel] 回复: " Wu Jianhua
0 siblings, 1 reply; 2+ messages in thread
From: Dmitrii Ovchinnikov @ 2025-06-26 14:11 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Dmitrii Ovchinnikov
---
libavutil/hwcontext_d3d12va.c | 22 +++++++++++++++++++++-
libavutil/hwcontext_d3d12va.h | 6 ++++++
2 files changed, 27 insertions(+), 1 deletion(-)
diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
index 6507cf69c1..b2b58ac6f8 100644
--- a/libavutil/hwcontext_d3d12va.c
+++ b/libavutil/hwcontext_d3d12va.c
@@ -254,7 +254,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;
@@ -281,6 +281,7 @@ fail:
static int d3d12va_frames_init(AVHWFramesContext *ctx)
{
AVD3D12VAFramesContext *hwctx = ctx->hwctx;
+ AVD3D12VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
int i;
for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
@@ -298,6 +299,9 @@ static int d3d12va_frames_init(AVHWFramesContext *ctx)
return AVERROR(EINVAL);
}
+ hwctx->flags |= device_hwctx->flags;
+ hwctx->heap_flags |= device_hwctx->heap_flags;
+
ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2(sizeof(AVD3D12VAFrame),
ctx, d3d12va_pool_alloc, NULL);
@@ -673,6 +677,22 @@ static int d3d12va_device_create(AVHWDeviceContext *hwdev, const char *device,
}
}
+ ctx->flags = 0;
+ ctx->heap_flags = 0;
+
+ // "shader_resouce" already enabled by default.
+
+ if (av_dict_get(opts, "uav_res", NULL, 0))
+ ctx->flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
+
+ if (av_dict_get(opts, "render_target_res", NULL, 0))
+ ctx->flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
+
+ ctx->heap_flags = D3D12_HEAP_FLAG_NONE;
+
+ if (av_dict_get(opts, "shared_res", NULL, 0))
+ ctx->heap_flags |= D3D12_HEAP_FLAG_SHARED;
+
return 0;
}
diff --git a/libavutil/hwcontext_d3d12va.h b/libavutil/hwcontext_d3d12va.h
index 212a6a6146..2075bd4a48 100644
--- a/libavutil/hwcontext_d3d12va.h
+++ b/libavutil/hwcontext_d3d12va.h
@@ -75,6 +75,11 @@ typedef struct AVD3D12VADeviceContext {
void (*lock)(void *lock_ctx);
void (*unlock)(void *lock_ctx);
void *lock_ctx;
+ /**
+ * Need to pass value to frames context from command line
+ */
+ D3D12_RESOURCE_FLAGS flags;
+ D3D12_HEAP_FLAGS heap_flags;
} AVD3D12VADeviceContext;
/**
@@ -137,6 +142,7 @@ typedef struct AVD3D12VAFramesContext {
* @see https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_resource_flags
*/
D3D12_RESOURCE_FLAGS flags;
+ D3D12_HEAP_FLAGS heap_flags;
} AVD3D12VAFramesContext;
#endif /* AVUTIL_HWCONTEXT_D3D12VA_H */
--
2.47.1.windows.1
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
* [FFmpeg-devel] 回复: [PATCH v2] avutil/hwcontext_d3d12va: added resource Flags support to command line
2025-06-26 14:11 [FFmpeg-devel] [PATCH v2] avutil/hwcontext_d3d12va: added resource Flags support to command line Dmitrii Ovchinnikov
@ 2025-07-06 16:47 ` Wu Jianhua
0 siblings, 0 replies; 2+ messages in thread
From: Wu Jianhua @ 2025-07-06 16:47 UTC (permalink / raw)
To: ffmpeg-devel; +Cc: Dmitrii Ovchinnikov
From Dmitrii Ovchinnikov:
> ---
> libavutil/hwcontext_d3d12va.c | 22 +++++++++++++++++++++-
> libavutil/hwcontext_d3d12va.h | 6 ++++++
> 2 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
> index 6507cf69c1..b2b58ac6f8 100644
> --- a/libavutil/hwcontext_d3d12va.c
> +++ b/libavutil/hwcontext_d3d12va.c
> @@ -254,7 +254,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;
> @@ -281,6 +281,7 @@ fail:
> static int d3d12va_frames_init(AVHWFramesContext *ctx)
> {
> AVD3D12VAFramesContext *hwctx = ctx->hwctx;
> + AVD3D12VADeviceContext *device_hwctx = ctx->device_ctx->hwctx;
> int i;
>
> for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) {
> @@ -298,6 +299,9 @@ static int d3d12va_frames_init(AVHWFramesContext *ctx)
> return AVERROR(EINVAL);
> }
>
> + hwctx->flags |= device_hwctx->flags;
> + hwctx->heap_flags |= device_hwctx->heap_flags;
> +
> ffhwframesctx(ctx)->pool_internal = av_buffer_pool_init2(sizeof(AVD3D12VAFrame),
> ctx, d3d12va_pool_alloc, NULL);
>
> @@ -673,6 +677,22 @@ static int d3d12va_device_create(AVHWDeviceContext *hwdev, const char *device,
> }
> }
>
> + ctx->flags = 0;
> + ctx->heap_flags = 0;
> +
We cannot set them to zero. It will clear the flags set by the API user.
> + // "shader_resouce" already enabled by default.
> +
> + if (av_dict_get(opts, "uav_res", NULL, 0))
> + ctx->flags |= D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS;
> +
> + if (av_dict_get(opts, "render_target_res", NULL, 0))
> + ctx->flags |= D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET;
> +
> + ctx->heap_flags = D3D12_HEAP_FLAG_NONE;
> +
> + if (av_dict_get(opts, "shared_res", NULL, 0))
> + ctx->heap_flags |= D3D12_HEAP_FLAG_SHARED;
> +
> return 0;
> }
>
Maybe we can simply use UAV and RTV, which are also used by d3d12 officially, and SHARED.
> diff --git a/libavutil/hwcontext_d3d12va.h b/libavutil/hwcontext_d3d12va.h
> index 212a6a6146..2075bd4a48 100644
> --- a/libavutil/hwcontext_d3d12va.h
> +++ b/libavutil/hwcontext_d3d12va.h
> @@ -75,6 +75,11 @@ typedef struct AVD3D12VADeviceContext {
> void (*lock)(void *lock_ctx);
> void (*unlock)(void *lock_ctx);
> void *lock_ctx;
> + /**
> + * Need to pass value to frames context from command line
> + */
Not `from command line`, for that it can be set by C API, we may comment that it's a global
resource flags instead.
Please also check the comments of other codes in hwcontext_d3d12va.h. These are exposed
to the public API, we need to make it formal. And we may need to change the flags to
frame_flags or resource_flags, or it will confuse the user if it is a flags related to
the device instead of the frame.
> + D3D12_RESOURCE_FLAGS flags;
> + D3D12_HEAP_FLAGS heap_flags;
> } AVD3D12VADeviceContext;
>
> /**
> @@ -137,6 +142,7 @@ typedef struct AVD3D12VAFramesContext {
> * @see https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ne-d3d12-d3d12_resource_flags
> */
> D3D12_RESOURCE_FLAGS flags;
> + D3D12_HEAP_FLAGS heap_flags;
> } AVD3D12VAFramesContext;
>
> #endif /* AVUTIL_HWCONTEXT_D3D12VA_H */
_______________________________________________
ffmpeg-devel mailing list
ffmpeg-devel@ffmpeg.org
https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
To unsubscribe, visit link above, or email
ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-07-06 16:47 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-06-26 14:11 [FFmpeg-devel] [PATCH v2] avutil/hwcontext_d3d12va: added resource Flags support to command line Dmitrii Ovchinnikov
2025-07-06 16:47 ` [FFmpeg-devel] 回复: " Wu Jianhua
Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
This inbox may be cloned and mirrored by anyone:
git clone --mirror https://master.gitmailbox.com/ffmpegdev/0 ffmpegdev/git/0.git
# If you have public-inbox 1.1+ installed, you may
# initialize and index your mirror using the following commands:
public-inbox-init -V2 ffmpegdev ffmpegdev/ https://master.gitmailbox.com/ffmpegdev \
ffmpegdev@gitmailbox.com
public-inbox-index ffmpegdev
Example config snippet for mirrors.
AGPL code for this site: git clone https://public-inbox.org/public-inbox.git