Blender V5.0
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
8
10#include "BLI_stack.hh"
11
12#include <sstream>
13#include <xxhash.h>
14
15namespace blender {
16
17ComputeContextHash ComputeContextHash::from_bytes(const void *data, const int64_t len)
18{
19 ComputeContextHash final_hash;
20 const XXH128_hash_t hash = XXH3_128bits(data, len);
21 /* Cast to void * to avoid warnings. */
22 memcpy(static_cast<void *>(&final_hash), &hash, sizeof(hash));
23 static_assert(sizeof(ComputeContextHash) == sizeof(hash));
24 return final_hash;
25}
26
27std::ostream &operator<<(std::ostream &stream, const ComputeContextHash &hash)
28{
29 std::stringstream ss;
30 ss << "0x" << std::hex << hash.v1 << hash.v2;
31 stream << ss.str();
32 return stream;
33}
34
35void ComputeContext::print_stack(std::ostream &stream, StringRef name) const
36{
38 for (const ComputeContext *current = this; current; current = current->parent_) {
39 stack.push(current);
40 }
41 stream << "Context Stack: " << name << "\n";
42 while (!stack.is_empty()) {
43 const ComputeContext *current = stack.pop();
44 stream << "-> ";
45 current->print_current_in_line(stream);
46 const ComputeContextHash &current_hash = current->hash_;
47 stream << " \t(hash: " << current_hash << ")\n";
48 }
49}
50
51std::ostream &operator<<(std::ostream &stream, const ComputeContext &compute_context)
52{
53 compute_context.print_stack(stream, "");
54 return stream;
55}
56
57} // namespace blender
BMesh const char void * data
long long int int64_t
ComputeContext(const ComputeContext *parent)
void print_stack(std::ostream &stream, StringRef name) const
virtual void print_current_in_line(std::ostream &stream) const =0
bool is_empty() const
Definition BLI_stack.hh:308
void push(const T &value)
Definition BLI_stack.hh:213
std::ostream & operator<<(std::ostream &stream, const eAlpha &space)
Definition BLI_color.cc:15
const char * name
uint len