Page MenuHome

Proposal, RNA API direct memory access for arrays via buffer protocol
Open, NormalPublic

Description

While we already have some lower level interfaces to RNA (RNA_property_collection_raw_set),
an intermediate array is still needed.

This proposal is to have the ability to expose the RNA arrays as a buffer with an optional stride.

This can be used by Cycles to copy geometry directly, and by Python for accessing pixels for example.

https://docs.python.org/3/c-api/buffer.html#c.Py_buffer

Note that the length of the array is set by the RNA API which also sets the stride and data format, so this is safer than simply exposing raw pointers.

The C++ API can have a similar interface to The python buffers.

For the initial version of this we could have it read-only, to test it out and avoid developers bypassing RNA and writing bad data into the array.
Later on we can investigate making it writable too.

See conversation on this topic

Details

Type
Design

Event Timeline

Campbell Barton (campbellbarton) triaged this task as Normal priority.

There's RNA_property_collection_raw_array for this, which if it succeeds means it's safe to read and write values I think.

How would we handle cases where the underlying data has a different type than exposed through the API, like MVert.no? Would that affect the public API, or would we hide it by copying data into an array that can be accessed this way?

And how to solve with an array of pointers? A stride would not suit those cases. For example, the looptris array of the BMEditMesh structure is an array of pointers (the content and not the offset would be most desirable).

@Brecht Van Lommel (brecht), good point, either we couldnt access these or the underlying type would need to be exposed. Which isn't nice but there are very few places where this happens (in fact vertex normal is the only one I can think of off hand, vertex color too I suppose but exposing it as uchar isn't so unreasonable since it's a common format for RGBA color).

@Germano Cavalcante (mano-wii), this would be used only for arrays. BMesh woudn't work in this case.