[vlc-devel] [PATCH] specify direct3d adapter on command line

Rémi Denis-Courmont remi at remlab.net
Tue Jul 30 17:19:37 CEST 2013


Inline... And again, attached patches are a PITA to read and write reviews.

>From 0f5152f0c7e5e7552b770564251ef76ffa575942 Mon Sep 17 00:00:00 2001
From: David Robison <kc7bfi at debian>
Date: Mon, 29 Jul 2013 15:01:48 -0400
Subject: [PATCH] Specify the Direct3d Adapter from the command line

---
 modules/codec/avcodec/dxva2.c       |   12 +++++++-----
 modules/video_output/msw/direct3d.c |   25 +++++++++++++++++++------
 2 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index 490e424..8d348a2 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -297,7 +297,7 @@ static vlc_va_dxva2_t *vlc_va_dxva2_Get(vlc_va_t 
*external)
 }
 
 /* */
-static int D3dCreateDevice(vlc_va_dxva2_t *);
+static int D3dCreateDevice(vlc_va_dxva2_t *, int d3dadapter);
 static void D3dDestroyDevice(vlc_va_dxva2_t *);
 static char *DxDescribe(vlc_va_dxva2_t *);
 
@@ -520,7 +520,9 @@ static int Open(vlc_va_t *external, int codec_id, const 
es_format_t *fmt)
     msg_Dbg(va->log, "DLLs loaded");
 
     /* */
-    if (D3dCreateDevice(va)) {
+    int d3dadapter = var_InheritInteger(external, "direct3d-adapter");
+    msg_Dbg(va->log, "dxva2 using adapter %d", d3dadapter );
+    if (D3dCreateDevice(va, d3dadapter)) {
         msg_Err(va->log, "Failed to create Direct3D device");
         goto error;
     }
@@ -560,7 +562,7 @@ error:
 /**
  * It creates a Direct3D device usable for DXVA 2
  */
-static int D3dCreateDevice(vlc_va_dxva2_t *va)
+static int D3dCreateDevice(vlc_va_dxva2_t *va, int d3dadapter)
 {
     /* */
     LPDIRECT3D9 (WINAPI *Create9)(UINT SDKVersion);
@@ -583,7 +585,7 @@ static int D3dCreateDevice(vlc_va_dxva2_t *va)
     /* */
     D3DADAPTER_IDENTIFIER9 *d3dai = &va->d3dai;
     if (FAILED(IDirect3D9_GetAdapterIdentifier(va->d3dobj,
-                                               D3DADAPTER_DEFAULT, 0, 
d3dai))) {
+                                               d3dadapter, 0, d3dai))) {
         msg_Warn(va->log, "IDirect3D9_GetAdapterIdentifier failed");
         ZeroMemory(d3dai, sizeof(*d3dai));
     }
@@ -607,7 +609,7 @@ static int D3dCreateDevice(vlc_va_dxva2_t *va)
     this HWND is used to alert Direct3D when there's a change of focus 
window.
     For now, use GetDesktopWindow, as it looks harmless */
     LPDIRECT3DDEVICE9 d3ddev;
