Cleanup: simplify resource scope methods
Previously, a debug name had to be passed to all methods that added a resource to the `ResourceScope`. The idea was that this would make it easier to find certain bugs. In reality I never found this to be useful, and it was mostly annoying. The thing is, something that is in a resource scope never leaks (unless the resource scope is not destructed of course). Removing the name parameter makes the structure easier to use.
This commit is contained in:
@@ -1315,7 +1315,7 @@ const GVArray *AttributeFieldInput::get_varray_for_context(const fn::FieldContex
|
|||||||
const AttributeDomain domain = geometry_context->domain();
|
const AttributeDomain domain = geometry_context->domain();
|
||||||
const CustomDataType data_type = cpp_type_to_custom_data_type(*type_);
|
const CustomDataType data_type = cpp_type_to_custom_data_type(*type_);
|
||||||
GVArrayPtr attribute = component.attribute_try_get_for_read(name_, domain, data_type);
|
GVArrayPtr attribute = component.attribute_try_get_for_read(name_, domain, data_type);
|
||||||
return scope.add(std::move(attribute), __func__);
|
return scope.add(std::move(attribute));
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
@@ -1350,7 +1350,7 @@ const GVArray *AnonymousAttributeFieldInput::get_varray_for_context(
|
|||||||
const CustomDataType data_type = cpp_type_to_custom_data_type(*type_);
|
const CustomDataType data_type = cpp_type_to_custom_data_type(*type_);
|
||||||
GVArrayPtr attribute = component.attribute_try_get_for_read(
|
GVArrayPtr attribute = component.attribute_try_get_for_read(
|
||||||
anonymous_id_.get(), domain, data_type);
|
anonymous_id_.get(), domain, data_type);
|
||||||
return scope.add(std::move(attribute), __func__);
|
return scope.add(std::move(attribute));
|
||||||
}
|
}
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
@@ -50,11 +50,10 @@ class ResourceScope : NonCopyable, NonMovable {
|
|||||||
struct ResourceData {
|
struct ResourceData {
|
||||||
void *data;
|
void *data;
|
||||||
void (*free)(void *data);
|
void (*free)(void *data);
|
||||||
const char *debug_name;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
LinearAllocator<> m_allocator;
|
LinearAllocator<> allocator_;
|
||||||
Vector<ResourceData> m_resources;
|
Vector<ResourceData> resources_;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ResourceScope() = default;
|
ResourceScope() = default;
|
||||||
@@ -62,8 +61,8 @@ class ResourceScope : NonCopyable, NonMovable {
|
|||||||
~ResourceScope()
|
~ResourceScope()
|
||||||
{
|
{
|
||||||
/* Free in reversed order. */
|
/* Free in reversed order. */
|
||||||
for (int64_t i = m_resources.size(); i--;) {
|
for (int64_t i = resources_.size(); i--;) {
|
||||||
ResourceData &data = m_resources[i];
|
ResourceData &data = resources_[i];
|
||||||
data.free(data.data);
|
data.free(data.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -72,20 +71,17 @@ class ResourceScope : NonCopyable, NonMovable {
|
|||||||
* Pass ownership of the resource to the ResourceScope. It will be destructed and freed when
|
* Pass ownership of the resource to the ResourceScope. It will be destructed and freed when
|
||||||
* the collector is destructed.
|
* the collector is destructed.
|
||||||
*/
|
*/
|
||||||
template<typename T> T *add(std::unique_ptr<T> resource, const char *name)
|
template<typename T> T *add(std::unique_ptr<T> resource)
|
||||||
{
|
{
|
||||||
BLI_assert(resource.get() != nullptr);
|
BLI_assert(resource.get() != nullptr);
|
||||||
T *ptr = resource.release();
|
T *ptr = resource.release();
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) {
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
this->add(
|
this->add(ptr, [](void *data) {
|
||||||
ptr,
|
T *typed_data = reinterpret_cast<T *>(data);
|
||||||
[](void *data) {
|
delete typed_data;
|
||||||
T *typed_data = reinterpret_cast<T *>(data);
|
});
|
||||||
delete typed_data;
|
|
||||||
},
|
|
||||||
name);
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,7 +89,7 @@ class ResourceScope : NonCopyable, NonMovable {
|
|||||||
* Pass ownership of the resource to the ResourceScope. It will be destructed when the
|
* Pass ownership of the resource to the ResourceScope. It will be destructed when the
|
||||||
* collector is destructed.
|
* collector is destructed.
|
||||||
*/
|
*/
|
||||||
template<typename T> T *add(destruct_ptr<T> resource, const char *name)
|
template<typename T> T *add(destruct_ptr<T> resource)
|
||||||
{
|
{
|
||||||
T *ptr = resource.release();
|
T *ptr = resource.release();
|
||||||
if (ptr == nullptr) {
|
if (ptr == nullptr) {
|
||||||
@@ -104,13 +100,10 @@ class ResourceScope : NonCopyable, NonMovable {
|
|||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
this->add(
|
this->add(ptr, [](void *data) {
|
||||||
ptr,
|
T *typed_data = reinterpret_cast<T *>(data);
|
||||||
[](void *data) {
|
typed_data->~T();
|
||||||
T *typed_data = reinterpret_cast<T *>(data);
|
});
|
||||||
typed_data->~T();
|
|
||||||
},
|
|
||||||
name);
|
|
||||||
return ptr;
|
return ptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -118,33 +111,31 @@ class ResourceScope : NonCopyable, NonMovable {
|
|||||||
* Pass ownership of some resource to the ResourceScope. The given free function will be
|
* Pass ownership of some resource to the ResourceScope. The given free function will be
|
||||||
* called when the collector is destructed.
|
* called when the collector is destructed.
|
||||||
*/
|
*/
|
||||||
void add(void *userdata, void (*free)(void *), const char *name)
|
void add(void *userdata, void (*free)(void *))
|
||||||
{
|
{
|
||||||
ResourceData data;
|
ResourceData data;
|
||||||
data.debug_name = name;
|
|
||||||
data.data = userdata;
|
data.data = userdata;
|
||||||
data.free = free;
|
data.free = free;
|
||||||
m_resources.append(data);
|
resources_.append(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct an object with the same value in the ResourceScope and return a reference to the
|
* Construct an object with the same value in the ResourceScope and return a reference to the
|
||||||
* new value.
|
* new value.
|
||||||
*/
|
*/
|
||||||
template<typename T> T &add_value(T &&value, const char *name)
|
template<typename T> T &add_value(T &&value)
|
||||||
{
|
{
|
||||||
return this->construct<T>(name, std::forward<T>(value));
|
return this->construct<T>(std::forward<T>(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The passed in function will be called when the scope is destructed.
|
* The passed in function will be called when the scope is destructed.
|
||||||
*/
|
*/
|
||||||
template<typename Func> void add_destruct_call(Func func, const char *name)
|
template<typename Func> void add_destruct_call(Func func)
|
||||||
{
|
{
|
||||||
void *buffer = m_allocator.allocate(sizeof(Func), alignof(Func));
|
void *buffer = allocator_.allocate(sizeof(Func), alignof(Func));
|
||||||
new (buffer) Func(std::move(func));
|
new (buffer) Func(std::move(func));
|
||||||
this->add(
|
this->add(buffer, [](void *data) { (*(Func *)data)(); });
|
||||||
buffer, [](void *data) { (*(Func *)data)(); }, name);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -153,37 +144,19 @@ class ResourceScope : NonCopyable, NonMovable {
|
|||||||
*/
|
*/
|
||||||
LinearAllocator<> &linear_allocator()
|
LinearAllocator<> &linear_allocator()
|
||||||
{
|
{
|
||||||
return m_allocator;
|
return allocator_;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method to construct an instance of type T that will be owned by the ResourceScope.
|
* Utility method to construct an instance of type T that will be owned by the ResourceScope.
|
||||||
*/
|
*/
|
||||||
template<typename T, typename... Args> T &construct(const char *name, Args &&...args)
|
template<typename T, typename... Args> T &construct(Args &&...args)
|
||||||
{
|
{
|
||||||
destruct_ptr<T> value_ptr = m_allocator.construct<T>(std::forward<Args>(args)...);
|
destruct_ptr<T> value_ptr = allocator_.construct<T>(std::forward<Args>(args)...);
|
||||||
T &value_ref = *value_ptr;
|
T &value_ref = *value_ptr;
|
||||||
this->add(std::move(value_ptr), name);
|
this->add(std::move(value_ptr));
|
||||||
return value_ref;
|
return value_ref;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Print the names of all the resources that are owned by this ResourceScope. This can be
|
|
||||||
* useful for debugging.
|
|
||||||
*/
|
|
||||||
void print(StringRef name) const
|
|
||||||
{
|
|
||||||
if (m_resources.size() == 0) {
|
|
||||||
std::cout << "\"" << name << "\" has no resources.\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
std::cout << "Resources for \"" << name << "\":\n";
|
|
||||||
for (const ResourceData &data : m_resources) {
|
|
||||||
std::cout << " " << data.data << ": " << data.debug_name << '\n';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace blender
|
} // namespace blender
|
||||||
|
@@ -370,7 +370,7 @@ static void spreadsheet_main_region_draw(const bContext *C, ARegion *region)
|
|||||||
std::unique_ptr<ColumnValues> values_ptr = data_source->get_column_values(*column->id);
|
std::unique_ptr<ColumnValues> values_ptr = data_source->get_column_values(*column->id);
|
||||||
/* Should have been removed before if it does not exist anymore. */
|
/* Should have been removed before if it does not exist anymore. */
|
||||||
BLI_assert(values_ptr);
|
BLI_assert(values_ptr);
|
||||||
const ColumnValues *values = scope.add(std::move(values_ptr), __func__);
|
const ColumnValues *values = scope.add(std::move(values_ptr));
|
||||||
const int width = get_column_width_in_pixels(*values);
|
const int width = get_column_width_in_pixels(*values);
|
||||||
spreadsheet_layout.columns.append({values, width});
|
spreadsheet_layout.columns.append({values, width});
|
||||||
|
|
||||||
|
@@ -70,7 +70,7 @@ std::unique_ptr<ColumnValues> GeometryDataSource::get_column_values(
|
|||||||
if (!attribute) {
|
if (!attribute) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
const fn::GVArray *varray = scope_.add(std::move(attribute.varray), __func__);
|
const fn::GVArray *varray = scope_.add(std::move(attribute.varray));
|
||||||
if (attribute.domain != domain_) {
|
if (attribute.domain != domain_) {
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
@@ -328,7 +328,7 @@ Span<int64_t> spreadsheet_filter_rows(const SpaceSpreadsheet &sspreadsheet,
|
|||||||
geometry_data_source->apply_selection_filter(rows_included);
|
geometry_data_source->apply_selection_filter(rows_included);
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector<int64_t> &indices = scope.construct<Vector<int64_t>>(__func__);
|
Vector<int64_t> &indices = scope.construct<Vector<int64_t>>();
|
||||||
index_vector_from_bools(rows_included, indices);
|
index_vector_from_bools(rows_included, indices);
|
||||||
|
|
||||||
return indices;
|
return indices;
|
||||||
|
@@ -381,7 +381,7 @@ class FieldEvaluator : NonMovable, NonCopyable {
|
|||||||
/** Same as #add_with_destination but typed. */
|
/** Same as #add_with_destination but typed. */
|
||||||
template<typename T> int add_with_destination(Field<T> field, VMutableArray<T> &dst)
|
template<typename T> int add_with_destination(Field<T> field, VMutableArray<T> &dst)
|
||||||
{
|
{
|
||||||
GVMutableArray &varray = scope_.construct<GVMutableArray_For_VMutableArray<T>>(__func__, dst);
|
GVMutableArray &varray = scope_.construct<GVMutableArray_For_VMutableArray<T>>(dst);
|
||||||
return this->add_with_destination(GField(std::move(field)), varray);
|
return this->add_with_destination(GField(std::move(field)), varray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -401,7 +401,7 @@ class FieldEvaluator : NonMovable, NonCopyable {
|
|||||||
*/
|
*/
|
||||||
template<typename T> int add_with_destination(Field<T> field, MutableSpan<T> dst)
|
template<typename T> int add_with_destination(Field<T> field, MutableSpan<T> dst)
|
||||||
{
|
{
|
||||||
GVMutableArray &varray = scope_.construct<GVMutableArray_For_MutableSpan<T>>(__func__, dst);
|
GVMutableArray &varray = scope_.construct<GVMutableArray_For_MutableSpan<T>>(dst);
|
||||||
return this->add_with_destination(std::move(field), varray);
|
return this->add_with_destination(std::move(field), varray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -417,10 +417,10 @@ class FieldEvaluator : NonMovable, NonCopyable {
|
|||||||
{
|
{
|
||||||
const int field_index = fields_to_evaluate_.append_and_get_index(std::move(field));
|
const int field_index = fields_to_evaluate_.append_and_get_index(std::move(field));
|
||||||
dst_varrays_.append(nullptr);
|
dst_varrays_.append(nullptr);
|
||||||
output_pointer_infos_.append(OutputPointerInfo{
|
output_pointer_infos_.append(
|
||||||
varray_ptr, [](void *dst, const GVArray &varray, ResourceScope &scope) {
|
OutputPointerInfo{varray_ptr, [](void *dst, const GVArray &varray, ResourceScope &scope) {
|
||||||
*(const VArray<T> **)dst = &*scope.construct<GVArray_Typed<T>>(__func__, varray);
|
*(const VArray<T> **)dst = &*scope.construct<GVArray_Typed<T>>(varray);
|
||||||
}});
|
}});
|
||||||
return field_index;
|
return field_index;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -443,7 +443,7 @@ class FieldEvaluator : NonMovable, NonCopyable {
|
|||||||
template<typename T> const VArray<T> &get_evaluated(const int field_index)
|
template<typename T> const VArray<T> &get_evaluated(const int field_index)
|
||||||
{
|
{
|
||||||
const GVArray &varray = this->get_evaluated(field_index);
|
const GVArray &varray = this->get_evaluated(field_index);
|
||||||
GVArray_Typed<T> &typed_varray = scope_.construct<GVArray_Typed<T>>(__func__, varray);
|
GVArray_Typed<T> &typed_varray = scope_.construct<GVArray_Typed<T>>(varray);
|
||||||
return *typed_varray;
|
return *typed_varray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -62,25 +62,24 @@ class MFParamsBuilder {
|
|||||||
|
|
||||||
template<typename T> void add_readonly_single_input_value(T value, StringRef expected_name = "")
|
template<typename T> void add_readonly_single_input_value(T value, StringRef expected_name = "")
|
||||||
{
|
{
|
||||||
T *value_ptr = &scope_.add_value<T>(std::move(value), __func__);
|
T *value_ptr = &scope_.add_value<T>(std::move(value));
|
||||||
this->add_readonly_single_input(value_ptr, expected_name);
|
this->add_readonly_single_input(value_ptr, expected_name);
|
||||||
}
|
}
|
||||||
template<typename T> void add_readonly_single_input(const T *value, StringRef expected_name = "")
|
template<typename T> void add_readonly_single_input(const T *value, StringRef expected_name = "")
|
||||||
{
|
{
|
||||||
this->add_readonly_single_input(scope_.construct<GVArray_For_SingleValueRef>(
|
this->add_readonly_single_input(
|
||||||
__func__, CPPType::get<T>(), min_array_size_, value),
|
scope_.construct<GVArray_For_SingleValueRef>(CPPType::get<T>(), min_array_size_, value),
|
||||||
expected_name);
|
expected_name);
|
||||||
}
|
}
|
||||||
void add_readonly_single_input(const GSpan span, StringRef expected_name = "")
|
void add_readonly_single_input(const GSpan span, StringRef expected_name = "")
|
||||||
{
|
{
|
||||||
this->add_readonly_single_input(scope_.construct<GVArray_For_GSpan>(__func__, span),
|
this->add_readonly_single_input(scope_.construct<GVArray_For_GSpan>(span), expected_name);
|
||||||
expected_name);
|
|
||||||
}
|
}
|
||||||
void add_readonly_single_input(GPointer value, StringRef expected_name = "")
|
void add_readonly_single_input(GPointer value, StringRef expected_name = "")
|
||||||
{
|
{
|
||||||
this->add_readonly_single_input(scope_.construct<GVArray_For_SingleValueRef>(
|
this->add_readonly_single_input(
|
||||||
__func__, *value.type(), min_array_size_, value.get()),
|
scope_.construct<GVArray_For_SingleValueRef>(*value.type(), min_array_size_, value.get()),
|
||||||
expected_name);
|
expected_name);
|
||||||
}
|
}
|
||||||
void add_readonly_single_input(const GVArray &ref, StringRef expected_name = "")
|
void add_readonly_single_input(const GVArray &ref, StringRef expected_name = "")
|
||||||
{
|
{
|
||||||
@@ -91,13 +90,13 @@ class MFParamsBuilder {
|
|||||||
|
|
||||||
void add_readonly_vector_input(const GVectorArray &vector_array, StringRef expected_name = "")
|
void add_readonly_vector_input(const GVectorArray &vector_array, StringRef expected_name = "")
|
||||||
{
|
{
|
||||||
this->add_readonly_vector_input(
|
this->add_readonly_vector_input(scope_.construct<GVVectorArray_For_GVectorArray>(vector_array),
|
||||||
scope_.construct<GVVectorArray_For_GVectorArray>(__func__, vector_array), expected_name);
|
expected_name);
|
||||||
}
|
}
|
||||||
void add_readonly_vector_input(const GSpan single_vector, StringRef expected_name = "")
|
void add_readonly_vector_input(const GSpan single_vector, StringRef expected_name = "")
|
||||||
{
|
{
|
||||||
this->add_readonly_vector_input(
|
this->add_readonly_vector_input(
|
||||||
scope_.construct<GVVectorArray_For_SingleGSpan>(__func__, single_vector, min_array_size_),
|
scope_.construct<GVVectorArray_For_SingleGSpan>(single_vector, min_array_size_),
|
||||||
expected_name);
|
expected_name);
|
||||||
}
|
}
|
||||||
void add_readonly_vector_input(const GVVectorArray &ref, StringRef expected_name = "")
|
void add_readonly_vector_input(const GVVectorArray &ref, StringRef expected_name = "")
|
||||||
@@ -225,7 +224,7 @@ class MFParams {
|
|||||||
template<typename T> const VArray<T> &readonly_single_input(int param_index, StringRef name = "")
|
template<typename T> const VArray<T> &readonly_single_input(int param_index, StringRef name = "")
|
||||||
{
|
{
|
||||||
const GVArray &array = this->readonly_single_input(param_index, name);
|
const GVArray &array = this->readonly_single_input(param_index, name);
|
||||||
return builder_->scope_.construct<GVArray_Typed<T>>(__func__, array);
|
return builder_->scope_.construct<GVArray_Typed<T>>(array);
|
||||||
}
|
}
|
||||||
const GVArray &readonly_single_input(int param_index, StringRef name = "")
|
const GVArray &readonly_single_input(int param_index, StringRef name = "")
|
||||||
{
|
{
|
||||||
@@ -266,8 +265,7 @@ class MFParams {
|
|||||||
if (!type.is_trivially_destructible()) {
|
if (!type.is_trivially_destructible()) {
|
||||||
/* Make sure the temporary elements will be destructed in the end. */
|
/* Make sure the temporary elements will be destructed in the end. */
|
||||||
builder_->scope_.add_destruct_call(
|
builder_->scope_.add_destruct_call(
|
||||||
[&type, buffer, mask = builder_->mask_]() { type.destruct_indices(buffer, mask); },
|
[&type, buffer, mask = builder_->mask_]() { type.destruct_indices(buffer, mask); });
|
||||||
__func__);
|
|
||||||
}
|
}
|
||||||
span = GMutableSpan{type, buffer, builder_->min_array_size_};
|
span = GMutableSpan{type, buffer, builder_->min_array_size_};
|
||||||
}
|
}
|
||||||
@@ -278,7 +276,7 @@ class MFParams {
|
|||||||
const VVectorArray<T> &readonly_vector_input(int param_index, StringRef name = "")
|
const VVectorArray<T> &readonly_vector_input(int param_index, StringRef name = "")
|
||||||
{
|
{
|
||||||
const GVVectorArray &vector_array = this->readonly_vector_input(param_index, name);
|
const GVVectorArray &vector_array = this->readonly_vector_input(param_index, name);
|
||||||
return builder_->scope_.construct<VVectorArray_For_GVVectorArray<T>>(__func__, vector_array);
|
return builder_->scope_.construct<VVectorArray_For_GVVectorArray<T>>(vector_array);
|
||||||
}
|
}
|
||||||
const GVVectorArray &readonly_vector_input(int param_index, StringRef name = "")
|
const GVVectorArray &readonly_vector_input(int param_index, StringRef name = "")
|
||||||
{
|
{
|
||||||
|
@@ -92,7 +92,7 @@ static Vector<const GVArray *> get_field_context_inputs(
|
|||||||
if (varray == nullptr) {
|
if (varray == nullptr) {
|
||||||
const CPPType &type = field_input.cpp_type();
|
const CPPType &type = field_input.cpp_type();
|
||||||
varray = &scope.construct<GVArray_For_SingleValueRef>(
|
varray = &scope.construct<GVArray_For_SingleValueRef>(
|
||||||
__func__, type, mask.min_array_size(), type.default_value());
|
type, mask.min_array_size(), type.default_value());
|
||||||
}
|
}
|
||||||
field_context_inputs.append(varray);
|
field_context_inputs.append(varray);
|
||||||
}
|
}
|
||||||
@@ -237,8 +237,8 @@ static void build_multi_function_procedure_for_fields(MFProcedure &procedure,
|
|||||||
if (!already_output_variables.add(variable)) {
|
if (!already_output_variables.add(variable)) {
|
||||||
/* One variable can be output at most once. To output the same value twice, we have to make
|
/* One variable can be output at most once. To output the same value twice, we have to make
|
||||||
* a copy first. */
|
* a copy first. */
|
||||||
const MultiFunction ©_fn = scope.construct<CustomMF_GenericCopy>(
|
const MultiFunction ©_fn = scope.construct<CustomMF_GenericCopy>("copy",
|
||||||
__func__, "copy", variable->data_type());
|
variable->data_type());
|
||||||
variable = builder.add_call<1>(copy_fn, {variable})[0];
|
variable = builder.add_call<1>(copy_fn, {variable})[0];
|
||||||
}
|
}
|
||||||
builder.add_output_parameter(*variable);
|
builder.add_output_parameter(*variable);
|
||||||
@@ -381,14 +381,13 @@ Vector<const GVArray *> evaluate_fields(ResourceScope &scope,
|
|||||||
buffer = scope.linear_allocator().allocate(type.size() * array_size, type.alignment());
|
buffer = scope.linear_allocator().allocate(type.size() * array_size, type.alignment());
|
||||||
|
|
||||||
/* Make sure that elements in the buffer will be destructed. */
|
/* Make sure that elements in the buffer will be destructed. */
|
||||||
PartiallyInitializedArray &destruct_helper = scope.construct<PartiallyInitializedArray>(
|
PartiallyInitializedArray &destruct_helper = scope.construct<PartiallyInitializedArray>();
|
||||||
__func__);
|
|
||||||
destruct_helper.buffer = buffer;
|
destruct_helper.buffer = buffer;
|
||||||
destruct_helper.mask = mask;
|
destruct_helper.mask = mask;
|
||||||
destruct_helper.type = &type;
|
destruct_helper.type = &type;
|
||||||
|
|
||||||
r_varrays[out_index] = &scope.construct<GVArray_For_GSpan>(
|
r_varrays[out_index] = &scope.construct<GVArray_For_GSpan>(
|
||||||
__func__, GSpan{type, buffer, array_size});
|
GSpan{type, buffer, array_size});
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
/* Write the result into the existing span. */
|
/* Write the result into the existing span. */
|
||||||
@@ -427,8 +426,7 @@ Vector<const GVArray *> evaluate_fields(ResourceScope &scope,
|
|||||||
void *buffer = scope.linear_allocator().allocate(type.size(), type.alignment());
|
void *buffer = scope.linear_allocator().allocate(type.size(), type.alignment());
|
||||||
|
|
||||||
/* Use this to make sure that the value is destructed in the end. */
|
/* Use this to make sure that the value is destructed in the end. */
|
||||||
PartiallyInitializedArray &destruct_helper = scope.construct<PartiallyInitializedArray>(
|
PartiallyInitializedArray &destruct_helper = scope.construct<PartiallyInitializedArray>();
|
||||||
__func__);
|
|
||||||
destruct_helper.buffer = buffer;
|
destruct_helper.buffer = buffer;
|
||||||
destruct_helper.mask = IndexRange(1);
|
destruct_helper.mask = IndexRange(1);
|
||||||
destruct_helper.type = &type;
|
destruct_helper.type = &type;
|
||||||
@@ -439,7 +437,7 @@ Vector<const GVArray *> evaluate_fields(ResourceScope &scope,
|
|||||||
/* Create virtual array that can be used after the procedure has been executed below. */
|
/* Create virtual array that can be used after the procedure has been executed below. */
|
||||||
const int out_index = constant_field_indices[i];
|
const int out_index = constant_field_indices[i];
|
||||||
r_varrays[out_index] = &scope.construct<GVArray_For_SingleValueRef>(
|
r_varrays[out_index] = &scope.construct<GVArray_For_SingleValueRef>(
|
||||||
__func__, type, array_size, buffer);
|
type, array_size, buffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
procedure_executor.call(IndexRange(1), mf_params, mf_context);
|
procedure_executor.call(IndexRange(1), mf_params, mf_context);
|
||||||
@@ -608,7 +606,7 @@ int FieldEvaluator::add_with_destination(GField field, GVMutableArray &dst)
|
|||||||
|
|
||||||
int FieldEvaluator::add_with_destination(GField field, GMutableSpan dst)
|
int FieldEvaluator::add_with_destination(GField field, GMutableSpan dst)
|
||||||
{
|
{
|
||||||
GVMutableArray &varray = scope_.construct<GVMutableArray_For_GMutableSpan>(__func__, dst);
|
GVMutableArray &varray = scope_.construct<GVMutableArray_For_GMutableSpan>(dst);
|
||||||
return this->add_with_destination(std::move(field), varray);
|
return this->add_with_destination(std::move(field), varray);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -661,7 +659,7 @@ IndexMask FieldEvaluator::get_evaluated_as_mask(const int field_index)
|
|||||||
return IndexRange(0);
|
return IndexRange(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
return scope_.add_value(indices_from_selection(*typed_varray), __func__).as_span();
|
return scope_.add_value(indices_from_selection(*typed_varray)).as_span();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace blender::fn
|
} // namespace blender::fn
|
||||||
|
@@ -41,7 +41,7 @@ class IndexFieldInput final : public FieldInput {
|
|||||||
auto index_func = [](int i) { return i; };
|
auto index_func = [](int i) { return i; };
|
||||||
return &scope.construct<
|
return &scope.construct<
|
||||||
GVArray_For_EmbeddedVArray<int, VArray_For_Func<int, decltype(index_func)>>>(
|
GVArray_For_EmbeddedVArray<int, VArray_For_Func<int, decltype(index_func)>>>(
|
||||||
__func__, mask.min_array_size(), mask.min_array_size(), index_func);
|
mask.min_array_size(), mask.min_array_size(), index_func);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -114,7 +114,7 @@ inline void NodeMultiFunctionBuilder::set_matching_fn(const MultiFunction &fn)
|
|||||||
template<typename T, typename... Args>
|
template<typename T, typename... Args>
|
||||||
inline void NodeMultiFunctionBuilder::construct_and_set_matching_fn(Args &&...args)
|
inline void NodeMultiFunctionBuilder::construct_and_set_matching_fn(Args &&...args)
|
||||||
{
|
{
|
||||||
const T &fn = resource_scope_.construct<T>(__func__, std::forward<Args>(args)...);
|
const T &fn = resource_scope_.construct<T>(std::forward<Args>(args)...);
|
||||||
this->set_matching_fn(&fn);
|
this->set_matching_fn(&fn);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -37,7 +37,7 @@ class IndexFieldInput final : public fn::FieldInput {
|
|||||||
auto index_func = [](int i) { return i; };
|
auto index_func = [](int i) { return i; };
|
||||||
return &scope.construct<
|
return &scope.construct<
|
||||||
fn::GVArray_For_EmbeddedVArray<int, VArray_For_Func<int, decltype(index_func)>>>(
|
fn::GVArray_For_EmbeddedVArray<int, VArray_For_Func<int, decltype(index_func)>>>(
|
||||||
__func__, mask.min_array_size(), mask.min_array_size(), index_func);
|
mask.min_array_size(), mask.min_array_size(), index_func);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@@ -104,10 +104,10 @@ static const GVArray *construct_mesh_normals_gvarray(const MeshComponent &mesh_c
|
|||||||
|
|
||||||
switch (domain) {
|
switch (domain) {
|
||||||
case ATTR_DOMAIN_FACE: {
|
case ATTR_DOMAIN_FACE: {
|
||||||
return scope.add_value(mesh_face_normals(mesh, verts, polys, loops, mask), __func__).get();
|
return scope.add_value(mesh_face_normals(mesh, verts, polys, loops, mask)).get();
|
||||||
}
|
}
|
||||||
case ATTR_DOMAIN_POINT: {
|
case ATTR_DOMAIN_POINT: {
|
||||||
return scope.add_value(mesh_vertex_normals(mesh, verts, polys, loops, mask), __func__).get();
|
return scope.add_value(mesh_vertex_normals(mesh, verts, polys, loops, mask)).get();
|
||||||
}
|
}
|
||||||
case ATTR_DOMAIN_EDGE: {
|
case ATTR_DOMAIN_EDGE: {
|
||||||
/* In this case, start with vertex normals and convert to the edge domain, since the
|
/* In this case, start with vertex normals and convert to the edge domain, since the
|
||||||
@@ -128,7 +128,7 @@ static const GVArray *construct_mesh_normals_gvarray(const MeshComponent &mesh_c
|
|||||||
}
|
}
|
||||||
|
|
||||||
return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float3>>>(
|
return &scope.construct<fn::GVArray_For_ArrayContainer<Array<float3>>>(
|
||||||
__func__, std::move(edge_normals));
|
std::move(edge_normals));
|
||||||
}
|
}
|
||||||
case ATTR_DOMAIN_CORNER: {
|
case ATTR_DOMAIN_CORNER: {
|
||||||
/* The normals on corners are just the mesh's face normals, so start with the face normal
|
/* The normals on corners are just the mesh's face normals, so start with the face normal
|
||||||
@@ -140,7 +140,7 @@ static const GVArray *construct_mesh_normals_gvarray(const MeshComponent &mesh_c
|
|||||||
* will still be normalized, since the face normal is just copied to every corner. */
|
* will still be normalized, since the face normal is just copied to every corner. */
|
||||||
GVArrayPtr loop_normals = mesh_component.attribute_try_adapt_domain(
|
GVArrayPtr loop_normals = mesh_component.attribute_try_adapt_domain(
|
||||||
std::move(face_normals), ATTR_DOMAIN_FACE, ATTR_DOMAIN_CORNER);
|
std::move(face_normals), ATTR_DOMAIN_FACE, ATTR_DOMAIN_CORNER);
|
||||||
return scope.add_value(std::move(loop_normals), __func__).get();
|
return scope.add_value(std::move(loop_normals)).get();
|
||||||
}
|
}
|
||||||
default:
|
default:
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
Reference in New Issue
Block a user