Blender V5.0
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
11
12#include <Python.h>
13
14#include "GPU_context.hh"
15#include "GPU_platform.hh"
16
17#include "gpu_py.hh"
18#include "gpu_py_platform.hh" /* Own include. */
19
20/* -------------------------------------------------------------------- */
23
25 /* Wrap. */
26 pygpu_platform_vendor_get_doc,
27 ".. function:: vendor_get()\n"
28 "\n"
29 " Get GPU vendor.\n"
30 "\n"
31 " :return: Vendor name.\n"
32 " :rtype: str\n");
33static PyObject *pygpu_platform_vendor_get(PyObject * /*self*/)
34{
36
37 return PyUnicode_FromString(GPU_platform_vendor());
38}
39
41 /* Wrap. */
42 pygpu_platform_renderer_get_doc,
43 ".. function:: renderer_get()\n"
44 "\n"
45 " Get GPU to be used for rendering.\n"
46 "\n"
47 " :return: GPU name.\n"
48 " :rtype: str\n");
49static PyObject *pygpu_platform_renderer_get(PyObject * /*self*/)
50{
52
53 return PyUnicode_FromString(GPU_platform_renderer());
54}
55
57 /* Wrap. */
58 pygpu_platform_version_get_doc,
59 ".. function:: version_get()\n"
60 "\n"
61 " Get GPU driver version.\n"
62 "\n"
63 " :return: Driver version.\n"
64 " :rtype: str\n");
65static PyObject *pygpu_platform_version_get(PyObject * /*self*/)
66{
68
69 return PyUnicode_FromString(GPU_platform_version());
70}
71
73 /* Wrap. */
74 pygpu_platform_device_type_get_doc,
75 ".. function:: device_type_get()\n"
76 "\n"
77 " Get GPU device type.\n"
78 "\n"
79 " :return: Device type ('APPLE', 'NVIDIA', 'AMD', 'INTEL', 'SOFTWARE', 'QUALCOMM', "
80 "'UNKNOWN').\n"
81 " :rtype: str\n");
82static PyObject *pygpu_platform_device_type_get(PyObject * /*self*/)
83{
85
86 const char *device;
88 device = "APPLE";
89 }
91 device = "NVIDIA";
92 }
94 device = "AMD";
95 }
97 device = "INTEL";
98 }
100 device = "SOFTWARE";
101 }
102 /* Right now we can only detect Qualcomm GPUs on Windows, not other OSes */
104 device = "QUALCOMM";
105 }
106 else {
107 device = "UNKNOWN";
108 }
109 return PyUnicode_FromString(device);
110}
111
113 /* Wrap. */
114 pygpu_platform_backend_type_get_doc,
115 ".. function:: backend_type_get()\n"
116 "\n"
117 " Get actuve GPU backend.\n"
118 "\n"
119 " :return: Backend type ('OPENGL', 'VULKAN', 'METAL', 'NONE', 'UNKNOWN').\n"
120 " :rtype: str\n");
121static PyObject *pygpu_platform_backend_type_get(PyObject * /*self*/)
122{
124
125 const char *backend = "UNKNOWN";
126 switch (GPU_backend_get_type()) {
127 case GPU_BACKEND_VULKAN: {
128 backend = "VULKAN";
129 break;
130 }
131 case GPU_BACKEND_METAL: {
132 backend = "METAL";
133 break;
134 }
135 case GPU_BACKEND_NONE: {
136 backend = "NONE";
137 break;
138 }
139 case GPU_BACKEND_OPENGL: {
140 backend = "OPENGL";
141 break;
142 }
143 case GPU_BACKEND_ANY:
144 break;
145 }
146 return PyUnicode_FromString(backend);
147}
148
150
151/* -------------------------------------------------------------------- */
154
155#ifdef __GNUC__
156# ifdef __clang__
157# pragma clang diagnostic push
158# pragma clang diagnostic ignored "-Wcast-function-type"
159# else
160# pragma GCC diagnostic push
161# pragma GCC diagnostic ignored "-Wcast-function-type"
162# endif
163#endif
164
165static PyMethodDef pygpu_platform__tp_methods[] = {
166 {"vendor_get",
167 (PyCFunction)pygpu_platform_vendor_get,
168 METH_NOARGS,
169 pygpu_platform_vendor_get_doc},
170 {"renderer_get",
171 (PyCFunction)pygpu_platform_renderer_get,
172 METH_NOARGS,
173 pygpu_platform_renderer_get_doc},
174 {"version_get",
175 (PyCFunction)pygpu_platform_version_get,
176 METH_NOARGS,
177 pygpu_platform_version_get_doc},
178 {"device_type_get",
180 METH_NOARGS,
181 pygpu_platform_device_type_get_doc},
182 {"backend_type_get",
184 METH_NOARGS,
185 pygpu_platform_backend_type_get_doc},
186 {nullptr, nullptr, 0, nullptr},
187};
188
189#ifdef __GNUC__
190# ifdef __clang__
191# pragma clang diagnostic pop
192# else
193# pragma GCC diagnostic pop
194# endif
195#endif
196
198 /* Wrap. */
199 pygpu_platform__tp_doc,
200 "This module provides access to GPU Platform definitions.");
201static PyModuleDef pygpu_platform_module_def = {
202 /*m_base*/ PyModuleDef_HEAD_INIT,
203 /*m_name*/ "gpu.platform",
204 /*m_doc*/ pygpu_platform__tp_doc,
205 /*m_size*/ 0,
206 /*m_methods*/ pygpu_platform__tp_methods,
207 /*m_slots*/ nullptr,
208 /*m_traverse*/ nullptr,
209 /*m_clear*/ nullptr,
210 /*m_free*/ nullptr,
211};
212
214{
215 PyObject *submodule;
216
217 submodule = PyModule_Create(&pygpu_platform_module_def);
218
219 return submodule;
220}
221
GPUBackendType GPU_backend_get_type()
@ 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_vendor()
bool GPU_type_matches(GPUDeviceType device, GPUOSType os, GPUDriverType driver)
const char * GPU_platform_renderer()
const char * GPU_platform_version()
@ GPU_DRIVER_ANY
@ GPU_OS_WIN
@ GPU_OS_ANY
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
Definition gpu_py.hh:20
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")