Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gpu_py_capabilities.c « gpu « python « blender « source - git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 2345982eb427dfa06e0d47cde257ca760fb6aa3c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
/* SPDX-License-Identifier: GPL-2.0-or-later */

/** \file
 * \ingroup bpygpu
 *
 * - Use `bpygpu_` for local API.
 * - Use `BPyGPU` for public API.
 */

#include <Python.h>

#include "BLI_utildefines.h"

#include "GPU_capabilities.h"

#include "gpu_py_capabilities.h" /* own include */

/* -------------------------------------------------------------------- */
/** \name Functions
 * \{ */

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_texture_size_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_texture_size());
}

PyDoc_STRVAR(pygpu_max_texture_layers_get_doc,
             ".. function:: max_texture_layers_get()\n"
             "\n"
             "   Get maximum number of layers in texture.\n"
             "\n"
             "   :return: Number of layers.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_texture_layers_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_texture_layers());
}

PyDoc_STRVAR(pygpu_max_textures_get_doc,
             ".. function:: max_textures_get()\n"
             "\n"
             "   Get maximum supported texture image units used for\n"
             "   accessing texture maps from the vertex shader and the\n"
             "   fragment processor.\n"
             "\n"
             "   :return: Texture image units.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_textures_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_textures());
}

PyDoc_STRVAR(pygpu_max_textures_vert_get_doc,
             ".. function:: max_textures_vert_get()\n"
             "\n"
             "   Get maximum supported texture image units used for\n"
             "   accessing texture maps from the vertex shader.\n"
             "\n"
             "   :return: Texture image units.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_textures_vert_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_textures_vert());
}

PyDoc_STRVAR(pygpu_max_textures_geom_get_doc,
             ".. function:: max_textures_geom_get()\n"
             "\n"
             "   Get maximum supported texture image units used for\n"
             "   accessing texture maps from the geometry shader.\n"
             "\n"
             "   :return: Texture image units.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_textures_geom_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_textures_geom());
}

PyDoc_STRVAR(pygpu_max_textures_frag_get_doc,
             ".. function:: max_textures_frag_get()\n"
             "\n"
             "   Get maximum supported texture image units used for\n"
             "   accessing texture maps from the fragment shader.\n"
             "\n"
             "   :return: Texture image units.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_textures_frag_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_textures_frag());
}

PyDoc_STRVAR(pygpu_max_uniforms_vert_get_doc,
             ".. function:: max_uniforms_vert_get()\n"
             "\n"
             "   Get maximum number of values held in uniform variable\n"
             "   storage for a vertex shader.\n"
             "\n"
             "   :return: Number of values.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_uniforms_vert_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_uniforms_vert());
}

PyDoc_STRVAR(pygpu_max_uniforms_frag_get_doc,
             ".. function:: max_uniforms_frag_get()\n"
             "\n"
             "   Get maximum number of values held in uniform variable\n"
             "   storage for a fragment shader.\n"
             "\n"
             "   :return: Number of values.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_uniforms_frag_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_uniforms_frag());
}

PyDoc_STRVAR(pygpu_max_batch_indices_get_doc,
             ".. function:: max_batch_indices_get()\n"
             "\n"
             "   Get maximum number of vertex array indices.\n"
             "\n"
             "   :return: Number of indices.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_batch_indices_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_batch_indices());
}

PyDoc_STRVAR(pygpu_max_batch_vertices_get_doc,
             ".. function:: max_batch_vertices_get()\n"
             "\n"
             "   Get maximum number of vertex array vertices.\n"
             "\n"
             "   :return: Number of vertices.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_batch_vertices_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_batch_vertices());
}

PyDoc_STRVAR(pygpu_max_vertex_attribs_get_doc,
             ".. function:: max_vertex_attribs_get()\n"
             "\n"
             "   Get maximum number of vertex attributes accessible to\n"
             "   a vertex shader.\n"
             "\n"
             "   :return: Number of attributes.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_vertex_attribs_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_vertex_attribs());
}

PyDoc_STRVAR(pygpu_max_varying_floats_get_doc,
             ".. function:: max_varying_floats_get()\n"
             "\n"
             "   Get maximum number of varying variables used by\n"
             "   vertex and fragment shaders.\n"
             "\n"
             "   :return: Number of variables.\n"
             "   :rtype: int\n");
static PyObject *pygpu_max_varying_floats_get(PyObject *UNUSED(self))
{
  return PyLong_FromLong(GPU_max_varying_floats());
}

PyDoc_STRVAR(pygpu_extensions_get_doc,
             ".. function:: extensions_get()\n"
             "\n"
             "   Get supported extensions in the current context.\n"
             "\n"
             "   :return: Extensions.\n"
             "   :rtype: tuple of string\n");
static PyObject *pygpu_extensions_get(PyObject *UNUSED(self))
{
  int extensions_len = GPU_extensions_len();
  PyObject *ret = PyTuple_New(extensions_len);
  PyObject **ob_items = ((PyTupleObject *)ret)->ob_item;
  for (int i = 0; i < extensions_len; i++) {
    ob_items[i] = PyUnicode_FromString(GPU_extension_get(i));
  }

  return ret;
}

