Git Inbox Mirror of the ffmpeg-devel mailing list - see https://ffmpeg.org/mailman/listinfo/ffmpeg-devel
 help / color / mirror / Atom feed
From: Timo Rothenpieler via ffmpeg-devel <ffmpeg-devel@ffmpeg.org>
To: ffmpeg-devel@ffmpeg.org
Cc: Timo Rothenpieler <code@ffmpeg.org>
Subject: [FFmpeg-devel] [PATCH] avutil/hwcontext_d3d11va: remove D3D11_BIND_RENDER_TARGET restriction for array textures (PR #20480)
Date: Tue, 09 Sep 2025 19:53:30 -0000
Message-ID: <175744761102.25.15729934998483635433@463a07221176> (raw)

PR #20480 opened by Timo Rothenpieler (BtbN)
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20480
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/20480.patch

This was added in 4f78711f9c, with the
commit message claiming that it's a Microsoft restriction that array
textures with ArraySize > 2 cannot be created with
D3D11_BIND_RENDER_TARGET.

I was unable to find any documentation or other references on that, and
a quick test also found it to not be the case. So this patch removes
that restriction.

This enables frame sources, like the d3d11 capture filters, to output
frames in an array texture, which is neccesary to pass those frames as
input to some hardware encoders.


>From a3db834b9b029adb04eb0d2625b7bfd1995692f5 Mon Sep 17 00:00:00 2001
From: Timo Rothenpieler <timo@rothenpieler.org>
Date: Tue, 9 Sep 2025 20:08:22 +0200
Subject: [PATCH 1/2] avfilter/vsrc_ddagrab: support rendering mouse cursor
 onto array textures

---
 libavfilter/vsrc_ddagrab.c | 19 +++++++++++++++----
 1 file changed, 15 insertions(+), 4 deletions(-)

diff --git a/libavfilter/vsrc_ddagrab.c b/libavfilter/vsrc_ddagrab.c
index 6533e2b66e..e035ac9bc4 100644
--- a/libavfilter/vsrc_ddagrab.c
+++ b/libavfilter/vsrc_ddagrab.c
@@ -818,6 +818,8 @@ static av_cold int init_hwframes_ctx(AVFilterContext *avctx)
     dda->frames_ctx->format    = AV_PIX_FMT_D3D11;
     dda->frames_ctx->width     = dda->width;
     dda->frames_ctx->height    = dda->height;
+    if (avctx->extra_hw_frames > 0)
+        dda->frames_ctx->initial_pool_size = 8 + avctx->extra_hw_frames;
 
     switch (dda->raw_format) {
     case DXGI_FORMAT_B8G8R8A8_UNORM:
@@ -936,7 +938,7 @@ static int draw_mouse_pointer(AVFilterContext *avctx, AVFrame *frame)
     D3D11_RENDER_TARGET_VIEW_DESC target_desc = { 0 };
     ID3D11RenderTargetView* target_view = NULL;
     ID3D11Buffer *mouse_vertex_buffer = NULL;
-    D3D11_TEXTURE2D_DESC tex_desc;
+    D3D11_TEXTURE2D_DESC tex_desc, frame_desc;
     int num_vertices = 0;
     int x, y;
     HRESULT hr;
@@ -946,6 +948,7 @@ static int draw_mouse_pointer(AVFilterContext *avctx, AVFrame *frame)
         return 0;
 
     ID3D11Texture2D_GetDesc(dda->mouse_texture, &tex_desc);
+    ID3D11Texture2D_GetDesc(frame_tex, &frame_desc);
 
     x = dda->mouse_x - dda->offset_x;
     y = dda->mouse_y - dda->offset_y;
@@ -954,9 +957,17 @@ static int draw_mouse_pointer(AVFilterContext *avctx, AVFrame *frame)
         -x >= (int)tex_desc.Width || -y >= (int)tex_desc.Height)
         return 0;
 
-    target_desc.Format = dda->raw_format;
-    target_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
-    target_desc.Texture2D.MipSlice = 0;
+    target_desc.Format = frame_desc.Format;
+
+    if (frame_desc.ArraySize > 1) {
+        target_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2DARRAY;
+        target_desc.Texture2DArray.ArraySize = 1;
+        target_desc.Texture2DArray.FirstArraySlice = (uintptr_t)frame->data[1];
+        target_desc.Texture2DArray.MipSlice = 0;
+    } else {
+        target_desc.ViewDimension = D3D11_RTV_DIMENSION_TEXTURE2D;
+        target_desc.Texture2D.MipSlice = 0;
+    }
 
     hr = ID3D11Device_CreateRenderTargetView(dda->device_hwctx->device,
         (ID3D11Resource*)frame_tex,
-- 
2.49.1


>From 684127be1e06676290b8d15358ef202cc3947d75 Mon Sep 17 00:00:00 2001
From: Timo Rothenpieler <timo@rothenpieler.org>
Date: Tue, 9 Sep 2025 21:46:25 +0200
Subject: [PATCH 2/2] avutil/hwcontext_d3d11va: remove D3D11_BIND_RENDER_TARGET
 restriction for array textures

This was added in 4f78711f9c28b11dae4e4b96be46b6b4925eb8c6, with the
commit message claiming that it's a Microsoft restriction that array
textures with ArraySize > 2 cannot be created with
D3D11_BIND_RENDER_TARGET.

I was unable to find any documentation or other references on that, and
a quick test also found it to not be the case. So this patch removes
that restriction.

This enables frame sources, like the d3d11 capture filters, to output
frames in an array texture, which is neccesary to pass those frames as
input to some hardware encoders.
---
 libavutil/hwcontext_d3d11va.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index 9831f530c1..83414ad0d4 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -318,7 +318,7 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx)
         ctx->initial_pool_size = texDesc2.ArraySize;
         hwctx->BindFlags = texDesc2.BindFlags;
         hwctx->MiscFlags = texDesc2.MiscFlags;
-    } else if (!(texDesc.BindFlags & D3D11_BIND_RENDER_TARGET) && texDesc.ArraySize > 0) {
+    } else if (texDesc.ArraySize > 0) {
         hr = ID3D11Device_CreateTexture2D(device_hwctx->device, &texDesc, NULL, &hwctx->texture);
         if (FAILED(hr)) {
             av_log(ctx, AV_LOG_ERROR, "Could not create the texture (%lx)\n", (long)hr);
-- 
2.49.1

_______________________________________________
ffmpeg-devel mailing list -- ffmpeg-devel@ffmpeg.org
To unsubscribe send an email to ffmpeg-devel-leave@ffmpeg.org

                 reply	other threads:[~2025-09-09 19:53 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=175744761102.25.15729934998483635433@463a07221176 \
    --to=ffmpeg-devel@ffmpeg.org \
    --cc=code@ffmpeg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

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