Loading...
Searching...
No Matches
networkUtil.h
Go to the documentation of this file.
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_EXEC_VDF_NETWORK_UTIL_H
8#define PXR_EXEC_VDF_NETWORK_UTIL_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
16#include "pxr/exec/vdf/input.h"
18#include "pxr/exec/vdf/node.h"
19#include "pxr/exec/vdf/types.h"
20
21#include "pxr/base/tf/token.h"
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25class VdfMaskedOutput;
26class VdfOutput;
27
33
34
39VDF_API
40bool VdfIsSpeculating(const VdfMaskedOutput &maskedOutput);
41
49VDF_API
51 const VdfNode &startNode,
52 const VdfNode &nodeToFind,
53 bool *foundSpecNode = nullptr);
54
59VDF_API
61
64VDF_API
66
73template <class Callable>
75 const VdfNode &startNode,
76 Callable &&callback)
77{
78 // Keep track of the nodes we have already visited.
79 TfBits visited(startNode.GetNetwork().GetNodeCapacity());
80
81 // Maintain a stack of nodes to traverse.
82 std::vector<const VdfNode *> stack(1, &startNode);
83
84 // Keep traversing as long as there are entries on the stack.
85 while (!stack.empty()) {
86
87 // The stack top is the node we are currently looking at.
88 const VdfNode *top = stack.back();
89 stack.pop_back();
90
91 // Only consider this node, if it hasn't already been visited.
92 const VdfIndex idx = VdfNode::GetIndexFromId(top->GetId());
93 if (visited.IsSet(idx)) {
94 continue;
95 }
96 visited.Set(idx);
97
98 // Invoke the callback for the node, and push the input dependencies
99 // on the stack, as long as the callback returns true.
100 if (std::forward<Callable>(callback)(*top)) {
101 for (const std::pair<TfToken, VdfInput *> &i :
102 top->GetInputsIterator()) {
103 for (const VdfConnection *c : i.second->GetConnections()) {
104 stack.push_back(&c->GetSourceNode());
105 }
106 }
107 }
108 }
109}
110
112
113PXR_NAMESPACE_CLOSE_SCOPE
114
115#endif
116
117
Fast bit array that keeps track of the number of bits set and can find the next set in a timely manne...
Definition: bits.h:49
void Set(size_t index)
Sets bit # index to one.
Definition: bits.h:377
bool IsSet(size_t index) const
Returns true, if bit # index is set.
Definition: bits.h:412
A class that fully represents a connection between two VdfNodes.
Definition: connection.h:30
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:32
size_t GetNodeCapacity() const
Returns the number of entries currently available for nodes and for which it is valid to call GetNode...
Definition: network.h:95
This is the base class for all nodes in a VdfNetwork.
Definition: node.h:53
const InputMapIterator GetInputsIterator() const
Returns an iterator class that can be used with TF_FOR_ALL to iterate through the inputs.
Definition: node.h:177
static VdfIndex GetIndexFromId(const VdfId id)
Get the node index from the node id.
Definition: node.h:123
VdfId GetId() const
Returns the unique id of this node in its network.
Definition: node.h:116
const VdfNetwork & GetNetwork() const
Returns the network to which this node belongs.
Definition: node.h:138
A VdfOutput represents an output on a node.
Definition: output.h:32
uint32_t VdfIndex
The index type for Vdf objects.
Definition: types.h:110
void VdfTraverseTopologicalSourceNodes(const VdfNode &startNode, Callable &&callback)
Traverses nodes starting at startNode and moving along its inputs.
Definition: networkUtil.h:74
VDF_API void VdfEmptyNodeCallback(const VdfNode &)
Empty callback node, does nothing.
VDF_API const VdfOutput * VdfGetAssociatedSourceOutput(const VdfOutput &output)
Returns the output that is the source of the associated input of output, if any and NULL otherwise.
VDF_API bool VdfIsTopologicalSourceNode(const VdfNode &startNode, const VdfNode &nodeToFind, bool *foundSpecNode=nullptr)
Searches for nodeToFind via topological (ie.
VDF_API bool VdfIsSpeculating(const VdfMaskedOutput &maskedOutput)
Returns true, if maskedOutput is computed via speculation node.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...