[Bf-blender-cvs] [3bb8d173e70] blender-v3.0-release: Fix T93109: Cycles HIP missing check for correct driver version

Sayak Biswas noreply at git.blender.org
Tue Nov 23 15:45:45 CET 2021


Commit: 3bb8d173e70c1ec80612733c63efedc5e1d854e5
Author: Sayak Biswas
Date:   Tue Nov 23 14:16:24 2021 +0100
Branches: blender-v3.0-release
https://developer.blender.org/rB3bb8d173e70c1ec80612733c63efedc5e1d854e5

Fix T93109: Cycles HIP missing check for correct driver version

21.Q4 is required, older version should not show devices in the preferences.
This adds a check for the file version of amdhip64.dll file during hipew
initialization.

Differential Revision: https://developer.blender.org/D13324

===================================================================

M	extern/hipew/include/hipew.h
M	extern/hipew/src/hipew.c
M	intern/cycles/device/hip/device.cpp

===================================================================

diff --git a/extern/hipew/include/hipew.h b/extern/hipew/include/hipew.h
index 9351ec4d30c..50f6d6607ec 100644
--- a/extern/hipew/include/hipew.h
+++ b/extern/hipew/include/hipew.h
@@ -1333,6 +1333,7 @@ enum {
   HIPEW_SUCCESS = 0,
   HIPEW_ERROR_OPEN_FAILED = -1,
   HIPEW_ERROR_ATEXIT_FAILED = -2,
+  HIPEW_ERROR_OLD_DRIVER = -3,
 };
 
 enum {
diff --git a/extern/hipew/src/hipew.c b/extern/hipew/src/hipew.c
index 92022778dfc..593901aad9c 100644
--- a/extern/hipew/src/hipew.c
+++ b/extern/hipew/src/hipew.c
@@ -214,6 +214,36 @@ static void hipewHipExit(void) {
   }
 }
 
+#ifdef _WIN32
+static int hipewHasOldDriver(const char *hip_path) {
+  DWORD verHandle = 0;
+  DWORD verSize = GetFileVersionInfoSize(hip_path, &verHandle);
+  int old_driver = 0;
+  if(verSize != 0) {
+    LPSTR verData = (LPSTR)malloc(verSize);
+    if(GetFileVersionInfo(hip_path, verHandle, verSize, verData)) {
+      LPBYTE lpBuffer = NULL;
+      UINT size = 0;
+      if(VerQueryValue(verData, "\\", (VOID FAR * FAR *)&lpBuffer, &size)) {
+        if(size) {
+          VS_FIXEDFILEINFO *verInfo = (VS_FIXEDFILEINFO *)lpBuffer;
+          /* Magic value from
+           * https://docs.microsoft.com/en-us/windows/win32/api/verrsrc/ns-verrsrc-vs_fixedfileinfo */
+          if(verInfo->dwSignature == 0xfeef04bd) {
+            unsigned int fileVersionLS0 = (verInfo->dwFileVersionLS >> 16) & 0xffff;
+            unsigned int fileversionLS1 = (verInfo->dwFileVersionLS >> 0) & 0xffff;
+            /* Corresponds to versions older than AMD Radeon Pro 21.Q4. */
+            old_driver = ((fileVersionLS0 < 3354) || (fileVersionLS0 == 3354 && fileversionLS1 < 13));
+          }
+        }
+      }
+    }
+    free(verData);
+  }
+  return old_driver;
+}
+#endif
+
 static int hipewHipInit(void) {
   /* Library paths. */
 #ifdef _WIN32
@@ -241,6 +271,14 @@ static int hipewHipInit(void) {
     return result;
   }
 
+#ifdef _WIN32
+  /* Test for driver version. */
+  if(hipewHasOldDriver(hip_paths[0])) {
+     result = HIPEW_ERROR_OLD_DRIVER;
+     return result;
+  }
+#endif
+
   /* Load library. */
   hip_lib = dynamic_library_open_find(hip_paths);
 
diff --git a/intern/cycles/device/hip/device.cpp b/intern/cycles/device/hip/device.cpp
index 29304e50247..ecc109b2bb9 100644
--- a/intern/cycles/device/hip/device.cpp
+++ b/intern/cycles/device/hip/device.cpp
@@ -57,9 +57,16 @@ bool device_hip_init()
     }
   }
   else {
-    VLOG(1) << "HIPEW initialization failed: "
-            << ((hipew_result == HIPEW_ERROR_ATEXIT_FAILED) ? "Error setting up atexit() handler" :
-                                                              "Error opening the library");
+    if (hipew_result == HIPEW_ERROR_ATEXIT_FAILED) {
+      VLOG(1) << "HIPEW initialization failed: Error setting up atexit() handler";
+    }
+    else if (hipew_result == HIPEW_ERROR_OLD_DRIVER) {
+      VLOG(1) << "HIPEW initialization failed: Driver version too old, requires AMD Radeon Pro "
+                 "21.Q4 driver or newer";
+    }
+    else {
+      VLOG(1) << "HIPEW initialization failed: Error opening HIP dynamic library";
+    }
   }
 
   return result;



More information about the Bf-blender-cvs mailing list