[FFmpeg-devel] 回复: [PATCH v3] avutil/hwcontext_d3d12va: added resource and heap flags to DeviceContext

Wu Jianhua toqsxw at outlook.com
Wed Aug 6 19:26:33 EEST 2025


Dmitrii Ovchinnikov:
> ---
>  libavutil/hwcontext_d3d12va.c | 17 ++++++++++++++++-
>  libavutil/hwcontext_d3d12va.h | 11 +++++++++++
>  2 files changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/libavutil/hwcontext_d3d12va.c b/libavutil/hwcontext_d3d12va.c
> index 6507cf69c1..dca8ddc0c3 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->resource_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,17 @@ 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;
> +
> +    ctx->heap_flags = D3D12_HEAP_FLAG_NONE;
> +
> +    if (av_dict_get(opts, "SHARED", 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..0d3a4cc1ec 100644
> --- a/libavutil/hwcontext_d3d12va.h
> +++ b/libavutil/hwcontext_d3d12va.h
> @@ -75,6 +75,16 @@ typedef struct AVD3D12VADeviceContext {
>      void (*lock)(void *lock_ctx);
>      void (*unlock)(void *lock_ctx);
>      void *lock_ctx;
> +    /**
> +     * Resource flags and Heap flags to be applied to D3D12 resources allocated
> +     * for frames using this device context.
> +     *
> +     * Can be set by the user before initialization via av_hwdevice_ctx_create().
> +     *
> +     * These apply globally to all frames allocated from this device context.
> +     */
> +    D3D12_RESOURCE_FLAGS resource_flags;
> +    D3D12_HEAP_FLAGS heap_flags;
>  } AVD3D12VADeviceContext;
>
>  /**
> @@ -137,6 +147,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

Hi there,

This patch looks good to me. Will push if there is no more comments.

Thanks,
Jianhua


More information about the ffmpeg-devel mailing list