[vlc-devel] [PATCH 2/4] d3d11_fmt: add a function to query the driver version

Steve Lhomme robux4 at videolabs.io
Thu Nov 30 17:44:38 CET 2017


---
 modules/video_chroma/d3d11_fmt.c | 72 ++++++++++++++++++++++++++++++++++++++++
 modules/video_chroma/d3d11_fmt.h |  7 ++++
 2 files changed, 79 insertions(+)

diff --git a/modules/video_chroma/d3d11_fmt.c b/modules/video_chroma/d3d11_fmt.c
index 1eb71b502c..978ec91a73 100644
--- a/modules/video_chroma/d3d11_fmt.c
+++ b/modules/video_chroma/d3d11_fmt.c
@@ -278,6 +278,78 @@ bool isNvidiaHardware(ID3D11Device *d3ddev)
     return result;
 }
 
+
+static HKEY GetAdapterRegistry(DXGI_ADAPTER_DESC *adapterDesc)
+{
+    HKEY hKey;
+    TCHAR key[128];
+    TCHAR szData[256], lookup[256];
+    DWORD len = 256;
+
+    _sntprintf(lookup, 256, TEXT("pci\\ven_%04x&dev_%04x"), adapterDesc->VendorId, adapterDesc->DeviceId);
+    for (int i=0;;i++)
+    {
+        _sntprintf(key, 128, TEXT("SYSTEM\\CurrentControlSet\\Control\\Class\\{4d36e968-e325-11ce-bfc1-08002be10318}\\%04d"), i);
+        if( RegOpenKeyEx(HKEY_LOCAL_MACHINE, key, 0, KEY_READ, &hKey) != ERROR_SUCCESS )
+            return NULL;
+
+        len = sizeof(szData);
+        if( RegQueryValueEx( hKey, TEXT("MatchingDeviceId"), NULL, NULL, (LPBYTE) &szData, &len ) == ERROR_SUCCESS ) {
+            if (_tcsncmp(lookup, szData, _tcslen(lookup)) == 0)
+                return hKey;
+        }
+
+        RegCloseKey(hKey);
+    }
+    return NULL;
+}
+
+int D3D11CheckDriverVersion(ID3D11Device *d3ddev, UINT vendorId, const struct wdmm_version *min_ver)
+{
+    IDXGIAdapter *pAdapter = D3D11DeviceAdapter(d3ddev);
+    if (!pAdapter)
+        return VLC_EGENERIC;
+
+    DXGI_ADAPTER_DESC adapterDesc;
+    HRESULT hr = IDXGIAdapter_GetDesc(pAdapter, &adapterDesc);
+    IDXGIAdapter_Release(pAdapter);
+    if (FAILED(hr))
+        return VLC_EGENERIC;
+
+    if (vendorId && adapterDesc.VendorId != vendorId)
+        return VLC_SUCCESS;
+
+    LONG err = ERROR_ACCESS_DENIED;
+#if !VLC_WINSTORE_APP
+    TCHAR szData[256];
+    DWORD len = 256;
+    HKEY hKey = GetAdapterRegistry(&adapterDesc);
+    if (hKey == NULL)
+        return VLC_EGENERIC;
+
+    err = RegQueryValueEx( hKey, TEXT("DriverVersion"), NULL, NULL, (LPBYTE) &szData, &len );
+    RegCloseKey(hKey);
+#endif
+
+    if (err != ERROR_SUCCESS )
+        return VLC_EGENERIC;
+
+    int wddm, d3d_features, revision, build;
+    /* see https://msdn.microsoft.com/windows/hardware/commercialize/design/compatibility/device-graphics */
+    if (_stscanf(szData, TEXT("%d.%d.%d.%d"), &wddm, &d3d_features, &revision, &build) != 4)
+        return VLC_EGENERIC;
+
+    bool newer =
+           wddm > min_ver->wddm ||
+          (wddm == min_ver->wddm && (d3d_features > min_ver->d3d_features ||
+                                    (d3d_features == min_ver->d3d_features &&
+                                                (revision > min_ver->revision ||
+                                                (revision == min_ver->revision &&
+                                                       build > min_ver->build)))));
+
+    return newer ? VLC_SUCCESS : VLC_EGENERIC;
+}
+
 const d3d_format_t *FindD3D11Format(ID3D11Device *d3ddevice,
                                     vlc_fourcc_t i_src_chroma,
                                     uint8_t bits_per_channel,
diff --git a/modules/video_chroma/d3d11_fmt.h b/modules/video_chroma/d3d11_fmt.h
index 867084d736..663cc99203 100644
--- a/modules/video_chroma/d3d11_fmt.h
+++ b/modules/video_chroma/d3d11_fmt.h
@@ -104,10 +104,17 @@ void D3D11_Destroy(d3d11_handle_t *);
 #define GPU_MANUFACTURER_S3            0x5333
 #define GPU_MANUFACTURER_QUALCOMM  0x4D4F4351
 
+/* see https://msdn.microsoft.com/windows/hardware/commercialize/design/compatibility/device-graphics */
+struct wdmm_version
+{
+    int wddm, d3d_features, revision, build;
+};
 
 bool isXboxHardware(ID3D11Device *d3ddev);
 bool isNvidiaHardware(ID3D11Device *d3ddev);
 IDXGIAdapter *D3D11DeviceAdapter(ID3D11Device *d3ddev);
+int D3D11CheckDriverVersion(ID3D11Device *d3ddev, UINT vendorId,
+                            const struct wdmm_version *min_ver);
 
 static inline bool DeviceSupportsFormat(ID3D11Device *d3ddevice,
                                         DXGI_FORMAT format, UINT supportFlags)
-- 
2.14.2



More information about the vlc-devel mailing list