PyDoc_STRVAR(pygpu_compute_shader_support_get_doc,
             ".. function:: compute_shader_support_get()\n"
             "\n"
             "   Are compute shaders supported.\n"
             "\n"
             "   :return: True when supported, False when not supported.\n"
             "   :rtype: bool\n");
static PyObject *pygpu_compute_shader_support_get(PyObject *UNUSED(self))
{
  return PyBool_FromLong(GPU_compute_shader_support());
}

PyDoc_STRVAR(pygpu_shader_storage_buffer_objects_support_get_doc,
             ".. function:: shader_storage_buffer_objects_support_get()\n"
             "\n"
             "   Are SSBO's supported.\n"
             "\n"
             "   :return: True when supported, False when not supported.\n"
             "   :rtype: bool\n");
static PyObject *pygpu_shader_storage_buffer_objects_support_get(PyObject *UNUSED(self))
{
  return PyBool_FromLong(GPU_shader_storage_buffer_objects_support());
}
PyDoc_STRVAR(pygpu_shader_image_load_store_support_get_doc,
             ".. function:: shader_image_load_store_support_get()\n"
             "\n"
             "   Is image load/store supported.\n"
             "\n"
             "   :return: True when supported, False when not supported.\n"
             "   :rtype: bool\n");
static PyObject *pygpu_shader_image_load_store_support_get(PyObject *UNUSED(self))
{
  return PyBool_FromLong(GPU_shader_image_load_store_support());
}
/** \} */

/* -------------------------------------------------------------------- */
/** \name Module
 * \{ */

static struct PyMethodDef pygpu_capabilities__tp_methods[] = {
    {"max_texture_size_get",
     (PyCFunction)pygpu_max_texture_size_get,
     METH_NOARGS,
     pygpu_max_texture_size_get_doc},
    {"max_texture_layers_get",
     (PyCFunction)pygpu_max_texture_layers_get,
     METH_NOARGS,
     pygpu_max_texture_layers_get_doc},
    {"max_textures_get",
     (PyCFunction)pygpu_max_textures_get,
     METH_NOARGS,
     pygpu_max_textures_get_doc},
    {"max_textures_vert_get",
     (PyCFunction)pygpu_max_textures_vert_get,
     METH_NOARGS,
     pygpu_max_textures_vert_get_doc},
    {"max_textures_geom_get",
     (PyCFunction)pygpu_max_textures_geom_get,
     METH_NOARGS,
     pygpu_max_textures_geom_get_doc},
    {"max_textures_frag_get",
     (PyCFunction)pygpu_max_textures_frag_get,
     METH_NOARGS,
     pygpu_max_textures_frag_get_doc},
    {"max_uniforms_vert_get",
     (PyCFunction)pygpu_max_uniforms_vert_get,
     METH_NOARGS,
     pygpu_max_uniforms_vert_get_doc},
    {"max_uniforms_frag_get",
     (PyCFunction)pygpu_max_uniforms_frag_get,
     METH_NOARGS,
     pygpu_max_uniforms_frag_get_doc},
    {"max_batch_indices_get",
     (PyCFunction)pygpu_max_batch_indices_get,
     METH_NOARGS,
     pygpu_max_batch_indices_get_doc},
    {"max_batch_vertices_get",
     (PyCFunction)pygpu_max_batch_vertices_get,
     METH_NOARGS,
     pygpu_max_batch_vertices_get_doc},
    {"max_vertex_attribs_get",
     (PyCFunction)pygpu_max_vertex_attribs_get,
     METH_NOARGS,
     pygpu_max_vertex_attribs_get_doc},
    {"max_varying_floats_get",
     (PyCFunction)pygpu_max_varying_floats_get,
     METH_NOARGS,
     pygpu_max_varying_floats_get_doc},
    {"extensions_get", (PyCFunction)pygpu_extensions_get, METH_NOARGS, pygpu_extensions_get_doc},

    {"compute_shader_support_get",
     (PyCFunction)pygpu_compute_shader_support_get,
     METH_NOARGS,
     pygpu_compute_shader_support_get_doc},
    {"shader_storage_buffer_objects_support_get",
     (PyCFunction)pygpu_shader_storage_buffer_objects_support_get,
     METH_NOARGS,
     pygpu_shader_storage_buffer_objects_support_get_doc},
    {"shader_image_load_store_support_get",
     (PyCFunction)pygpu_shader_image_load_store_support_get,
     METH_NOARGS,
     pygpu_shader_image_load_store_support_get_doc},

    {NULL, NULL, 0, NULL},
};

PyDoc_STRVAR(pygpu_capabilities__tp_doc, "This module provides access to the GPU capabilities.");
static PyModuleDef pygpu_capabilities_module_def = {
    PyModuleDef_HEAD_INIT,
    /*m_name*/ "gpu.capabilities",
    /*m_doc*/ pygpu_capabilities__tp_doc,
    /*m_size*/ 0,
    /*m_methods*/ pygpu_capabilities__tp_methods,
    /*m_slots*/ NULL,
    /*m_traverse*/ NULL,
    /*m_clear*/ NULL,
    /*m_free*/ NULL,
};

PyObject *bpygpu_capabilities_init(void)
{
  PyObject *submodule;

  submodule = PyModule_Create(&pygpu_capabilities_module_def);

  return submodule;
}

/** \} */