Blender  V2.93
gpu_py_buffer.c File Reference
#include <Python.h>
#include "BLI_utildefines.h"
#include "MEM_guardedalloc.h"
#include "GPU_texture.h"
#include "../generic/py_capi_utils.h"
#include "gpu_py.h"
#include "gpu_py_buffer.h"

Go to the source code of this file.

Functions

Utility Functions
static bool pygpu_buffer_dimensions_compare (int ndim, const Py_ssize_t *shape_a, const Py_ssize_t *shape_b)
 
static const char * pygpu_buffer_formatstr (eGPUDataFormat data_format)
 

BPyGPUBuffer API

#define MAX_DIMENSIONS   64
 
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
 
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, int i)
 
static PyObject * pygpu_buffer_to_list (BPyGPUBuffer *self)
 
static PyObject * pygpu_buffer_to_list_recursive (BPyGPUBuffer *self)
 
static PyObject * pygpu_buffer_dimensions (BPyGPUBuffer *self, void *UNUSED(arg))
 
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, int 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 *UNUSED(type), PyObject *args, PyObject *kwds)
 
static int 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)
 
 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` and `10_11_11_REV`.\n" " :type type: str\n" " :arg dimensions: Array describing the dimensions.\n" " :type dimensions: int\n" " :arg data: Optional data array.\n" " :type data: sequence\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.

Definition in file gpu_py_buffer.c.

Macro Definition Documentation

◆ MAX_DIMENSIONS

#define MAX_DIMENSIONS   64

Definition at line 283 of file gpu_py_buffer.c.

Function Documentation

◆ BPyGPU_Buffer_CreatePyObject()

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

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 649 of file gpu_py_buffer.c.

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

Referenced by pygpu_buffer__tp_new(), and pygpu_texture_read().

◆ bpygpu_Buffer_size()

size_t bpygpu_Buffer_size ( BPyGPUBuffer buffer)

Definition at line 637 of file gpu_py_buffer.c.

References buffer, and pygpu_buffer_calc_size().

Referenced by pygpu_texture__tp_new(), and pygpu_uniformbuffer__tp_new().

◆ 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` and `10_11_11_REV`.\n" " :type type:str\n" " :arg dimensions:Array describing the dimensions.\n" " :type dimensions:int\n" " :arg data:Optional data array.\n" " :type data:sequence\n"   
)

◆ pygpu_buffer__mp_ass_subscript()

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

Definition at line 480 of file gpu_py_buffer.c.

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

◆ pygpu_buffer__mp_subscript()

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

Definition at line 444 of file gpu_py_buffer.c.

References NULL, pygpu_buffer__sq_item(), pygpu_buffer_slice(), and self.

◆ pygpu_buffer__sq_ass_item()

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

◆ pygpu_buffer__sq_item()

static PyObject* pygpu_buffer__sq_item ( BPyGPUBuffer self,
int  i 
)
static

◆ pygpu_buffer__sq_length()

static int pygpu_buffer__sq_length ( BPyGPUBuffer self)
static

Definition at line 381 of file gpu_py_buffer.c.

◆ pygpu_buffer__tp_clear()

static int pygpu_buffer__tp_clear ( BPyGPUBuffer self)
static

Definition at line 195 of file gpu_py_buffer.c.

References self.

◆ pygpu_buffer__tp_dealloc()

static void pygpu_buffer__tp_dealloc ( BPyGPUBuffer self)
static

Definition at line 201 of file gpu_py_buffer.c.

References MEM_freeN, and self.

◆ pygpu_buffer__tp_new()

static PyObject* pygpu_buffer__tp_new ( PyTypeObject *  UNUSEDtype,
PyObject *  args,
PyObject *  kwds 
)
static

◆ pygpu_buffer__tp_repr()

static PyObject* pygpu_buffer__tp_repr ( BPyGPUBuffer self)
static

◆ pygpu_buffer__tp_traverse()

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

Definition at line 189 of file gpu_py_buffer.c.

References self.

◆ pygpu_buffer_ass_slice()

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

◆ pygpu_buffer_calc_size()

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

Definition at line 624 of file gpu_py_buffer.c.

References GPU_texture_dataformat_size().

Referenced by BPyGPU_Buffer_CreatePyObject(), and bpygpu_Buffer_size().

◆ pygpu_buffer_dimensions()

static PyObject* pygpu_buffer_dimensions ( BPyGPUBuffer self,
void *  UNUSEDarg 
)
static

Definition at line 177 of file gpu_py_buffer.c.

References self.

◆ pygpu_buffer_dimensions_compare()

