|
Blender V4.3
|
#include <optional>#include "BLI_array.hh"#include "BLI_linear_allocator.hh"#include "BLI_stack.hh"#include "BLI_string_ref.hh"#include "BLI_struct_equality_utils.hh"Go to the source code of this file.
Classes | |
| struct | blender::ComputeContextHash |
| class | blender::ComputeContext |
| class | blender::ComputeContextBuilder |
Namespaces | |
| namespace | blender |
When logging computed values, we generally want to know where the value was computed. For example, geometry nodes logs socket values so that they can be displayed in the ui. For that we can combine the logged value with a ComputeContext, which identifies the place where the value was computed.
This is not a trivial problem because e.g. just storing a pointer to the socket a value belongs to is not enough. That's because the same socket may correspond to many different values when the socket is used in a node group that is used multiple times. In this case, not only does the socket have to be stored but also the entire nested node group path that led to the evaluation of the socket.
Storing the entire "context path" for every logged value is not feasible, because that path can become quite long. So that would need much more memory, more compute overhead and makes it complicated to compare if two contexts are the same. If the identifier for a compute context would have a variable size, it would also be much harder to create a map from context to values.
The solution implemented below uses the following key ideas:
ComputeContextHash). While technically there could be hash collisions, the hashing algorithm has to be chosen to make that practically impossible. This way an entire context path, possibly consisting of many nested contexts, is represented by a single value that can be stored easily.Definition in file BLI_compute_context.hh.