[Bf-blender-cvs] [b986ced8aa0] temp-T99046-platform-reference-images: Added Python API for devce type, documented usage of gpu_info, removed references to platform.

Jeroen Bakker noreply at git.blender.org
Wed Jun 22 17:51:22 CEST 2022


Commit: b986ced8aa0ebd3941efaac1d7effdfa368afc2d
Author: Jeroen Bakker
Date:   Wed Jun 22 17:12:10 2022 +0200
Branches: temp-T99046-platform-reference-images
https://developer.blender.org/rBb986ced8aa0ebd3941efaac1d7effdfa368afc2d

Added Python API for devce type, documented usage of gpu_info, removed references to platform.

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

M	source/blender/python/gpu/gpu_py_platform.c
M	tests/python/eevee_render_tests.py
M	tests/python/gpu_info.py
M	tests/python/modules/render_report.py

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

diff --git a/source/blender/python/gpu/gpu_py_platform.c b/source/blender/python/gpu/gpu_py_platform.c
index 656024ae22c..b877e3ceb98 100644
--- a/source/blender/python/gpu/gpu_py_platform.c
+++ b/source/blender/python/gpu/gpu_py_platform.c
@@ -55,6 +55,34 @@ static PyObject *pygpu_platform_version_get(PyObject *UNUSED(self))
   return PyUnicode_FromString(GPU_platform_version());
 }
 
+PyDoc_STRVAR(
+    pygpu_platform_device_type_get_doc,
+    ".. function:: device_type_get()\n"
+    "\n"
+    "   Get GPU device type.\n"
+    "\n"
+    "   :return: Device type ('APPLE', 'NVIDIA', 'AMD', 'INTEL', 'SOFTWARE', 'UNKNOWN').\n"
+    "   :rtype: str\n");
+static PyObject *pygpu_platform_device_type_get(PyObject *UNUSED(self))
+{
+  if (GPU_type_matches(GPU_DEVICE_APPLE, GPU_OS_ANY, GPU_DRIVER_ANY)) {
+    return PyUnicode_FromString("APPLE");
+  }
+  if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY)) {
+    return PyUnicode_FromString("NVIDIA");
+  }
+  if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
+    return PyUnicode_FromString("AMD");
+  }
+  if (GPU_type_matches(GPU_DEVICE_INTEL | GPU_DEVICE_INTEL_UHD, GPU_OS_ANY, GPU_DRIVER_ANY)) {
+    return PyUnicode_FromString("INTEL");
+  }
+  if (GPU_type_matches(GPU_DEVICE_SOFTWARE, GPU_OS_ANY, GPU_DRIVER_ANY)) {
+    return PyUnicode_FromString("SOFTWARE");
+  }
+  return PyUnicode_FromString("UNKNOWN");
+}
+
 /** \} */
 
 /* -------------------------------------------------------------------- */
@@ -74,6 +102,10 @@ static struct PyMethodDef pygpu_platform__tp_methods[] = {
      (PyCFunction)pygpu_platform_version_get,
      METH_NOARGS,
      pygpu_platform_version_get_doc},
+    {"device_type_get",
+     (PyCFunction)pygpu_platform_device_type_get,
+     METH_NOARGS,
+     pygpu_platform_device_type_get_doc},
     {NULL, NULL, 0, NULL},
 };
 
diff --git a/tests/python/eevee_render_tests.py b/tests/python/eevee_render_tests.py
index 1d7eff62c30..062a6d0006b 100644
--- a/tests/python/eevee_render_tests.py
+++ b/tests/python/eevee_render_tests.py
@@ -98,7 +98,7 @@ if inside_blender:
         print(e)
         sys.exit(1)
 
-def get_gpu_vendor(blender):
+def get_gpu_device_type(blender):
     command = [
         blender,
         "-noaudio",
@@ -106,16 +106,15 @@ def get_gpu_vendor(blender):
         "--python",
         str(pathlib.Path(__file__).parent / "gpu_info.py")
     ]
-    vendor = None
     try:
         completed_process = subprocess.run(command, stdout=subprocess.PIPE)
         for line in completed_process.stdout.read_text():
-            if line.startswith("GPU_VENDOR:"):
+            if line.startswith("GPU_DEVICE_TYPE:"):
                 vendor = line.split(':')[1]
-                break
+                return vendor
     except BaseException as e:
         return None
-    return vendor
+    return None
 
 
 
@@ -154,9 +153,9 @@ def main():
     idiff = args.idiff[0]
     output_dir = args.outdir[0]
 
-    gpu_vendor = get_gpu_vendor(blender)
+    gpu_device_type = get_gpu_device_type(blender)
     reference_override_dir = None
-    if gpu_vendor == "AMD":
+    if gpu_device_type == "AMD":
         reference_override_dir = "eevee_renders/amd"
 
     from modules import render_report
diff --git a/tests/python/gpu_info.py b/tests/python/gpu_info.py
index bae1148a961..f964816c5cf 100644
--- a/tests/python/gpu_info.py
+++ b/tests/python/gpu_info.py
@@ -1,7 +1,16 @@
+"""
+    Prints GPU backend information to the console and exits.
+    
+    Use this script as `blender --python gpu_info.py`.
+    Doesn't work with `--background` parameter as then the GPU backend won't
+    be initialized.
+"""
 import gpu
 import sys
 
-print('GPU_VENDOR:'+gpu.platform.vendor_get())
-print('GPU_RENDERER:'+gpu.platform.renderer_get())
-print('GPU_VERSION:'+gpu.platform.version_get())
-sys.exit(0)
+print('GPU_VENDOR:' + gpu.platform.vendor_get())
+print('GPU_RENDERER:' + gpu.platform.renderer_get())
+print('GPU_VERSION:' + gpu.platform.version_get())
+print('GPU_DEVICE_TYPE:' + gpu.platform.device_type_get())
+
+sys.exit(0)
\ No newline at end of file
diff --git a/tests/python/modules/render_report.py b/tests/python/modules/render_report.py
index 24b066a4167..2f2219a2bfe 100755
--- a/tests/python/modules/render_report.py
+++ b/tests/python/modules/render_report.py
@@ -85,11 +85,11 @@ def test_get_images(output_dir, filepath, reference_dir, reference_override_dir)
     old_dirpath = os.path.join(dirpath, reference_dir)
     old_img = os.path.join(old_dirpath, testname + ".png")
     if reference_override_dir:
-        platform_dirpath = os.path.join(dirpath, reference_override_dir)
-        platform_img = os.path.join(platform_dirpath, testname + ".png")
+        override_dirpath = os.path.join(dirpath, reference_override_dir)
+        override_img = os.path.join(override_dirpath, testname + ".png")
         if os.path.exists(old_img):
-            old_dirpath = platform_dirpath
-            old_img = platform_img
+            old_dirpath = override_dirpath
+            old_img = override_img
 
     ref_dirpath = os.path.join(output_dir, os.path.basename(dirpath), "ref")
     ref_img = os.path.join(ref_dirpath, testname + ".png")



More information about the Bf-blender-cvs mailing list