[FFmpeg-devel] [PATCH v12 2/9] avcodec: add D3D12VA hardware accelerated H264 decoding

Michael Niedermayer michael at niedermayer.cc
Mon Dec 25 01:06:52 EET 2023


On Tue, Dec 05, 2023 at 02:46:44PM +0800, Tong Wu wrote:
> From: Wu Jianhua <toqsxw at outlook.com>
> 
> The implementation is based on:
> https://learn.microsoft.com/en-us/windows/win32/medfound/direct3d-12-video-overview
> 
> With the Direct3D 12 video decoding support, we can render or process
> the decoded images by the pixel shaders or compute shaders directly
> without the extra copy overhead, which is beneficial especially if you
> are trying to render or post-process a 4K or 8K video.
> 
> The command below is how to enable d3d12va:
> ffmpeg -hwaccel d3d12va -i input.mp4 output.mp4
> 
> Signed-off-by: Wu Jianhua <toqsxw at outlook.com>
> Signed-off-by: Tong Wu <tong1.wu at intel.com>
> ---
[...]
> +unsigned ff_d3d12va_get_surface_index(const AVCodecContext *avctx,
> +                                      D3D12VADecodeContext *ctx, const AVFrame *frame,
> +                                      int curr)
> +{
> +    AVD3D12VAFrame *f;
> +    ID3D12Resource *res;
> +    unsigned i;
> +
> +    f = (AVD3D12VAFrame *)frame->data[0];
> +    if (!f)
> +        goto fail;
> +
> +    res = f->texture;
> +    if (!res)
> +        goto fail;
> +
> +    if (!curr) {
> +        for (i = 0; i < ctx->max_num_ref; i++) {
> +            if (ctx->ref_resources[i] && res == ctx->ref_resources[i]) {
> +                ctx->used_mask |= 1 << i;
> +                return i;
> +            }
> +        }
> +    } else {
> +        for (i = 0; i < ctx->max_num_ref; i++) {
> +            if (!((ctx->used_mask >> i) & 0x1)) {
> +                ctx->ref_resources[i] = res;
> +                return i;
> +            }
> +        }
> +    }
> +
> +fail:
> +    assert(0);

this should probably be some av_assert*

thx

[...]
-- 
Michael     GnuPG fingerprint: 9FF2128B147EF6730BADF133611EC787040B0FAB

If the United States is serious about tackling the national security threats 
related to an insecure 5G network, it needs to rethink the extent to which it
values corporate profits and government espionage over security.-Bruce Schneier
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 195 bytes
Desc: not available
URL: <https://ffmpeg.org/pipermail/ffmpeg-devel/attachments/20231225/3b3264f6/attachment.sig>


More information about the ffmpeg-devel mailing list