HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataManagerVector.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_DATA_MANAGER_VECTOR_H
8 #define PXR_EXEC_VDF_DATA_MANAGER_VECTOR_H
9 
10 ///\file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
17 #include "pxr/exec/vdf/types.h"
18 
20 
21 ////////////////////////////////////////////////////////////////////////////////
22 ///
23 /// Enum representing the deallocation strategy for the data manager.
24 ///
26 {
27  /// Deallocate in the background
28  ///
29  Background = 0,
30 
31  /// Deallocate immediately
32  ///
33  Immediate
34 };
35 
36 ////////////////////////////////////////////////////////////////////////////////
37 
38 template<VdfDataManagerDeallocationMode DeallocationMode>
42 class VdfNetwork;
43 class VdfOutput;
45 
46 ///////////////////////////////////////////////////////////////////////////////
47 ///
48 /// \class Vdf_ExecutorDataManagerTraits<VdfDataManagerVector>
49 ///
50 /// \brief Type traits specialization for the VdfDataManagerVector.
51 ///
52 template<VdfDataManagerDeallocationMode Mode>
54 
55  /// The data handle type. For the VdfDataManagerVector this is an index
56  /// into the vector.
57  ///
59 };
60 
61 
62 ///////////////////////////////////////////////////////////////////////////////
63 ///
64 /// Private functions for memory management strategies
65 ///
66 
67 // Allocates an executor data vector for the given \p network.
68 VDF_API
71 
72 // Deallocates the executor data vector \p data that was alloacted with
73 // Vdf_DataManagerVectorAllocate, and does so immediately.
74 VDF_API
75 void
77 
78 // Queues up deallocation of the executor data vector \p data that was
79 // alloacted with Vdf_DataManagerVectorAllocate. The actually memory
80 // will be deallocated at an unspecified time in the future.
81 VDF_API
82 void
84 
85 
86 ///////////////////////////////////////////////////////////////////////////////
87 ///
88 /// \class VdfDataManagerVector
89 ///
90 /// \brief This is a data manager for executors that uses data stored in a
91 /// vector indexed by output ids.
92 ///
93 template<VdfDataManagerDeallocationMode DeallocationMode>
94 class VdfDataManagerVector :
95  public VdfExecutorDataManager<VdfDataManagerVector<DeallocationMode> >
96 {
97 public:
98 
99  /// The base class.
100  ///
101  typedef
104 
105  /// The data handle type from the type traits class.
106  ///
107  typedef
111 
112  /// Constructor.
113  ///
114  VdfDataManagerVector() : _data(nullptr) { }
115 
116  /// Destructor
117  ///
119 
120  /// Resize the data manager to accommodate the given network.
121  ///
122  void Resize(const VdfNetwork &network);
123 
124  /// Returns \c true if the given data \p handle is valid, i.e. it is valid
125  /// to ask for data for this given \p handle.
126  ///
127  /// Note that attempting to resolve data at an invalid handle results in
128  /// undefined behavior.
129  ///
130  bool IsValidDataHandle(const DataHandle handle) const {
131  return handle != Vdf_ExecutorDataVector::InvalidHandle;
132  }
133 
134  /// Returns an existing data handle, or creates a new one for the given
135  /// \p outputId.
136  ///
137  /// This method is guaranteed to return a valid data handle.
138  ///
139  DataHandle GetOrCreateDataHandle(const VdfId outputId) const {
140  return _data->GetOrCreateDataHandle(outputId);
141  }
142 
143  /// Returns an existing data handle for the given \p outputId. This method
144  /// will return an invalid data handle, if no handle has been created
145  /// for the given \p outputId.
146  ///
147  DataHandle GetDataHandle(const VdfId outputId) const {
148  return _data
149  ? _data->GetDataHandle(outputId)
151  }
152 
153  /// Returns the VdfExecutorBufferData associated with the given \p handle.
154  ///
155  /// Note it is undefined behavior to call this method with an invalid
156  /// data \p handle.
157  ///
159  return _data->GetBufferData(handle);
160  }
161 
162  /// Returns the VdfExecutorInvalidationData associated with the given
163  /// \p handle.
164  ///
165  /// Note it is undefined behavior to call this method with an invalid
166  /// data \p handle.
167  ///
169  const DataHandle handle) const {
170  return _data->GetInvalidationData(handle);
171  }
172 
173  /// Un-hide the GetInvalidationTimestamp method declared in the base class.
174  ///
176 
177  /// Returns the VdfInvalidationTimestamp associated with the given
178  /// \p handle.
179  ///
180  /// Note it is undefined behavior to call this method with an invalid
181  /// data \p handle.
182  ///
184  const DataHandle handle) const {
185  return _data->GetInvalidationTimestamp(handle);
186  }
187 
188  /// Sets the invalidation \p timestamp for the give data \p handle.
189  ///
190  /// Note it is undefined behavior to call this method with an invalid
191  /// data \p handle.
192  ///
194  const DataHandle handle,
195  VdfInvalidationTimestamp timestamp) {
196  _data->SetInvalidationTimestamp(handle, timestamp);
197  }
198 
199  /// Returns an existing \p VdfSMBLData associated with the given \p handle.
200  /// Returns \c nullptr if there is no SMBL data associated with this
201  /// data \p handle.
202  ///
203  /// Note it is undefined behavior to call this method with an invalid
204  /// data \p handle.
205  ///
206  VdfSMBLData * GetSMBLData(const DataHandle handle) const {
207  return _data->GetSMBLData(handle);
208  }
209 
210  /// Returns an existing \p VdfSMBLData associated with the given \p handle
211  /// or creates a new one of none exists.
212  ///
213  /// Note it is undefined behavior to call this method with an invalid
214  /// data \p handle.
215  ///
217  return _data->GetOrCreateSMBLData(handle);
218  }
219 
220  /// Returns \c true if the data at the given \p handle has been touched by
221  /// evaluation.
222  ///
223  /// Note it is undefined behavior to call this method with an invalid
224  /// data \p handle.
225  ///
226  bool IsTouched(const DataHandle handle) const {
227  return _data->IsTouched(handle);
228  }
229 
230  /// Marks the data at the given \p handle as having been touched by
231  /// evaluation.
232  ///
233  /// Note it is undefined behavior to call this method with an invalid
234  /// data \p handle.
235  ///
236  void Touch(const DataHandle handle) const {
237  _data->Touch(handle);
238  }
239 
240  /// Marks the data at the given \p handle as not having been touched by
241  /// evaluation. Returns \c true if the data has previously been touched.
242  ///
243  /// Note it is undefined behavior to call this method with an invalid
244  /// data \p handle.
245  ///
246  bool Untouch(const DataHandle handle) {
247  return _data->Untouch(handle);
248  }
249 
250  /// Clears the executor data for a specific output
251  ///
252  void ClearDataForOutput(const VdfId outputId);
253 
254  /// Clears all the data from this manager.
255  ///
256  void Clear();
257 
258  /// Returns \c true if this data manager is empty.
259  ///
260  bool IsEmpty() const {
261  return !_data || _data->GetNumData() == 0;
262  }
263 
264 
265 private:
266 
267  // The Vdf_ExecutorDataVector instance that holds the data.
268  mutable Vdf_ExecutorDataVector *_data;
269 
270 };
271 
272 ///////////////////////////////////////////////////////////////////////////////
273 
274 template<VdfDataManagerDeallocationMode DeallocationMode>
276 {
277  if (DeallocationMode == VdfDataManagerDeallocationMode::Immediate) {
279  } else {
281  }
282 }
283 
284 template<VdfDataManagerDeallocationMode DeallocationMode>
285 void
287 {
288  // Allocate a new Vdf_ExecutorDataVector if necessary.
289  if (!_data) {
290  _data = Vdf_DataManagerVectorAllocate(network);
291  }
292 
293  // Otherwise, make sure to resize our current instance.
294  else {
295  _data->Resize(network);
296  }
297 }
298 
299 template<VdfDataManagerDeallocationMode DeallocationMode>
300 void
302  const VdfId outputId)
303 {
304  // Clear the data associated with the given output (if it exists).
305  if (_data) {
306  const DataHandle dataHandle = _data->GetDataHandle(outputId);
307  if (IsValidDataHandle(dataHandle)) {
308  _data->Reset(dataHandle, outputId);
309  }
310  }
311 }
312 
313 template<VdfDataManagerDeallocationMode DeallocationMode>
314 void
316 {
317  // Clear all data.
318  if (_data) {
319  _data->Clear();
320  }
321 }
322 
324 
325 #endif
VdfSMBLData * GetOrCreateSMBLData(const DataHandle handle)
VDF_API Vdf_ExecutorDataVector * Vdf_DataManagerVectorAllocate(const VdfNetwork &network)
bool IsTouched(const DataHandle handle)
VdfInvalidationTimestamp GetInvalidationTimestamp() const
VDF_API void Vdf_DataManagerVectorDeallocateNow(Vdf_ExecutorDataVector *data)
void Touch(const DataHandle handle)
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
bool IsTouched(const DataHandle handle) const
VdfInvalidationTimestamp GetInvalidationTimestamp(const DataHandle handle) const
void ClearDataForOutput(const VdfId outputId)
Vdf_ExecutorDataManagerTraits< VdfDataManagerVector >::DataHandle DataHandle
bool Untouch(const DataHandle handle)
bool IsValidDataHandle(const DataHandle handle) const
DataHandle GetDataHandle(const VdfId outputId) const
void Touch(const DataHandle handle) const
#define VDF_API
Definition: api.h:25
This class provides functionality to manage the executor specific data associated with each output in...
void SetInvalidationTimestamp(const DataHandle handle, VdfInvalidationTimestamp timestamp)
bool Untouch(const DataHandle handle)
This is a data manager for executors that uses data stored in a vector indexed by output ids...
VdfExecutorInvalidationData * GetInvalidationData(const DataHandle handle) const
VdfExecutorInvalidationData * GetInvalidationData(const DataHandle handle)
VdfSMBLData holds per-output data that is meant to be consumed by the executor. This data is an optio...
Definition: smblData.h:30
VdfExecutorBufferData * GetBufferData(const DataHandle handle) const
VDF_API void Vdf_DataManagerVectorDeallocateLater(Vdf_ExecutorDataVector *data)
void SetInvalidationTimestamp(const DataHandle &handle, VdfInvalidationTimestamp ts)
VdfSMBLData * GetSMBLData(const DataHandle handle) const
This object is responsible for storing the executor buffer data, comprised of the executor cache vect...
DataHandle GetDataHandle(const VdfId outputId) const
VdfExecutorBufferData * GetBufferData(const DataHandle handle)
DataHandle GetOrCreateDataHandle(const VdfId outputId) const
VdfInvalidationTimestamp GetInvalidationTimestamp(const DataHandle handle) const
A vector-like container for executor data used by the VdfDataManagerVector. Unlike a hash-map...
unsigned int VdfInvalidationTimestamp
Type of the timestamp that identifies the most recent round of invalidation.
Definition: types.h:74
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
static const size_t InvalidHandle
VdfSMBLData * GetSMBLData(const DataHandle handle) const
VdfSMBLData * GetOrCreateSMBLData(const DataHandle handle) const
void Resize(const VdfNetwork &network)
DataHandle GetOrCreateDataHandle(const VdfId outputId)
VdfExecutorDataManager< VdfDataManagerVector > Base
Definition: format.h:1821
VdfDataManagerDeallocationMode
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107