Currently, the import nodes always reimport on each evaluation. This patch adds support for caching the loaded geometries. This is integrated with `BLI_memory_cache.hh` and thus also takes the cache size limit into account. If an imported file is modified on disk, the cache is invalidated. However, Geometry Nodes will not automatically reevaluate when a file changes, so the user would have to trigger the evaluation in some other way. This is an alternative solution to #124369. The main benefits are that the cache invalidation happens automatically and that the cache system is more general and does not have to know about e.g. the different file types. Caching speeds up node setups that heavily rely on import nodes significantly. Pull Request: https://projects.blender.org/blender/blender/pulls/138425
49 lines
1.2 KiB
C++
49 lines
1.2 KiB
C++
/* SPDX-FileCopyrightText: 2025 Blender Authors
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
#include "BLI_generic_key.hh"
|
|
#include "BLI_string_ref.hh"
|
|
#include "BLI_struct_equality_utils.hh"
|
|
#include "BLI_utility_mixins.hh"
|
|
|
|
namespace blender {
|
|
|
|
/** Utility class that to easy create a #GenericKey from a string. */
|
|
class GenericStringKey : public GenericKey, NonMovable {
|
|
private:
|
|
std::string value_;
|
|
/** This may reference the string stored in value_. */
|
|
StringRef value_ref_;
|
|
|
|
public:
|
|
GenericStringKey(StringRef value) : value_ref_(value) {}
|
|
|
|
uint64_t hash() const override
|
|
{
|
|
return get_default_hash(value_ref_);
|
|
}
|
|
|
|
BLI_STRUCT_EQUALITY_OPERATORS_1(GenericStringKey, value_ref_)
|
|
|
|
bool equal_to(const GenericKey &other) const override
|
|
{
|
|
if (const auto *other_typed = dynamic_cast<const GenericStringKey *>(&other)) {
|
|
return value_ref_ == other_typed->value_ref_;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::unique_ptr<GenericKey> to_storable() const override
|
|
{
|
|
auto storable_key = std::make_unique<GenericStringKey>("");
|
|
storable_key->value_ = value_ref_;
|
|
storable_key->value_ref_ = storable_key->value_;
|
|
return storable_key;
|
|
}
|
|
};
|
|
|
|
} // namespace blender
|