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