This commit extends Cycles to allow using Attribute array implicit
sharing info from Blender. This is used to avoid a copy of the evaluated
attribute arrays before they're added to the final buffer for their type.
We can only do this when the attribute type layout match between Blender
and Cycles, which means float and float2 attributes can skip the copy on
the point or curve domain, and also the face corner and face domains in
the adaptive subdivision case.
The buffer stored in attributes is now a raw pointer rather than a
std::vector. As a side effect, resizing the attribute no longer
zero-initializes new values. That was wasted work in practice anyway.
Unfortunately float color and float4 attributes are not covered here
because Blender does not allocate these types with the necessary
alignment. That can be addressed later; I've started it here: !156035.
Besides that, there are some other next steps:
- Use implicit sharing to avoid copying data that Cycles doesn't process
as attributes, like topology arrays for adaptive subdivision (and
maybe investigate removing padding so that float3 can be shared too).
- Add some sort of global cache to avoid creating multiple Cycles arrays
for attributes that aren't layout compatible or are on non-matching
domains.
- Add some way to delay the attribute type conversion and flattening
until constructing the final arrays, to benefit non-layout-compatible
types.
- Looking much further into the future, completely avoid the "large
buffer per data type" system that Cycles uses to hold geometry data
(just mentioning this because "completely avoid all copies of Blender
data" is an interesting prospect).
Pull Request: https://projects.blender.org/blender/blender/pulls/155970