Blender V5.0
gpu_py_buffer.cc File Reference
#include <Python.h>
#include <algorithm>
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
#include "GPU_texture.hh"
#include "../generic/py_capi_utils.hh"
#include "gpu_py.hh"
#include "gpu_py_buffer.hh"

Go to the source code of this file.

Macros

#define PYGPU_BUFFER_PROTOCOL
#define MAX_DIMENSIONS   64

Functions

Utility Functions
static Py_ssize_t pygpu_buffer_dimensions_tot_elem (const Py_ssize_t *shape, Py_ssize_t shape_len)
static bool pygpu_buffer_dimensions_tot_len_compare (const Py_ssize_t *shape_a, const Py_ssize_t shape_a_len, const Py_ssize_t *shape_b, const Py_ssize_t shape_b_len)
static bool pygpu_buffer_pyobj_as_shape (PyObject *shape_obj, Py_ssize_t r_shape[MAX_DIMENSIONS], Py_ssize_t *r_shape_len)
static const char * pygpu_buffer_formatstr (eGPUDataFormat data_format)

BPyGPUBuffer API

static PyMethodDef pygpu_buffer__tp_methods []
static PyGetSetDef pygpu_buffer_getseters []
static PySequenceMethods pygpu_buffer__tp_as_sequence
static PyMappingMethods pygpu_buffer__tp_as_mapping
static PyBufferProcs pygpu_buffer__tp_as_buffer
PyTypeObject BPyGPU_BufferType
static BPyGPUBufferpygpu_buffer_make_from_data (PyObject *parent, const eGPUDataFormat format, const int shape_len, const Py_ssize_t *shape, void *buf)
static PyObject * pygpu_buffer__sq_item (BPyGPUBuffer *self, Py_ssize_t i)
static PyObject * pygpu_buffer_to_list (BPyGPUBuffer *self)
static PyObject * pygpu_buffer_to_list_recursive (BPyGPUBuffer *self)
static PyObject * pygpu_buffer_dimensions_get (BPyGPUBuffer *self, void *)
static int pygpu_buffer_dimensions_set (BPyGPUBuffer *self, PyObject *value, void *)
static int pygpu_buffer__tp_traverse (BPyGPUBuffer *self, visitproc visit, void *arg)
static int pygpu_buffer__tp_clear (BPyGPUBuffer *self)
static void pygpu_buffer__tp_dealloc (BPyGPUBuffer *self)
static PyObject * pygpu_buffer__tp_repr (BPyGPUBuffer *self)
static int pygpu_buffer__sq_ass_item (BPyGPUBuffer *self, Py_ssize_t i, PyObject *v)
static int pygpu_buffer_ass_slice (BPyGPUBuffer *self, Py_ssize_t begin, Py_ssize_t end, PyObject *seq)
static PyObject * pygpu_buffer__tp_new (PyTypeObject *, PyObject *args, PyObject *kwds)
static int pygpu_buffer__tp_is_gc (BPyGPUBuffer *self)
static Py_ssize_t pygpu_buffer__sq_length (BPyGPUBuffer *self)
static PyObject * pygpu_buffer_slice (BPyGPUBuffer *self, Py_ssize_t begin, Py_ssize_t end)
static PyObject * pygpu_buffer__mp_subscript (BPyGPUBuffer *self, PyObject *item)
static int pygpu_buffer__mp_ass_subscript (BPyGPUBuffer *self, PyObject *item, PyObject *value)
static void pygpu_buffer_strides_calc (const eGPUDataFormat format, const int shape_len, const Py_ssize_t *shape, Py_ssize_t *r_strides)
static int pygpu_buffer__bf_getbuffer (BPyGPUBuffer *self, Py_buffer *view, int flags)
static void pygpu_buffer__bf_releasebuffer (PyObject *, Py_buffer *view)
 PyDoc_STRVAR (pygpu_buffer__tp_doc, ".. class:: Buffer(format, dimensions, data)\n" "\n" " For Python access to GPU functions requiring a pointer.\n" "\n" " :arg format: Format type to interpret the buffer.\n" " Possible values are ``FLOAT``, ``INT``, ``UINT``, ``UBYTE``, ``UINT_24_8`` & " "``10_11_11_REV``.\n" " ``UINT_24_8`` is deprecated, use ``FLOAT`` instead.\n" " :type format: str\n" " :arg dimensions: Array describing the dimensions.\n" " :type dimensions: int\n" " :arg data: Optional data array.\n" " :type data: Buffer | Sequence[float] | Sequence[int]\n")
