Files
test/source/blender/blenlib/intern/compute_context.cc
Jacques Lucke be266a1c0c Refactor: Geometry Nodes: replace ComputeContextBuilder with ComputeContextCache
While `ComputeContextBuilder` worked well for building simple linear compute
contexts, it was fairly limiting for all the slightly more complex cases where
an entire tree of compute contexts is built. Using `ComputeContextCache` that is
easier to do more explicitly. There were only very few cases where using
`ComputeContextBuilder` would have still helped a bit, but it's not really worth
keeping that abstraction around just for those few cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/137370
2025-04-14 17:47:56 +02:00

62 lines
1.6 KiB
C++

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
/** \file
* \ingroup bli
*/
#include "BLI_compute_context.hh"
#include "BLI_stack.hh"
#include <sstream>
#include <xxhash.h>
namespace blender {
void ComputeContextHash::mix_in(const void *data, int64_t len)
{
const int64_t hash_size = sizeof(ComputeContextHash);
const int64_t buffer_len = hash_size + len;
DynamicStackBuffer<> buffer_owner(buffer_len, 8);
char *buffer = static_cast<char *>(buffer_owner.buffer());
memcpy(buffer, this, hash_size);
memcpy(buffer + hash_size, data, len);
const XXH128_hash_t hash = XXH3_128bits(buffer, buffer_len);
memcpy(this, &hash, sizeof(hash));
static_assert(sizeof(ComputeContextHash) == sizeof(hash));
}
std::ostream &operator<<(std::ostream &stream, const ComputeContextHash &hash)
{
std::stringstream ss;
ss << "0x" << std::hex << hash.v1 << hash.v2;
stream << ss.str();
return stream;
}
void ComputeContext::print_stack(std::ostream &stream, StringRef name) const
{
Stack<const ComputeContext *> stack;
for (const ComputeContext *current = this; current; current = current->parent_) {
stack.push(current);
}
stream << "Context Stack: " << name << "\n";
while (!stack.is_empty()) {
const ComputeContext *current = stack.pop();
stream << "-> ";
current->print_current_in_line(stream);
const ComputeContextHash &current_hash = current->hash_;
stream << " \t(hash: " << current_hash << ")\n";
}
}
std::ostream &operator<<(std::ostream &stream, const ComputeContext &compute_context)
{
compute_context.print_stack(stream, "");
return stream;
}
} // namespace blender