This refactors how a geometry nodes node tree is converted to a lazy-function graph. Previously, all nodes were inserted into a single graph. This was fine because every node was evaluated at most once per node group evaluation. However, loops (#108896) break this assumption since now nodes may be evaluated multiple times and thus a single flat graph does not work anymore. Now, a separate lazy-function is build for every zone which gives us much more flexibility for what can happen in a zone. Right now, the change only applies to simulation zones since that's the only kind of zone we have. Technically, those zones could be inlined, but turning them into a separate lazy-function also does not hurt and makes it possible to test this refactor without implementing loops first. Also, having them as separate functions might help in the future if we integrate a substep loop directly into the simulation zone. The most tricky part here is to just link everything up correctly, especially with respect to deterministic anonymous attribute lifetimes. Fortunately, correctness can be checked visually by looking at the generated graphs. The logging/viewer system also had to be refactored a bit, because now there can be multiple different `ComputeContext` in a single node tree. Each zone is in a separate `ComputeContext`. To make it work, the `ViewerPath` system now explicitly supports zones and drawing code will look up the right logger for showing inspection data. No functional changes are expected, except that the spreadsheet now shows "Simulation Zone" in the context path if the viewer is in a simulation.
82 lines
2.0 KiB
C++
82 lines
2.0 KiB
C++
/* SPDX-FileCopyrightText: 2023 Blender Foundation
|
|
*
|
|
* SPDX-License-Identifier: GPL-2.0-or-later */
|
|
|
|
#pragma once
|
|
|
|
/**
|
|
* This file implements some specific compute contexts for concepts in Blender.
|
|
*/
|
|
|
|
#include <optional>
|
|
|
|
#include "BLI_compute_context.hh"
|
|
|
|
struct bNode;
|
|
|
|
namespace blender::bke {
|
|
|
|
class ModifierComputeContext : public ComputeContext {
|
|
private:
|
|
static constexpr const char *s_static_type = "MODIFIER";
|
|
|
|
/**
|
|
* Use modifier name instead of something like `session_uuid` for now because:
|
|
* - It's more obvious that the name matches between the original and evaluated object.
|
|
* - We might want that the context hash is consistent between sessions in the future.
|
|
*/
|
|
std::string modifier_name_;
|
|
|
|
public:
|
|
ModifierComputeContext(const ComputeContext *parent, std::string modifier_name);
|
|
|
|
private:
|
|
void print_current_in_line(std::ostream &stream) const override;
|
|
};
|
|
|
|
class NodeGroupComputeContext : public ComputeContext {
|
|
private:
|
|
static constexpr const char *s_static_type = "NODE_GROUP";
|
|
|
|
int32_t node_id_;
|
|
|
|
#ifdef DEBUG
|
|
std::string debug_node_name_;
|
|
#endif
|
|
|
|
public:
|
|
NodeGroupComputeContext(const ComputeContext *parent,
|
|
int32_t node_id,
|
|
const std::optional<ComputeContextHash> &cached_hash = {});
|
|
NodeGroupComputeContext(const ComputeContext *parent, const bNode &node);
|
|
|
|
int32_t node_id() const
|
|
{
|
|
return node_id_;
|
|
}
|
|
|
|
private:
|
|
void print_current_in_line(std::ostream &stream) const override;
|
|
};
|
|
|
|
class SimulationZoneComputeContext : public ComputeContext {
|
|
private:
|
|
static constexpr const char *s_static_type = "SIMULATION_ZONE";
|
|
|
|
int32_t output_node_id_;
|
|
|
|
public:
|
|
SimulationZoneComputeContext(const ComputeContext *parent, int output_node_id);
|
|
SimulationZoneComputeContext(const ComputeContext *parent, const bNode &node);
|
|
|
|
int32_t output_node_id() const
|
|
{
|
|
return output_node_id_;
|
|
}
|
|
|
|
private:
|
|
void print_current_in_line(std::ostream &stream) const override;
|
|
};
|
|
|
|
} // namespace blender::bke
|