Loading...
Searching...
No Matches
sparseVectorizedOutputTraverser.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_SPARSE_VECTORIZED_OUTPUT_TRAVERSER_H
8#define PXR_EXEC_VDF_SPARSE_VECTORIZED_OUTPUT_TRAVERSER_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
15#include "pxr/exec/vdf/mask.h"
21
22#include <tbb/concurrent_unordered_map.h>
23
24#include <functional>
25#include <map>
26#include <vector>
27
28PXR_NAMESPACE_OPEN_SCOPE
29
30class VdfNode;
31
40{
41public:
42
46 using NodeCallback = std::function<bool (const VdfNode &, size_t)>;
47
53 VDF_API
55 const VdfMaskedOutputVector &outputs,
56 const NodeCallback &callback);
57
60 VDF_API
61 void Invalidate();
62
63private:
64
65 // A cached dependency on a pool output.
66 struct _PoolDependency {
67 VdfPoolChainIndex poolChainIndex;
68 VdfMaskedOutput maskedOutput;
69 };
70
71 // An entry with cached dependencies.
72 struct _Dependencies {
76 };
77
78 // A pair of output pointer and mask pointer used for building the
79 // traversal stack (and queue.) The pointer-to-mask is used in order to
80 // avoid expensive traffic on the mask ref count.
81 struct _OutputAndMask {
82 VdfOutput *output;
83 const VdfMask *mask;
84 };
85
86 // A map with entries of outputs that have been visited, and with which
87 // mask these outputs have been visited with.
88 using _VisitedOutputs =
89 TfHashMap<const VdfOutput *, const VdfMask *, TfHash>;
90
91 // The type of output stack used to guide the traversal.
92 using _OutputStack = std::vector<_OutputAndMask>;
93
94 // The type of queue used to guide the traversal along the pool.
95 using _PoolQueue = std::map<const VdfPoolChainIndex, _OutputAndMask>;
96
97 // Returns true if the output should be visited and false if it already has
98 // been visited with the given mask.
99 bool _Visit(
100 const _OutputAndMask &outputAndMask,
101 _VisitedOutputs *visitedOutputs);
102
103 // Start a new traversal at the given output.
104 void _Traverse(
105 size_t index,
106 const VdfMaskedOutput &maskedOutput,
107 const NodeCallback &callback);
108
109 // Visits a single output.
110 void _TraverseOutput(
111 size_t index,
112 const _OutputAndMask &outputAndMask,
113 const NodeCallback &callback,
114 _OutputStack *stack,
115 _PoolQueue *queue);
116
117 // Queue a pool output.
118 void _QueuePoolOutput(
119 const VdfPoolChainIndex &poolChainIndex,
120 const _OutputAndMask &outputAndMask,
121 _PoolQueue *queue);
122
123 // Take a shortcut through the pool, if possible.
124 bool _TakePoolShortcut(
125 const _OutputAndMask &outputAndMask,
126 _PoolQueue *queue);
127
128 // Retrieves the dependencies for a single output, if cached, or computes
129 // dependencies of uncached.
130 const _Dependencies &_GetDependencies(
131 const _OutputAndMask &outputAndMask);
132
133 // Computes the dependencies for a single output.
134 void _ComputeDependencies(
135 const _OutputAndMask &outputAndMask,
136 _Dependencies *dependencies);
137
138 // The cached dependencies.
139 using _DependencyMap = tbb::concurrent_unordered_map<
140 VdfMaskedOutput, _Dependencies, VdfMaskedOutput::Hash>;
141 _DependencyMap _dependencyMap;
142
143 // The memoized mask operations.
145};
146
147PXR_NAMESPACE_CLOSE_SCOPE
148
149#endif
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:157
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:37
Memoizes the results of mask append (union) operations.
Definition: maskMemoizer.h:34
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:32
This is the base class for all nodes in a VdfNetwork.
Definition: node.h:53
A VdfOutput represents an output on a node.
Definition: output.h:32
Opaque pool chain index type.
Traverses a VdfNetwork in the input-to-output direction, while treating each output in the traversal ...
std::function< bool(const VdfNode &, size_t)> NodeCallback
The callback invoked for all all terminal nodes.
VDF_API void Traverse(const VdfMaskedOutputVector &outputs, const NodeCallback &callback)
Starts a traversal with the given outputs request and node callback.
VDF_API void Invalidate()
Invalidate the internal traversal cache.