[Bf-blender-cvs] [317a2ff1e99] functions: unify float and float3 caching
Jacques Lucke
noreply at git.blender.org
Wed Jul 10 12:01:00 CEST 2019
Commit: 317a2ff1e99aa8e030d6d16386373432181dff02
Author: Jacques Lucke
Date: Wed Jul 10 11:22:27 2019 +0200
Branches: functions
https://developer.blender.org/rB317a2ff1e99aa8e030d6d16386373432181dff02
unify float and float3 caching
===================================================================
M source/blender/blenloader/intern/readfile.c
M source/blender/blenloader/intern/writefile.c
M source/blender/makesdna/DNA_modifier_types.h
M source/blender/simulations/bparticles/c_wrapper.cpp
===================================================================
diff --git a/source/blender/blenloader/intern/readfile.c b/source/blender/blenloader/intern/readfile.c
index 79ef8a81337..b853333155c 100644
--- a/source/blender/blenloader/intern/readfile.c
+++ b/source/blender/blenloader/intern/readfile.c
@@ -5810,17 +5810,7 @@ static void direct_link_modifiers(FileData *fd, ListBase *lb)
for (uint type = 0; type < cached_frame->num_particle_types; type++) {
BParticlesTypeCache *cached_type = &cached_frame->particle_types[type];
- cached_type->attributes_float3 = newdataadr(fd, cached_type->attributes_float3);
-
- for (uint i = 0; i < cached_type->num_attributes_float3; i++) {
- BParticlesAttributeCacheFloat3 *cached_attribute = &cached_type->attributes_float3[i];
- cached_attribute->values = newdataadr(fd, cached_attribute->values);
-
- if (fd->flags & FD_FLAGS_SWITCH_ENDIAN) {
- BLI_endian_switch_float_array(cached_attribute->values,
- cached_type->particle_amount * 3);
- }
- }
+ cached_type->attributes_float = newdataadr(fd, cached_type->attributes_float);
for (uint i = 0; i < cached_type->num_attributes_float; i++) {
BParticlesAttributeCacheFloat *cached_attribute = &cached_type->attributes_float[i];
diff --git a/source/blender/blenloader/intern/writefile.c b/source/blender/blenloader/intern/writefile.c
index 56218d7231b..c6539650b1d 100644
--- a/source/blender/blenloader/intern/writefile.c
+++ b/source/blender/blenloader/intern/writefile.c
@@ -1774,23 +1774,18 @@ static void write_modifiers(WriteData *wd, ListBase *modbase)
BParticlesTypeCache *cached_type = &cached_frame->particle_types[type];
writestruct(wd,
DATA,
- BParticlesAttributeCacheFloat3,
- cached_type->num_attributes_float3,
- cached_type->attributes_float3);
+ BParticlesAttributeCacheFloat,
+ cached_type->num_attributes_float,
+ cached_type->attributes_float);
- for (uint i = 0; i < cached_type->num_attributes_float3; i++) {
- BParticlesAttributeCacheFloat3 *attribute_cache = &cached_type->attributes_float3[i];
+ for (uint i = 0; i < cached_type->num_attributes_float; i++) {
+ BParticlesAttributeCacheFloat *attribute_cache = &cached_type->attributes_float[i];
writedata(wd,
DATA,
- sizeof(float) * 3 * cached_type->particle_amount,
+ sizeof(float) * attribute_cache->floats_per_particle *
+ cached_type->particle_amount,
attribute_cache->values);
}
-
- for (uint i = 0; i < cached_type->num_attributes_float; i++) {
- BParticlesAttributeCacheFloat *attribute_cache = &cached_type->attributes_float[i];
- writedata(
- wd, DATA, sizeof(float) * cached_type->particle_amount, attribute_cache->values);
- }
}
}
}
diff --git a/source/blender/makesdna/DNA_modifier_types.h b/source/blender/makesdna/DNA_modifier_types.h
index 1c2457ad335..05279fe7772 100644
--- a/source/blender/makesdna/DNA_modifier_types.h
+++ b/source/blender/makesdna/DNA_modifier_types.h
@@ -1963,25 +1963,18 @@ typedef struct FunctionPointsModifierData {
struct bNodeTree *function_tree;
} FunctionPointsModifierData;
-typedef struct BParticlesAttributeCacheFloat3 {
- char name[64];
- float *values;
-} BParticlesAttributeCacheFloat3;
-
typedef struct BParticlesAttributeCacheFloat {
char name[64];
+ unsigned int floats_per_particle;
+ char _pad[4];
float *values;
} BParticlesAttributeCacheFloat;
typedef struct BParticlesTypeCache {
char name[64];
unsigned int particle_amount;
- char _pad[4];
- unsigned int num_attributes_float3;
unsigned int num_attributes_float;
-
- BParticlesAttributeCacheFloat3 *attributes_float3;
BParticlesAttributeCacheFloat *attributes_float;
} BParticlesTypeCache;
diff --git a/source/blender/simulations/bparticles/c_wrapper.cpp b/source/blender/simulations/bparticles/c_wrapper.cpp
index 63fe4899e5f..4ce50f09f67 100644
--- a/source/blender/simulations/bparticles/c_wrapper.cpp
+++ b/source/blender/simulations/bparticles/c_wrapper.cpp
@@ -188,15 +188,6 @@ void BParticles_modifier_free_cache(BParticlesModifierData *bpmd)
for (auto &cached_frame : BLI::ref_c_array(bpmd->cached_frames, bpmd->num_cached_frames)) {
for (auto &cached_type :
BLI::ref_c_array(cached_frame.particle_types, cached_frame.num_particle_types)) {
- for (auto &cached_attribute :
- BLI::ref_c_array(cached_type.attributes_float3, cached_type.num_attributes_float3)) {
- if (cached_attribute.values != nullptr) {
- MEM_freeN(cached_attribute.values);
- }
- }
- if (cached_type.attributes_float3 != nullptr) {
- MEM_freeN(cached_type.attributes_float3);
- }
for (auto &cached_attribute :
BLI::ref_c_array(cached_type.attributes_float, cached_type.num_attributes_float)) {
if (cached_attribute.values != nullptr) {
@@ -228,8 +219,8 @@ Mesh *BParticles_modifier_mesh_from_cache(BParticlesFrameCache *cached_frame)
BParticlesTypeCache &type = cached_frame->particle_types[i];
particle_counts.append(type.particle_amount);
positions.extend(
- ArrayRef<float3>((float3 *)type.attributes_float3[0].values, type.particle_amount));
- sizes.extend(ArrayRef<float>(type.attributes_float[0].values, type.particle_amount));
+ ArrayRef<float3>((float3 *)type.attributes_float[0].values, type.particle_amount));
+ sizes.extend(ArrayRef<float>(type.attributes_float[1].values, type.particle_amount));
}
Mesh *mesh = distribute_tetrahedons(positions, sizes);
@@ -279,31 +270,23 @@ void BParticles_modifier_cache_state(BParticlesModifierData *bpmd,
strncpy(cached_type.name, container_names[i].data(), sizeof(cached_type.name));
cached_type.particle_amount = container.count_active();
- /* Cache Position */
- {
- cached_type.num_attributes_float3 = 1;
- cached_type.attributes_float3 = (BParticlesAttributeCacheFloat3 *)MEM_calloc_arrayN(
- cached_type.num_attributes_float3, sizeof(BParticlesAttributeCacheFloat3), __func__);
-
- BParticlesAttributeCacheFloat3 &cached_attribute = cached_type.attributes_float3[0];
- strncpy(cached_attribute.name, "Position", sizeof(cached_attribute.name));
- cached_attribute.values = (float *)MEM_malloc_arrayN(
- cached_type.particle_amount, sizeof(float3), __func__);
- container.flatten_attribute_data("Position", cached_attribute.values);
- }
-
- /* Cache Size */
- {
- cached_type.num_attributes_float = 1;
- cached_type.attributes_float = (BParticlesAttributeCacheFloat *)MEM_calloc_arrayN(
- cached_type.num_attributes_float, sizeof(BParticlesAttributeCacheFloat), __func__);
-
- BParticlesAttributeCacheFloat &cached_attribute = cached_type.attributes_float[0];
- strncpy(cached_attribute.name, "Size", sizeof(cached_attribute.name));
- cached_attribute.values = (float *)MEM_malloc_arrayN(
- cached_type.particle_amount, sizeof(float), __func__);
- container.flatten_attribute_data("Size", cached_attribute.values);
- }
+ cached_type.num_attributes_float = 2;
+ cached_type.attributes_float = (BParticlesAttributeCacheFloat *)MEM_calloc_arrayN(
+ cached_type.num_attributes_float, sizeof(BParticlesAttributeCacheFloat), __func__);
+
+ BParticlesAttributeCacheFloat &position_attribute = cached_type.attributes_float[0];
+ position_attribute.floats_per_particle = 3;
+ strncpy(position_attribute.name, "Position", sizeof(position_attribute.name));
+ position_attribute.values = (float *)MEM_malloc_arrayN(
+ cached_type.particle_amount, sizeof(float3), __func__);
+ container.flatten_attribute_data("Position", position_attribute.values);
+
+ BParticlesAttributeCacheFloat &size_attribute = cached_type.attributes_float[1];
+ size_attribute.floats_per_particle = 1;
+ strncpy(size_attribute.name, "Size", sizeof(size_attribute.name));
+ size_attribute.values = (float *)MEM_malloc_arrayN(
+ cached_type.particle_amount, sizeof(float), __func__);
+ container.flatten_attribute_data("Size", size_attribute.values);
}
bpmd->cached_frames = (BParticlesFrameCache *)MEM_reallocN(
More information about the Bf-blender-cvs
mailing list