Blender V4.3
compute_context.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
6
7#include <sstream>
8#include <xxhash.h>
9
10namespace blender {
11
12void ComputeContextHash::mix_in(const void *data, int64_t len)
13{
14 const int64_t hash_size = sizeof(ComputeContextHash);
15 const int64_t buffer_len = hash_size + len;
16 DynamicStackBuffer<> buffer_owner(buffer_len, 8);
17 char *buffer = static_cast<char *>(buffer_owner.buffer());
18 memcpy(buffer, this, hash_size);
19 memcpy(buffer + hash_size, data, len);
20
21 const XXH128_hash_t hash = XXH3_128bits(buffer, buffer_len);
22 memcpy(this, &hash, sizeof(hash));
23 static_assert(sizeof(ComputeContextHash) == sizeof(hash));
24}
25
26std::ostream &operator<<(std::ostream &stream, const ComputeContextHash &hash)
27{
28 std::stringstream ss;
29 ss << "0x" << std::hex << hash.v1 << hash.v2;
30 stream << ss.str();
31 return stream;
32}
33
34void ComputeContext::print_stack(std::ostream &stream, StringRef name) const
35{
37 for (const ComputeContext *current = this; current; current = current->parent_) {
38 stack.push(current);
39 }
40 stream << "Context Stack: " << name << "\n";
41 while (!stack.is_empty()) {
42 const ComputeContext *current = stack.pop();
43 stream << "-> ";
44 current->print_current_in_line(stream);
45 const ComputeContextHash &current_hash = current->hash_;
46 stream << " \t(hash: " << current_hash << ")\n";
47 }
48}
49
50std::ostream &operator<<(std::ostream &stream, const ComputeContext &compute_context)
51{
52 compute_context.print_stack(stream, "");
53 return stream;
54}
55
56} // namespace blender
void print_stack(std::ostream &stream, StringRef name) const
bool is_empty() const
Definition BLI_stack.hh:308
void push(const T &value)
Definition BLI_stack.hh:213
int len
std::ostream & operator<<(std::ostream &stream, const eAlpha &space)
Definition BLI_color.cc:11
#define hash
Definition noise.c:154
__int64 int64_t
Definition stdint.h:89
void mix_in(const void *data, int64_t len)