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 
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/vdf/api.h"
17 #include "pxr/exec/vdf/types.h"
18 
19 PXR_NAMESPACE_OPEN_SCOPE
20 
26 {
29  Background = 0,
30 
33  Immediate
34 };
35 
37 
38 template<VdfDataManagerDeallocationMode DeallocationMode>
41 class VdfExecutorInvalidationData;
42 class VdfNetwork;
43 class VdfOutput;
45 
52 template<VdfDataManagerDeallocationMode Mode>
54 
58  typedef Vdf_ExecutorDataVector::DataHandle DataHandle;
59 };
60 
61 
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
76 Vdf_DataManagerVectorDeallocateNow(Vdf_ExecutorDataVector *data);
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
83 Vdf_DataManagerVectorDeallocateLater(Vdf_ExecutorDataVector *data);
84 
85 
93 template<VdfDataManagerDeallocationMode DeallocationMode>
94 class VdfDataManagerVector :
95  public VdfExecutorDataManager<VdfDataManagerVector<DeallocationMode> >
96 {
97 public:
98 
101  typedef
104 
107  typedef
111 
114  VdfDataManagerVector() : _data(nullptr) { }
115 
119 
122  void Resize(const VdfNetwork &network);
123 
130  bool IsValidDataHandle(const DataHandle handle) const {
131  return handle != Vdf_ExecutorDataVector::InvalidHandle;
132  }
133 
139  DataHandle GetOrCreateDataHandle(const VdfId outputId) const {
140  return _data->GetOrCreateDataHandle(outputId);
141  }
142 
147  DataHandle GetDataHandle(const VdfId outputId) const {
148  return _data
149  ? _data->GetDataHandle(outputId)
151  }
152 
159  return _data->GetBufferData(handle);
160  }
161 
168  VdfExecutorInvalidationData * GetInvalidationData(
169  const DataHandle handle) const {
170  return _data->GetInvalidationData(handle);
171  }
172 
176 
184  const DataHandle handle) const {
185  return _data->GetInvalidationTimestamp(handle);
186  }
187 
194  const DataHandle handle,
195  VdfInvalidationTimestamp timestamp) {
196  _data->SetInvalidationTimestamp(handle, timestamp);
197  }
198 
206  VdfSMBLData * GetSMBLData(const DataHandle handle) const {
207  return _data->GetSMBLData(handle);
208  }
209 
217  return _data->GetOrCreateSMBLData(handle);
218  }
219 
226  bool IsTouched(const DataHandle handle) const {
227  return _data->IsTouched(handle);
228  }
229 
236  void Touch(const DataHandle handle) const {
237  _data->Touch(handle);
238  }
239 
246  bool Untouch(const DataHandle handle) {
247  return _data->Untouch(handle);
248  }
249 
252  void ClearDataForOutput(const VdfId outputId);
253 
256  void Clear();
257 
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 
273 
274 template<VdfDataManagerDeallocationMode DeallocationMode>
276 {
277  if (DeallocationMode == VdfDataManagerDeallocationMode::Immediate) {
278  Vdf_DataManagerVectorDeallocateNow(_data);
279  } else {
280  Vdf_DataManagerVectorDeallocateLater(_data);
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 
323 PXR_NAMESPACE_CLOSE_SCOPE
324 
325 #endif
A VdfNetwork is a collection of VdfNodes and their connections.
Definition: network.h:59
void SetInvalidationTimestamp(const DataHandle &handle, VdfInvalidationTimestamp ts)
Sets the invalidation timestamp for the give data handle.
VdfDataManagerVector()
Constructor.
void Resize(const VdfNetwork &network)
Resize the data manager to accommodate the given network.
VDF_API Vdf_ExecutorDataVector * Vdf_DataManagerVectorAllocate(const VdfNetwork &network)
Private functions for memory management strategies.
VdfExecutorInvalidationData * GetInvalidationData(const DataHandle handle)
Returns the VdfExecutorInvalidationData associated with the given handle.
DataHandle GetOrCreateDataHandle(const VdfId outputId) const
Returns an existing data handle, or creates a new one for the given outputId.
DataHandle GetDataHandle(const VdfId outputId) const
Returns an existing data handle for the given outputId.
This class provides functionality to manage the executor specific data associated with each output in...
VdfExecutorBufferData * GetBufferData(const DataHandle handle) const
Returns the VdfExecutorBufferData associated with the given handle.
VdfExecutorDataManager< VdfDataManagerVector > Base
The base class.
This is a data manager for executors that uses data stored in a vector indexed by output ids.
VdfSMBLData * GetSMBLData(const DataHandle handle) const
Returns an existing VdfSMBLData associated with the given handle.
bool IsValidDataHandle(const DataHandle handle) const
Returns true if the given data handle is valid, i.e.
bool Untouch(const DataHandle handle)
Marks the data at the given handle as not having been touched by evaluation.
bool Untouch(const DataHandle handle)
Marks the data at the given handle as not having been touched by evaluation.
void Clear()
Clears all the data from this manager.
VdfSMBLData holds per-output data that is meant to be consumed by the executor.
Definition: smblData.h:30
DataHandle GetOrCreateDataHandle(const VdfId outputId)
Returns an existing data handle, or creates a new one for the given output.
VdfSMBLData * GetSMBLData(const DataHandle handle) const
Returns an existing VdfSMBLData associated with the given handle.
~VdfDataManagerVector()
Destructor.
This object is responsible for storing the executor buffer data, comprised of the executor cache vect...
size_t GetNumData() const
Returns the number of outputs that have data associated with them.
bool IsEmpty() const
Returns true if this data manager is empty.
Vdf_ExecutorDataManagerTraits< VdfDataManagerVector >::DataHandle DataHandle
The data handle type from the type traits class.
Deallocate in the background.
VdfExecutorBufferData * GetBufferData(const DataHandle handle)
Returns the VdfExecutorBufferData associated with the given handle.
VdfExecutorInvalidationData * GetInvalidationData(const DataHandle handle) const
Returns the VdfExecutorInvalidationData associated with the given handle.
DataHandle GetDataHandle(const VdfId outputId) const
Returns an existing data handle for the given output.
A VdfOutput represents an output on a node.
Definition: output.h:31
VdfSMBLData * GetOrCreateSMBLData(const DataHandle handle)
Returns an existing VdfSMBLData associated with the given handle or creates a new one of none exists.
A vector-like container for executor data used by the VdfDataManagerVector.
VdfInvalidationTimestamp GetInvalidationTimestamp(const DataHandle handle) const
Returns the VdfInvalidationTimestamp associated with the given handle.
void Touch(const DataHandle handle)
Marks the data at the given handle as having been touched by evaluation.
bool IsTouched(const DataHandle handle) const
Returns true if the data at the given handle has been touched by evaluation.
unsigned int VdfInvalidationTimestamp
Type of the timestamp that identifies the most recent round of invalidation.
Definition: types.h:74
void Touch(const DataHandle handle) const
Marks the data at the given handle as having been touched by evaluation.
void SetInvalidationTimestamp(const DataHandle handle, VdfInvalidationTimestamp timestamp)
Sets the invalidation timestamp for the give data handle.
VdfInvalidationTimestamp GetInvalidationTimestamp() const
Returns the current invalidation timestamp on this executor.
void ClearDataForOutput(const VdfId outputId)
Clears the buffer data for a specific output.
VdfSMBLData * GetOrCreateSMBLData(const DataHandle handle) const
Returns an existing VdfSMBLData associated with the given handle or creates a new one of none exists.
static const size_t InvalidHandle
This sentinel index denotes an invalid handle.
VdfInvalidationTimestamp GetInvalidationTimestamp(const DataHandle handle) const
Returns the VdfInvalidationTimestamp associated with the given handle.
bool IsTouched(const DataHandle handle)
Returns true if the data at the given handle has been touched by evaluation.
Forward definition of the traits class, which will be specialized by the derived data manager impleme...
VdfDataManagerDeallocationMode
Enum representing the deallocation strategy for the data manager.
size_t DataHandle
The data handle type is an index into the internal data vectors.
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107