[vlc-commits] d3d9: allow setting the Direct3D9 adapter to use

Steve Lhomme git at videolan.org
Tue Jul 2 09:46:07 CEST 2019


vlc | branch: master | Steve Lhomme <robux4 at ycbcr.xyz> | Tue Jul  2 09:41:28 2019 +0200| [41d7a66a4d12b6736e3c5db66ba5403a6a7384f8] | committer: Steve Lhomme

d3d9: allow setting the Direct3D9 adapter to use

By default use the NVIDIA PerfHUD in debug mode as before.

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=41d7a66a4d12b6736e3c5db66ba5403a6a7384f8
---

 modules/codec/avcodec/dxva2.c          |  2 +-
 modules/video_chroma/d3d9_fmt.c        | 30 ++++++++++++++++--------------
 modules/video_chroma/d3d9_fmt.h        |  4 ++--
 modules/video_output/win32/direct3d9.c | 11 +++++------
 4 files changed, 24 insertions(+), 23 deletions(-)

diff --git a/modules/codec/avcodec/dxva2.c b/modules/codec/avcodec/dxva2.c
index a3cde68f88..6ee8888131 100644
--- a/modules/codec/avcodec/dxva2.c
+++ b/modules/codec/avcodec/dxva2.c
@@ -359,7 +359,7 @@ static int D3dCreateDevice(vlc_va_t *va)
         return VLC_SUCCESS;
     }
 
