From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTPS id A53D44C9FB for ; Mon, 10 Feb 2025 15:18:34 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 9C3BB68BD36; Mon, 10 Feb 2025 17:18:30 +0200 (EET) Received: from AUS01-SY4-obe.outbound.protection.outlook.com (mail-sy4aus01olkn2017.outbound.protection.outlook.com [40.92.62.17]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 18F9E68B93D for ; Mon, 10 Feb 2025 17:18:23 +0200 (EET) ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=CVB3ttwFwLcCU5NEjz+RAYGQ9MzbNei5PnEqrnTWQgie+1fcbLGTjiEFivltQz6k2a1LRdjZZ45vrudHDNRHU8Rkxw1VoZ7f8ZKwBDOHmmwjqDGdkrpVxB9Fqlib0J9bnKsbHUNO2g8Pxo5iRrOaNhQg48YwrtFZT0S2RN3DcOieLZocFCViP4mipRKu1TjWmiuUG4C3z36u7WnVrEnOrEYnMJApXFMjtKjm3NuY82fEXVmEW+S1DyyW9D+OfbdWGjroxnLwS8LYm2E2GBeJfztL2LuhoLBr5fIn5N4l/56lYVwyY5g8ZrJjJd7JY31WYMwjKw20HjIjRAsW5BN6jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Q5LZaNACPDslGLJMwIswnO+c3CZNWKSpw/bUFEpJpuU=; b=oRKnplhjs09Y7qinASzIorJbFSKB8x/P+nNHzvlAT37gR1+8Ewgrn+Avy0Bgxzq23Qs1jRsMomprwxVSxVAfasdDSE75mAFBQ3AXfDXjEUSfqO2r6yu5yHO6DFeEACeGEsYWiic6oGmrPVsIIeNXnS3xe/VBei44ew9Wv6S23nq9yyH17SKOuYlBsRotLXFoS5WWQlZ6g47Bvvw70taKXUnTxBGE7J2OZ6lJpZ8frxWTjreK1s9vZ3rUGrQu/1/PIRq36yVb1zZxbIyvr384iNZgdeJW2l1YsNQ4sk36zLKx41+f/sPQcyjkY5rx9ql43c+K+gPWtndHNZElBjH3jQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=outlook.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Q5LZaNACPDslGLJMwIswnO+c3CZNWKSpw/bUFEpJpuU=; b=EcxDtcq1EYHZhSx9bbz4BJ3Rcr+RWmXHn6AVtD+d4RCqSGrRR0mZWqtDhgNoRC6RA2PYd6zvuz7fCQc9C79AoDf4kKpm7b58nd0forJigS+ep50NmFpeP+g6uPtXoNaVq7khVaTo685CPCo0SVy0HwQrz7YIsWi/j0utyf0FS3bAMTkMXBnsFg/jwgXBz2vHmOxA4+wYPwLPbPMdhYd908eyA9Jsn9vcQrPucivTc/50VcLlIA1i2bMWbJ2ssVGLOj8f6Q0O7I3olAKzDaUr9w0tFBVHymDGBo1VoGpEJwoICTtcRCZrtlsDT7wkawWdEGTcGy/o0BV/1bgKNoAvAA== Received: from SY7P300MB0845.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:288::12) by SY7P300MB0291.AUSP300.PROD.OUTLOOK.COM (2603:10c6:10:239::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8422.18; Mon, 10 Feb 2025 15:18:18 +0000 Received: from SY7P300MB0845.AUSP300.PROD.OUTLOOK.COM ([fe80::eaec:d3ce:9584:3e10]) by SY7P300MB0845.AUSP300.PROD.OUTLOOK.COM ([fe80::eaec:d3ce:9584:3e10%2]) with mapi id 15.20.8422.015; Mon, 10 Feb 2025 15:18:18 +0000 From: Tong Wu To: FFmpeg development discussions and patches Thread-Topic: [FFmpeg-devel] [PATCH] avcodec/amfenc: DX12 Reference-only feature support Thread-Index: AQHbcyCogf9DhsMUC029AgZd9DSE3LNAtm1Q Date: Mon, 10 Feb 2025 15:18:18 +0000 Message-ID: References: <20250130140934.1800-1-Primeadvice@gmail.com> In-Reply-To: <20250130140934.1800-1-Primeadvice@gmail.com> Accept-Language: en-US, zh-CN Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-ms-exchange-messagesentrepresentingtype: 1 x-ms-publictraffictype: Email x-ms-traffictypediagnostic: SY7P300MB0845:EE_|SY7P300MB0291:EE_ x-ms-office365-filtering-correlation-id: a9a9d7b1-1482-47f4-b4c9-08dd49e625f0 x-microsoft-antispam: BCL:0; ARA:14566002|19110799003|8060799006|7092599003|461199028|15080799006|8062599003|3412199025|440099028|10035399004|41001999003|102099032|56899033; x-microsoft-antispam-message-info: =?us-ascii?Q?iC5hatK5UkTf2mNdGGiOssbFj57mYQcpvmMOTQL46Ji6I1o/ewk7bBdA2NKN?= =?us-ascii?Q?E/dR3R5kD6rrgDr3a0XblLs47ofHkJt2ByZkIcwZLntGZr3aAPdQINlU3QoQ?= =?us-ascii?Q?tsGLWi+ks4SXmGclQqCaEF+8ynf9KqGutXrDMtaCxate29wnE7yit6EmXwe5?= =?us-ascii?Q?bOg/xPbwXaVvGQ41Q7vpGu5wavSi5MqCCX8SiT3cUqUIemZafOSzkDX2KQNz?= =?us-ascii?Q?tqa4GeUDWa9dXc1OAyAUQs99kdjL3pH4+rhsGurcORaAwqv2S/21DI7TPO6D?= =?us-ascii?Q?kxdeXDNG2uxHjww5F3CstgW5Ail/QUh1Lc7O7VH+g36kVp21jUPyEISpEaTC?= =?us-ascii?Q?QUVWr9fWNxR+F58X0fjxxTQ9NmI7aGmkQw9g76L24JkniUVFFY0Tt/DNa3MO?= =?us-ascii?Q?IiCNLnBOfgqf6cEAZy7yY2dZMaZNj4gD+fD6GctOpmVdX2twOm7G4rW+Vb+t?= =?us-ascii?Q?feZNNPgfrOZR5tKBvvXIkAte8Ts91N0KQPn5dtT3DM1WoNZjUdzNBRCFQV0s?= =?us-ascii?Q?o+MwOylx1IjCjd7+oGNq6Zp7gvlfXu9gwpNII8iFUM+9drGi59lL7Um6/dit?= =?us-ascii?Q?rFAHaVdLUxRbzOSILFJWRE7QesZ4g8Ma/g2cl2cUAkAQq8K/i+13Jvd48ULj?= =?us-ascii?Q?Tz4KGUXhMrbCpil9zCcFsZOXOBwvGx3rrwhOXa8X99Twp52jNP2EL8hYu01T?= =?us-ascii?Q?52Ob4tY0jZRg9dZhmXv1FknyZX+7HKJrVDjg7qXOZsV2WGmEc7yVflCdcDsv?= =?us-ascii?Q?i7jZhs3RxAllcBiLJTPTBddWVq3kV4Tvz4ylzRzTVkvcvpUzavt3P4/3wnjP?= =?us-ascii?Q?Ml0O3xfSCXf3mS7443nClPiZMFXbHfVDIs5w0PXcWtiBGMyn/0VqwTuImV+N?= =?us-ascii?Q?TY30le5+36Y6XH1ZV79FDnWxjSCCQBp19Ee0Mx7KbLPeukSAtkXAO2Hmki8d?= =?us-ascii?Q?RPNrnZLUx7tfQbzoWC01vcUBg5tDARlRz9vY8K7VexZV5BNzkFL4WBL0l2Rn?= =?us-ascii?Q?A5CQwnNA1gttjaG5QhoxH4IuzEgV5VcpnAOMK9YPO5o0gTl22T7NtG5f+TJK?= =?us-ascii?Q?sige6+R6c2WGY3trP47sGT32vszkUXUQ3hNkSi/o97+vQ6mSJmZK4VcMVuqZ?= =?us-ascii?Q?w5PpJs3DCRx6Po8/ZRGNdc/4APB5UK7bO2eCoPc7x+faZ0hoDtK0YXQ=3D?= x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?us-ascii?Q?JFXU/cHh8NKmEjWbTdsFW57sd8nbPUJ3Km/qdQK8j0PMG9oQlHcQJC3nCV67?= =?us-ascii?Q?f9eVN3R8G7RpCYFhxPqVbNiZ+x/EkBrnTl5cpoPM35ljXyKDVHkekTgGndUo?= =?us-ascii?Q?7s9sYgArFn7QkjwWINdB0EBAK2+XdFnG9O0Fn/knvaVAscz+wNg9HJ/eCbs9?= =?us-ascii?Q?4fwhcAOpVepo6VbS4eaJogYA2tM5cW3TIXIj3i9AyvbZwx2TyS7+IrA8wqow?= =?us-ascii?Q?N1hI0beRg05Og9vGUZnzMyINA5k9crs5vgHCupcgst0RQoklRgPsk9Vu1yb2?= =?us-ascii?Q?PlEjo8xM5tbvaXsbyMqWfFlTdEwLBUa9NPfuiKnO+HRpOCby6vCUAmAQAX6u?= =?us-ascii?Q?cdatYh8togGi2BwnVr4VJHFfkaEdFxazhUBfAXyTL1r0P7VStPHQGGvTprNp?= =?us-ascii?Q?IBLob7ajOyFK+yxQa1QwvJCHL08dbTzoDHc8qpmyxYIP/ySfia/t8ZL77NKl?= =?us-ascii?Q?/8Z511AUdxB11LxG6hrmR301U4R1W7rI4Al5cvYoxVDcDEmjyuii9o1bV/Mk?= =?us-ascii?Q?MNRITjtBMozTjt4oQJomn8wYzLX+8U4d9TH57nP3tAO3+b6bc4LquTeHtQfx?= =?us-ascii?Q?zbpz1xK95lMqE9xs68AhUyluiiFiBln4vFo5okumdqdcgSmm8KeaMZlLhOb5?= =?us-ascii?Q?YPmSlZm+pYW4x5o+yQHOtYlscsFaLmXTjJxbo/XPdfUdQEezfsQOGzPg5rs5?= =?us-ascii?Q?FsTOEfaFZRUvw7QAFS1oUfi4thqCIXj2PIjzPwRIpZ5viJ72QS2yHiZIKhlU?= =?us-ascii?Q?sLGtiZb5+kvqaAsrTmNsZzBe31lxyCJiJdR6qic1azLMmCv4TGJbDqkloDNq?= =?us-ascii?Q?ke64F6UrBDQatKQyRnC6J4XqpNsH+NDu0/ZnS6j9yJbkEuNVS0xQ0qnDrhvS?= =?us-ascii?Q?v1fZ3WyFI4z5nsz6yhptJbxpYqygdyFVnwlEfGloj5278tUOMDo5oeCX6esX?= =?us-ascii?Q?28AHBTVZYKIzY6PRr/K9+lOPXPRiL4Eo5mF0vJbO8ig1ZTTA9E3P2PsG27+t?= =?us-ascii?Q?E6nZvlBYeycocokqOYbhhzBPUPaYszpLfcha/KNBlv/7EYI+0iVtwobQFI9A?= =?us-ascii?Q?lmEwKUpO7yd4FQhxRDXJLZIoK7G/LF5MU1U5mHcW5+B+WbfMBWgW6ffGdKGn?= =?us-ascii?Q?nT5+HmgL7EHdqDo2Y9zJPD9xPii5NjXXATKgruxzTg4opdW0ZwuAKqaNHVfx?= =?us-ascii?Q?F5+neDXqTXAZK8UCGKuDHpJZyifNesgBIDQ2attzoBw2Qlxs/wwFYyJ6zs0?= =?us-ascii?Q?=3D?= MIME-Version: 1.0 X-OriginatorOrg: outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: SY7P300MB0845.AUSP300.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: a9a9d7b1-1482-47f4-b4c9-08dd49e625f0 X-MS-Exchange-CrossTenant-originalarrivaltime: 10 Feb 2025 15:18:18.4106 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: SY7P300MB0291 Subject: Re: [FFmpeg-devel] [PATCH] avcodec/amfenc: DX12 Reference-only feature support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Araz Iusubov Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: Araz Iusubov: >Subject: [FFmpeg-devel] [PATCH] avcodec/amfenc: DX12 Reference-only feature >support > >The Reference-Only feature in DirectX 12 is a memory optimization technique >designed for video decoding scenarios. >This feature requires that reference resources must be allocated with the >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY resource flag. >Reference textures must also be separated from output textures. >This feature is not supported in the current version of ffmpeg. >Since AMD GPU uses this feature in Direct 12 decoder, ffmpeg does not support >AMD GPU Direct 12 decoding. >To properly support the Reference-Only feature, two parallel resource pools must >be configured and managed: >General Resource Pool: >Contains resources used for output decoded frames. >Defined in AVHWFramesContext and manages the final decoded textures. >Reference-Only Resource Pool: >Intended for storing reference frame resources. >Resources created with the >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY flag are allocated >to AVBufferPool. > >--- > libavcodec/d3d12va_decode.c | 58 ++++++++++++++++++++++++++++--- > libavutil/hwcontext_d3d12va.c | 65 ++++++++++++++++++++++++++++++++--- > 2 files changed, 115 insertions(+), 8 deletions(-) > >diff --git a/libavcodec/d3d12va_decode.c b/libavcodec/d3d12va_decode.c index >3b8978635e..8916f94d10 100644 >--- a/libavcodec/d3d12va_decode.c >+++ b/libavcodec/d3d12va_decode.c >@@ -51,11 +51,19 @@ unsigned ff_d3d12va_get_surface_index(const >AVCodecContext *avctx, > D3D12VADecodeContext *ctx, const AVFrame *frame, > int curr) { >+ AVHWFramesContext *frames_ctx = D3D12VA_FRAMES_CONTEXT(avctx); >+ AVD3D12VAFramesContext *frames_hwctx = frames_ctx->hwctx; >+ > AVD3D12VAFrame *f; > ID3D12Resource *res; > unsigned i; > >- f = (AVD3D12VAFrame *)frame->data[0]; >+ if (frames_hwctx->flags & >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY) { >+ f = (AVD3D12VAFrame*)frame->data[1]; >+ } else { >+ f = (AVD3D12VAFrame*)frame->data[0]; >+ } >+ > if (!f) > goto fail; > >@@ -250,6 +258,11 @@ static int d3d12va_create_decoder(AVCodecContext >*avctx) > return AVERROR_PATCHWELCOME; > } Need to handle when DecodeTier == D3D12_VIDEO_DECODE_TIER_2? > >+ if (feature.ConfigurationFlags & >D3D12_VIDEO_DECODE_CONFIGURATION_FLAG_REFERENCE_ONLY_ALLOCATI >ONS_REQUIRED) { >+ frames_hwctx->flags |= >(D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY | >D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE); >+ av_log(avctx, AV_LOG_INFO, "Reference-Only Allocations are required for >this configuration.\n"); >+ } >+ > desc = (D3D12_VIDEO_DECODER_DESC) { > .NodeMask = 0, > .Configuration = ctx->cfg, >@@ -440,8 +453,19 @@ int ff_d3d12va_common_end_frame(AVCodecContext >*avctx, AVFrame *frame, > D3D12VADecodeContext *ctx = D3D12VA_DECODE_CONTEXT(avctx); > ID3D12Resource *buffer = NULL; > ID3D12CommandAllocator *command_allocator = NULL; >- AVD3D12VAFrame *f = (AVD3D12VAFrame *)frame->data[0]; >- ID3D12Resource *resource = (ID3D12Resource *)f->texture; >+ AVHWFramesContext *frames_ctx = >D3D12VA_FRAMES_CONTEXT(avctx); >+ AVD3D12VAFramesContext *frames_hwctx = frames_ctx->hwctx; >+ AVD3D12VAFrame *f = NULL; >+ AVD3D12VAFrame *output_data = NULL; >+ >+ if (frames_hwctx->flags & >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY) { >+ f = (AVD3D12VAFrame*)frame->data[1]; >+ output_data = (AVD3D12VAFrame*)frame->data[0]; >+ } else { >+ f = (AVD3D12VAFrame*)frame->data[0]; >+ } >+ >+ ID3D12Resource* resource = (ID3D12Resource*)f->texture; > > ID3D12VideoDecodeCommandList *cmd_list = ctx->command_list; > D3D12_RESOURCE_BARRIER barriers[32] = { 0 }; @@ -469,6 +493,14 @@ int >ff_d3d12va_common_end_frame(AVCodecContext *avctx, AVFrame *frame, > .pOutputTexture2D = resource, > }; > >+ if (frames_hwctx->flags & >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY) { >+ output_args.pOutputTexture2D = output_data->texture; >+ >+ output_args.ConversionArguments.Enable = 1; >+ output_args.ConversionArguments.pReferenceTexture2D = resource; >+ output_args.ConversionArguments.ReferenceSubresource = 0; >+ } >+ > UINT num_barrier = 1; > barriers[0] = (D3D12_RESOURCE_BARRIER) { > .Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, >@@ -481,6 +513,20 @@ int ff_d3d12va_common_end_frame(AVCodecContext >*avctx, AVFrame *frame, > }, > }; > >+ if (frames_hwctx->flags & >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY) { >+ barriers[1] = (D3D12_RESOURCE_BARRIER) { >+ .Type = D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, >+ .Flags = D3D12_RESOURCE_BARRIER_FLAG_NONE, >+ .Transition = { >+ .pResource = output_data->texture, >+ .Subresource = D3D12_RESOURCE_BARRIER_ALL_SUBRESOURCES, >+ .StateBefore = D3D12_RESOURCE_STATE_COMMON, >+ .StateAfter = D3D12_RESOURCE_STATE_VIDEO_DECODE_WRITE, >+ }, >+ }; >+ num_barrier++; >+ } >+ > memset(ctx->ref_subresources, 0, sizeof(UINT) * ctx->max_num_ref); > input_args.ReferenceFrames.NumTexture2Ds = ctx->max_num_ref; > input_args.ReferenceFrames.ppTexture2Ds = ctx->ref_resources; @@ -505,7 >+551,7 @@ int ff_d3d12va_common_end_frame(AVCodecContext *avctx, >AVFrame *frame, > > DX_CHECK(ID3D12VideoDecodeCommandList_Reset(cmd_list, >command_allocator)); > >- num_barrier += d3d12va_update_reference_frames_state(avctx, &barriers[1], >resource, D3D12_RESOURCE_STATE_COMMON, >D3D12_RESOURCE_STATE_VIDEO_DECODE_READ); >+ num_barrier += d3d12va_update_reference_frames_state(avctx, >+ &barriers[num_barrier], resource, D3D12_RESOURCE_STATE_COMMON, >+ D3D12_RESOURCE_STATE_VIDEO_DECODE_READ); > > ID3D12VideoDecodeCommandList_ResourceBarrier(cmd_list, num_barrier, >barriers); > >@@ -522,6 +568,10 @@ int ff_d3d12va_common_end_frame(AVCodecContext >*avctx, AVFrame *frame, > > DX_CHECK(ID3D12CommandQueue_Signal(ctx->command_queue, f- >>sync_ctx.fence, ++f->sync_ctx.fence_value)); > >+ if (frames_hwctx->flags & >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY) { >+ DX_CHECK(ID3D12CommandQueue_Signal(ctx->command_queue, >output_data->sync_ctx.fence, ++output_data->sync_ctx.fence_value)); >+ } >+ > DX_CHECK(ID3D12CommandQueue_Signal(ctx->command_queue, ctx- >>sync_ctx.fence, ++ctx->sync_ctx.fence_value)); > > ret = d3d12va_discard_helper_objects(avctx, command_allocator, buffer, ctx- >>sync_ctx.fence_value); diff --git a/libavutil/hwcontext_d3d12va.c >b/libavutil/hwcontext_d3d12va.c index 6507cf69c1..328827b040 100644 >--- a/libavutil/hwcontext_d3d12va.c >+++ b/libavutil/hwcontext_d3d12va.c >@@ -49,6 +49,24 @@ typedef struct D3D12VAFramesContext { > ID3D12GraphicsCommandList *command_list; > AVD3D12VASyncContext sync_ctx; > UINT luma_component_size; >+ >+ /** >+ * The Reference-Only feature in DirectX 12 is a memory optimization >+ * technique designed for video decoding/encoding scenarios. >+ * This feature requires that reference resources must be allocated >+ * with the `D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY` >resource flag. >+ * Reference textures must also be separated from output textures. >+ * To correctly support the Reference-Only feature, two parallel resource >+ * pools must be configured and managed: >+ * 1. General Resource Pool: >+ * - Contains resources used for outputting decoded frames. >+ * - Defined in `AVHWFramesContext` and manages the final decoded >textures. >+ * 2. Reference-Only Resource Pool: >+ * - Dedicated to storing reference frame resources. >+ * - Resources created with the >`D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY` >+ * flag are allocated to this pool. >+ */ >+ AVBufferPool *pool_reference_only; > } D3D12VAFramesContext; > > typedef struct D3D12VADevicePriv { >@@ -174,7 +192,8 @@ fail: > > static void d3d12va_frames_uninit(AVHWFramesContext *ctx) { >- D3D12VAFramesContext *s = ctx->hwctx; >+ D3D12VAFramesContext *s = ctx->hwctx; >+ AVD3D12VAFramesContext *frames_hwctx = &s->p; > > D3D12_OBJECT_RELEASE(s->sync_ctx.fence); > if (s->sync_ctx.event) >@@ -185,6 +204,11 @@ static void d3d12va_frames_uninit(AVHWFramesContext >*ctx) > D3D12_OBJECT_RELEASE(s->command_allocator); > D3D12_OBJECT_RELEASE(s->command_list); > D3D12_OBJECT_RELEASE(s->command_queue); >+ >+ if (frames_hwctx->flags & >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY) { >+ if (s->pool_reference_only) >+ av_buffer_pool_uninit(&s->pool_reference_only); >+ } > } > > static int d3d12va_frames_get_constraints(AVHWDeviceContext *ctx, const void >*hwconfig, AVHWFramesConstraints *constraints) @@ -281,6 +305,7 @@ fail: > static int d3d12va_frames_init(AVHWFramesContext *ctx) { > AVD3D12VAFramesContext *hwctx = ctx->hwctx; >+ D3D12VAFramesContext *s = ctx->hwctx; > int i; > > for (i = 0; i < FF_ARRAY_ELEMS(supported_formats); i++) { @@ -304,16 +329,43 >@@ static int d3d12va_frames_init(AVHWFramesContext *ctx) > if (!ffhwframesctx(ctx)->pool_internal) > return AVERROR(ENOMEM); > >+ s->pool_reference_only = NULL; >+ > return 0; > } > > static int d3d12va_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) { > int ret; >+ D3D12VAFramesContext *s = ctx->hwctx; >+ AVD3D12VAFramesContext *frames_hwctx = &s->p; > >- frame->buf[0] = av_buffer_pool_get(ctx->pool); >- if (!frame->buf[0]) >- return AVERROR(ENOMEM); >+ if (frames_hwctx->flags & >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY) { >+ /* >+ * for the output texture, temporarily unset >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY >+ * and D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE >+ */ >+ D3D12_RESOURCE_FLAGS temp_flags = frames_hwctx->flags; >+ frames_hwctx->flags &= >+ ~(D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY | >+ D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE); >+ >+ frame->buf[0] = av_buffer_pool_get(ctx->pool); >+ if (!frame->buf[0]) >+ return AVERROR(ENOMEM); >+ >+ if (s->pool_reference_only == NULL) { >+ s->pool_reference_only = av_buffer_pool_init2(sizeof(AVD3D12VAFrame), >+ ctx, d3d12va_pool_alloc, NULL); >+ } >+ >+ frames_hwctx->flags = temp_flags; >+ frame->buf[1] = av_buffer_pool_get(s->pool_reference_only); >+ if (!frame->buf[1]) >+ return AVERROR(ENOMEM); >+ } else { >+ frame->buf[0] = av_buffer_pool_get(ctx->pool); >+ if (!frame->buf[0]) >+ return AVERROR(ENOMEM); >+ } > > ret = av_image_fill_arrays(frame->data, frame->linesize, NULL, > ctx->sw_format, ctx->width, ctx->height, @@ -322,6 +374,11 >@@ static int d3d12va_get_buffer(AVHWFramesContext *ctx, AVFrame *frame) > return ret; > > frame->data[0] = frame->buf[0]->data; >+ >+ if (frames_hwctx->flags & >D3D12_RESOURCE_FLAG_VIDEO_DECODE_REFERENCE_ONLY) { >+ frame->data[1] = frame->buf[1]->data; >+ } >+ > frame->format = AV_PIX_FMT_D3D12; > frame->width = ctx->width; > frame->height = ctx->height; >-- >2.45.2.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". _______________________________________________ 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".