static bool pygpu_buffer_dimensions_compare ( int  ndim,
const Py_ssize_t *  shape_a,
const Py_ssize_t *  shape_b 
)
static

Definition at line 46 of file gpu_py_buffer.c.

Referenced by pygpu_buffer__tp_new().

◆ pygpu_buffer_formatstr()

static const char* pygpu_buffer_formatstr ( eGPUDataFormat  data_format)
static

◆ pygpu_buffer_make_from_data()

static 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_slice()

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

Definition at line 386 of file gpu_py_buffer.c.

References count, pygpu_buffer__sq_item(), and self.

Referenced by pygpu_buffer__mp_subscript().

◆ pygpu_buffer_to_list()

static PyObject* pygpu_buffer_to_list ( BPyGPUBuffer self)
static

Definition at line 141 of file gpu_py_buffer.c.

References len, and pygpu_buffer__sq_item().

Referenced by pygpu_buffer_to_list_recursive().

◆ pygpu_buffer_to_list_recursive()

static PyObject* pygpu_buffer_to_list_recursive ( BPyGPUBuffer self)
static

Definition at line 153 of file gpu_py_buffer.c.

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

Referenced by pygpu_buffer__tp_repr().

Variable Documentation

◆ BPyGPU_BufferType

PyTypeObject BPyGPU_BufferType
Initial value:
= {
PyVarObject_HEAD_INIT(NULL, 0).tp_name = "Buffer",
.tp_basicsize = sizeof(BPyGPUBuffer),
.tp_dealloc = (destructor)pygpu_buffer__tp_dealloc,
.tp_repr = (reprfunc)pygpu_buffer__tp_repr,
.tp_as_sequence = &pygpu_buffer__tp_as_sequence,
.tp_as_mapping = &pygpu_buffer__tp_as_mapping,
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_HAVE_GC,
.tp_doc = pygpu_buffer__tp_doc,
.tp_traverse = (traverseproc)pygpu_buffer__tp_traverse,
.tp_clear = (inquiry)pygpu_buffer__tp_clear,
.tp_methods = pygpu_buffer__tp_methods,
.tp_getset = pygpu_buffer_getseters,
}
static int pygpu_buffer__tp_traverse(BPyGPUBuffer *self, visitproc visit, void *arg)
static PyMappingMethods pygpu_buffer__tp_as_mapping
static PySequenceMethods pygpu_buffer__tp_as_sequence
static PyObject * pygpu_buffer__tp_new(PyTypeObject *UNUSED(type), PyObject *args, PyObject *kwds)
static PyObject * pygpu_buffer__tp_repr(BPyGPUBuffer *self)
static PyMethodDef pygpu_buffer__tp_methods[]
static PyGetSetDef pygpu_buffer_getseters[]
static void pygpu_buffer__tp_dealloc(BPyGPUBuffer *self)
static int pygpu_buffer__tp_clear(BPyGPUBuffer *self)
struct BPyGPUBuffer BPyGPUBuffer

Definition at line 605 of file gpu_py_buffer.c.

Referenced by bpygpu_types_init(), pygpu_buffer_make_from_data(), pygpu_texture__tp_new(), and pygpu_uniformbuffer__tp_new().

◆ pygpu_buffer__tp_as_mapping

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

Definition at line 538 of file gpu_py_buffer.c.

◆ pygpu_buffer__tp_as_sequence

PySequenceMethods pygpu_buffer__tp_as_sequence
static
Initial value:
= {
(binaryfunc)NULL,
(ssizeargfunc)NULL,
(ssizeargfunc)pygpu_buffer__sq_item,
(ssizessizeargfunc)NULL,
(ssizeobjargproc)pygpu_buffer__sq_ass_item,
(ssizessizeobjargproc)NULL,
(objobjproc)NULL,
(binaryfunc)NULL,
(ssizeargfunc)NULL,
}
static PyObject * pygpu_buffer__sq_item(BPyGPUBuffer *self, int i)
static int pygpu_buffer__sq_ass_item(BPyGPUBuffer *self, int i, PyObject *v)

Definition at line 525 of file gpu_py_buffer.c.

◆ pygpu_buffer__tp_methods

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

Definition at line 512 of file gpu_py_buffer.c.

◆ pygpu_buffer_getseters

PyGetSetDef pygpu_buffer_getseters[]
static
Initial value:
= {
{"dimensions", (getter)pygpu_buffer_dimensions, NULL, NULL, NULL},
}
static PyObject * pygpu_buffer_dimensions(BPyGPUBuffer *self, void *UNUSED(arg))

Definition at line 520 of file gpu_py_buffer.c.