static size_t pygpu_buffer_calc_size (const int format, const int shape_len, const Py_ssize_t *shape)
size_t bpygpu_Buffer_size (BPyGPUBuffer *buffer)
BPyGPUBufferBPyGPU_Buffer_CreatePyObject (const int format, const Py_ssize_t *shape, const int shape_len, void *buffer)

Detailed Description

This file defines the gpu.state API.

  • Use bpygpu_ for local API.
  • Use BPyGPU for public API.

Definition in file gpu_py_buffer.cc.

Macro Definition Documentation

◆ MAX_DIMENSIONS

◆ PYGPU_BUFFER_PROTOCOL

#define PYGPU_BUFFER_PROTOCOL

Definition at line 30 of file gpu_py_buffer.cc.

Function Documentation

◆ BPyGPU_Buffer_CreatePyObject()

BPyGPUBuffer * BPyGPU_Buffer_CreatePyObject ( int format,
const Py_ssize_t * shape,
int shape_len,
void * buffer )
nodiscard

Create a buffer object

Parameters
shapeAn array of shape_len integers representing the size of each dimension.
bufferWhen not NULL holds a contiguous buffer with the correct format from which the buffer will be initialized

Definition at line 758 of file gpu_py_buffer.cc.

References MEM_callocN(), pygpu_buffer_calc_size(), pygpu_buffer_make_from_data(), and size().

Referenced by pygpu_buffer__tp_new(), pygpu_framebuffer_read_color(), pygpu_framebuffer_read_depth(), and pygpu_texture_read().

◆ bpygpu_Buffer_size()

◆ PyDoc_STRVAR()

