Geometry Nodes: new repeat zone #109164

Merged
Jacques Lucke merged 98 commits from JacquesLucke/blender:serial-loop into main 2023-07-11 22:36:17 +02:00
9 changed files with 171 additions and 8 deletions
Showing only changes of commit e3d662c8f7 - Show all commits

View File

@ -78,4 +78,29 @@ class SimulationZoneComputeContext : public ComputeContext {
void print_current_in_line(std::ostream &stream) const override;
};
class SerialLoopZoneComputeContext : public ComputeContext {
private:
static constexpr const char *s_static_type = "SERIAL_LOOP_ZONE";
int32_t output_node_id_;
int iteration_;
public:
SerialLoopZoneComputeContext(const ComputeContext *parent, int output_node_id, int iteration);
JacquesLucke marked this conversation as resolved Outdated

int -> int32_t

`int` -> `int32_t`
SerialLoopZoneComputeContext(const ComputeContext *parent, const bNode &node, int iteration);
int32_t output_node_id() const
{
return output_node_id_;
}
int iteration() const
{
return iteration_;
}
private:
void print_current_in_line(std::ostream &stream) const override;
};
} // namespace blender::bke

View File

@ -53,6 +53,7 @@ ModifierViewerPathElem *BKE_viewer_path_elem_new_modifier(void);
GroupNodeViewerPathElem *BKE_viewer_path_elem_new_group_node(void);
SimulationZoneViewerPathElem *BKE_viewer_path_elem_new_simulation_zone(void);
ViewerNodeViewerPathElem *BKE_viewer_path_elem_new_viewer_node(void);
SerialLoopZoneViewerPathElem *BKE_viewer_path_elem_new_serial_loop_zone(void);
ViewerPathElem *BKE_viewer_path_elem_copy(const ViewerPathElem *src);
bool BKE_viewer_path_elem_equal(const ViewerPathElem *a, const ViewerPathElem *b);
void BKE_viewer_path_elem_free(ViewerPathElem *elem);

View File

@ -88,4 +88,33 @@ void SimulationZoneComputeContext::print_current_in_line(std::ostream &stream) c
stream << "Simulation Zone ID: " << output_node_id_;
}
SerialLoopZoneComputeContext::SerialLoopZoneComputeContext(const ComputeContext *parent,
const int32_t output_node_id,
const int iteration)
: ComputeContext(s_static_type, parent), output_node_id_(output_node_id), iteration_(iteration)
{
/* Mix static type and node id into a single buffer so that only a single call to #mix_in is
* necessary. */
const int type_size = strlen(s_static_type);
const int buffer_size = type_size + 1 + sizeof(int32_t) + sizeof(int);
DynamicStackBuffer<64, 8> buffer_owner(buffer_size, 8);
char *buffer = static_cast<char *>(buffer_owner.buffer());
memcpy(buffer, s_static_type, type_size + 1);
memcpy(buffer + type_size + 1, &output_node_id_, sizeof(int32_t));
memcpy(buffer + type_size + 1 + sizeof(int32_t), &iteration_, sizeof(int));
hash_.mix_in(buffer, buffer_size);
}
SerialLoopZoneComputeContext::SerialLoopZoneComputeContext(const ComputeContext *parent,
const bNode &node,
const int iteration)
: SerialLoopZoneComputeContext(parent, node.identifier, iteration)
{
}
void SerialLoopZoneComputeContext::print_current_in_line(std::ostream &stream) const
{
stream << "Serial Loop Zone ID: " << output_node_id_;
}
} // namespace blender::bke

View File

