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 <germano.costa@ig.com.br>2022-04-13 04:34:52 +0300
committerGermano Cavalcante <germano.costa@ig.com.br>2022-04-13 04:34:52 +0300
commit132576ebb172e1bc354fdea56e9977438b1d5030 (patch)
tree6f278fe65920ed09a647d5065d969b63b55f759c /source
parent8fad71799f7188d16c20498942e337b674a84594 (diff)
gpu.types.Buffer: fill buffer interface with just what is requested
Use the `flags` parameter to avoid unnecessary allocations.
Diffstat (limited to 'source')
-rw-r--r--source/blender/python/gpu/gpu_py_buffer.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/source/blender/python/gpu/gpu_py_buffer.c b/source/blender/python/gpu/gpu_py_buffer.c
index d3f55517ae7..020535d002a 100644
--- a/source/blender/python/gpu/gpu_py_buffer.c
+++ b/source/blender/python/gpu/gpu_py_buffer.c
@@ -604,23 +604,31 @@ static void pygpu_buffer_strides_calc(const eGPUDataFormat format,
}
/* Here is the buffer interface function */
-static int pygpu_buffer__bf_getbuffer(BPyGPUBuffer *self, Py_buffer *view, int UNUSED(flags))
+static int pygpu_buffer__bf_getbuffer(BPyGPUBuffer *self, Py_buffer *view, int flags)
{
if (view == NULL) {
PyErr_SetString(PyExc_ValueError, "NULL view in getbuffer");
return -1;
}
+ memset(view, 0, sizeof(*view));
+
view->obj = (PyObject *)self;
view->buf = (void *)self->buf.as_void;
view->len = bpygpu_Buffer_size(self);
view->readonly = 0;
view->itemsize = GPU_texture_dataformat_size(self->format);
- view->format = (char *)pygpu_buffer_formatstr(self->format);
- view->ndim = self->shape_len;
- view->shape = self->shape;
- view->strides = MEM_mallocN(view->ndim * sizeof(*view->strides), "BPyGPUBuffer strides");
- pygpu_buffer_strides_calc(self->format, view->ndim, view->shape, view->strides);
+ if (flags & PyBUF_FORMAT) {
+ view->format = (char *)pygpu_buffer_formatstr(self->format);
+ }
+ if (flags & PyBUF_ND) {
+ view->ndim = self->shape_len;
+ view->shape = self->shape;
+ }
+ if (flags & PyBUF_STRIDES) {
+ view->strides = MEM_mallocN(view->ndim * sizeof(*view->strides), "BPyGPUBuffer strides");
+ pygpu_buffer_strides_calc(self->format, view->ndim, view->shape, view->strides);
+ }
view->suboffsets = NULL;
view->internal = NULL;