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"
|
|
|
|
|
|
2022-10-21 14:38:30 +02:00
|
|
|
#include "GPU_context.h"
|
2021-05-14 11:15:00 -03:00
|
|
|
#include "GPU_platform.h"
|
|
|
|
|
|
2022-11-29 13:55:37 -03:00
|
|
|
#include "gpu_py.h"
|
2022-06-22 14:59:42 +10:00
|
|
|
#include "gpu_py_platform.h" /* Own include. */
|
2021-05-14 11:15:00 -03:00
|
|
|
|
|
|
|
|
/* -------------------------------------------------------------------- */
|
|
|
|
|
/** \name Functions
|
|
|
|
|
* \{ */
|
|
|
|
|
|
2021-08-17 14:44:28 +10:00
|
|
|
PyDoc_STRVAR(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());
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 14:44:28 +10:00
|
|
|
PyDoc_STRVAR(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());
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-17 14:44:28 +10:00
|
|
|
PyDoc_STRVAR(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());
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-01 10:57:18 +02:00
|
|
|
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");
|
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
|
|
|
}
|
2023-08-11 09:58:44 +10:00
|
|
|
else {
|
|
|
|
|
device = "UNKNOWN";
|
|
|
|
|
}
|
|
|
|
|
return PyUnicode_FromString(device);
|
2022-08-01 10:57:18 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-21 14:38:30 +02:00
|
|
|
PyDoc_STRVAR(pygpu_platform_backend_type_get_doc,
|
|
|
|
|
".. function:: backend_type_get()\n"
|
|
|
|
|
"\n"
|
|
|
|
|
" Get actuve GPU backend.\n"
|
|
|
|
|
"\n"
|
2022-10-31 16:01:02 +01:00
|
|
|
" :return: Backend type ('OPENGL', 'VULKAN', 'METAL', 'NONE', 'UNKNOWN').\n"
|
2022-10-21 14:38:30 +02:00
|
|
|
" :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
|
|
|
|
|
|
2021-05-14 11:15:00 -03:00
|
|
|
PyDoc_STRVAR(pygpu_platform__tp_doc, "This module provides access to GPU Platform definitions.");
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** \} */
|