[Bf-blender-cvs] [a39dc76dec5] functions: pass buffer cache to functions via context
Jacques Lucke
noreply at git.blender.org
Mon Jan 27 22:10:55 CET 2020
Commit: a39dc76dec5a8e3b0632350ba2441057ae69f97e
Author: Jacques Lucke
Date: Mon Jan 27 21:30:59 2020 +0100
Branches: functions
https://developer.blender.org/rBa39dc76dec5a8e3b0632350ba2441057ae69f97e
pass buffer cache to functions via context
===================================================================
M source/blender/blenlib/BLI_parallel.h
M source/blender/functions/FN_multi_function_context.h
M source/blender/functions/intern/multi_functions/network.cc
M source/blender/simulations/bparticles/actions.cpp
M source/blender/simulations/bparticles/block_step_data.hpp
M source/blender/simulations/bparticles/events.cpp
M source/blender/simulations/bparticles/forces.cpp
M source/blender/simulations/bparticles/particle_action.cpp
M source/blender/simulations/bparticles/particle_action.hpp
M source/blender/simulations/bparticles/simulate.cpp
===================================================================
diff --git a/source/blender/blenlib/BLI_parallel.h b/source/blender/blenlib/BLI_parallel.h
index 0011a70ef8c..b7de28167ba 100644
--- a/source/blender/blenlib/BLI_parallel.h
+++ b/source/blender/blenlib/BLI_parallel.h
@@ -46,7 +46,7 @@ void blocked_parallel_for(IndexRange range, uint grain_size, const FuncT &func)
tbb::blocked_range<uint>(range.first(), range.one_after_last(), grain_size),
[&](const tbb::blocked_range<uint> &sub_range) { func(IndexRange(sub_range)); });
#else
- UNUSED_VARS_NDEBUG(grain_size);
+ UNUSED_VARS(grain_size);
func(range);
#endif
}
diff --git a/source/blender/functions/FN_multi_function_context.h b/source/blender/functions/FN_multi_function_context.h
index fd17d335b9b..ee84c617cbd 100644
--- a/source/blender/functions/FN_multi_function_context.h
+++ b/source/blender/functions/FN_multi_function_context.h
@@ -8,6 +8,7 @@
#include "BLI_utility_mixins.h"
#include "BLI_index_range.h"
#include "BLI_static_class_ids.h"
+#include "BLI_buffer_cache.h"
#include "BKE_id_handle.h"
@@ -15,6 +16,7 @@ namespace FN {
using BKE::IDHandleLookup;
using BLI::ArrayRef;
+using BLI::BufferCache;
using BLI::IndexRange;
using BLI::Optional;
using BLI::Vector;
@@ -99,14 +101,21 @@ class MFContextBuilder : BLI::NonCopyable, BLI::NonMovable {
private:
MFElementContexts m_element_contexts;
MFGlobalContexts m_global_contexts;
+ BufferCache m_buffer_cache_fallback;
+ BufferCache *m_buffer_cache = nullptr;
friend class MFContext;
public:
- MFContextBuilder()
+ MFContextBuilder() : m_buffer_cache(&m_buffer_cache_fallback)
{
}
+ void set_buffer_cache(BufferCache &buffer_cache)
+ {
+ m_buffer_cache = &buffer_cache;
+ }
+
void add_global_contexts(const MFContext &other);
template<typename T> void add_element_context(const T &context, MFElementContextIndices indices)
@@ -148,6 +157,11 @@ class MFContext {
{
return m_builder->m_global_contexts.try_find<T>();
}
+
+ BufferCache &buffer_cache()
+ {
+ return *m_builder->m_buffer_cache;
+ }
};
inline void MFContextBuilder::add_global_contexts(const MFContext &other)
diff --git a/source/blender/functions/intern/multi_functions/network.cc b/source/blender/functions/intern/multi_functions/network.cc
index b5272495c13..f02e3749524 100644
--- a/source/blender/functions/intern/multi_functions/network.cc
+++ b/source/blender/functions/intern/multi_functions/network.cc
@@ -544,10 +544,9 @@ void MF_EvaluateNetwork::call(IndexMask mask, MFParams params, MFContext context
return;
}
- BufferCache buffer_cache;
const MFNetwork &network = m_outputs[0]->node().network();
+ Storage storage(context.buffer_cache(), mask, network.socket_ids().size());
- Storage storage(buffer_cache, mask, network.socket_ids().size());
this->copy_inputs_to_storage(params, storage);
this->evaluate_network_to_compute_outputs(context, storage);
this->copy_computed_values_to_outputs(params, storage);
diff --git a/source/blender/simulations/bparticles/actions.cpp b/source/blender/simulations/bparticles/actions.cpp
index 8f6970ef3a7..e0bef9167df 100644
--- a/source/blender/simulations/bparticles/actions.cpp
+++ b/source/blender/simulations/bparticles/actions.cpp
@@ -44,6 +44,7 @@ static void update_position_and_velocity_offsets(ParticleActionContext &context)
void ConditionAction::execute(ParticleActionContext &context)
{
ParticleFunctionEvaluator inputs{m_inputs_fn, context.mask(), context.attributes()};
+ inputs.context_builder().set_buffer_cache(context.buffer_cache());
inputs.compute();
Vector<uint> true_pindices, false_pindices;
@@ -72,6 +73,7 @@ void SetAttributeAction::execute(ParticleActionContext &context)
GenericMutableArrayRef attribute = *attribute_opt;
ParticleFunctionEvaluator inputs{m_inputs_fn, context.mask(), context.attributes()};
+ inputs.context_builder().set_buffer_cache(context.buffer_cache());
inputs.compute();
for (uint pindex : context.mask()) {
@@ -103,6 +105,7 @@ void SpawnParticlesAction::execute(ParticleActionContext &context)
uint array_size = context.mask().min_array_size();
ParticleFunctionEvaluator inputs{m_spawn_function, context.mask(), context.attributes()};
+ inputs.context_builder().set_buffer_cache(context.buffer_cache());
inputs.compute();
LargeScopedArray<int> particle_counts(array_size, -1);
diff --git a/source/blender/simulations/bparticles/block_step_data.hpp b/source/blender/simulations/bparticles/block_step_data.hpp
index 4e33a148ccc..d89cb60fae5 100644
--- a/source/blender/simulations/bparticles/block_step_data.hpp
+++ b/source/blender/simulations/bparticles/block_step_data.hpp
@@ -3,17 +3,20 @@
#include "FN_attributes_ref.h"
#include "BLI_float_interval.h"
+#include "BLI_buffer_cache.h"
#include "simulation_state.hpp"
namespace BParticles {
+using BLI::BufferCache;
using BLI::FloatInterval;
using FN::AttributesRef;
using FN::MutableAttributesRef;
struct BlockStepData {
SimulationState &simulation_state;
+ BufferCache &buffer_cache;
MutableAttributesRef attributes;
MutableAttributesRef attribute_offsets;
MutableArrayRef<float> remaining_durations;
@@ -39,6 +42,11 @@ class BlockStepDataAccess {
return m_step_data.simulation_state;
}
+ BufferCache &buffer_cache()
+ {
+ return m_step_data.buffer_cache;
+ }
+
uint array_size() const
{
return m_step_data.array_size();
diff --git a/source/blender/simulations/bparticles/events.cpp b/source/blender/simulations/bparticles/events.cpp
index ea1d759ece7..4b212beee74 100644
--- a/source/blender/simulations/bparticles/events.cpp
+++ b/source/blender/simulations/bparticles/events.cpp
@@ -15,6 +15,7 @@ void AgeReachedEvent::filter(EventFilterInterface &interface)
AttributesRef attributes = interface.attributes();
ParticleFunctionEvaluator inputs{m_inputs_fn, interface.mask(), interface.attributes()};
+ inputs.context_builder().set_buffer_cache(interface.buffer_cache());
inputs.compute();
float end_time = interface.step_end_time();
@@ -65,9 +66,11 @@ void CustomEvent::filter(EventFilterInterface &interface)
FN::EventFilterDurationsContext durations_context = {interface.remaining_durations()};
ParticleFunctionEvaluator inputs{m_inputs_fn, interface.mask(), interface.attributes()};
- inputs.context_builder().add_global_context(end_time_context);
- inputs.context_builder().add_element_context(durations_context,
- FN::MFElementContextIndices::FromDirectMapping());
+ FN::MFContextBuilder &context_builder = inputs.context_builder();
+ context_builder.set_buffer_cache(interface.buffer_cache());
+ context_builder.add_global_context(end_time_context);
+ context_builder.add_element_context(durations_context,
+ FN::MFElementContextIndices::FromDirectMapping());
inputs.compute();
for (uint pindex : interface.mask()) {
diff --git a/source/blender/simulations/bparticles/forces.cpp b/source/blender/simulations/bparticles/forces.cpp
index f7544171b3a..79a0f026008 100644
--- a/source/blender/simulations/bparticles/forces.cpp
+++ b/source/blender/simulations/bparticles/forces.cpp
@@ -13,6 +13,7 @@ void CustomForce::add_force(ForceInterface &interface)
MutableArrayRef<float3> dst = interface.combined_destination();
ParticleFunctionEvaluator inputs{m_inputs_fn, interface.mask(), interface.attributes()};
+ inputs.context_builder().set_buffer_cache(interface.buffer_cache());
inputs.compute();
for (uint pindex : interface.mask()) {
diff --git a/source/blender/simulations/bparticles/particle_action.cpp b/source/blender/simulations/bparticles/particle_action.cpp
index 42ec6728333..800dbeffc62 100644
--- a/source/blender/simulations/bparticles/particle_action.cpp
+++ b/source/blender/simulations/bparticles/particle_action.cpp
@@ -15,6 +15,8 @@ ParticleAction::~ParticleAction()
void ParticleAction::execute_from_emitter(AttributesRefGroup &new_particles,
EmitterInterface &emitter_interface)
{
+ BufferCache buffer_cache;
+
for (MutableAttributesRef attributes : new_particles) {
ParticleCurrentTimesContext current_times_context;
current_times_context.current_times = attributes.get<float>("Birth Time");
@@ -22,6 +24,7 @@ void ParticleAction::execute_from_emitter(AttributesRefGroup &new_particles,
ParticleActionContext context(emitter_interface.particle_allocator(),
IndexMask(attributes.size()),
attributes,
+ buffer_cache,
{BLI::get_class_id<ParticleCurrentTimesContext>()},
{(void *)¤t_times_context});
this->execute(context);
@@ -39,6 +42,7 @@ void ParticleAction::execute_for_new_particles(AttributesRefGroup &new_particles
ParticleActionContext context(parent_context.particle_allocator(),
IndexMask(attributes.size()),
attributes,
+ parent_context.buffer_cache(),
{BLI::get_class_id<ParticleCurrentTimesContext>()},
{(void *)¤t_times_context});
this->execute(context);
@@ -55,6 +59,7 @@ void ParticleAction::execute_for_new_particles(AttributesRefGroup &new_particles
ParticleActionContext context(offset_handler_interface.particle_allocator(),
IndexMask(attributes.size()),
attributes,
+ offset_handler_interface.buffer_cache(),
{BLI::get_class_id<ParticleCurrentTimesContext>()},
{(void *)¤t_times_context});
this->execute(context);
@@ -75,6 +80,7 @@ void ParticleAction::execute_from_event(EventExecuteInterface &event_interface)
event_interface.particle_allocator(),
event_interface.pindices(),
event_interface.attributes(),
+ event_interface.buffer_cache(),
{BLI::get_class_id<ParticleCurrentTimesContext>
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list