Blender V5.0
gpu_py_capabilities.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_capabilities.hh"
15
16#include "gpu_py.hh"
17#include "gpu_py_capabilities.hh" /* own include */
18
19/* -------------------------------------------------------------------- */
22
24 /* Wrap. */
25 pygpu_max_texture_size_get_doc,
26 ".. function:: max_texture_size_get()\n"
27 "\n"
28 " Get estimated maximum texture size to be able to handle.\n"
29 "\n"
30 " :return: Texture size.\n"
31 " :rtype: int\n");
32static PyObject *pygpu_max_texture_size_get(PyObject * /*self*/)
33{
35
36 return PyLong_FromLong(GPU_max_texture_size());
37}
38
40 /* Wrap. */
41 pygpu_max_texture_layers_get_doc,
42 ".. function:: max_texture_layers_get()\n"
43 "\n"
44 " Get maximum number of layers in texture.\n"
45 "\n"
46 " :return: Number of layers.\n"
47 " :rtype: int\n");
48static PyObject *pygpu_max_texture_layers_get(PyObject * /*self*/)
49{
51
52 return PyLong_FromLong(GPU_max_texture_layers());
53}
54
56 /* Wrap. */
57 pygpu_max_textures_get_doc,
58 ".. function:: max_textures_get()\n"
59 "\n"
60 " Get maximum supported texture image units used for\n"
61 " accessing texture maps from the vertex shader and the\n"
62 " fragment processor.\n"
63 "\n"
64 " :return: Texture image units.\n"
65 " :rtype: int\n");
66static PyObject *pygpu_max_textures_get(PyObject * /*self*/)
67{
69
70 return PyLong_FromLong(GPU_max_textures());
71}
72
74 /* Wrap. */
75 pygpu_max_textures_vert_get_doc,
76 ".. function:: max_textures_vert_get()\n"
77 "\n"
78 " Get maximum supported texture image units used for\n"
79 " accessing texture maps from the vertex shader.\n"
80 "\n"
81 " :return: Texture image units.\n"
82 " :rtype: int\n");
83static PyObject *pygpu_max_textures_vert_get(PyObject * /*self*/)
84{
86
87 return PyLong_FromLong(GPU_max_textures_vert());
88}
89
91 /* Wrap. */
92 pygpu_max_textures_geom_get_doc,
93 ".. function:: max_textures_geom_get()\n"
94 "\n"
95 " Get maximum supported texture image units used for\n"
96 " accessing texture maps from the geometry shader.\n"
97 "\n"
98 " :return: Texture image units.\n"
99 " :rtype: int\n");
100static PyObject *pygpu_max_textures_geom_get(PyObject * /*self*/)
101{
103
104 return PyLong_FromLong(GPU_max_textures_geom());
105}
106
108 /* Wrap. */
109 pygpu_max_textures_frag_get_doc,
110 ".. function:: max_textures_frag_get()\n"
111 "\n"
112 " Get maximum supported texture image units used for\n"
113 " accessing texture maps from the fragment shader.\n"
114 "\n"
115 " :return: Texture image units.\n"
116 " :rtype: int\n");
117static PyObject *pygpu_max_textures_frag_get(PyObject * /*self*/)
118{
120
121 return PyLong_FromLong(GPU_max_textures_frag());
122}
123
125 /* Wrap. */
126 pygpu_max_images_get_doc,
127 ".. function:: max_images_get()\n"
128 "\n"
129 " Get maximum supported number of image units.\n"
130 "\n"
131 " :return: Number of image units.\n"
132 " :rtype: int\n");
133static PyObject *pygpu_max_images_get(PyObject * /*self*/)
134{
136
137 return PyLong_FromLong(GPU_max_images());
138}
139
141 /* Wrap. */
142 pygpu_max_uniforms_vert_get_doc,
143 ".. function:: max_uniforms_vert_get()\n"
144 "\n"
145 " Get maximum number of values held in uniform variable\n"
146 " storage for a vertex shader.\n"
147 "\n"
148 " :return: Number of values.\n"
149 " :rtype: int\n");
150static PyObject *pygpu_max_uniforms_vert_get(PyObject * /*self*/)
151{
153
154 return PyLong_FromLong(GPU_max_uniforms_vert());
155}
156
158 /* Wrap. */
159 pygpu_max_uniforms_frag_get_doc,
160 ".. function:: max_uniforms_frag_get()\n"
161 "\n"
162 " Get maximum number of values held in uniform variable\n"
163 " storage for a fragment shader.\n"
164 "\n"
165 " :return: Number of values.\n"
166 " :rtype: int\n");
167static PyObject *pygpu_max_uniforms_frag_get(PyObject * /*self*/)
168{
170
171 return PyLong_FromLong(GPU_max_uniforms_frag());
172}
173
175 /* Wrap. */
176 pygpu_max_batch_indices_get_doc,
177 ".. function:: max_batch_indices_get()\n"
178 "\n"
179 " Get maximum number of vertex array indices.\n"
180 "\n"
181 " :return: Number of indices.\n"
182 " :rtype: int\n");
183static PyObject *pygpu_max_batch_indices_get(PyObject * /*self*/)
184{
186
187 return PyLong_FromLong(GPU_max_batch_indices());
188}
189
191 /* Wrap. */
192 pygpu_max_batch_vertices_get_doc,
193 ".. function:: max_batch_vertices_get()\n"
194 "\n"
195 " Get maximum number of vertex array vertices.\n"
196 "\n"
197 " :return: Number of vertices.\n"
198 " :rtype: int\n");
199static PyObject *pygpu_max_batch_vertices_get(PyObject * /*self*/)
200{
202
203 return PyLong_FromLong(GPU_max_batch_vertices());
204}
205
207 /* Wrap. */
208 pygpu_max_vertex_attribs_get_doc,
209 ".. function:: max_vertex_attribs_get()\n"
210 "\n"
211 " Get maximum number of vertex attributes accessible to\n"
212 " a vertex shader.\n"
213 "\n"
214 " :return: Number of attributes.\n"
215 " :rtype: int\n");
216static PyObject *pygpu_max_vertex_attribs_get(PyObject * /*self*/)
217{
219
220 return PyLong_FromLong(GPU_max_vertex_attribs());
221}
222
224 /* Wrap. */
225 pygpu_max_varying_floats_get_doc,
226 ".. function:: max_varying_floats_get()\n"
227 "\n"
228 " Get maximum number of varying variables used by\n"
229 " vertex and fragment shaders.\n"
230 "\n"
231 " :return: Number of variables.\n"
232 " :rtype: int\n");
233static PyObject *pygpu_max_varying_floats_get(PyObject * /*self*/)
234{
236
237 return PyLong_FromLong(GPU_max_varying_floats());
238}
239
241 /* Wrap. */
242 pygpu_extensions_get_doc,
243 ".. function:: extensions_get()\n"
244 "\n"
245 " Get supported extensions in the current context.\n"
246 "\n"
247 " :return: Extensions.\n"
248 " :rtype: tuple[str]\n");
249static PyObject *pygpu_extensions_get(PyObject * /*self*/)
250{
252
253 int extensions_len = GPU_extensions_len();
254 PyObject *ret = PyTuple_New(extensions_len);
255 PyObject **ob_items = ((PyTupleObject *)ret)->ob_item;
256 for (int i = 0; i < extensions_len; i++) {
257 ob_items[i] = PyUnicode_FromString(GPU_extension_get(i));
258 }
259
260 return ret;
261}
262
264 /* Wrap. */
265 pygpu_compute_shader_support_get_doc,
266 ".. function:: compute_shader_support_get()\n"
267 "\n"
268 " Are compute shaders supported.\n"
269 "\n"
270 " :return: True when supported, False when not supported.\n"
271 " :rtype: bool\n");
272static PyObject *pygpu_compute_shader_support_get(PyObject * /*self*/)
273{
275
276 static bool deprecation_warning_issued = false;
277 if (!deprecation_warning_issued) {
278 PyErr_WarnEx(PyExc_DeprecationWarning,
279 "compute_shader_support_get is deprecated. All platforms have support for "
280 "compute shaders.",
281 1);
282 deprecation_warning_issued = true;
283 }
284
285 return PyBool_FromLong(true);
286}
287
289 /* Wrap. */
290 pygpu_shader_image_load_store_support_get_doc,
291 ".. function:: shader_image_load_store_support_get()\n"
292 "\n"
293 " Is image load/store supported.\n"
294 "\n"
295 " :return: True when supported, False when not supported.\n"
296 " :rtype: bool\n");
297static PyObject *pygpu_shader_image_load_store_support_get(PyObject * /*self*/)
298{
300
301 static bool deprecation_warning_issued = false;
302 if (!deprecation_warning_issued) {
303 PyErr_WarnEx(
304 PyExc_DeprecationWarning,
305 "shader_image_load_store_support_get is deprecated. All platforms have support for "
306 "image load store.",
307 1);
308 deprecation_warning_issued = true;
309 }
310 /* Now required to start Blender. */
311 return PyBool_FromLong(true);
312}
313
315 /* Wrap. */
316 pygpu_hdr_support_get_doc,
317 ".. function:: hdr_support_get()\n"
318 "\n"
319 " Return whether GPU backend supports High Dynamic range for viewport.\n"
320 "\n"
321 " :return: HDR support available.\n"
322 " :rtype: bool\n");
323static PyObject *pygpu_hdr_support_get(PyObject * /*self*/)
324{
326
327 return PyBool_FromLong(GPU_hdr_support());
328}
329
331 /* Wrap. */
332 pygpu_max_work_group_count_get_doc,
333 ".. function:: max_work_group_count_get(index)\n"
334 "\n"
335 " Get maximum number of work groups that may be dispatched to a compute shader.\n"
336 "\n"
337 " :arg index: Index of the dimension.\n"
338 " :type index: int\n"
339 " :return: Maximum number of work groups for the queried dimension.\n"
340 " :rtype: int\n");
341static PyObject *pygpu_max_work_group_count_get(PyObject * /*self*/, PyObject *args)
342{
344
345 int index;
346 if (!PyArg_ParseTuple(args, "i", &index)) {
347 return nullptr;
348 }
349
350 const int max_work_group_count = GPU_max_work_group_count(index);
351
352 return PyLong_FromLong(max_work_group_count);
353}
354
356 /* Wrap. */
357 pygpu_max_work_group_size_get_doc,
358 ".. function:: max_work_group_size_get(index)\n"
359 "\n"
360 " Get maximum size of a work group that may be dispatched to a compute shader.\n"
361 "\n"
362 " :arg index: Index of the dimension.\n"
363 " :type index: int\n"
364 " :return: Maximum size of a work group for the queried dimension.\n"
365 " :rtype: int\n");
366static PyObject *pygpu_max_work_group_size_get(PyObject * /*self*/, PyObject *args)
367{
369
370 int index;
371 if (!PyArg_ParseTuple(args, "i", &index)) {
372 return nullptr;
373 }
374
375 const int max_work_group_size = GPU_max_work_group_size(index);
376
377 return PyLong_FromLong(max_work_group_size);
378}
379
381
382/* -------------------------------------------------------------------- */
385
386#ifdef __GNUC__
387# ifdef __clang__
388# pragma clang diagnostic push
389# pragma clang diagnostic ignored "-Wcast-function-type"
390# else
391# pragma GCC diagnostic push
392# pragma GCC diagnostic ignored "-Wcast-function-type"
393# endif
394#endif
395
396static PyMethodDef pygpu_capabilities__tp_methods[] = {
397 {"max_texture_size_get",
398 (PyCFunction)pygpu_max_texture_size_get,
399 METH_NOARGS,
400 pygpu_max_texture_size_get_doc},
401 {"max_texture_layers_get",
402 (PyCFunction)pygpu_max_texture_layers_get,
403 METH_NOARGS,
404 pygpu_max_texture_layers_get_doc},
405 {"max_textures_get",
406 (PyCFunction)pygpu_max_textures_get,
407 METH_NOARGS,
408 pygpu_max_textures_get_doc},
409 {"max_textures_vert_get",
410 (PyCFunction)pygpu_max_textures_vert_get,
411 METH_NOARGS,
412 pygpu_max_textures_vert_get_doc},
413 {"max_textures_geom_get",
414 (PyCFunction)pygpu_max_textures_geom_get,
415 METH_NOARGS,
416 pygpu_max_textures_geom_get_doc},
417 {"max_textures_frag_get",
418 (PyCFunction)pygpu_max_textures_frag_get,
419 METH_NOARGS,
420 pygpu_max_textures_frag_get_doc},
421 {"max_images_get", (PyCFunction)pygpu_max_images_get, METH_NOARGS, pygpu_max_images_get_doc},
422 {"max_uniforms_vert_get",
423 (PyCFunction)pygpu_max_uniforms_vert_get,
424 METH_NOARGS,
425 pygpu_max_uniforms_vert_get_doc},
426 {"max_uniforms_frag_get",
427 (PyCFunction)pygpu_max_uniforms_frag_get,
428 METH_NOARGS,
429 pygpu_max_uniforms_frag_get_doc},
430 {"max_batch_indices_get",
431 (PyCFunction)pygpu_max_batch_indices_get,
432 METH_NOARGS,
433 pygpu_max_batch_indices_get_doc},
434 {"max_batch_vertices_get",
435 (PyCFunction)pygpu_max_batch_vertices_get,
436 METH_NOARGS,
437 pygpu_max_batch_vertices_get_doc},
438 {"max_vertex_attribs_get",
439 (PyCFunction)pygpu_max_vertex_attribs_get,
440 METH_NOARGS,
441 pygpu_max_vertex_attribs_get_doc},
442 {"max_varying_floats_get",
443 (PyCFunction)pygpu_max_varying_floats_get,
444 METH_NOARGS,
445 pygpu_max_varying_floats_get_doc},
446 {"extensions_get", (PyCFunction)pygpu_extensions_get, METH_NOARGS, pygpu_extensions_get_doc},
447
448 {"compute_shader_support_get",
450 METH_NOARGS,
451 pygpu_compute_shader_support_get_doc},
452 {"shader_image_load_store_support_get",
454 METH_NOARGS,
455 pygpu_shader_image_load_store_support_get_doc},
456 {"hdr_support_get",
457 (PyCFunction)pygpu_hdr_support_get,
458 METH_NOARGS,
459 pygpu_hdr_support_get_doc},
460 {
461 "max_work_group_count_get",
463 METH_VARARGS,
464 pygpu_max_work_group_count_get_doc,
465 },
466 {
467 "max_work_group_size_get",
469 METH_VARARGS,
470 pygpu_max_work_group_size_get_doc,
471 },
472 {nullptr, nullptr, 0, nullptr},
473};
474
475#ifdef __GNUC__
476# ifdef __clang__
477# pragma clang diagnostic pop
478# else
479# pragma GCC diagnostic pop
480# endif
481#endif
482
484 /* Wrap. */
485 pygpu_capabilities__tp_doc,
486 "This module provides access to the GPU capabilities.");
487static PyModuleDef pygpu_capabilities_module_def = {
488 /*m_base*/ PyModuleDef_HEAD_INIT,
489 /*m_name*/ "gpu.capabilities",
490 /*m_doc*/ pygpu_capabilities__tp_doc,
491 /*m_size*/ 0,
492 /*m_methods*/ pygpu_capabilities__tp_methods,
493 /*m_slots*/ nullptr,
494 /*m_traverse*/ nullptr,
495 /*m_clear*/ nullptr,
496 /*m_free*/ nullptr,
497};
498
500{
501 PyObject *submodule;
502
503 submodule = PyModule_Create(&pygpu_capabilities_module_def);
504
505 return submodule;
506}
507
int GPU_max_batch_indices()
int GPU_max_textures()
bool GPU_hdr_support()
int GPU_max_work_group_size(int index)
int GPU_max_texture_layers()
int GPU_max_images()
int GPU_max_uniforms_vert()
int GPU_max_work_group_count(int index)
int GPU_max_textures_geom()
int GPU_max_textures_frag()
int GPU_max_vertex_attribs()
const char * GPU_extension_get(int i)
int GPU_max_varying_floats()
int GPU_max_batch_vertices()
int GPU_extensions_len()
int GPU_max_uniforms_frag()
int GPU_max_texture_size()
int GPU_max_textures_vert()
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
Definition gpu_py.hh:20
static PyObject * pygpu_max_batch_indices_get(PyObject *)
static PyObject * pygpu_max_batch_vertices_get(PyObject *)
static PyObject * pygpu_max_texture_size_get(PyObject *)
static PyObject * pygpu_max_varying_floats_get(PyObject *)
static PyObject * pygpu_max_textures_get(PyObject *)
PyObject * bpygpu_capabilities_init()
static PyObject * pygpu_max_uniforms_vert_get(PyObject *)
static PyObject * pygpu_max_textures_frag_get(PyObject *)
static PyObject * pygpu_shader_image_load_store_support_get(PyObject *)
static PyObject * pygpu_max_work_group_size_get(PyObject *, PyObject *args)
static PyObject * pygpu_max_images_get(PyObject *)
static PyObject * pygpu_max_vertex_attribs_get(PyObject *)
static PyObject * pygpu_extensions_get(PyObject *)
static PyObject * pygpu_max_work_group_count_get(PyObject *, PyObject *args)
static PyObject * pygpu_max_textures_geom_get(PyObject *)
static PyObject * pygpu_compute_shader_support_get(PyObject *)
static PyObject * pygpu_max_textures_vert_get(PyObject *)
static PyModuleDef pygpu_capabilities_module_def
static PyObject * pygpu_hdr_support_get(PyObject *)
static PyObject * pygpu_max_texture_layers_get(PyObject *)
static PyMethodDef pygpu_capabilities__tp_methods[]
PyDoc_STRVAR(pygpu_max_texture_size_get_doc, ".. function:: max_texture_size_get()\n" "\n" " Get estimated maximum texture size to be able to handle.\n" "\n" " :return: Texture size.\n" " :rtype: int\n")
static PyObject * pygpu_max_uniforms_frag_get(PyObject *)
return ret
i
Definition text_draw.cc:230