diff mbox series

[FFmpeg-devel,v4,04/11] libavutil/hwcontext_d3d11va: adding the vendor option to D3D11 device creation

Message ID 20200508151821.49051-4-artem.galin@gmail.com
State New
Headers show
Series [FFmpeg-devel,v4,01/11] fftools/qsv: enabling d3d11va/dxva2 device selection
Related show

Checks

Context Check Description
andriy/default pending
andriy/make success Make finished
andriy/make_fate success Make fate finished

Commit Message

Artem Galin May 8, 2020, 3:18 p.m. UTC
From: Artem Galin <artem.galin@intel.com>

Example: --init_hw_device d3d11va:,vendor=0x8086

qsv_device option is still works and has higher priority over vendor
option.

Signed-off-by: Artem Galin <artem.galin@intel.com
---
 libavutil/hwcontext_d3d11va.c | 39 +++++++++++++++++++++++++++++++++--
 1 file changed, 37 insertions(+), 2 deletions(-)
diff mbox series

Patch

diff --git a/libavutil/hwcontext_d3d11va.c b/libavutil/hwcontext_d3d11va.c
index cd80931dd3..2d8406427a 100644
--- a/libavutil/hwcontext_d3d11va.c
+++ b/libavutil/hwcontext_d3d11va.c
@@ -531,9 +531,12 @@  static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
     AVD3D11VADeviceContext *device_hwctx = ctx->hwctx;
 
     HRESULT hr;
+    AVDictionaryEntry *e;
     IDXGIAdapter           *pAdapter = NULL;
     ID3D10Multithread      *pMultithread;
     UINT creationFlags = D3D11_CREATE_DEVICE_VIDEO_SUPPORT;
+    int adapter = -1;
+    long int vendor_id = -1;
     int is_debug       = !!av_dict_get(opts, "debug", NULL, 0);
     int ret;
 
@@ -553,13 +556,45 @@  static int d3d11va_device_create(AVHWDeviceContext *ctx, const char *device,
         return AVERROR_UNKNOWN;
     }
 
+    e = av_dict_get(opts, "vendor", NULL, 0);
+    if (e) {
+        vendor_id = strtol(e->value, NULL, 0);
+    }
+
     if (device) {
+        adapter = atoi(device);
+    }
+
+    if (adapter >= 0 || vendor_id != -1) {
         IDXGIFactory2 *pDXGIFactory;
         hr = mCreateDXGIFactory(&IID_IDXGIFactory2, (void **)&pDXGIFactory);
         if (SUCCEEDED(hr)) {
-            int adapter = atoi(device);
-            if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, &pAdapter)))
+            if (adapter < 0) {
+                int adapter_cnt = 0;
+                while (IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter_cnt++, &pAdapter) != DXGI_ERROR_NOT_FOUND) {
+                    DXGI_ADAPTER_DESC adapter_desc;
+                    hr = IDXGIAdapter2_GetDesc(pAdapter, &adapter_desc);
+                    if (FAILED(hr)) {
+                        av_log(ctx, AV_LOG_ERROR, "IDXGIAdapter2_GetDesc returned error with adapter id %d\n", adapter_cnt);
+                        continue;
+                    }
+
+                    if (adapter_desc.VendorId == vendor_id) {
+                        break;
+                    }
+
+                    if (adapter)
+                        IDXGIAdapter_Release(pAdapter);
+                }
+                if (adapter_cnt < 0) {
+                    av_log(ctx, AV_LOG_ERROR, "Failed to find d3d11va adapter by vendor id %ld\n", vendor_id);
+                    IDXGIFactory2_Release(pDXGIFactory);
+                    return AVERROR_UNKNOWN;
+                }
+            } else {
+                if (FAILED(IDXGIFactory2_EnumAdapters(pDXGIFactory, adapter, &pAdapter)))
                 pAdapter = NULL;
+            }
             IDXGIFactory2_Release(pDXGIFactory);
         }
     }