[PR] avutil/hwcontext_d3d11va: Set BindFlags for AMD GPUs (PR #24046)

softworkz via ffmpeg-devel <[email protected]>
Newsgroups gmane.comp.video.ffmpeg.devel
Message-ID <178613213575.59.17157294641008475976@29965ddac10e>
PR #24046 opened by softworkz
URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24046
Patch URL: https://code.ffmpeg.org/FFmpeg/FFmpeg/pulls/24046.patch

- AMD drivers require the shader_resource flag for all processing and encoding. 
- When bind flags are zero, texture creation fails, so set the most compatible bind_decoder flag which works in all cases.

### Why this is needed (and hasn't before)

It's a prerequisite for upcoming PRs which will enable mapping hw frames

- from D3D11(AMD) to OpenCL(AMD)
- from OpenCL(AMD) back to D3D11(AMD)
- from AMF to D3D11
- from D3D11 to AMF




>From ec6aa7e356f93ad03d8cefcfe275b582df1477d8 Mon Sep 17 00:00:00 2001
From: softworkz <[email protected]>
Date: Wed, 29 Jul 2026 04:19:24 +0200
Subject: [PATCH] avutil/hwcontext_d3d11va: Set BindFlags for AMD GPUs

AMD drivers require the shader_resource flag for all processing and
encoding. When bind flags are zero, texture creation fails, so set
the most compatible bind_decoder flag which works in all cases.

Signed-off-by: softworkz <[email protected]>
---
 libavutil/hwcontext_d3d11va.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index 834c2ce3dd..faa9ce52c9 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -116,6 +116,31 @@ static const struct {
     { DXGI_FORMAT_420_OPAQUE,   AV_PIX_FMT_YUV420P },
 };
 
+static int d3d11va_is_amd(const AVD3D11VADeviceContext *device_hwctx)
+{
+    IDXGIDevice *dxgi_device = NULL;
+    IDXGIAdapter *adapter = NULL;
+    DXGI_ADAPTER_DESC desc;
+    HRESULT hr;
+    int is_amd = 0;
+
+    hr = ID3D11Device_QueryInterface(device_hwctx->device, &IID_IDXGIDevice, (void **)&dxgi_device);
+    if (FAILED(hr))
+        return 0;
+
+    hr = IDXGIDevice_GetAdapter(dxgi_device, &adapter);
+    if (SUCCEEDED(hr)) {
+        hr = IDXGIAdapter_GetDesc(adapter, &desc);
+        if (SUCCEEDED(hr))
+            is_amd = desc.VendorId == 0x1002; // AMD
+        IDXGIAdapter_Release(adapter);
+    }
+
+    IDXGIDevice_Release(dxgi_device);
+
+    return is_amd;
+}
+
 static void d3d11va_default_lock(void *ctx)
 {
     WaitForSingleObjectEx(ctx, INFINITE, FALSE);
@@ -294,6 +319,14 @@ static int d3d11va_frames_init(AVHWFramesContext *ctx)
     hwctx->BindFlags |= device_hwctx->BindFlags;
     hwctx->MiscFlags |= device_hwctx->MiscFlags;
 
+    // AMD drivers require the shader_resource flag for all processing and encoding and 
+    // texture creation fails when BindFlags is zero
+    if (d3d11va_is_amd(device_hwctx)) {
+        if (hwctx->BindFlags == 0)
+            hwctx->BindFlags = D3D11_BIND_DECODER;
+        hwctx->BindFlags  |= D3D11_BIND_SHADER_RESOURCE;
+    }
+
     ctx->initial_pool_size = FFMIN(ctx->initial_pool_size, MAX_ARRAY_SIZE);
 
     texDesc = (D3D11_TEXTURE2D_DESC){
-- 
2.52.0

_______________________________________________
ffmpeg-devel mailing list -- [email protected]
To unsubscribe send an email to [email protected]
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.