40 if (bpygpu_ssbo->
ssbo ==
nullptr) [[unlikely]] {
41 PyErr_SetString(PyExc_ReferenceError,
43 "GPU storage buffer was freed, no further access is valid");
46 "GPU storage buffer: internal error");
53#define BPYGPU_STORAGEBUF_CHECK_OBJ(bpygpu) \
55 if (pygpu_storagebuffer_valid_check(bpygpu) == -1) [[unlikely]] { \
73 const size_t size = size_t(pybuffer.len);
75 if (size == padded_size) {
78 r_padded_data.
resize(padded_size, 0);
79 memcpy(r_padded_data.
data(), pybuffer.buf, size);
80 return r_padded_data.
data();
96 PyObject *pybuffer_obj;
97 char err_out[256] =
"unknown error. See console";
99 static const char *_keywords[] = {
"data",
nullptr};
100 static _PyArg_Parser _parser = {
102 ":GPUStorageBuf.__new__",
106 if (!_PyArg_ParseTupleAndKeywordsFast(args, kwds, &_parser, &pybuffer_obj)) {
115 if (PyObject_GetBuffer(pybuffer_obj, &pybuffer, PyBUF_SIMPLE) == -1) {
125 "python_storagebuffer");
126 PyBuffer_Release(&pybuffer);
129 if (ssbo ==
nullptr) {
130 PyErr_Format(PyExc_RuntimeError,
"GPUStorageBuf.__new__(...) failed with '%s'", err_out);
139 pygpu_storagebuffer_update_doc,
140 ".. method:: update(data)\n"
142 " Update the data of the storage buffer object.\n"
144 " :param data: Data to fill the buffer.\n"
145 " :type data: Buffer\n");
151 if (PyObject_GetBuffer(obj, &pybuffer, PyBUF_SIMPLE) == -1) {
160 PyErr_Format(PyExc_ValueError,
161 "GPUStorageBuf.update(): expected a buffer of size %zu "
162 "(once padded to a multiple of 16 bytes), got %zu",
164 size_t(pybuffer.len));
165 PyBuffer_Release(&pybuffer);
171 PyBuffer_Release(&pybuffer);
177 pygpu_storagebuffer_clear_to_zero_doc,
178 ".. method:: clear_to_zero()\n"
180 " Clear the storage buffer data to zero.\n");
191 pygpu_storagebuffer_read_doc,
192 ".. method:: read()\n"
194 " Read back the contents of the storage buffer.\n"
195 " This waits until all GPU operations are finished, performing the necessary "
198 " :return: The Buffer with the read data.\n"
199 " :rtype: :class:`gpu.types.Buffer`\n");
208 const Py_ssize_t shape = Py_ssize_t(size);
209 return reinterpret_cast<PyObject *
>(
213#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
216 pygpu_storagebuffer_free_doc,
217 ".. method:: free()\n"
219 " Free the storage buffer object.\n"
220 " The storage buffer object will no longer be accessible.\n");
221static PyObject *pygpu_storagebuffer_free(BPyGPUStorageBuf *self)
226 self->ssbo =
nullptr;
236 Py_TYPE(self)->tp_free(
reinterpret_cast<PyObject *
>(self));
240 {
nullptr,
nullptr,
nullptr,
nullptr,
nullptr}
247 pygpu_storagebuffer_update_doc},
251 pygpu_storagebuffer_clear_to_zero_doc},
255 pygpu_storagebuffer_read_doc},
256#ifdef BPYGPU_USE_GPUOBJ_FREE_METHOD
257 {
"free", (PyCFunction)pygpu_storagebuffer_free, METH_NOARGS, pygpu_storagebuffer_free_doc},
259 {
nullptr,
nullptr, 0,
nullptr},
264 pygpu_storagebuffer__tp_doc,
265 ".. class:: GPUStorageBuf\n"
267 " This object gives access to storage buffers.\n"
269 " .. method:: __init__(data)\n"
271 " :param data: Data to fill the buffer.\n"
272 " :type data: Buffer\n");
274 PyVarObject_HEAD_INIT(
nullptr, 0)
294 pygpu_storagebuffer__tp_doc,
338 return reinterpret_cast<PyObject *
>(self);
343#undef BPYGPU_STORAGEBUF_CHECK_OBJ
#define STRNCPY_UTF8(dst, src)
PyDoc_STRVAR(FalseBP1D___doc__, "Class hierarchy: :class:`freestyle.types.BinaryPredicate1D` > :class:`FalseBP1D`\n" "\n" ".. method:: __call__(inter1, inter2)\n" "\n" " Always returns false.\n" "\n" " :param inter1: The first Interface1D object.\n" " :type inter1: :class:`freestyle.types.Interface1D`\n" " :param inter2: The second Interface1D object.\n" " :type inter2: :class:`freestyle.types.Interface1D`\n" " :return: False.\n" " :rtype: bool\n")
Read Blender memory allocation and freeing.
void resize(const int64_t new_size)
#define BPYGPU_IS_INIT_OR_ERROR_OBJ
#define BPYGPU_USE_GPUOBJ_FREE_METHOD
#define BPYGPU_STORAGEBUF_CHECK_OBJ(bpygpu)
void * MEM_new_uninitialized(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void GPU_storagebuf_update(gpu::StorageBuf *ssbo, const void *data)
void GPU_storagebuf_clear_to_zero(gpu::StorageBuf *ssbo)
static PyObject * pygpu_storagebuffer__tp_new(PyTypeObject *, PyObject *args, PyObject *kwds)
gpu::StorageBuf * GPU_storagebuf_create_ex(size_t size, const void *data, GPUUsageType usage, const char *name)
PyDoc_STRVAR(bpy_bm_new_doc, ".. function:: new(*, use_operators=True)\n" "\n" " :param use_operators: Support calling operators in :mod:`bmesh.ops` (uses some " "extra memory per vert/edge/face).\n" " :type use_operators: bool\n" " :return: Return a new, empty BMesh.\n" " :rtype: :class:`bmesh.types.BMesh`\n")
static int pygpu_storagebuffer_valid_check(BPyGPUStorageBuf *bpygpu_ssbo)
static size_t pygpu_storagebuffer_padded_size(const Py_buffer &pybuffer)
MINLINE uint64_t ceil_to_multiple_ul(uint64_t a, uint64_t b)
BMesh const char void * data
PyTypeObject BPyGPUStorageBuf_Type
size_t GPU_storagebuf_usage_size_get(const gpu::StorageBuf *ssbo)
static PyGetSetDef pygpu_storagebuffer__tp_getseters[]
static PyObject * pygpu_storagebuffer_update(BPyGPUStorageBuf *self, PyObject *obj)
BPyGPUBuffer * BPyGPU_Buffer_CreatePyObject(const int format, const Py_ssize_t *shape, const int shape_len, void *buffer)
static PyObject * pygpu_storagebuffer_clear_to_zero(BPyGPUStorageBuf *self)
static PyObject * pygpu_storagebuffer_read(BPyGPUStorageBuf *self)
static const void * pygpu_storagebuffer_data_padded(const Py_buffer &pybuffer, Vector< uchar > &r_padded_data)
static void BPyGPUStorageBuf__tp_dealloc(BPyGPUStorageBuf *self)
void GPU_storagebuf_free(gpu::StorageBuf *ssbo)
PyObject * BPyGPUStorageBuf_CreatePyObject(gpu::StorageBuf *ssbo)
static PyMethodDef pygpu_storagebuffer__tp_methods[]
GPUContext * GPU_context_active_get()
void GPU_storagebuf_read(gpu::StorageBuf *ssbo, void *data)
header-only compatibility defines.
PyObject_HEAD gpu::StorageBuf * ssbo