Blender V4.3
gpu_py_platform.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
12#include <Python.h>
13
14#include "BLI_utildefines.h"
15
16#include "GPU_context.hh"
17#include "GPU_platform.hh"
18
19#include "gpu_py.hh"
20#include "gpu_py_platform.hh" /* Own include. */
21
22/* -------------------------------------------------------------------- */
27 /* Wrap. */
28 pygpu_platform_vendor_get_doc,
29 ".. function:: vendor_get()\n"
30 "\n"
31 " Get GPU vendor.\n"
32 "\n"
33 " :return: Vendor name.\n"
34 " :rtype: str\n");
35static PyObject *pygpu_platform_vendor_get(PyObject * /*self*/)
36{
38
39 return PyUnicode_FromString(GPU_platform_vendor());
40}
41
43 /* Wrap. */
44 pygpu_platform_renderer_get_doc,
45 ".. function:: renderer_get()\n"
46 "\n"
47 " Get GPU to be used for rendering.\n"
48 "\n"
49 " :return: GPU name.\n"
50 " :rtype: str\n");
51static PyObject *pygpu_platform_renderer_get(PyObject * /*self*/)
52{
54
55 return PyUnicode_FromString(GPU_platform_renderer());
56}
57
59 /* Wrap. */
60 pygpu_platform_version_get_doc,
61 ".. function:: version_get()\n"
62 "\n"
63 " Get GPU driver version.\n"
64 "\n"
65 " :return: Driver version.\n"
66 " :rtype: str\n");
67static PyObject *pygpu_platform_version_get(PyObject * /*self*/)
68{
70
71 return PyUnicode_FromString(GPU_platform_version());
72}
73
75 /* Wrap. */
76 pygpu_platform_device_type_get_doc,
77 ".. function:: device_type_get()\n"
78 "\n"
79 " Get GPU device type.\n"
80 "\n"
81 " :return: Device type ('APPLE', 'NVIDIA', 'AMD', 'INTEL', 'SOFTWARE', 'QUALCOMM', "
82 "'UNKNOWN').\n"
83 " :rtype: str\n");
84static PyObject *pygpu_platform_device_type_get(PyObject * /*self*/)
85{
87
88 const char *device;
90 device = "APPLE";
91 }
93 device = "NVIDIA";
94 }
96 device = "AMD";
97 }
99 device = "INTEL";
100 }
102 device = "SOFTWARE";
103 }
104 /* Right now we can only detect Qualcomm GPUs on Windows, not other OSes */
106 device = "QUALCOMM";
107 }
108 else {
109 device = "UNKNOWN";
110 }
111 return PyUnicode_FromString(device);
112}
113
115 /* Wrap. */
116 pygpu_platform_backend_type_get_doc,
117 ".. function:: backend_type_get()\n"
118 "\n"
119 " Get actuve GPU backend.\n"
120 "\n"
121 " :return: Backend type ('OPENGL', 'VULKAN', 'METAL', 'NONE', 'UNKNOWN').\n"
122 " :rtype: str\n");
123static PyObject *pygpu_platform_backend_type_get(PyObject * /*self*/)
124{
126
127 const char *backend = "UNKNOWN";
128 switch (GPU_backend_get_type()) {
129 case GPU_BACKEND_VULKAN: {
130 backend = "VULKAN";
131 break;
132 }
133 case GPU_BACKEND_METAL: {
134 backend = "METAL";
135 break;
136 }
137 case GPU_BACKEND_NONE: {
138 backend = "NONE";
139 break;
140 }
141 case GPU_BACKEND_OPENGL: {
142 backend = "OPENGL";
143 break;
144 }
145 case GPU_BACKEND_ANY:
146 break;
147 }
148 return PyUnicode_FromString(backend);
149}
150
153/* -------------------------------------------------------------------- */
157#if (defined(__GNUC__) && !defined(__clang__))
158# pragma GCC diagnostic push
159# pragma GCC diagnostic ignored "-Wcast-function-type"
160#endif
161
162static PyMethodDef pygpu_platform__tp_methods[] = {
163 {"vendor_get",
164 (PyCFunction)pygpu_platform_vendor_get,
165 METH_NOARGS,
166 pygpu_platform_vendor_get_doc},
167 {"renderer_get",
168 (PyCFunction)pygpu_platform_renderer_get,
169 METH_NOARGS,
170 pygpu_platform_renderer_get_doc},
171 {"version_get",
172 (PyCFunction)pygpu_platform_version_get,
173 METH_NOARGS,
174 pygpu_platform_version_get_doc},
175 {"device_type_get",
177 METH_NOARGS,
178 pygpu_platform_device_type_get_doc},
179 {"backend_type_get",
181 METH_NOARGS,
182 pygpu_platform_backend_type_get_doc},
183 {nullptr, nullptr, 0, nullptr},
184};
185
186#if (defined(__GNUC__) && !defined(__clang__))
187# pragma GCC diagnostic pop
188#endif
189
191 /* Wrap. */
192 pygpu_platform__tp_doc,
193 "This module provides access to GPU Platform definitions.");
194static PyModuleDef pygpu_platform_module_def = {
195 /*m_base*/ PyModuleDef_HEAD_INIT,
196 /*m_name*/ "gpu.platform",
197 /*m_doc*/ pygpu_platform__tp_doc,
198 /*m_size*/ 0,
199 /*m_methods*/ pygpu_platform__tp_methods,
200 /*m_slots*/ nullptr,
201 /*m_traverse*/ nullptr,
202 /*m_clear*/ nullptr,
203 /*m_free*/ nullptr,
204};
205
207{
208 PyObject *submodule;
209
210 submodule = PyModule_Create(&pygpu_platform_module_def);
211
212 return submodule;
213}
214
eGPUBackendType GPU_backend_get_type()
@ GPU_DRIVER_ANY
const char * GPU_platform_vendor()
const char * GPU_platform_renderer()
@ GPU_OS_WIN
@ GPU_OS_ANY
@ GPU_DEVICE_ATI
@ GPU_DEVICE_INTEL_UHD
@ GPU_DEVICE_QUALCOMM
@ GPU_DEVICE_SOFTWARE
@ GPU_DEVICE_NVIDIA
@ GPU_DEVICE_APPLE
@ GPU_DEVICE_INTEL
const char * GPU_platform_version()
bool GPU_type_matches(eGPUDeviceType device, eGPUOSType os, eGPUDriverType driver)
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
Definition gpu_py.hh:18
static PyObject * pygpu_platform_device_type_get(PyObject *)
PyObject * bpygpu_platform_init()
static PyObject * pygpu_platform_vendor_get(PyObject *)
static PyModuleDef pygpu_platform_module_def
static PyMethodDef pygpu_platform__tp_methods[]
static PyObject * pygpu_platform_version_get(PyObject *)
static PyObject * pygpu_platform_renderer_get(PyObject *)
static PyObject * pygpu_platform_backend_type_get(PyObject *)
PyDoc_STRVAR(pygpu_platform_vendor_get_doc, ".. function:: vendor_get()\n" "\n" " Get GPU vendor.\n" "\n" " :return: Vendor name.\n" " :rtype: str\n")