Loading...
Searching...
No Matches
executorInvalidator.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_EXECUTOR_INVALIDATOR_H
8#define PXR_EXEC_VDF_EXECUTOR_INVALIDATOR_H
9
11
12#include "pxr/pxr.h"
13
14#include "pxr/exec/vdf/api.h"
16#include "pxr/exec/vdf/mask.h"
21#include "pxr/exec/vdf/types.h"
22
23#include "pxr/base/tf/hashmap.h"
25
26#include <map>
27#include <vector>
28
29PXR_NAMESPACE_OPEN_SCOPE
30
32
42{
43public:
44
49 _executor(executor),
50 _timestamp(0),
51 _replayLRU(16)
52 {}
53
57 VDF_API
58 void Invalidate(const VdfMaskedOutputVector &request);
59
63 VDF_API
64 void Reset();
65
66private:
67
68 // Information about a visited output.
69 struct _Visited {
70 explicit _Visited(uint32_t ts) : timestamp(ts), index(0) {}
71 uint32_t timestamp;
72 uint32_t index;
73 VdfMask mask;
74 };
75
76 // A cached dependency on a pool output.
77 struct _PoolDependency {
78 VdfPoolChainIndex poolChainIndex;
79 VdfMaskedOutput maskedOutput;
80 };
81
82 // An entry with cached dependencies.
83 struct _Dependencies {
87 };
88
89 // A cached invalidation entry for fast invalidation replay. The entry
90 // stores two masks, one for visits for which the invalidation callback
91 // returned true, and one for visits where it returned false.
92 struct _ReplayEntry {
93 explicit _ReplayEntry(const VdfOutput *o) : output(o) {}
94 const VdfOutput *output;
95 VdfMask masks[2];
96 };
97
98 // The cache of invalidation entries for fast replay. Every output has a
99 // unique entry in the cache, so that it can be replayed in parallel
100 // without risk of racing on the same output.
101 struct _ReplayCache {
102 std::vector<_ReplayEntry> entries;
104 };
105
106 // Array of visited outputs to information about the visit, indexed by
107 // output id.
108 using _VisitedMap = std::vector<_Visited>;
109
110 // The type of output stack used to guide the traversal.
111 using _OutputStack = std::vector<VdfMaskedOutput>;
112
113 // The type of queue used to guide the traversal along the pool.
114 using _PoolQueue = std::map<const VdfPoolChainIndex, VdfMaskedOutput>;
115
116 // Returns true if all the outputs in the given request are already invalid.
117 bool _IsInvalid(const VdfMaskedOutputVector &request) const;
118
119 // Returns a pointer to an existing replay cache for the given outputs.
120 // Creates a new cache if one does not already exist.
121 _ReplayCache* _GetReplayCache(const VdfMaskedOutputVector &outputs);
122
123 // Returns a valid pointer to an index if this output should be visited, or
124 // nullptr if the output has already been visited with the given mask. If
125 // the returned index equals nextIndex, the output is being visited for the
126 // first time.
127 uint32_t *_Visit(const VdfMaskedOutput &maskedOutput, uint32_t nextIndex);
128
129 // Initiates a new traversal starting at the outputs in request.
130 void _Traverse(
131 const VdfMaskedOutputVector &request,
132 _ReplayCache *replayCache);
133
134 // Visits a single output.
135 bool _TraverseOutput(
136 const VdfMaskedOutput &maskedOutput,
137 _OutputStack *stack,
138 _PoolQueue *queue,
140
141 // Replay a cached invalidation traversal. Returns false if the cache could
142 // not be successfully replayed and a new traversal must be started.
143 bool _Replay(const _ReplayCache &replayCache);
144
145 // Retrieves the dependencies for a single output, if cached, or computes
146 // dependencies of uncached.
147 const _Dependencies &_GetDependencies(
148 const VdfMaskedOutput &maskedOutput);
149
150 // Computes the dependencies for a single output.
151 void _ComputeDependencies(
152 const VdfMaskedOutput &maskedOutput,
153 _Dependencies *dependencies);
154
155 // Pointer to the executor that is being invalidated.
156 VdfExecutorInterface *_executor;
157
158 // The map of visited outputs.
159 _VisitedMap _visited;
160
161 // A timestamp denoting the current round of invalidation. Will be
162 // incremented for every subsequent round of invalidaiton.
163 uint32_t _timestamp;
164
165 // The cached dependencies.
166 using _DependencyMap = TfHashMap<
167 VdfMaskedOutput, _Dependencies, VdfMaskedOutput::Hash>;
168 _DependencyMap _dependencyMap;
169
170 // A list of recently used replay caches.
171 using _ReplayLRU = VdfLRUCache<
172 VdfMaskedOutputVector, _ReplayCache, VdfMaskedOutputVector_Hash>;
173 _ReplayLRU _replayLRU;
174
175 // The memoized mask operations.
176 VdfMaskMemoizer<TfHashMap> _maskMemoizer;
177
178};
179
181
182PXR_NAMESPACE_CLOSE_SCOPE
183
184#endif
This is a small-vector class with local storage optimization, the local storage can be specified via ...
Definition: smallVector.h:157
Abstract base class for classes that execute a VdfNetwork to compute a requested set of values.
Invalidates state and temporary buffers of all outputs dependent on the outputs supplied in the inval...
VDF_API void Invalidate(const VdfMaskedOutputVector &request)
Invalidate all the outputs in the request, as well as all the outputs dependent on the request.
VdfExecutorInvalidator(VdfExecutorInterface *executor)
Construct an executor invalidator for the given executor.
VDF_API void Reset()
Reset the internal state of the invalidator.
A simple cache with a fixed capacity and a least-recently-used eviction policy.
Definition: lruCache.h:28
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
A VdfOutput represents an output on a node.
Definition: output.h:32
Opaque pool chain index type.
TfHashMap< const VdfNode *, VdfInputPtrVector, TfHash > VdfNodeToInputPtrVectorMap
A map from node pointer to VdfInputPtrVector.
Definition: types.h:95
Hashing functor for VdfMaskedOutputVectors.