HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parallelDataManagerVector.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_PARALLEL_DATA_MANAGER_VECTOR_H
8 #define PXR_EXEC_VDF_PARALLEL_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 
23 class VdfNetwork;
25 
26 ///////////////////////////////////////////////////////////////////////////////
27 ///
28 /// \class Vdf_ParallelExecutorDataManagerTraits<VdfParallelDataManagerVector>
29 ///
30 /// \brief Type traits specialization for the VdfParallelDataManagerVector.
31 ///
32 template<>
34 
35  /// The data handle type. For the VdfParallelDataManagerVector this is an
36  /// index into the vector.
37  ///
39 
40 };
41 
42 ///////////////////////////////////////////////////////////////////////////////
43 ///
44 /// \class VdfParallelDataManagerVector
45 ///
46 /// \brief This is a data manager for executors that uses data stored in a
47 /// vector indexed by output ids. Note that all methods on this data
48 /// manager are thread-safe unless specifically called out to not
49 /// be thread-safe in their documentation.
50 ///
52  public VdfParallelExecutorDataManager<VdfParallelDataManagerVector>
53 {
54 public:
55 
56  /// The base class
57  ///
58  typedef
61 
62  /// The data handle type from the type traits class.
63  ///
64  typedef
68 
69  /// Constructor.
70  ///
71  VdfParallelDataManagerVector() : _data(nullptr) {}
72 
73  /// Destructor.
74  ///
75  VDF_API
77 
78  /// Resize the data manager to accommodate the given network.
79  ///
80  /// This method is not thread-safe. It can only be called during quiescent
81  /// state.
82  ///
83  VDF_API
84  void Resize(const VdfNetwork &network);
85 
86  /// Returns \c true if the given data \p handle is valid, i.e. it is valid
87  /// to ask for data for this given \p handle.
88  ///
89  /// Note that attempting to resolve data at an invalid handle results in
90  /// undefined behavior.
91  ///
92  bool IsValidDataHandle(const DataHandle handle) const {
94  }
95 
96  /// Returns an existing data handle, or creates a new one for the given
97  /// \p outputId.
98  ///
99  /// This method is guaranteed to return a valid data handle.
100  ///
101  /// This method is not thread-safe when invoken with the same \p output
102  /// parameter from multiple threads. It is safe to call this method with
103  /// concurrently, with different \p output parameters.
104  ///
105  inline DataHandle GetOrCreateDataHandle(const VdfId outputId) const {
106  return _data->GetOrCreateDataHandle(outputId);
107  }
108 
109  /// Returns an existing data handle for the given \p outputId. This method
110  /// will return an invalid data handle, if no handle has been created
111  /// for the given \p output.
112  ///
113  inline DataHandle GetDataHandle(const VdfId outputId) const {
114  return _data
115  ? _data->GetDataHandle(outputId)
117  }
118 
119  /// Returns the VdfExecutorBufferData associated with the given \p handle.
120  ///
121  /// Note it is undefined behavior to call this method with an invalid
122  /// data \p handle.
123  ///
125  return _data->GetPrivateBufferData(handle);
126  }
127 
128  /// Returns the VdfExecutorBufferData associated with the given \p handle.
129  ///
130  /// Note it is undefined behavior to call this method with an invalid
131  /// data \p handle.
132  ///
134  return _data->GetScratchBufferData(handle);
135  }
136 
137  /// Returns the VdfExecutorBufferData associated with the given \p handle.
138  ///
139  /// Note it is undefined behavior to call this method with an invalid
140  /// data \p handle.
141  ///
143  return _data->GetPublicBufferData(handle);
144  }
145 
146  /// Publishes the private VdfExecutorBufferData, and retains the previously
147  /// public VdfExecutorBufferData.
148  /// After this method returns, clients may still read from the private data,
149  /// but are no longer allowed to mutate it.
150  ///
151  /// Note it is undefined behavior to call this method with an invalid
152  /// data \p handle.
153  ///
154  void PublishPrivateBufferData(const DataHandle handle) const {
155  _data->PublishPrivateBufferData(handle);
156  }
157 
158  /// Publishes the scratch VdfExecutorBufferData, and retains the previously
159  /// public VdfExecutorBufferData.
160  /// After this method returns, clients may still read from the scratch data,
161  /// but are no longer allowed to mutate it.
162  ///
163  /// Note it is undefined behavior to call this method with an invalid
164  /// data \p handle.
165  ///
166  void PublishScratchBufferData(const DataHandle handle) const {
167  _data->PublishScratchBufferData(handle);
168  }
169 
170  /// Returns the transferred VdfExecutorBufferData associated with the given
171  /// \p handle. This method will return nullptr, if no value has been written
172  /// back to this output.
173  ///
174  /// Note it is undefined behavior to call this method with an invalid data
175  /// \p handle.
176  ///
178  const DataHandle handle) const {
179  return _data->GetTransferredBufferData(handle);
180  }
181 
182  /// Transfers ownership of the \p value to the output associated with
183  /// \p handle. Returns \c true if the transfer of ownership was successful.
184  /// If the transfer of ownership was successful, the responsibility of
185  /// lifetime management for \p value transfers to this data manager.
186  /// Otherwise, the call site maintains this responsibility.
187  ///
188  /// Note that only one \p value can be transferred to each output.
189  /// Subsequent attempts to transfer will fail for that output.
190  ///
191  /// Note it is undefined behavior to call this method with an invalid
192  /// data \p handle.
193  ///
195  const DataHandle handle,
196  VdfVector *value,
197  const VdfMask &mask) {
198  return _data->TransferBufferData(handle, value, mask);
199  }
200 
201  /// Resets the transferred buffer associated with the given \p handle. If
202  /// any value has previously been written back to this output, its storage
203  /// will be freed.
204  ///
205  /// Note it is undefined behavior to call this method with an invalid data
206  /// \p handle.
207  ///
209  _data->ResetTransferredBufferData(handle);
210  }
211 
212  /// Returns the VdfExecutorInvalidationData associated with the given
213  /// \p handle.
214  ///
215  /// Note it is undefined behavior to call this method with an invalid
216  /// data \p handle.
217  ///
219  const DataHandle handle) const {
220  return _data->GetInvalidationData(handle);
221  }
222 
223  /// Un-hide the GetInvalidationTimestamp method declared in the base class.
224  ///
225  using Base::GetInvalidationTimestamp;
226 
227  /// Returns the VdfInvalidationTimestamp associated with the given
228  /// \p handle.
229  ///
230  /// Note it is undefined behavior to call this method with an invalid
231  /// data \p handle.
232  ///
234  const DataHandle handle) const {
235  return _data->GetInvalidationTimestamp(handle);
236  }
237 
238  /// Sets the invalidation \p timestamp for the give data \p handle.
239  ///
240  /// Note it is undefined behavior to call this method with an invalid
241  /// data \p handle.
242  ///
244  const DataHandle handle,
245  VdfInvalidationTimestamp timestamp) {
246  _data->SetInvalidationTimestamp(handle, timestamp);
247  }
248 
249  /// Returns \c true if the data at the given \p outputId has been touched by
250  /// evaluation.
251  ///
252  bool IsTouched(const VdfId outputId) const {
253  return _data->IsTouched(outputId);
254  }
255 
256  /// Marks the data at the given \p outputId as having been touched by
257  /// evaluation.
258  ///
259  void Touch(const VdfId outputId) const {
260  _data->Touch(outputId);
261  }
262 
263  /// Marks the data at the given \p outputId as not having been touched by
264  /// evaluation. Returns \c true if the data has previously been touched.
265  ///
266  bool Untouch(const VdfId outputId) {
267  return _data->Untouch(outputId);
268  }
269 
270  /// Clears the executor data for a specific output
271  ///
272  /// This method is not thread-safe. It must be invoked during quiescent
273  /// state only.
274  ///
275  VDF_API
276  void ClearDataForOutput(const VdfId outputId);
277 
278  /// Clears all the data from this manager.
279  ///
280  /// This method is not thread-safe. It must be invoked during quiescent
281  /// state only.
282  ///
283  VDF_API
284  void Clear();
285 
286  /// Returns \c true if this data manager is empty.
287  ///
288  bool IsEmpty() const {
289  return !_data || _data->GetNumData() == 0;
290  }
291 
292 
293 private:
294 
295  // Pointer the the executor data vector.
296  mutable Vdf_ParallelExecutorDataVector *_data;
297 
298 };
299 
300 ///////////////////////////////////////////////////////////////////////////////
301 
303 
304 #endif
This is a data container for executor data managers that uses data stored in vectors indexed by outpu...
void Touch(const VdfId outputId) const
bool IsValidDataHandle(const DataHandle handle) const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
void ResetTransferredBufferData(const DataHandle handle)
VdfExecutorBufferData * GetPublicBufferData(const DataHandle handle) const
VdfExecutorBufferData * GetPrivateBufferData(const DataHandle handle) const
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
VdfExecutorBufferData * GetTransferredBufferData(const DataHandle handle) const
VdfExecutorInvalidationData * GetInvalidationData(const DataHandle handle) const
This class provides functionality to manage executor data stored as VdfExecutorData from multiple thr...
bool TransferBufferData(const DataHandle handle, VdfVector *value, const VdfMask &mask)
#define VDF_API
Definition: api.h:25
bool IsTouched(const VdfId outputId) const
void PublishScratchBufferData(const DataHandle handle) const
DataHandle GetDataHandle(const VdfId outputId) const
void SetInvalidationTimestamp(const DataHandle handle, VdfInvalidationTimestamp timestamp)
VdfExecutorBufferData * GetScratchBufferData(const DataHandle handle) const
GLint GLuint mask
Definition: glcorearb.h:124
void PublishPrivateBufferData(const DataHandle handle) const
This object is responsible for storing the executor buffer data, comprised of the executor cache vect...
DataHandle GetOrCreateDataHandle(const VdfId outputId) const
This is a data manager for executors that uses data stored in a vector indexed by output ids...
#define VDF_API_TYPE
Definition: api.h:26
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
Vdf_ParallelExecutorDataManagerTraits< VdfParallelDataManagerVector >::DataHandle DataHandle
bool Untouch(const VdfId outputId)
VdfParallelExecutorDataManager< VdfParallelDataManagerVector > Base
VdfInvalidationTimestamp GetInvalidationTimestamp(const DataHandle handle) const
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107