-    if (FAILED(IDirect3D9_CreateDevice(d3dobj, D3DADAPTER_DEFAULT,
+    if (FAILED(IDirect3D9_CreateDevice(d3dobj, d3dadapter,
                                        D3DDEVTYPE_HAL, GetDesktopWindow(),
                                        D3DCREATE_SOFTWARE_VERTEXPROCESSING |
                                        D3DCREATE_MULTITHREADED,
diff --git a/modules/video_output/msw/direct3d.c 
b/modules/video_output/msw/direct3d.c
index 2d95d95..014a3c4 100644
--- a/modules/video_output/msw/direct3d.c
+++ b/modules/video_output/msw/direct3d.c
@@ -59,6 +59,10 @@ static void Close(vlc_object_t *);
 #define HW_BLENDING_LONGTEXT N_(\
     "Try to use hardware acceleration for subtitle/OSD blending.")
 
+#define HW_D3DADAPTER_TEXT N_("The Direct3D adaptor number")

Drop "The ". Might as well drop "Direct3D " too.

+#define HW_D3DADAPTER_LONGTEXT N_(\
+    "Identifies the Direct3D adaptor to use for hardware acceleration.")
+
 #define D3D_HELP N_("Recommended video output for Windows Vista and later 
versions")
 
 vlc_module_begin ()
@@ -69,6 +73,7 @@ vlc_module_begin ()
     set_subcategory(SUBCAT_VIDEO_VOUT)
 
     add_bool("direct3d-hw-blending", true, HW_BLENDING_TEXT, 
HW_BLENDING_LONGTEXT, true)
+    add_integer("direct3d-adapter", D3DADAPTER_DEFAULT, HW_D3DADAPTER_TEXT, 
HW_D3DADAPTER_LONGTEXT, true)

Probably missing change_integer_range().
 
     set_capability("vout display", 240)
     add_shortcut("direct3d")
@@ -501,7 +506,8 @@ static int Direct3DCreate(vout_display_t *vd)
     ** Get device capabilities
     */
     ZeroMemory(&sys->d3dcaps, sizeof(sys->d3dcaps));
-    HRESULT hr = IDirect3D9_GetDeviceCaps(d3dobj, D3DADAPTER_DEFAULT, 
D3DDEVTYPE_HAL, &sys->d3dcaps);
+    int d3dadapter = var_InheritInteger(vd, "direct3d-adapter");
+    HRESULT hr = IDirect3D9_GetDeviceCaps(d3dobj, d3dadapter, D3DDEVTYPE_HAL, 
&sys->d3dcaps);
     if (FAILED(hr)) {
        msg_Err(vd, "Could not read adapter capabilities. (hr=0x%lX)", hr);
        return VLC_EGENERIC;
@@ -548,8 +554,9 @@ static int 
Direct3DFillPresentationParameters(vout_display_t *vd)
     ** buffer of the same format
     */
     D3DDISPLAYMODE d3ddm;
+    int d3dadapter = var_InheritInteger(vd, "direct3d-adapter");

There is no warranty that the configuration parameter does not change 
asynchronously between invocations. You need to use var_Create/var_Get instead 
of var_Inherit().

     HRESULT hr = IDirect3D9_GetAdapterDisplayMode(sys->d3dobj,
-                                                  D3DADAPTER_DEFAULT, 
&d3ddm);
+                                                  d3dadapter, &d3ddm);
     if (FAILED(hr)) {
        msg_Err(vd, "Could not read adapter display mode. (hr=0x%lX)", hr);
        return VLC_EGENERIC;
@@ -600,8 +607,10 @@ static int Direct3DOpen(vout_display_t *vd, 
video_format_t *fmt)
     // Create the D3DDevice
     LPDIRECT3DDEVICE9 d3ddev;
 
-    UINT AdapterToUse = D3DADAPTER_DEFAULT;
+    int d3dadapter = var_InheritInteger(vd, "direct3d-adapter");
+    UINT AdapterToUse = d3dadapter;
     D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
+    if (d3dadapter == D3DADAPTER_DEFAULT) {
 
 #ifndef NDEBUG
     // Look for 'NVIDIA PerfHUD' adapter
@@ -616,6 +625,7 @@ static int Direct3DOpen(vout_display_t *vd, video_format_t 
*fmt)
         }
     }
 #endif
+    }
 
     /* */
     D3DADAPTER_IDENTIFIER9 d3dai;
@@ -720,10 +730,12 @@ static int Direct3DCreateResources(vout_display_t *vd, 
video_format_t *fmt)
         return VLC_EGENERIC;
     }
     sys->d3dregion_format = D3DFMT_UNKNOWN;
+    int d3dadapter = var_InheritInteger(vd, "direct3d-adapter");
+    msg_Dbg(vd, "Direct3d using adapter %d", d3dadapter );
     for (int i = 0; i < 2; i++) {
         D3DFORMAT fmt = i == 0 ? D3DFMT_A8B8G8R8 : D3DFMT_A8R8G8B8;
         if (SUCCEEDED(IDirect3D9_CheckDeviceFormat(sys->d3dobj,
-                                                   D3DADAPTER_DEFAULT,
+                                                   d3dadapter,
                                                    D3DDEVTYPE_HAL,
                                                    sys-
>d3dpp.BackBufferFormat,
                                                    D3DUSAGE_DYNAMIC,
@@ -755,7 +767,8 @@ static int Direct3DCheckConversion(vout_display_t *vd,
     HRESULT hr;
 
     /* test whether device can create a surface of that format */
-    hr = IDirect3D9_CheckDeviceFormat(d3dobj, D3DADAPTER_DEFAULT,
+    int d3dadapter = var_InheritInteger(vd, "direct3d-adapter");
+    hr = IDirect3D9_CheckDeviceFormat(d3dobj, d3dadapter,
                                       D3DDEVTYPE_HAL, dst, 0,
                                       D3DRTYPE_SURFACE, src);
     if (SUCCEEDED(hr)) {
@@ -763,7 +776,7 @@ static int Direct3DCheckConversion(vout_display_t *vd,
         ** from that format to target format
         */
         hr = IDirect3D9_CheckDeviceFormatConversion(d3dobj,
-                                                    D3DADAPTER_DEFAULT,
+                                                    d3dadapter,
                                                     D3DDEVTYPE_HAL,
                                                     src, dst);
     }
-- 
1.7.10.4




-- 
Rémi Denis-Courmont
http://www.remlab.net/




More information about the vlc-devel mailing list