PyDoc_STRVAR ( pygpu_buffer__tp_doc ,
".. class:: Buffer(format, dimensions, data)\n" "\n" " For Python access to GPU functions requiring a pointer.\n" "\n" " :arg format: Format type to interpret the buffer.\n" " Possible values are ``FLOAT`` ,
``INT`` ,
``UINT`` ,
``UBYTE`` ,
``UINT_24_8`` &" "``10_11_11_REV``.\n" " ``UINT_24_8`` is deprecated,
use ``FLOAT`` instead.\n" " :type format:str\n" " :arg dimensions:Array describing the dimensions.\n" " :type dimensions:int\n" " :arg data:Optional data array.\n" " :type data:Buffer|Sequence|Sequence\n" [float][int] )

◆ pygpu_buffer__bf_getbuffer()

int pygpu_buffer__bf_getbuffer ( BPyGPUBuffer * self,
Py_buffer * view,
int flags )
static

◆ pygpu_buffer__bf_releasebuffer()

void pygpu_buffer__bf_releasebuffer ( PyObject * ,
Py_buffer * view )
static

Definition at line 662 of file gpu_py_buffer.cc.

References MEM_SAFE_FREE, and view.

◆ pygpu_buffer__mp_ass_subscript()

int pygpu_buffer__mp_ass_subscript ( BPyGPUBuffer * self,
PyObject * item,
PyObject * value )
static

Definition at line 530 of file gpu_py_buffer.cc.

References i, pygpu_buffer__sq_ass_item(), pygpu_buffer_ass_slice(), self, and step.

◆ pygpu_buffer__mp_subscript()

PyObject * pygpu_buffer__mp_subscript ( BPyGPUBuffer * self,
PyObject * item )
static

Definition at line 494 of file gpu_py_buffer.cc.

References i, pygpu_buffer__sq_item(), pygpu_buffer_slice(), self, and step.

◆ pygpu_buffer__sq_ass_item()

int pygpu_buffer__sq_ass_item ( BPyGPUBuffer * self,
Py_ssize_t i,
PyObject * v )
static

◆ pygpu_buffer__sq_item()

◆ pygpu_buffer__sq_length()

Py_ssize_t pygpu_buffer__sq_length ( BPyGPUBuffer * self)
static

Definition at line 437 of file gpu_py_buffer.cc.

References self.

◆ pygpu_buffer__tp_clear()

int pygpu_buffer__tp_clear ( BPyGPUBuffer * self)
static

Definition at line 283 of file gpu_py_buffer.cc.

References self.

◆ pygpu_buffer__tp_dealloc()

void pygpu_buffer__tp_dealloc ( BPyGPUBuffer * self)
static

Definition at line 292 of file gpu_py_buffer.cc.

References MEM_freeN(), and self.

◆ pygpu_buffer__tp_is_gc()

int pygpu_buffer__tp_is_gc ( BPyGPUBuffer * self)
static

Definition at line 430 of file gpu_py_buffer.cc.

References self.

◆ pygpu_buffer__tp_new()

◆ pygpu_buffer__tp_repr()

PyObject * pygpu_buffer__tp_repr ( BPyGPUBuffer * self)
static

◆ pygpu_buffer__tp_traverse()

int pygpu_buffer__tp_traverse ( BPyGPUBuffer * self,
visitproc visit,
void * arg )
static

Definition at line 277 of file gpu_py_buffer.cc.

References self.

◆ pygpu_buffer_ass_slice()

int pygpu_buffer_ass_slice ( BPyGPUBuffer * self,
Py_ssize_t begin,
Py_ssize_t end,
PyObject * seq )
static

◆ pygpu_buffer_calc_size()

size_t pygpu_buffer_calc_size ( const int format,
const int shape_len,
const Py_ssize_t * shape )
static

◆ pygpu_buffer_dimensions_get()

PyObject * pygpu_buffer_dimensions_get ( BPyGPUBuffer * self,
void *  )
static

Definition at line 242 of file gpu_py_buffer.cc.

References i, and self.

◆ pygpu_buffer_dimensions_set()

int pygpu_buffer_dimensions_set ( BPyGPUBuffer * self,
PyObject * value,
void *  )
static

◆ pygpu_buffer_dimensions_tot_elem()

Py_ssize_t pygpu_buffer_dimensions_tot_elem ( const Py_ssize_t * shape,
Py_ssize_t shape_len )
static

Definition at line 37 of file gpu_py_buffer.cc.

References i.

Referenced by pygpu_buffer_calc_size(), and pygpu_buffer_dimensions_tot_len_compare().

◆ pygpu_buffer_dimensions_tot_len_compare()

bool pygpu_buffer_dimensions_tot_len_compare ( const Py_ssize_t * shape_a,
const Py_ssize_t shape_a_len,
const Py_ssize_t * shape_b,
const Py_ssize_t shape_b_len )
static

◆ pygpu_buffer_formatstr()

const char * pygpu_buffer_formatstr ( eGPUDataFormat data_format)
static

◆ pygpu_buffer_make_from_data()

BPyGPUBuffer * pygpu_buffer_make_from_data ( PyObject * parent,
const eGPUDataFormat format,
const int shape_len,
const Py_ssize_t * shape,
void * buf )
static

◆ pygpu_buffer_pyobj_as_shape()

bool pygpu_buffer_pyobj_as_shape ( PyObject * shape_obj,
Py_ssize_t r_shape[MAX_DIMENSIONS],
Py_ssize_t * r_shape_len )
static

Definition at line 62 of file gpu_py_buffer.cc.

References i, MAX_DIMENSIONS, Py_DECREF(), and STRINGIFY.

Referenced by pygpu_buffer__tp_new(), and pygpu_buffer_dimensions_set().

◆ pygpu_buffer_slice()

PyObject * pygpu_buffer_slice ( BPyGPUBuffer * self,
Py_ssize_t begin,
Py_ssize_t end )
static

Definition at line 442 of file gpu_py_buffer.cc.

References begin(), count, pygpu_buffer__sq_item(), and self.

Referenced by pygpu_buffer__mp_subscript().

◆ pygpu_buffer_strides_calc()

void pygpu_buffer_strides_calc ( const eGPUDataFormat format,
const int shape_len,
const Py_ssize_t * shape,
Py_ssize_t * r_strides )
static

Definition at line 617 of file gpu_py_buffer.cc.

References GPU_texture_dataformat_size(), and i.

Referenced by pygpu_buffer__bf_getbuffer().

◆ pygpu_buffer_to_list()

PyObject * pygpu_buffer_to_list ( BPyGPUBuffer * self)
static

Definition at line 206 of file gpu_py_buffer.cc.

References i, len, pygpu_buffer__sq_item(), and self.

Referenced by pygpu_buffer_to_list_recursive().

◆ pygpu_buffer_to_list_recursive()

PyObject * pygpu_buffer_to_list_recursive ( BPyGPUBuffer * self)
static

Variable Documentation

◆ BPyGPU_BufferType

◆ pygpu_buffer__tp_as_buffer

PyBufferProcs pygpu_buffer__tp_as_buffer
static
Initial value:
= {
(releasebufferproc)pygpu_buffer__bf_releasebuffer,
}
static void pygpu_buffer__bf_releasebuffer(PyObject *, Py_buffer *view)
static int pygpu_buffer__bf_getbuffer(BPyGPUBuffer *self, Py_buffer *view, int flags)

Definition at line 667 of file gpu_py_buffer.cc.

◆ pygpu_buffer__tp_as_mapping

PyMappingMethods pygpu_buffer__tp_as_mapping
static
Initial value:
= {
}
static Py_ssize_t pygpu_buffer__sq_length(BPyGPUBuffer *self)
static PyObject * pygpu_buffer__mp_subscript(BPyGPUBuffer *self, PyObject *item)
static int pygpu_buffer__mp_ass_subscript(BPyGPUBuffer *self, PyObject *item, PyObject *value)

Definition at line 610 of file gpu_py_buffer.cc.

◆ pygpu_buffer__tp_as_sequence

PySequenceMethods pygpu_buffer__tp_as_sequence
static
Initial value:
= {
nullptr,
nullptr,
(ssizeargfunc)pygpu_buffer__sq_item,
nullptr,
(ssizeobjargproc)pygpu_buffer__sq_ass_item,
nullptr,
nullptr,
nullptr,
nullptr,
}
static PyObject * pygpu_buffer__sq_item(BPyGPUBuffer *self, Py_ssize_t i)
static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, Py_ssize_t i, PyObject *v)

Definition at line 597 of file gpu_py_buffer.cc.

◆ pygpu_buffer__tp_methods

PyMethodDef pygpu_buffer__tp_methods[]
static
Initial value:
= {
{"to_list",
METH_NOARGS,
"return the buffer as a list"},
{nullptr, nullptr, 0, nullptr},
}
static PyObject * pygpu_buffer_to_list_recursive(BPyGPUBuffer *self)

Definition at line 572 of file gpu_py_buffer.cc.

◆ pygpu_buffer_getseters

PyGetSetDef pygpu_buffer_getseters[]
static
Initial value:
= {
{"dimensions",
nullptr,
nullptr},
{nullptr, nullptr, nullptr, nullptr, nullptr},
}
static int pygpu_buffer_dimensions_set(BPyGPUBuffer *self, PyObject *value, void *)
static PyObject * pygpu_buffer_dimensions_get(BPyGPUBuffer *self, void *)

Definition at line 588 of file gpu_py_buffer.cc.