Loading...
Searching...
No Matches
sparseOutputTraverser.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_OUTPUT_TRAVERSER_H
8#define PXR_EXEC_VDF_SPARSE_OUTPUT_TRAVERSER_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
16#include "pxr/exec/vdf/types.h"
17
18#include "pxr/base/tf/hashmap.h"
19
20#include <queue>
21#include <vector>
22
23PXR_NAMESPACE_OPEN_SCOPE
24
25class VdfInput;
26class VdfMask;
27class VdfOutput;
28
40{
41public:
54 static const int MaxRequestsBeforeEviction = 10;
55
62 VDF_API
63 VdfSparseOutputTraverser(bool enableCaching = true);
64
74 typedef std::function<
75 bool (const VdfOutput &, const VdfMask &, const VdfInput *) >
77
78
81
95 VDF_API
96 static void Traverse(
97 const VdfMaskedOutputVector &outputs,
98 const OutputCallback &outputCallback,
99 const VdfNodeCallback &nodeCallback);
100
108 VDF_API
110 const VdfMaskedOutputVector &outputs,
111 const OutputCallback &outputCallback,
112 const VdfNodeCallback &nodeCallback);
113
115
116
121 VDF_API
123
124private:
125
126 struct _CacheEntry;
127
128 // A cache line stored in the traversal cache map
129 struct _Cache
130 {
131 // The indices to all the root cache entries, representing the root
132 // nodes in the cached request
133 std::vector<int> rootIndices;
134
135 // A vector of cache entries
136 typedef std::vector<_CacheEntry> CacheEntries;
137 CacheEntries cacheEntries;
138 };
139
140 // Returns a new or existing cache entry keyed off of the sorted request.
141 // This method will also enforce the eviction policy.
142 _Cache* _GetOrCreateCacheEntry(const VdfMaskedOutputVector &sortedOutputs);
143
144 class _TraversalHelper;
145
146private:
147
148 // Flag to switch caching on and off (defaults to on).
149 bool _enableCaching;
150
151 // A map from masked outputs to _Cache objects.
152 using _TraversalCache =
153 TfHashMap<VdfMaskedOutputVector, _Cache, VdfMaskedOutputVector_Hash>;
154
155 // Cache used to speed up repeated traversals.
156 _TraversalCache _cache;
157
158 // The cache history is defined as a queue adaptor with an underlaying deque
159 using _CacheHistory = std::queue<_TraversalCache::iterator>;
160
161 // Maintain a history of added cache entries to allow for eviction
162 // of oldest cache entries
163 _CacheHistory _cacheHistory;
164
165};
166
167PXR_NAMESPACE_CLOSE_SCOPE
168
169#endif
A VdfInput is used to connect a VdfNode to one or more VdfNodes' outputs.
Definition: input.h:36
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:37
A VdfOutput represents an output on a node.
Definition: output.h:32
A class used for fast traversals of VdfNetworks in the input-to-output direction.
VDF_API void InvalidateAll()
Invalidates all cached traversals.
VDF_API VdfSparseOutputTraverser(bool enableCaching=true)
Creates a new VdfSparseOutputTraverser.
static VDF_API void Traverse(const VdfMaskedOutputVector &outputs, const OutputCallback &outputCallback, const VdfNodeCallback &nodeCallback)
Traverses the network, starting from the masked outputs in outputs.
std::function< bool(const VdfOutput &, const VdfMask &, const VdfInput *) > OutputCallback
Callback used when traversing a network.
VDF_API void TraverseWithCaching(const VdfMaskedOutputVector &outputs, const OutputCallback &outputCallback, const VdfNodeCallback &nodeCallback)
Traverses the network, starting from the masked outputs in request.
static const int MaxRequestsBeforeEviction
The number of requests to remain in the cache.
std::function< void(const VdfNode &)> VdfNodeCallback
Type of callback used when processing nodes.
Definition: types.h:68