HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
parallelExecutorDataManagerInterface.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_EXECUTOR_DATA_MANAGER_INTERFACE_H
8 #define PXR_EXEC_VDF_PARALLEL_EXECUTOR_DATA_MANAGER_INTERFACE_H
9 
10 #include "pxr/pxr.h"
11 
12 #include "pxr/exec/vdf/types.h"
13 
15 
18 class VdfNetwork;
19 class VdfOutput;
20 class VdfVector;
21 
22 ///////////////////////////////////////////////////////////////////////////////
23 ///
24 /// \class Vdf_ParallelExecutorDataManagerInterface
25 ///
26 /// \brief The interface contract for the static polymorphism used by parallel
27 /// executor data manager implementations.
28 ///
29 template <typename DerivedClass, typename DataHandle>
31 {
32 protected:
33 
34  /// Allow construction via derived classes, only.
35  ///
37 
38  /// Prevent destruction via base class pointers (static polymorphism only).
39  ///
41 
42  /// Resize the data manager to accommodate all the outputs in the given
43  /// network.
44  ///
45  void _Resize(const VdfNetwork &network) {
46  _Self()->Resize(network);
47  }
48 
49  /// Returns \c true if the given data \p handle is valid, i.e. it is valid
50  /// to ask for data for this given \p handle.
51  ///
52  /// Note that attempting to resolve data at an invalid handle need not be
53  /// supported.
54  ///
55  bool _IsValidDataHandle(const DataHandle handle) const {
56  return _Self()->IsValidDataHandle(handle);
57  }
58 
59  /// Returns an existing data handle, or creates a new one for the given
60  /// \p outputId.
61  ///
62  /// This method must always return a valid data handle.
63  ///
64  DataHandle _GetOrCreateDataHandle(const VdfId outputId) const {
65  return _Self()->GetOrCreateDataHandle(outputId);
66  }
67 
68  /// Returns an existing data handle for the given \p outputId. This method
69  /// must return an invalid data handle, if no handle has been created
70  /// for the given \p outputId.
71  ///
72  DataHandle _GetDataHandle(const VdfId outputId) const {
73  return _Self()->GetDataHandle(outputId);
74  }
75 
76  /// Returns the private VdfExecutorBufferData associated with the given
77  /// \p handle.
78  ///
79  /// Note that attempting to retrieve data at an invalid handle need not
80  /// be supported.
81  ///
83  const DataHandle handle) const {
84  return _Self()->GetPrivateBufferData(handle);
85  }
86 
87  /// Returns the scratch VdfExecutorBufferData associated with the given
88  /// \p handle.
89  ///
90  /// Note that attempting to retrieve data at an invalid handle need not
91  /// be supported.
92  ///
94  const DataHandle handle) const {
95  return _Self()->GetScratchBufferData(handle);
96  }
97 
98  /// Returns the public VdfExecutorBufferData associated with the given
99  /// \p handle.
100  ///
101  /// Note that attempting to retrieve data at an invalid handle need not
102  /// be supported.
103  ///
105  const DataHandle handle) const {
106  return _Self()->GetPublicBufferData(handle);
107  }
108 
109  /// Publishes the private VdfExecutorBufferData, and retains the previously
110  /// public VdfExecutorBufferData as private data.
111  /// After this method returns, clients may still read from the private data,
112  /// but are no longer allowed to mutate it.
113  ///
114  /// Note it is undefined behavior to call this method with an invalid
115  /// data \p handle.
116  ///
117  void _PublishPrivateBufferData(const DataHandle handle) const {
118  _Self()->PublishPrivateBufferData(handle);
119  }
120 
121  /// Publishes the scratch VdfExecutorBufferData, and retains the previously
122  /// public VdfExecutorBufferData as scratch data.
123  /// After this method returns, clients may still read from the scratch data,
124  /// but are no longer allowed to mutate it.
125  ///
126  /// Note it is undefined behavior to call this method with an invalid
127  /// data \p handle.
128  ///
129  void _PublishScratchBufferData(const DataHandle handle) const {
130  _Self()->PublishScratchBufferData(handle);
131  }
132 
133  /// Returns the transferred VdfExecutorBufferData associated with the given
134  /// \p handle. This method will return nullptr, if no value has been written
135  /// back to this output.
136  ///
137  /// Note it is undefined behavior to call this method with an invalid data
138  /// \p handle.
139  ///
141  const DataHandle handle) const {
142  return _Self()->GetTransferredBufferData(handle);
143  }
144 
145  /// Transfers ownership of the \p value to the output associated with
146  /// \p handle. Returns \c true if the transfer of ownership was successful.
147  /// If the transfer of ownership was successful, the responsibility of
148  /// lifetime management for \p value transfers to this data manager.
149  /// Otherwise, the call site maintains this responsibility.
150  ///
151  /// Note that only one \p value can be transferred to each output.
152  /// Subsequent attempts to transfer will fail for that output.
153  ///
154  /// Note it is undefined behavior to call this method with an invalid
155  /// data \p handle.
156  ///
158  const DataHandle handle,
159  VdfVector *value,
160  const VdfMask &mask) {
161  return _Self()->TransferBufferData(handle, value, mask);
162  }
163 
164  /// Resets the transferred buffer associated with the given \p handle. If
165  /// any value has previously been written back to this output, its storage
166  /// will be freed.
167  ///
168  /// Note it is undefined behavior to call this method with an invalid data
169  /// \p handle.
170  ///
171  void _ResetTransferredBufferData(const DataHandle handle) {
172  _Self()->ResetTransferredBufferData(handle);
173  }
174 
175  /// Returns the VdfExecutorInvalidationData associated with the given
176  /// \p handle.
177  ///
178  /// Note that attempting to retrieve data at an invalid handle need not
179  /// be supported.
180  ///
182  const DataHandle handle) const {
183  return _Self()->GetInvalidationData(handle);
184  }
185 
186  /// Returns the VdfInvalidationTimestamp associated with the given
187  /// \p handle.
188  ///
189  /// Note that attempting to retrieve data at an invalid handle need not
190  /// be supported.
191  ///
193  const DataHandle handle) const {
194  return _Self()->GetInvalidationTimestamp(handle);
195  }
196 
197  /// Sets the invalidation \p timestamp for the give data \p handle.
198  ///
199  /// Note that attempting to retrieve data at an invalid handle need not
200  /// be supported.
201  ///
203  const DataHandle handle,
205  _Self()->SetInvalidationTimestamp(handle, ts);
206  }
207 
208  /// Returns \c true if the data at the given \p output has been touched by
209  /// evaluation.
210  ///
211  bool _IsTouched(const VdfId outputId) const {
212  return _Self()->IsTouched(outputId);
213  }
214 
215  /// Marks the data at the given \p output as having been touched by
216  /// evaluation.
217  ///
218  void _Touch(const VdfId outputId) const {
219  _Self()->Touch(outputId);
220  }
221 
222  /// Marks the data at the given \p output as not having been touched by
223  /// evaluation. Returns \c true if the data has previously been touched.
224  ///
225  bool _Untouch(const VdfId outputId) {
226  return _Self()->Untouch(outputId);
227  }
228 
229  /// Clears the executor data for a specific output
230  ///
231  void _ClearDataForOutput(const VdfOutput &output) {
232  return _Self()->ClearDataForOutput(output);
233  }
234 
235 private:
236 
237  // Returns the constant this pointer to the derived class.
238  const DerivedClass * _Self() const {
239  return static_cast<const DerivedClass *>(this);
240  }
241 
242 
243  // Returns the mutable this pointer to the derived class.
244  DerivedClass * _Self() {
245  return static_cast<DerivedClass *>(this);
246  }
247 
248 };
249 
251 
252 #endif
The interface contract for the static polymorphism used by parallel executor data manager implementat...
VdfExecutorInvalidationData * _GetInvalidationData(const DataHandle handle) const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
DataHandle _GetOrCreateDataHandle(const VdfId outputId) const
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
bool _TransferBufferData(const DataHandle handle, VdfVector *value, const VdfMask &mask)
void _PublishScratchBufferData(const DataHandle handle) const
GLint GLuint mask
Definition: glcorearb.h:124
VdfExecutorBufferData * _GetPrivateBufferData(const DataHandle handle) const
This object is responsible for storing the executor buffer data, comprised of the executor cache vect...
VdfInvalidationTimestamp _GetInvalidationTimestamp(const DataHandle handle) const
VdfExecutorBufferData * _GetPublicBufferData(const DataHandle handle) const
DataHandle _GetDataHandle(const VdfId outputId) const
VdfExecutorBufferData * _GetTransferredBufferData(const DataHandle handle) const
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
VdfExecutorBufferData * _GetScratchBufferData(const DataHandle handle) const
void _PublishPrivateBufferData(const DataHandle handle) const
void _SetInvalidationTimestamp(const DataHandle handle, VdfInvalidationTimestamp ts)
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107