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

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/source
diff options
context:
space:
mode:
authorGermano Cavalcante <mano-wii>2021-05-14 17:15:00 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2021-05-14 18:26:40 +0300
commit3f4f109646059ee0780bb40dbd65b3bc8c3a8f3f (patch)
tree73f81510dbed74a3e5048d3aaa366d91b14d6e9f /source
parent079f415debd85b44f9ceaca17edfb82517240448 (diff)
Python GPU: New 'capabilities' module
This module exposes the capabilities defined in the GPU module in C. This will be useful for porting existing code in `bgl` to `gpu`. Reviewed By: fclem, brecht, campbellbarton Maniphest Tasks: T80730 Part of D11147
Diffstat (limited to 'source')
-rw-r--r--source/blender/gpu/GPU_capabilities.h9
-rw-r--r--source/blender/gpu/intern/gpu_capabilities.cc40
-rw-r--r--source/blender/gpu/intern/gpu_capabilities_private.hh9
-rw-r--r--source/blender/gpu/opengl/gl_backend.cc19
-rw-r--r--source/blender/python/gpu/CMakeLists.txt2
-rw-r--r--source/blender/python/gpu/gpu_py_api.c4
-rw-r--r--source/blender/python/gpu/gpu_py_capabilities.c148
-rw-r--r--source/blender/python/gpu/gpu_py_capabilities.h23
8 files changed, 252 insertions, 2 deletions
diff --git a/source/blender/gpu/GPU_capabilities.h b/source/blender/gpu/GPU_capabilities.h
index b95053a3715..f54ecece659 100644
--- a/source/blender/gpu/GPU_capabilities.h
+++ b/source/blender/gpu/GPU_capabilities.h
@@ -37,6 +37,15 @@ int GPU_max_textures(void);
int GPU_max_textures_vert(void);
int GPU_max_textures_geom(void);
int GPU_max_textures_frag(void);
+int GPU_max_uniforms_vert(void);
+int GPU_max_uniforms_frag(void);
+int GPU_max_batch_indices(void);
+int GPU_max_batch_vertices(void);
+int GPU_max_vertex_attribs(void);
+int GPU_max_varying_floats(void);
+
+int GPU_extensions_len(void);
+const char *GPU_extension_get(int i);
int GPU_texture_size_with_limit(int res, bool limit_gl_texture_size);
diff --git a/source/blender/gpu/intern/gpu_capabilities.cc b/source/blender/gpu/intern/gpu_capabilities.cc
index 6d9182dcf17..d8764502800 100644
--- a/source/blender/gpu/intern/gpu_capabilities.cc
+++ b/source/blender/gpu/intern/gpu_capabilities.cc
@@ -82,6 +82,46 @@ int GPU_max_textures(void)
return GCaps.max_textures;
}
+int GPU_max_uniforms_vert(void)
+{
+ return GCaps.max_uniforms_vert;
+}
+
+int GPU_max_uniforms_frag(void)
+{
+ return GCaps.max_uniforms_frag;
+}
+
+int GPU_max_batch_indices(void)
+{
+ return GCaps.max_batch_indices;
+}
+
+int GPU_max_batch_vertices(void)
+{
+ return GCaps.max_batch_vertices;
+}
+
+int GPU_max_vertex_attribs(void)
+{
+ return GCaps.max_vertex_attribs;
+}
+
+int GPU_max_varying_floats(void)
+{
+ return GCaps.max_varying_floats;
+}
+
+int GPU_extensions_len(void)
+{
+ return GCaps.extensions_len;
+}
+
+const char *GPU_extension_get(int i)
+{
+ return GCaps.extension_get ? GCaps.extension_get(i) : "\0";
+}
+
bool GPU_mip_render_workaround(void)
{
return GCaps.mip_render_workaround;
diff --git a/source/blender/gpu/intern/gpu_capabilities_private.hh b/source/blender/gpu/intern/gpu_capabilities_private.hh
index 2b3292749f8..7c1d4590ce8 100644
--- a/source/blender/gpu/intern/gpu_capabilities_private.hh
+++ b/source/blender/gpu/intern/gpu_capabilities_private.hh
@@ -41,6 +41,15 @@ struct GPUCapabilities {
int max_textures_vert = 0;
int max_textures_geom = 0;
int max_textures_frag = 0;
+ int max_uniforms_vert = 0;
+ int max_uniforms_frag = 0;
+ int max_batch_indices = 0;
+ int max_batch_vertices = 0;
+ int max_vertex_attribs = 0;
+ int max_varying_floats = 0;
+ int extensions_len = 0;
+ const char *(*extension_get)(int);
+
bool mem_stats_support = false;
bool shader_image_load_store_support = false;
/* OpenGL related workarounds. */
diff --git a/source/blender/gpu/opengl/gl_backend.cc b/source/blender/gpu/opengl/gl_backend.cc
index a04d4be0e52..89bad1c9a4b 100644
--- a/source/blender/gpu/opengl/gl_backend.cc
+++ b/source/blender/gpu/opengl/gl_backend.cc
@@ -142,9 +142,9 @@ void GLBackend::platform_init()
GPG.support_level = GPU_SUPPORT_LEVEL_LIMITED;
}
}
+ GPG.create_key(GPG.support_level, vendor, renderer, version);
+ GPG.create_gpu_name(vendor, renderer, version);
}
- GPG.create_key(GPG.support_level, vendor, renderer, version);
- GPG.create_gpu_name(vendor, renderer, version);
}
void GLBackend::platform_exit()
@@ -204,6 +204,11 @@ static bool detect_mip_render_workaround()
return enable_workaround;
}
+const char *gl_extension_get(int i)
+{
+ return (char *)glGetStringi(GL_EXTENSIONS, i);
+}
+
static void detect_workarounds()
{
const char *vendor = (const char *)glGetString(GL_VENDOR);
@@ -419,6 +424,16 @@ void GLBackend::capabilities_init()
glGetIntegerv(GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS, &GCaps.max_textures_vert);
glGetIntegerv(GL_MAX_GEOMETRY_TEXTURE_IMAGE_UNITS, &GCaps.max_textures_geom);
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &GCaps.max_textures);
+ glGetIntegerv(GL_MAX_VERTEX_UNIFORM_COMPONENTS, &GCaps.max_uniforms_vert);
+ glGetIntegerv(GL_MAX_FRAGMENT_UNIFORM_COMPONENTS, &GCaps.max_uniforms_frag);
+ glGetIntegerv(GL_MAX_ELEMENTS_INDICES, &GCaps.max_batch_indices);
+ glGetIntegerv(GL_MAX_ELEMENTS_VERTICES, &GCaps.max_batch_vertices);
+ glGetIntegerv(GL_MAX_VERTEX_ATTRIBS, &GCaps.max_vertex_attribs);
+ glGetIntegerv(GL_MAX_VARYING_FLOATS, &GCaps.max_varying_floats);
+
+ glGetIntegerv(GL_NUM_EXTENSIONS, &GCaps.extensions_len);
+ GCaps.extension_get = gl_extension_get;
+
GCaps.mem_stats_support = GLEW_NVX_gpu_memory_info || GLEW_ATI_meminfo;
GCaps.shader_image_load_store_support = GLEW_ARB_shader_image_load_store;
/* GL specific capabilities. */
diff --git a/source/blender/python/gpu/CMakeLists.txt b/source/blender/python/gpu/CMakeLists.txt
index fe5c559fcc0..9742664d107 100644
--- a/source/blender/python/gpu/CMakeLists.txt
+++ b/source/blender/python/gpu/CMakeLists.txt
@@ -37,6 +37,7 @@ set(SRC
gpu_py_api.c
gpu_py_batch.c
gpu_py_buffer.c
+ gpu_py_capabilities.c
gpu_py_element.c
gpu_py_framebuffer.c
gpu_py_matrix.c
@@ -54,6 +55,7 @@ set(SRC
gpu_py_api.h
gpu_py_batch.h
gpu_py_buffer.h
+ gpu_py_capabilities.h
gpu_py_element.h
gpu_py_framebuffer.h
gpu_py_matrix.h
diff --git a/source/blender/python/gpu/gpu_py_api.c b/source/blender/python/gpu/gpu_py_api.c
index 0bc18e73d0c..18e5fa41c44 100644
--- a/source/blender/python/gpu/gpu_py_api.c
+++ b/source/blender/python/gpu/gpu_py_api.c
@@ -30,6 +30,7 @@
#include "../generic/python_utildefines.h"
+#include "gpu_py_capabilities.h"
#include "gpu_py_matrix.h"
#include "gpu_py_select.h"
#include "gpu_py_state.h"
@@ -61,6 +62,9 @@ PyObject *BPyInit_gpu(void)
PyModule_AddObject(mod, "types", (submodule = bpygpu_types_init()));
PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+ PyModule_AddObject(mod, "capabilities", (submodule = bpygpu_capabilities_init()));
+ PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
+
PyModule_AddObject(mod, "matrix", (submodule = bpygpu_matrix_init()));
PyDict_SetItem(sys_modules, PyModule_GetNameObject(submodule), submodule);
diff --git a/source/blender/python/gpu/gpu_py_capabilities.c b/source/blender/python/gpu/gpu_py_capabilities.c
new file mode 100644
index 00000000000..cedce485253
--- /dev/null
+++ b/source/blender/python/gpu/gpu_py_capabilities.c
@@ -0,0 +1,148 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \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
+ * \{ */
+
+static PyObject *pygpu_max_texture_size_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_texture_size());
+}
+
+static PyObject *pygpu_max_texture_layers_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_texture_layers());
+}
+
+static PyObject *pygpu_max_textures_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_textures());
+}
+
+static PyObject *pygpu_max_textures_vert_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_textures_vert());
+}
+
+static PyObject *pygpu_max_textures_geom_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_textures_geom());
+}
+
+static PyObject *pygpu_max_textures_frag_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_textures_frag());
+}
+
+static PyObject *pygpu_max_uniforms_vert_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_uniforms_vert());
+}
+
+static PyObject *pygpu_max_uniforms_frag_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_uniforms_frag());
+}
+
+static PyObject *pygpu_max_batch_indices_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_batch_indices());
+}
+
+static PyObject *pygpu_max_batch_vertices_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_batch_vertices());
+}
+
+static PyObject *pygpu_max_vertex_attribs_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_vertex_attribs());
+}
+
+static PyObject *pygpu_max_varying_floats_get(PyObject *UNUSED(self))
+{
+ return PyLong_FromLong(GPU_max_varying_floats());
+}
+
+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;
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Module
+ * \{ */
+
+static struct PyMethodDef pygpu_capabilities__tp_methods[] = {
+ {"max_texture_size_get", (PyCFunction)pygpu_max_texture_size_get, METH_NOARGS, NULL},
+ {"max_texture_layers_get", (PyCFunction)pygpu_max_texture_layers_get, METH_NOARGS, NULL},
+ {"max_textures_get", (PyCFunction)pygpu_max_textures_get, METH_NOARGS, NULL},
+ {"max_textures_vert_get", (PyCFunction)pygpu_max_textures_vert_get, METH_NOARGS, NULL},
+ {"max_textures_geom_get", (PyCFunction)pygpu_max_textures_geom_get, METH_NOARGS, NULL},
+ {"max_textures_frag_get", (PyCFunction)pygpu_max_textures_frag_get, METH_NOARGS, NULL},
+ {"max_uniforms_vert_get", (PyCFunction)pygpu_max_uniforms_vert_get, METH_NOARGS, NULL},
+ {"max_uniforms_frag_get", (PyCFunction)pygpu_max_uniforms_frag_get, METH_NOARGS, NULL},
+ {"max_batch_indices_get", (PyCFunction)pygpu_max_batch_indices_get, METH_NOARGS, NULL},
+ {"max_batch_vertices_get", (PyCFunction)pygpu_max_batch_vertices_get, METH_NOARGS, NULL},
+ {"max_vertex_attribs_get", (PyCFunction)pygpu_max_vertex_attribs_get, METH_NOARGS, NULL},
+ {"max_varying_floats_get", (PyCFunction)pygpu_max_varying_floats_get, METH_NOARGS, NULL},
+ {"extensions_get", (PyCFunction)pygpu_extensions_get, METH_NOARGS, NULL},
+ {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_methods = pygpu_capabilities__tp_methods,
+};
+
+PyObject *bpygpu_capabilities_init(void)
+{
+ PyObject *submodule;
+
+ submodule = PyModule_Create(&pygpu_capabilities_module_def);
+
+ return submodule;
+}
+
+/** \} */
diff --git a/source/blender/python/gpu/gpu_py_capabilities.h b/source/blender/python/gpu/gpu_py_capabilities.h
new file mode 100644
index 00000000000..ac138dda0c9
--- /dev/null
+++ b/source/blender/python/gpu/gpu_py_capabilities.h
@@ -0,0 +1,23 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+/** \file
+ * \ingroup bpygpu
+ */
+
+#pragma once
+
+PyObject *bpygpu_capabilities_init(void);