2023-08-16 00:20:26 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2023 Blender Authors
|
2023-05-31 16:19:06 +02:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
2021-05-14 11:15:00 -03:00
|
|
|
|
|
|
|
|
/** \file
|
|
|
|
|
* \ingroup bpygpu
|
|
|
|
|
*
|
2021-07-20 22:52:31 +10:00
|
|
|
* - Use `bpygpu_` for local API.
|
|
|
|
|
* - Use `BPyGPU` for public API.
|
2021-05-14 11:15:00 -03:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#include <Python.h>
|
|
|
|
|
|
|
|
|
|
#include "BLI_utildefines.h"
|
|
|
|
|
|
2024-03-23 01:24:18 +01:00
|
|
|
#include "GPU_context.hh"
|
|
|
|
|
#include "GPU_platform.hh"
|
2021-05-14 11:15:00 -03:00
|
|
|
|
2024-03-23 10:06:45 -04:00
|
|
|
#include "gpu_py.hh"
|
|
|
|
|
#include "gpu_py_platform.hh" /* Own include. */
|
2021-05-14 11:15:00 -03:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Functions
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
pygpu_platform_vendor_get_doc,
|
|
|
|
|
".. function:: vendor_get()\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" Get GPU vendor.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" :return: Vendor name.\n"
|
|
|
|
|
" :rtype: str\n");
|
2023-07-21 19:41:03 +02:00
|
|
|
static PyObject *pygpu_platform_vendor_get(PyObject * /*self*/)
|
2021-05-14 11:15:00 -03:00
|
|
|
{
|
|
|
|
|
return PyUnicode_FromString(GPU_platform_vendor());
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
pygpu_platform_renderer_get_doc,
|
|
|
|
|
".. function:: renderer_get()\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" Get GPU to be used for rendering.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" :return: GPU name.\n"
|
|
|
|
|
" :rtype: str\n");
|
2023-07-21 19:41:03 +02:00
|
|
|
static PyObject *pygpu_platform_renderer_get(PyObject * /*self*/)
|
2021-05-14 11:15:00 -03:00
|
|
|
{
|
|
|
|
|
return PyUnicode_FromString(GPU_platform_renderer());
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
pygpu_platform_version_get_doc,
|
|
|
|
|
".. function:: version_get()\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" Get GPU driver version.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" :return: Driver version.\n"
|
|
|
|
|
" :rtype: str\n");
|
2023-07-21 19:41:03 +02:00
|
|
|
static PyObject *pygpu_platform_version_get(PyObject * /*self*/)
|
2021-05-14 11:15:00 -03:00
|
|
|
{
|
|
|
|
|
return PyUnicode_FromString(GPU_platform_version());
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
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', 'QUALCOMM', "
|
|
|
|
|
"'UNKNOWN').\n"
|
|
|
|
|
" :rtype: str\n");
|
2023-07-21 19:41:03 +02:00
|
|
|
static PyObject *pygpu_platform_device_type_get(PyObject * /*self*/)
|
2022-08-01 10:57:18 +02:00
|
|
|
{
|
2023-08-11 09:58:44 +10:00
|
|
|
const char *device;
|
2022-08-01 10:57:18 +02:00
|
|
|
if (GPU_type_matches(GPU_DEVICE_APPLE, GPU_OS_ANY, GPU_DRIVER_ANY)) {
|
2023-08-11 09:58:44 +10:00
|
|
|
device = "APPLE";
|
2022-08-01 10:57:18 +02:00
|
|
|
}
|
2023-08-11 09:58:44 +10:00
|
|
|
else if (GPU_type_matches(GPU_DEVICE_NVIDIA, GPU_OS_ANY, GPU_DRIVER_ANY)) {
|
|
|
|
|
device = "NVIDIA";
|
2022-08-01 10:57:18 +02:00
|
|
|
}
|
2023-08-11 09:58:44 +10:00
|
|
|
else if (GPU_type_matches(GPU_DEVICE_ATI, GPU_OS_ANY, GPU_DRIVER_ANY)) {
|
|
|
|
|
device = "AMD";
|
2022-08-01 10:57:18 +02:00
|
|
|
}
|
2023-08-11 09:58:44 +10:00
|
|
|
else if (GPU_type_matches(GPU_DEVICE_INTEL | GPU_DEVICE_INTEL_UHD, GPU_OS_ANY, GPU_DRIVER_ANY)) {
|
|
|
|
|
device = "INTEL";
|
2022-08-01 10:57:18 +02:00
|
|
|
}
|
2023-08-11 09:58:44 +10:00
|
|
|
else if (GPU_type_matches(GPU_DEVICE_SOFTWARE, GPU_OS_ANY, GPU_DRIVER_ANY)) {
|
|
|
|
|
device = "SOFTWARE";
|
2022-08-01 10:57:18 +02:00
|
|
|
}
|
Add check for Qualcomm devices on Windows
Some of these devices are not capable of running >=4.0, due to issues
with Mesa's Compute Shaders and their D3D drivers.
This PR marks those GPUs as unsupported, and prints info to stdout.
A driver update will be available for 8cx Gen3 on the 17th October
from here:
https://www.qualcomm.com/products/mobile/snapdragon/pcs-and-tablets/snapdragon-8-series-mobile-compute-platforms/snapdragon-8cx-gen-3-compute-platform#Software
It will take longer via the standard MS Windows Update channels,
as there is certification, testing, etc required, but it is possible
to get the drivers, at least.
This issue applies even when using emulated x64.
If this does not get merged, all WoA devices will break with 4.0,
where older ones will just launch a grey screen and crash, and newer
ones will open, but scenes will not render correctly in Workbench.
These devices work by using Mesa's D3D12 Gallium driver ("GLOn12"),
which is why we have to read the DirectX driver version - the version
reported by OpenGL is the mesa version, which is independent of the
driver (which is the part with the bug).
Pull Request: https://projects.blender.org/blender/blender/pulls/113674
2023-10-20 17:18:35 +02:00
|
|
|
/* Right now we can only detect Qualcomm GPUs on Windows, not other OSes */
|
|
|
|
|
else if (GPU_type_matches(GPU_DEVICE_QUALCOMM, GPU_OS_WIN, GPU_DRIVER_ANY)) {
|
|
|
|
|
device = "QUALCOMM";
|
|
|
|
|
}
|
2023-08-11 09:58:44 +10:00
|
|
|
else {
|
|
|
|
|
device = "UNKNOWN";
|
|
|
|
|
}
|
|
|
|
|
return PyUnicode_FromString(device);
|
2022-08-01 10:57:18 +02:00
|
|
|
}
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
pygpu_platform_backend_type_get_doc,
|
|
|
|
|
".. function:: backend_type_get()\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" Get actuve GPU backend.\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" :return: Backend type ('OPENGL', 'VULKAN', 'METAL', 'NONE', 'UNKNOWN').\n"
|
|
|
|
|
" :rtype: str\n");
|
2023-07-21 19:41:03 +02:00
|
|
|
static PyObject *pygpu_platform_backend_type_get(PyObject * /*self*/)
|
2022-10-21 14:38:30 +02:00
|
|
|
{
|
2023-08-11 09:58:44 +10:00
|
|
|
const char *backend = "UNKNOWN";
|
2022-10-21 14:38:30 +02:00
|
|
|
switch (GPU_backend_get_type()) {
|
2023-08-11 09:58:44 +10:00
|
|
|
case GPU_BACKEND_VULKAN: {
|
|
|
|
|
backend = "VULKAN";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GPU_BACKEND_METAL: {
|
|
|
|
|
backend = "METAL";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GPU_BACKEND_NONE: {
|
|
|
|
|
backend = "NONE";
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case GPU_BACKEND_OPENGL: {
|
|
|
|
|
backend = "OPENGL";
|
|
|
|
|
break;
|
|
|
|
|
}
|
2022-10-21 14:38:30 +02:00
|
|
|
case GPU_BACKEND_ANY:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2023-08-11 09:58:44 +10:00
|
|
|
return PyUnicode_FromString(backend);
|
2022-10-21 14:38:30 +02:00
|
|
|
}
|
|
|
|
|
|
2021-05-14 11:15:00 -03:00
|
|
|
/** \} */
|
|
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Module
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2023-07-22 11:11:42 +10:00
|
|
|
#if (defined(__GNUC__) && !defined(__clang__))
|
|
|
|
|
# pragma GCC diagnostic push
|
|
|
|
|
# pragma GCC diagnostic ignored "-Wcast-function-type"
|
|
|
|
|
#endif
|
|
|
|
|
|
2023-06-03 08:36:28 +10:00
|
|
|
static PyMethodDef pygpu_platform__tp_methods[] = {
|
2021-08-17 14:46:46 +10:00
|
|
|
{"vendor_get",
|
|
|
|
|
(PyCFunction)pygpu_platform_vendor_get,
|
|
|
|
|
METH_NOARGS,
|
2021-08-17 14:44:28 +10:00
|
|
|
pygpu_platform_vendor_get_doc},
|
2021-08-17 14:46:46 +10:00
|
|
|
{"renderer_get",
|
|
|
|
|
(PyCFunction)pygpu_platform_renderer_get,
|
|
|
|
|
METH_NOARGS,
|
2021-08-17 14:44:28 +10:00
|
|
|
pygpu_platform_renderer_get_doc},
|
2021-08-17 14:46:46 +10:00
|
|
|
{"version_get",
|
|
|
|
|
(PyCFunction)pygpu_platform_version_get,
|
|
|
|
|
METH_NOARGS,
|
2021-08-17 14:44:28 +10:00
|
|
|
pygpu_platform_version_get_doc},
|
2022-08-01 10:57:18 +02:00
|
|
|
{"device_type_get",
|
|
|
|
|
(PyCFunction)pygpu_platform_device_type_get,
|
|
|
|
|
METH_NOARGS,
|
|
|
|
|
pygpu_platform_device_type_get_doc},
|
2022-10-21 14:38:30 +02:00
|
|
|
{"backend_type_get",
|
|
|
|
|
(PyCFunction)pygpu_platform_backend_type_get,
|
|
|
|
|
METH_NOARGS,
|
|
|
|
|
pygpu_platform_backend_type_get_doc},
|
2023-07-21 19:41:03 +02:00
|
|
|
{nullptr, nullptr, 0, nullptr},
|
2021-05-14 11:15:00 -03:00
|
|
|
};
|
|
|
|
|
|
2023-07-22 11:11:42 +10:00
|
|
|
#if (defined(__GNUC__) && !defined(__clang__))
|
|
|
|
|
# pragma GCC diagnostic pop
|
|
|
|
|
#endif
|
|
|
|
|
|
2024-01-25 10:22:16 +11:00
|
|
|
PyDoc_STRVAR(
|
|
|
|
|
/* Wrap. */
|
|
|
|
|
pygpu_platform__tp_doc,
|
|
|
|
|
"This module provides access to GPU Platform definitions.");
|
2021-05-14 11:15:00 -03:00
|
|
|
static PyModuleDef pygpu_platform_module_def = {
|
2023-07-16 17:43:31 +10:00
|
|
|
/*m_base*/ PyModuleDef_HEAD_INIT,
|
2022-11-08 11:13:58 +11:00
|
|
|
/*m_name*/ "gpu.platform",
|
|
|
|
|
/*m_doc*/ pygpu_platform__tp_doc,
|
|
|
|
|
/*m_size*/ 0,
|
|
|
|
|
/*m_methods*/ pygpu_platform__tp_methods,
|
2023-07-21 19:41:03 +02:00
|
|
|
/*m_slots*/ nullptr,
|
|
|
|
|
/*m_traverse*/ nullptr,
|
|
|
|
|
/*m_clear*/ nullptr,
|
|
|
|
|
/*m_free*/ nullptr,
|
2021-05-14 11:15:00 -03:00
|
|
|
};
|
|
|
|
|
|
2023-07-22 11:33:36 +10:00
|
|
|
PyObject *bpygpu_platform_init()
|
2021-05-14 11:15:00 -03:00
|
|
|
{
|
|
|
|
|
PyObject *submodule;
|
|
|
|
|
|
2022-11-29 13:55:37 -03:00
|
|
|
submodule = bpygpu_create_module(&pygpu_platform_module_def);
|
2021-05-14 11:15:00 -03:00
|
|
|
|
|
|
|
|
return submodule;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|