Skip to content

Commit

Permalink
Merge remote-tracking branch 'b/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
youle31 committed Mar 7, 2025
2 parents e524366 + 8076fa1 commit ed7d720
Show file tree
Hide file tree
Showing 106 changed files with 981 additions and 946 deletions.
2 changes: 1 addition & 1 deletion intern/cycles/bvh/binning.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ BVHObjectBinning::BVHObjectBinning(const BVHRange &job,

/* compute number of bins to use and precompute scaling factor for binning */
num_bins = min(size_t(MAX_BINS), size_t(4.0f + 0.05f * size()));
scale = safe_divide(cent_bounds_.size(), make_float3((float)num_bins));
scale = safe_divide(make_float3((float)num_bins), cent_bounds_.size());

/* initialize binning counter and bounds */
BoundBox bin_bounds[MAX_BINS][4]; /* bounds for every bin in every dimension */
Expand Down
10 changes: 8 additions & 2 deletions intern/cycles/kernel/integrator/shadow_state_template.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,10 @@ KERNEL_STRUCT_MEMBER(shadow_path,
/* Ratio of throughput to distinguish diffuse / glossy / transmission render passes. */
KERNEL_STRUCT_MEMBER(shadow_path, PackedSpectrum, pass_diffuse_weight, KERNEL_FEATURE_LIGHT_PASSES)
KERNEL_STRUCT_MEMBER(shadow_path, PackedSpectrum, pass_glossy_weight, KERNEL_FEATURE_LIGHT_PASSES)
/* Number of intersections found by ray-tracing. */
/* Number of intersections found by ray-tracing.
* Note that this is the total number of intersections for the shadow ray.
* The number of recorded intersections in the shadow_isect array might be different as it contains
* up INTEGRATOR_SHADOW_ISECT_SIZE closest intersections. */
KERNEL_STRUCT_MEMBER(shadow_path, uint16_t, num_hits, KERNEL_FEATURE_PATH_TRACING)
/* Light group. */
KERNEL_STRUCT_MEMBER(shadow_path, uint8_t, lightgroup, KERNEL_FEATURE_PATH_TRACING)
Expand All @@ -63,11 +66,14 @@ KERNEL_STRUCT_MEMBER_PACKED(shadow_ray, float, tmin, KERNEL_FEATURE_PATH_TRACING
KERNEL_STRUCT_MEMBER_PACKED(shadow_ray, float, tmax, KERNEL_FEATURE_PATH_TRACING)
KERNEL_STRUCT_MEMBER_PACKED(shadow_ray, float, time, KERNEL_FEATURE_PATH_TRACING)
KERNEL_STRUCT_MEMBER_PACKED(shadow_ray, float, dP, KERNEL_FEATURE_PATH_TRACING)
KERNEL_STRUCT_MEMBER_PACKED(shadow_ray, int, self_light_object, KERNEL_FEATURE_PATH_TRACING)
KERNEL_STRUCT_MEMBER_PACKED(shadow_ray, int, self_light_prim, KERNEL_FEATURE_PATH_TRACING)
KERNEL_STRUCT_END(shadow_ray)

/*********************** Shadow Intersection result **************************/

/* Result from scene intersection. */
/* Result from scene intersection.
* It contains INTEGRATOR_SHADOW_ISECT_SIZE closest intersections of the shadow ray. */
KERNEL_STRUCT_BEGIN(shadow_isect)
KERNEL_STRUCT_ARRAY_MEMBER(shadow_isect, float, t, KERNEL_FEATURE_PATH_TRACING)
KERNEL_STRUCT_ARRAY_MEMBER(shadow_isect, float, u, KERNEL_FEATURE_PATH_TRACING)
Expand Down
51 changes: 39 additions & 12 deletions intern/cycles/kernel/integrator/state_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,23 +98,50 @@ ccl_device_forceinline void integrator_state_read_shadow_ray(ConstIntegratorShad
ccl_device_forceinline void integrator_state_write_shadow_ray_self(
KernelGlobals kg, IntegratorShadowState state, const ccl_private Ray *ccl_restrict ray)
{
/* Save memory by storing the light and object indices in the shadow_isect. */
/* TODO(sergey): This optimization does not work on GPU where multiple iterations of intersection
* is needed if there are more than 4 transparent intersections. The indices starts to conflict
* with each other. */
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, 0, object) = ray->self.object;
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, 0, prim) = ray->self.prim;
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, 1, object) = ray->self.light_object;
INTEGRATOR_STATE_ARRAY_WRITE(state, shadow_isect, 1, prim) = ray->self.light_prim;
/* There is a bit of implicit knowledge about the way how the kernels are invoked and what the
* state is actually storing. Special logic here is needed because the intersect_shadow kernel
* might be called multiple times. This happens when the total number of intersections by the
* ray (shadow_path.num_hits) exceeds INTEGRATOR_SHADOW_ISECT_SIZE.
*
* Writing of the shadow_ray.self to the state happens only during the shadow ray setup, and
* the shadow_isect array gets overwritten by the intersect_shadow kernel. It is important to
* preserve the exact values of the light_object and light_prim for all invocations of the
* intersect_shadow kernel. Hence they are written to dedicated fields in the state.
*
* The self.object and self.prim are kept at the latest handled intersection: during shadow path
* branch-off it matches the main ray.self. For the consecutive calls of the intersect_shadow
* kernels it comes from the furthest intersection (the last element of the shadow_isect). So we
* use INTEGRATOR_SHADOW_ISECT_SIZE - 1 index for both writing and reading. This utilizes
* knowledge that intersect_shadow kernel is only called for either initial intersection, or when
* the number of ray intersections exceeds the shadow_isect size.
*
* This should help avoiding situations when the same intersection is recorded multiple times
* throughout separate invocations of the intersect_shadow kernel. However, it is still not
* fully reliable as there might be more than INTEGRATOR_SHADOW_ISECT_SIZE intersections at the
* same ray->t. There is no reliable way to deal with such situation, and offsetting ray from
* the shade_shadow kernel which will avoid potential false-positive detection of light being
* fully blocked at the expense of potentially ignoring some intersections. If the offset is
* used then preserving self.object and self.prim might not be as useful, but it definitely does
* not harm. */

INTEGRATOR_STATE_ARRAY_WRITE(
state, shadow_isect, INTEGRATOR_SHADOW_ISECT_SIZE - 1, object) = ray->self.object;
INTEGRATOR_STATE_ARRAY_WRITE(
state, shadow_isect, INTEGRATOR_SHADOW_ISECT_SIZE - 1, prim) = ray->self.prim;

INTEGRATOR_STATE_WRITE(state, shadow_ray, self_light_object) = ray->self.light_object;
INTEGRATOR_STATE_WRITE(state, shadow_ray, self_light_prim) = ray->self.light_prim;
}

ccl_device_forceinline void integrator_state_read_shadow_ray_self(
KernelGlobals kg, ConstIntegratorShadowState state, ccl_private Ray *ccl_restrict ray)
{
ray->self.object = INTEGRATOR_STATE_ARRAY(state, shadow_isect, 0, object);
ray->self.prim = INTEGRATOR_STATE_ARRAY(state, shadow_isect, 0, prim);
ray->self.light_object = INTEGRATOR_STATE_ARRAY(state, shadow_isect, 1, object);
ray->self.light_prim = INTEGRATOR_STATE_ARRAY(state, shadow_isect, 1, prim);
ray->self.object = INTEGRATOR_STATE_ARRAY(
state, shadow_isect, INTEGRATOR_SHADOW_ISECT_SIZE - 1, object);
ray->self.prim = INTEGRATOR_STATE_ARRAY(
state, shadow_isect, INTEGRATOR_SHADOW_ISECT_SIZE - 1, prim);
ray->self.light_object = INTEGRATOR_STATE(state, shadow_ray, self_light_object);
ray->self.light_prim = INTEGRATOR_STATE(state, shadow_ray, self_light_prim);
}

/* Intersection */
Expand Down
12 changes: 7 additions & 5 deletions scripts/addons_core/rigify/operators/copy_mirror_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ def copy_rigify_params(from_bone: bpy.types.PoseBone, to_bone: bpy.types.PoseBon
else:
rig_type = to_bone.rigify_type = from_type

# Delete any previously-existing parameters, before copying in the new ones.
# Direct assignment to this property, as happens in the code below, is only
# possible when there is no pre-existing value. See #135233 for more info.
if 'rigify_parameters' in to_bone:
del to_bone['rigify_parameters']

from_params = from_bone.get('rigify_parameters')
if from_params and rig_type:
param_dict = property_to_python(from_params)
Expand All @@ -161,11 +167,7 @@ def copy_rigify_params(from_bone: bpy.types.PoseBone, to_bone: bpy.types.PoseBon
copy_ref_list(getattr(to_params_typed, prop_name), ref_list, mirror=True)
else:
to_bone['rigify_parameters'] = param_dict
else:
try:
del to_bone['rigify_parameters']
except KeyError:
pass

return True


Expand Down
3 changes: 1 addition & 2 deletions source/blender/animrig/intern/action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2249,8 +2249,7 @@ int Channelbag::channel_group_containing_index(const int fcurve_array_index)

bActionGroup &Channelbag::channel_group_create(StringRefNull name)
{
bActionGroup *new_group = static_cast<bActionGroup *>(
MEM_callocN(sizeof(bActionGroup), __func__));
bActionGroup *new_group = MEM_callocN<bActionGroup>(__func__);

/* Find the end fcurve index of the current channel groups, to be used as the
* start of the new channel group. */
Expand Down
6 changes: 3 additions & 3 deletions source/blender/animrig/intern/action_legacy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class ActionLegacyTest : public testing::Test {

FCurve *fcurve_add_legacy(bAction *action, const StringRefNull rna_path, const int array_index)
{
FCurve *fcurve = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), __func__));
FCurve *fcurve = MEM_callocN<FCurve>(__func__);
BKE_fcurve_rnapath_set(*fcurve, rna_path);
fcurve->array_index = array_index;
BLI_addtail(&action->curves, fcurve);
Expand All @@ -77,7 +77,7 @@ TEST_F(ActionLegacyTest, fcurves_all)
{ /* Legacy Action. */
bAction *action = create_empty_action();

FCurve *fcurve = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), __func__));
FCurve *fcurve = MEM_callocN<FCurve>(__func__);
BLI_addtail(&action->curves, fcurve);

Vector<FCurve *> fcurves_expect = {fcurve};
Expand Down Expand Up @@ -119,7 +119,7 @@ TEST_F(ActionLegacyTest, fcurves_for_action_slot)
{ /* Legacy Action. */
bAction *action = create_empty_action();

FCurve *fcurve = static_cast<FCurve *>(MEM_callocN(sizeof(FCurve), __func__));
FCurve *fcurve = MEM_callocN<FCurve>(__func__);
BLI_addtail(&action->curves, fcurve);

Vector<FCurve *> fcurves_expect = {fcurve};
Expand Down
4 changes: 2 additions & 2 deletions source/blender/animrig/intern/anim_rna.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ Vector<float> get_rna_values(PointerRNA *ptr, PropertyRNA *prop)

switch (RNA_property_type(prop)) {
case PROP_BOOLEAN: {
bool *tmp_bool = static_cast<bool *>(MEM_malloc_arrayN(length, sizeof(bool), __func__));
bool *tmp_bool = MEM_malloc_arrayN<bool>(length, __func__);
RNA_property_boolean_get_array(ptr, prop, tmp_bool);
for (int i = 0; i < length; i++) {
values.append(float(tmp_bool[i]));
Expand All @@ -39,7 +39,7 @@ Vector<float> get_rna_values(PointerRNA *ptr, PropertyRNA *prop)
break;
}
case PROP_INT: {
int *tmp_int = static_cast<int *>(MEM_malloc_arrayN(length, sizeof(int), __func__));
int *tmp_int = MEM_malloc_arrayN<int>(length, __func__);
RNA_property_int_get_array(ptr, prop, tmp_int);
for (int i = 0; i < length; i++) {
values.append(float(tmp_int[i]));
Expand Down
3 changes: 1 addition & 2 deletions source/blender/animrig/intern/bone_collections.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1399,8 +1399,7 @@ blender::Map<BoneCollection *, BoneCollection *> ANIM_bonecoll_array_copy_no_mem
BLI_assert(*bcoll_array_dst == nullptr);
BLI_assert(*bcoll_array_dst_num == 0);

*bcoll_array_dst = static_cast<BoneCollection **>(
MEM_malloc_arrayN(bcoll_array_src_num, sizeof(BoneCollection *), __func__));
*bcoll_array_dst = MEM_malloc_arrayN<BoneCollection *>(bcoll_array_src_num, __func__);
*bcoll_array_dst_num = bcoll_array_src_num;

blender::Map<BoneCollection *, BoneCollection *> bcoll_map{};
Expand Down
14 changes: 5 additions & 9 deletions source/blender/animrig/intern/fcurve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -175,8 +175,7 @@ int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
/* Keyframing modes allow not replacing the keyframe. */
else if ((flag & INSERTKEY_REPLACE) == 0) {
/* Insert new - if we're not restricted to replacing keyframes only. */
BezTriple *newb = static_cast<BezTriple *>(
MEM_callocN((fcu->totvert + 1) * sizeof(BezTriple), "beztriple"));
BezTriple *newb = MEM_calloc_arrayN<BezTriple>(fcu->totvert + 1, "beztriple");

/* Add the beztriples that should occur before the beztriple to be pasted
* (originally in fcu). */
Expand Down Expand Up @@ -210,7 +209,7 @@ int insert_bezt_fcurve(FCurve *fcu, const BezTriple *bezt, eInsertKeyFlags flag)
*/
else if ((flag & INSERTKEY_REPLACE) == 0 && (fcu->fpt == nullptr)) {
/* Create new keyframes array. */
fcu->bezt = static_cast<BezTriple *>(MEM_callocN(sizeof(BezTriple), "beztriple"));
fcu->bezt = MEM_callocN<BezTriple>("beztriple");
*(fcu->bezt) = *bezt;
fcu->totvert = 1;
}
Expand Down Expand Up @@ -555,17 +554,15 @@ void bake_fcurve(FCurve *fcu,
{
BLI_assert(step > 0);
const int sample_count = (range[1] - range[0]) / step + 1;
float *samples = static_cast<float *>(
MEM_callocN(sample_count * sizeof(float), "Channel Bake Samples"));
float *samples = MEM_calloc_arrayN<float>(size_t(sample_count), "Channel Bake Samples");
const float sample_rate = 1.0f / step;
sample_fcurve_segment(fcu, range[0], sample_rate, samples, sample_count);

if (remove_existing != BakeCurveRemove::NONE) {
remove_fcurve_key_range(fcu, range, remove_existing);
}

BezTriple *baked_keys = static_cast<BezTriple *>(
MEM_callocN(sample_count * sizeof(BezTriple), "beztriple"));
BezTriple *baked_keys = MEM_calloc_arrayN<BezTriple>(size_t(sample_count), "beztriple");

const KeyframeSettings settings = get_keyframe_settings(true);

Expand Down Expand Up @@ -636,8 +633,7 @@ void bake_fcurve_segments(FCurve *fcu)
sfra = int(floor(start->vec[1][0]));

if (range) {
value_cache = static_cast<TempFrameValCache *>(
MEM_callocN(sizeof(TempFrameValCache) * range, "IcuFrameValCache"));
value_cache = MEM_calloc_arrayN<TempFrameValCache>(size_t(range), "IcuFrameValCache");

/* Sample values. */
for (n = 1, fp = value_cache; n < range && fp; n++, fp++) {
Expand Down
6 changes: 2 additions & 4 deletions source/blender/animrig/intern/keyframing_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,7 @@ class KeyframingTest : public testing::Test {
object = BKE_object_add_only_object(bmain, OB_EMPTY, "Empty");
object_rna_pointer = RNA_id_pointer_create(&object->id);

Bone *bone = static_cast<Bone *>(MEM_mallocN(sizeof(Bone), "BONE"));
memset(bone, 0, sizeof(Bone));
Bone *bone = MEM_callocN<Bone>("BONE");
STRNCPY(bone->name, "Bone");

armature = BKE_armature_add(bmain, "Armature");
Expand Down Expand Up @@ -160,8 +159,7 @@ class KeyframingTest : public testing::Test {
*/
void ensure_action_is_legacy(bAction &action)
{
bActionGroup *new_group = static_cast<bActionGroup *>(
MEM_callocN(sizeof(bActionGroup), __func__));
bActionGroup *new_group = MEM_callocN<bActionGroup>(__func__);
STRNCPY(new_group->name, "Legacy Forcer");
BLI_addtail(&action.groups, new_group);
}
Expand Down
8 changes: 4 additions & 4 deletions source/blender/animrig/intern/pose_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,11 @@ class PoseTest : public testing::Test {
bArmature *armature = BKE_armature_add(bmain, "ArmatureA");
obj_armature_a->data = armature;

Bone *bone = static_cast<Bone *>(MEM_callocN(sizeof(Bone), "BONE"));
Bone *bone = MEM_callocN<Bone>("BONE");
STRNCPY(bone->name, "BoneA");
BLI_addtail(&armature->bonebase, bone);

bone = static_cast<Bone *>(MEM_callocN(sizeof(Bone), "BONE"));
bone = MEM_callocN<Bone>("BONE");
STRNCPY(bone->name, "BoneB");
BLI_addtail(&armature->bonebase, bone);

Expand All @@ -80,11 +80,11 @@ class PoseTest : public testing::Test {
armature = BKE_armature_add(bmain, "ArmatureB");
obj_armature_b->data = armature;

bone = static_cast<Bone *>(MEM_callocN(sizeof(Bone), "BONE"));
bone = MEM_callocN<Bone>("BONE");
STRNCPY(bone->name, "BoneA");
BLI_addtail(&armature->bonebase, bone);

bone = static_cast<Bone *>(MEM_callocN(sizeof(Bone), "BONE"));
bone = MEM_callocN<Bone>("BONE");
STRNCPY(bone->name, "BoneB");
BLI_addtail(&armature->bonebase, bone);

Expand Down
3 changes: 2 additions & 1 deletion source/blender/blenkernel/BKE_curves.hh
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ class CurvesGeometryRuntime {
* See #SharedCache comments.
*/
mutable SharedCache<Bounds<float3>> bounds_cache;
mutable SharedCache<Bounds<float3>> bounds_with_radius_cache;

/**
* Cache of lengths along each evaluated curve for each evaluated point. If a curve is
Expand Down Expand Up @@ -304,7 +305,7 @@ class CurvesGeometry : public ::CurvesGeometry {
/**
* The largest and smallest position values of evaluated points.
*/
std::optional<Bounds<float3>> bounds_min_max() const;
std::optional<Bounds<float3>> bounds_min_max(bool use_radius = true) const;

void count_memory(MemoryCounter &memory) const;

Expand Down
2 changes: 1 addition & 1 deletion source/blender/blenkernel/BKE_geometry_set.hh
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ struct GeometrySet {
*/
Vector<const GeometryComponent *> get_components() const;

std::optional<Bounds<float3>> compute_boundbox_without_instances() const;
std::optional<Bounds<float3>> compute_boundbox_without_instances(bool use_radius = true) const;

friend std::ostream &operator<<(std::ostream &stream, const GeometrySet &geometry_set);

Expand Down
42 changes: 36 additions & 6 deletions source/blender/blenkernel/BKE_mesh_mapping.hh
Original file line number Diff line number Diff line change
Expand Up @@ -247,22 +247,52 @@ bool BKE_mesh_calc_islands_loop_face_uvmap(float (*vert_positions)[3],
MeshIslandStore *r_island_store);

/**
* Calculate smooth groups from sharp edges.
* Calculate smooth groups from sharp edges, using increasing numbers as identifier for each group.
*
* \param sharp_edges: Optional (possibly empty) span.
* \param sharp_faces: Optional (possibly empty) span.
* \param r_totgroup: The total number of groups, 1 or more.
* \return Polygon aligned array of group index values (bitflags if use_bitflags is true),
* starting at 1 (0 being used as 'invalid' flag).
* Note it's callers's responsibility to MEM_freeN returned array.
* \return Face aligned array of group index values, starting at 1 (0 being used as 'invalid'
* flag). Note that it's the callers's responsibility to MEM_freeN the returned array.
*/
int *BKE_mesh_calc_smoothgroups(int edges_num,
blender::OffsetIndices<int> faces,
blender::Span<int> corner_edges,
blender::Span<bool> sharp_edges,
blender::Span<bool> sharp_faces,
int *r_totgroup,
bool use_bitflags);
int *r_totgroup);
/**
* Same as #BKE_mesh_calc_smoothgroups, but use bitflags instead of increasing numbers for each
* group.
*
* This means that the same value (bit) can be re-used for different groups, as long as they are
* not neighbors. Values of each group are always powers of two.
*
* By default, only groups that share a same sharp edge are considered neighbors, and therefore
* prevented to use the same bitflag value.
*
* If #use_boundary_vertices_for_bitflags is set to `true`, then groups are also considered
* neighbors (and therefore cannot have the same bitflag value) if they share a single vertex, even
* if they have no common edge. This behavior seems to be required by some DCCs to recompute
* correct normals, see e.g. #104434. It will however make it much more likely to run out of
* available bits with certain types of topology (e.g. large fans of sharp faces).
*
* \param sharp_edges: Optional (possibly empty) span.
* \param sharp_faces: Optional (possibly empty) span.
* \param r_totgroup: The total number of groups, 1 or more.
* \return Face aligned array of group bitflags values (i.e. always powers of 2), starting at 1 (0
* being used as 'invalid' flag). Note that it's the callers's responsibility to MEM_freeN the
* returned array.
*/
int *BKE_mesh_calc_smoothgroups_bitflags(int edges_num,
int verts_num,
blender::OffsetIndices<int> faces,
blender::Span<int> corner_edges,
blender::Span<int> corner_verts,
blender::Span<bool> sharp_edges,
blender::Span<bool> sharp_faces,
bool use_boundary_vertices_for_bitflags,
int *r_totgroup);

/* Use on corner_tri vertex values. */
#define BKE_MESH_TESSTRI_VINDEX_ORDER(_tri, _v) \
Expand Down
Loading

0 comments on commit ed7d720

Please sign in to comment.