HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
requestImpl.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_EXEC_REQUEST_IMPL_H
8 #define PXR_EXEC_EXEC_REQUEST_IMPL_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/exec/api.h"
13 #include "pxr/exec/exec/request.h"
15 
16 #include "pxr/base/tf/bits.h"
20 #include "pxr/exec/vdf/types.h"
21 
22 #include <memory>
23 #include <vector>
24 
26 
27 class EfTime;
28 struct Exec_AttributeValueInvalidationResult;
29 class Exec_CacheView;
30 struct Exec_DisconnectedInputsInvalidationResult;
31 struct Exec_MetadataInvalidationResult;
32 class Exec_TimeChangeInvalidationResult;
33 class Exec_ValueExtractor;
34 class ExecSystem;
35 class ExecValueKey;
36 template <typename> class TfSpan;
37 class VdfRequest;
38 class VdfSchedule;
39 
40 /// Contains data structures necessary to implement exec requests that are
41 /// independent of scene description.
42 ///
43 /// Concrete implementations inherit from Exec_RequestImpl to implement any
44 /// functionality that is specific to the scene description system.
45 ///
47 {
48 public:
49  /// Notify the request of invalid computed values as a consequence of
50  /// attribute authored value invalidation.
51  ///
53  const Exec_AttributeValueInvalidationResult &invalidationResult);
54 
55  /// Notify the request of invalid computed values as a consequence of
56  /// metadata authored value invalidation.
57  ///
59  const Exec_MetadataInvalidationResult &invalidationResult);
60 
61  /// Notify the request of invalid computed values as a consequence of
62  /// uncompilation.
63  ///
65  const Exec_DisconnectedInputsInvalidationResult &invalidationResult);
66 
67  /// Notify the request to invalidate value keys that don't have a compiled
68  /// leaf node.
69  ///
71 
72  /// Notify the request of time having changed.
73  void DidChangeTime(
74  const Exec_TimeChangeInvalidationResult &invalidationResult);
75 
76  /// Expires all request indices and discards the request.
77  ///
78  /// Sends value invalidation for all indicies over all time and renders
79  /// the request unusuable for any future operation.
80  ///
81  void Expire();
82 
83 protected:
84  EXEC_API
86  ExecSystem *system,
89 
90  Exec_RequestImpl(const Exec_RequestImpl&) = delete;
91  Exec_RequestImpl& operator=(const Exec_RequestImpl&) = delete;
92 
93  EXEC_API
95 
96  /// Compiles outputs for the value keys in the request.
97  EXEC_API
98  void _Compile(TfSpan<const ExecValueKey> valueKeys);
99 
100  /// Builds the schedule for the request.
101  EXEC_API
102  void _Schedule();
103 
104  /// Computes the value keys in the request.
105  EXEC_API
107 
108  /// Computes the value keys in the request in the presence of the provided
109  /// \p valueOverrides.
110  ///
111  EXEC_API
113  ExecValueOverrideVector &&valueOverrides);
114 
115  /// Returns true if the request needs to be compiled.
116  ///
117  /// A request may skip compilation if its schedule is up-to-date and there
118  /// is no pending recompilation in the network.
119  ///
120  EXEC_API
121  bool _RequiresCompilation() const;
122 
123  /// Expires the indices in \p expired.
124  ///
125  /// Invalidation callbacks will be invoked for these indices one final
126  /// time. No values will be extractable and no further invalidation will
127  /// be sent for these indices.
128  ///
129  EXEC_API
130  void _ExpireIndices(const ExecRequestIndexSet &expired);
131 
132  /// Removes the request from the system.
133  ///
134  /// This prevents any further notification and releases internal request
135  /// data structures.
136  ///
137  EXEC_API
138  void _Discard();
139 
140 private:
141  // Ensures the _leafNodeToIndex map is up-to-date.
142  void _BuildLeafNodeToIndexMap();
143 
144  // Turns invalid leaf nodes into a set of requested - and not previously
145  // invalidated - indices.
146  //
147  void _InvalidateLeafOutputs(
148  bool isNewlyInvalidInterval,
150  ExecRequestIndexSet *invalidIndices);
151 
152 private:
153  // The system that issued this request.
154  ExecSystem *_system;
155 
156  // The compiled leaf output.
157  std::vector<VdfMaskedOutput> _leafOutputs;
158 
159  // Value extractors corresponding to each requested value.
160  std::vector<Exec_ValueExtractor> _extractors;
161 
162  // Maps leaf nodes to their index in the array of valueKeys the request
163  // was built with.
164  pxr_tsl::robin_map<VdfId, size_t> _leafNodeToIndex;
165 
166  // The compute request to cache values with.
167  std::unique_ptr<VdfRequest> _computeRequest;
168 
169  // The schedule to cache values with.
170  std::unique_ptr<VdfSchedule> _schedule;
171 
172  // The combined time interval for which invalidation has been sent out.
173  EfTimeInterval _lastInvalidatedInterval;
174 
175  // The combined set of indices for which invalidation has been sent out.
176  TfBits _lastInvalidatedIndices;
177 
178  // The invalidation callback to invoke when computed values change.
180 
181  // The invalidation callback to invoke when time changes.
183 };
184 
186 
187 #endif
EXEC_API void _Discard()
EXEC_API void _Compile(TfSpan< const ExecValueKey > valueKeys)
Compiles outputs for the value keys in the request.
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
void DidChangeTime(const Exec_TimeChangeInvalidationResult &invalidationResult)
Notify the request of time having changed.
Definition: time.h:36
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:48
void DidInvalidateComputedValues(const Exec_AttributeValueInvalidationResult &invalidationResult)
EXEC_API Exec_CacheView _ComputeWithOverrides(ExecValueOverrideVector &&valueOverrides)
EXEC_API bool _RequiresCompilation() const
Contains a specification of how to execute a particular VdfNetwork.
Definition: schedule.h:40
Definition: span.h:70
EXEC_API Exec_RequestImpl(ExecSystem *system, ExecRequestComputedValueInvalidationCallback &&valueCallback, ExecRequestTimeChangeInvalidationCallback &&timeCallback)
EXEC_API Exec_CacheView _Compute()
Computes the value keys in the request.
EXEC_API void _Schedule()
Builds the schedule for the request.
std::function< void(const ExecRequestIndexSet &)> ExecRequestTimeChangeInvalidationCallback
Definition: request.h:41
#define EXEC_API
Definition: api.h:25
EXEC_API ~Exec_RequestImpl()
Exec_RequestImpl & operator=(const Exec_RequestImpl &)=delete
void DidInvalidateUnknownValues()
EXEC_API void _ExpireIndices(const ExecRequestIndexSet &expired)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::function< void(const ExecRequestIndexSet &, const class EfTimeInterval &)> ExecRequestComputedValueInvalidationCallback
Definition: request.h:31
std::vector< ExecValueOverride > ExecValueOverrideVector
Definition: valueOverride.h:36