@ -88,6 +88,11 @@ void BKE_viewer_path_blend_write(BlendWriter *writer, const ViewerPath *viewer_p
BLO_write_struct(writer, ViewerNodeViewerPathElem, typed_elem);
break;
}
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
const auto *typed_elem = reinterpret_cast<SerialLoopZoneViewerPathElem *>(elem);
BLO_write_struct(writer, SerialLoopZoneViewerPathElem, typed_elem);
break;
}
}
BLO_write_string(writer, elem->ui_name);
}
@ -102,6 +107,7 @@ void BKE_viewer_path_blend_read_data(BlendDataReader *reader, ViewerPath *viewer
case VIEWER_PATH_ELEM_TYPE_GROUP_NODE:
case VIEWER_PATH_ELEM_TYPE_SIMULATION_ZONE:
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE:
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE:
case VIEWER_PATH_ELEM_TYPE_ID: {
break;
}
@ -126,7 +132,8 @@ void BKE_viewer_path_blend_read_lib(BlendLibReader *reader, ID *self_id, ViewerP
case VIEWER_PATH_ELEM_TYPE_MODIFIER:
case VIEWER_PATH_ELEM_TYPE_GROUP_NODE:
case VIEWER_PATH_ELEM_TYPE_SIMULATION_ZONE:
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE: {
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE:
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
break;
}
}
@ -145,7 +152,8 @@ void BKE_viewer_path_foreach_id(LibraryForeachIDData *data, ViewerPath *viewer_p
case VIEWER_PATH_ELEM_TYPE_MODIFIER:
case VIEWER_PATH_ELEM_TYPE_GROUP_NODE:
case VIEWER_PATH_ELEM_TYPE_SIMULATION_ZONE:
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE: {
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE:
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
break;
}
}
@ -164,7 +172,8 @@ void BKE_viewer_path_id_remap(ViewerPath *viewer_path, const IDRemapper *mapping
case VIEWER_PATH_ELEM_TYPE_MODIFIER:
case VIEWER_PATH_ELEM_TYPE_GROUP_NODE:
case VIEWER_PATH_ELEM_TYPE_SIMULATION_ZONE:
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE: {
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE:
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
break;
}
}
@ -196,6 +205,9 @@ ViewerPathElem *BKE_viewer_path_elem_new(const ViewerPathElemType type)
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE: {
return &make_elem<ViewerNodeViewerPathElem>(type)->base;
}
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
return &make_elem<SerialLoopZoneViewerPathElem>(type)->base;
}
}
BLI_assert_unreachable();
return nullptr;
@ -230,6 +242,12 @@ ViewerNodeViewerPathElem *BKE_viewer_path_elem_new_viewer_node()
BKE_viewer_path_elem_new(VIEWER_PATH_ELEM_TYPE_VIEWER_NODE));
}
SerialLoopZoneViewerPathElem *BKE_viewer_path_elem_new_serial_loop_zone()
{
return reinterpret_cast<SerialLoopZoneViewerPathElem *>(
BKE_viewer_path_elem_new(VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE));
}
ViewerPathElem *BKE_viewer_path_elem_copy(const ViewerPathElem *src)
{
ViewerPathElem *dst = BKE_viewer_path_elem_new(ViewerPathElemType(src->type));
@ -269,6 +287,13 @@ ViewerPathElem *BKE_viewer_path_elem_copy(const ViewerPathElem *src)
new_elem->node_id = old_elem->node_id;
break;
}
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
const auto *old_elem = reinterpret_cast<const SerialLoopZoneViewerPathElem *>(src);
auto *new_elem = reinterpret_cast<SerialLoopZoneViewerPathElem *>(dst);
new_elem->loop_output_node_id = old_elem->loop_output_node_id;
new_elem->iteration = old_elem->iteration;
break;
}
}
return dst;
}
@ -304,6 +329,12 @@ bool BKE_viewer_path_elem_equal(const ViewerPathElem *a, const ViewerPathElem *b
const auto *b_elem = reinterpret_cast<const ViewerNodeViewerPathElem *>(b);
return a_elem->node_id == b_elem->node_id;
}
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
const auto *a_elem = reinterpret_cast<const SerialLoopZoneViewerPathElem *>(a);
const auto *b_elem = reinterpret_cast<const SerialLoopZoneViewerPathElem *>(b);
return a_elem->loop_output_node_id == b_elem->loop_output_node_id &&
a_elem->iteration == b_elem->iteration;
}
}
return false;
}
@ -314,7 +345,8 @@ void BKE_viewer_path_elem_free(ViewerPathElem *elem)
case VIEWER_PATH_ELEM_TYPE_ID:
case VIEWER_PATH_ELEM_TYPE_GROUP_NODE:
case VIEWER_PATH_ELEM_TYPE_SIMULATION_ZONE:
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE: {
case VIEWER_PATH_ELEM_TYPE_VIEWER_NODE:
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
break;
}
case VIEWER_PATH_ELEM_TYPE_MODIFIER: {

View File

@ -83,9 +83,20 @@ static void viewer_path_for_geometry_node(const SpaceNode &snode,
const Vector<const bNodeTreeZone *> zone_stack = tree_zones->get_zone_stack_for_node(
node->identifier);
for (const bNodeTreeZone *zone : zone_stack) {
SimulationZoneViewerPathElem *node_elem = BKE_viewer_path_elem_new_simulation_zone();
node_elem->sim_output_node_id = zone->output_node->identifier;
BLI_addtail(&r_dst.path, node_elem);
switch (zone->output_node->type) {
case GEO_NODE_SIMULATION_OUTPUT: {
SimulationZoneViewerPathElem *node_elem = BKE_viewer_path_elem_new_simulation_zone();
node_elem->sim_output_node_id = zone->output_node->identifier;
BLI_addtail(&r_dst.path, node_elem);
break;
}
case GEO_NODE_SERIAL_LOOP_OUTPUT: {
SerialLoopZoneViewerPathElem *node_elem = BKE_viewer_path_elem_new_serial_loop_zone();
node_elem->loop_output_node_id = zone->output_node->identifier;
BLI_addtail(&r_dst.path, node_elem);
break;
}
}
}
GroupNodeViewerPathElem *node_elem = BKE_viewer_path_elem_new_group_node();
@ -221,7 +232,10 @@ std::optional<ViewerPathForGeometryNodesViewer> parse_geometry_nodes_viewer(
remaining_elems = remaining_elems.drop_front(1);
Vector<const ViewerPathElem *> node_path;
for (const ViewerPathElem *elem : remaining_elems.drop_back(1)) {
if (!ELEM(elem->type, VIEWER_PATH_ELEM_TYPE_GROUP_NODE, VIEWER_PATH_ELEM_TYPE_SIMULATION_ZONE))
if (!ELEM(elem->type,
VIEWER_PATH_ELEM_TYPE_GROUP_NODE,
VIEWER_PATH_ELEM_TYPE_SIMULATION_ZONE,
VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE))
{
return std::nullopt;
}
@ -275,6 +289,20 @@ bool exists_geometry_nodes_viewer(const ViewerPathForGeometryNodesViewer &parsed
zone = next_zone;
break;
}
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
const auto &typed_elem = *reinterpret_cast<const SerialLoopZoneViewerPathElem *>(
path_elem);
const bNodeTreeZone *next_zone = tree_zones->get_zone_by_node(
typed_elem.loop_output_node_id);
if (next_zone == nullptr) {
return false;
}
if (next_zone->parent_zone != zone) {
return false;
}
zone = next_zone;
break;
}
case VIEWER_PATH_ELEM_TYPE_GROUP_NODE: {
const auto &typed_elem = *reinterpret_cast<const GroupNodeViewerPathElem *>(path_elem);
const bNode *group_node = ngroup->node_by_id(typed_elem.node_id);

View File

@ -15,6 +15,7 @@ typedef enum ViewerPathElemType {
VIEWER_PATH_ELEM_TYPE_GROUP_NODE = 2,
VIEWER_PATH_ELEM_TYPE_SIMULATION_ZONE = 3,
VIEWER_PATH_ELEM_TYPE_VIEWER_NODE = 4,
VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE = 5,
} ViewerPathElemType;
typedef struct ViewerPathElem {
@ -48,6 +49,13 @@ typedef struct SimulationZoneViewerPathElem {
char _pad1[4];
} SimulationZoneViewerPathElem;
typedef struct SerialLoopZoneViewerPathElem {
ViewerPathElem base;
int loop_output_node_id;
int iteration;
} SerialLoopZoneViewerPathElem;
typedef struct ViewerNodeViewerPathElem {
ViewerPathElem base;

View File

@ -8056,6 +8056,7 @@ static const EnumPropertyItem viewer_path_elem_type_items[] = {
{VIEWER_PATH_ELEM_TYPE_GROUP_NODE, "GROUP_NODE", ICON_NONE, "Group Node", ""},
{VIEWER_PATH_ELEM_TYPE_SIMULATION_ZONE, "SIMULATION_ZONE", ICON_NONE, "Simulation Zone", ""},
{VIEWER_PATH_ELEM_TYPE_VIEWER_NODE, "VIEWER_NODE", ICON_NONE, "Viewer Node", ""},
{VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE, "SERIAL_LOOP_ZONE", ICON_NONE, "Serial Loop", ""},
{0, nullptr, 0, nullptr, nullptr},
};
@ -8123,6 +8124,17 @@ static void rna_def_simulation_zone_viewer_path_elem(BlenderRNA *brna)
RNA_def_property_ui_text(prop, "Simulation Output Node ID", "");
}
static void rna_def_serial_loop_zone_viewer_path_elem(BlenderRNA *brna)
{
StructRNA *srna;
PropertyRNA *prop;
srna = RNA_def_struct(brna, "SerialLoopZoneViewerPathElem", "ViewerPathElem");
prop = RNA_def_property(srna, "loop_output_node_id", PROP_INT, PROP_NONE);
RNA_def_property_ui_text(prop, "Loop Output Node ID", "");
}
static void rna_def_viewer_node_viewer_path_elem(BlenderRNA *brna)
{
StructRNA *srna;
@ -8144,6 +8156,7 @@ static void rna_def_viewer_path(BlenderRNA *brna)
rna_def_modifier_viewer_path_elem(brna);
rna_def_group_node_viewer_path_elem(brna);
rna_def_simulation_zone_viewer_path_elem(brna);
rna_def_serial_loop_zone_viewer_path_elem(brna);
rna_def_viewer_node_viewer_path_elem(brna);
srna = RNA_def_struct(brna, "ViewerPath", nullptr);

View File

@ -482,6 +482,27 @@ static void find_side_effect_nodes_for_viewer_path(
zone = next_zone;
break;
}
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
const auto &typed_elem = *reinterpret_cast<const SerialLoopZoneViewerPathElem *>(elem);
const bke::bNodeTreeZone *next_zone = tree_zones->get_zone_by_node(
typed_elem.loop_output_node_id);
if (next_zone == nullptr) {
return;
}
if (next_zone->parent_zone != zone) {
return;
}
const lf::FunctionNode *lf_zone_node = lf_graph_info->mapping.zone_node_map.lookup_default(
next_zone, nullptr);
if (lf_zone_node == nullptr) {
return;
}
local_side_effect_nodes.add(compute_context_builder.hash(), lf_zone_node);
compute_context_builder.push<bke::SerialLoopZoneComputeContext>(*next_zone->output_node,
typed_elem.iteration);
zone = next_zone;
break;
}
case VIEWER_PATH_ELEM_TYPE_GROUP_NODE: {
const auto &typed_elem = *reinterpret_cast<const GroupNodeViewerPathElem *>(elem);
const bNode *node = group->node_by_id(typed_elem.node_id);

View File

@ -638,6 +638,12 @@ const ViewerNodeLog *GeoModifierLog::find_viewer_node_log_for_path(const ViewerP
typed_elem.sim_output_node_id);
break;
}
case VIEWER_PATH_ELEM_TYPE_SERIAL_LOOP_ZONE: {
const auto &typed_elem = *reinterpret_cast<const SerialLoopZoneViewerPathElem *>(elem);
compute_context_builder.push<bke::SerialLoopZoneComputeContext>(
typed_elem.loop_output_node_id, typed_elem.iteration);
break;
}
default: {
BLI_assert_unreachable();
break;