-    HRESULT hr = D3D9_CreateDevice(va, &sys->hd3d, NULL, &sys->d3d_dev);
+    HRESULT hr = D3D9_CreateDevice(va, &sys->hd3d, -1, NULL, &sys->d3d_dev);
     if (FAILED(hr))
     {
         msg_Err(va, "IDirect3D9_CreateDevice failed");
diff --git a/modules/video_chroma/d3d9_fmt.c b/modules/video_chroma/d3d9_fmt.c
index 5c30af2f96..ec23efd565 100644
--- a/modules/video_chroma/d3d9_fmt.c
+++ b/modules/video_chroma/d3d9_fmt.c
@@ -31,28 +31,30 @@ typedef picture_sys_d3d9_t VA_PICSYS;
 #include "../codec/avcodec/va_surface.h"
 
 #undef D3D9_CreateDevice
-HRESULT D3D9_CreateDevice(vlc_object_t *o, d3d9_handle_t *hd3d, HWND hwnd,
+HRESULT D3D9_CreateDevice(vlc_object_t *o, d3d9_handle_t *hd3d, int AdapterToUse, HWND hwnd,
                           d3d9_device_t *out)
 {
     HRESULT hr;
-
-    UINT AdapterToUse = D3DADAPTER_DEFAULT;
     D3DDEVTYPE DeviceType = D3DDEVTYPE_HAL;
 
+    if (AdapterToUse == -1)
+    {
+        AdapterToUse = D3DADAPTER_DEFAULT;
 #ifndef NDEBUG
-    // Look for 'NVIDIA PerfHUD' adapter
-    // If it is present, override default settings for performance debugging
-    // see https://developer.nvidia.com/nvidia-perfhud up to Win7
-    for (UINT Adapter=0; Adapter< IDirect3D9_GetAdapterCount(hd3d->obj); ++Adapter) {
-        D3DADAPTER_IDENTIFIER9 Identifier;
-        hr = IDirect3D9_GetAdapterIdentifier(hd3d->obj,Adapter,0,&Identifier);
-        if (SUCCEEDED(hr) && strstr(Identifier.Description,"PerfHUD") != 0) {
-            AdapterToUse = Adapter;
-            DeviceType = D3DDEVTYPE_REF;
-            break;
+        // Check for 'NVIDIA PerfHUD' adapter
+        // If it is present, override default settings for performance debugging
+        // see https://developer.nvidia.com/nvidia-perfhud up to Win7
+        for (UINT Adapter=0; Adapter< IDirect3D9_GetAdapterCount(hd3d->obj); ++Adapter) {
+            D3DADAPTER_IDENTIFIER9 Identifier;
+            hr = IDirect3D9_GetAdapterIdentifier(hd3d->obj, Adapter, 0, &Identifier);
+            if (SUCCEEDED(hr) && strstr(Identifier.Description,"PerfHUD") != 0) {
+                AdapterToUse = Adapter;
+                DeviceType = D3DDEVTYPE_REF;
+                break;
+            }
         }
-    }
 #endif
+    }
 
     /*
     ** Get device capabilities
diff --git a/modules/video_chroma/d3d9_fmt.h b/modules/video_chroma/d3d9_fmt.h
index c2ac3098d4..8453d875f6 100644
--- a/modules/video_chroma/d3d9_fmt.h
+++ b/modules/video_chroma/d3d9_fmt.h
@@ -95,9 +95,9 @@ static inline void ReleaseD3D9PictureSys(picture_sys_d3d9_t *p_sys)
     FreeLibrary(p_sys->dxva2_dll);
 }
 
-HRESULT D3D9_CreateDevice(vlc_object_t *, d3d9_handle_t *, HWND,
+HRESULT D3D9_CreateDevice(vlc_object_t *, d3d9_handle_t *, int, HWND,
                           d3d9_device_t *out);
-#define D3D9_CreateDevice(a,b,c,d) D3D9_CreateDevice( VLC_OBJECT(a), b, c, d )
+#define D3D9_CreateDevice(a,b,c,d,e) D3D9_CreateDevice( VLC_OBJECT(a), b, c, d, e )
 HRESULT D3D9_CreateDeviceExternal(IDirect3DDevice9 *, d3d9_handle_t *, HWND,
                                   d3d9_device_t *out);
 
diff --git a/modules/video_output/win32/direct3d9.c b/modules/video_output/win32/direct3d9.c
index b0fe0343dd..4891847357 100644
--- a/modules/video_output/win32/direct3d9.c
+++ b/modules/video_output/win32/direct3d9.c
@@ -1690,16 +1690,15 @@ static int Open(vout_display_t *vd, const vout_display_cfg_t *cfg,
         .hardware_decoding = is_d3d9_opaque( vd->source.i_chroma ),
     };
     libvlc_video_direct3d_device_setup_t device_setup;
-    IDirect3D9 *d3d9_device = NULL;
-    if ( sys->setupDeviceCb( &sys->outside_opaque, &surface_cfg, &device_setup ) )
-        d3d9_device = device_setup.device_context;
-    if ( d3d9_device == NULL )
+    if ( !sys->setupDeviceCb( &sys->outside_opaque, &surface_cfg, &device_setup ) ||
+         device_setup.device_context == NULL )
     {
         msg_Err(vd, "Missing external IDirect3D9");
         return VLC_EGENERIC;
     }
+    IDirect3D9 *d3d9_device = device_setup.device_context;
     D3D9_CloneExternal( &sys->hd3d, d3d9_device );
-    HRESULT hr = D3D9_CreateDevice(vd, &sys->hd3d, sys->sys.hvideownd, &sys->d3d_dev);
+    HRESULT hr = D3D9_CreateDevice(vd, &sys->hd3d, -1, sys->sys.hvideownd, &sys->d3d_dev);
     if (FAILED(hr)) {
         msg_Err( vd, "D3D9 Creation failed! (hr=0x%lX)", hr);
         D3D9_Destroy(&sys->hd3d);
@@ -1961,7 +1960,7 @@ GLConvOpen(vlc_object_t *obj)
         goto error;
     }
 
-    if (FAILED(D3D9_CreateDevice(obj, &priv->hd3d, tc->gl->surface->handle.hwnd,
+    if (FAILED(D3D9_CreateDevice(obj, &priv->hd3d, -1, tc->gl->surface->handle.hwnd,
                                  &priv->d3d_dev)))
         goto error;
 



More information about the vlc-commits mailing list