blender/intern/cycles/util/implicit_sharing.cpp
Hans Goudey 197b0c2b41 Cycles: Use implicit sharing to avoid copying some attributes
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
2026-04-01 15:25:01 +02:00

18 lines
503 B
C++

/* SPDX-FileCopyrightText: 2026 Blender Authors
*
* SPDX-License-Identifier: Apache-2.0 */
#include "util/implicit_sharing.h"
CCL_NAMESPACE_BEGIN
ImplicitSharingUserAddFn g_implicit_sharing_user_add_fn = nullptr;
ImplicitSharingUserAddFn g_implicit_sharing_user_remove_fn = nullptr;
void implicit_sharing_init(ImplicitSharingUserAddFn add_fn, ImplicitSharingUserRemoveFn remove_fn)
{
g_implicit_sharing_user_add_fn = add_fn;
g_implicit_sharing_user_remove_fn = remove_fn;
}
CCL_NAMESPACE_END