HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
dataManagerBasedExecutor.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_BASED_EXECUTOR_H
8 #define PXR_EXEC_VDF_DATA_MANAGER_BASED_EXECUTOR_H
9 
10 ///\file
11 
12 #include "pxr/pxr.h"
13 
15 #include "pxr/exec/vdf/output.h"
16 #include "pxr/exec/vdf/vector.h"
17 
19 
20 ///////////////////////////////////////////////////////////////////////////////
21 ///
22 /// \class VdfDataManagerBasedExecutor
23 ///
24 /// Base class for executors that use a data manager.
25 ///
26 /// This implements much of the API from VdfExecutorInterface that simply passes
27 /// the work on to a data manager.
28 ///
29 
30 template<typename DataManagerType, typename BaseClass>
31 class VdfDataManagerBasedExecutor : public BaseClass
32 {
33 public:
34 
35  /// Default constructor.
36  ///
38 
39  /// Construct with a parent executor.
40  ///
42  const VdfExecutorInterface *parentExecutor) :
43  BaseClass(parentExecutor)
44  {}
45 
46  /// Destructor.
47  ///
49 
50  /// Resize the executor data manager to accommodate the given \p network.
51  ///
52  virtual void Resize(const VdfNetwork &network) override {
53  _dataManager.Resize(network);
54  }
55 
56  /// Sets the cached value for a given \p output.
57  ///
58  /// If the output already contains data, it will be merged with the new
59  /// data as indicated by \p value and \p mask.
60  ///
61  virtual void SetOutputValue(
62  const VdfOutput &output,
63  const VdfVector &value,
64  const VdfMask &mask) override {
65  _dataManager.SetOutputValue(output, value, mask);
66  }
67 
68  /// Transfers the \p value to the given \p output.
69  ///
70  virtual bool TakeOutputValue(
71  const VdfOutput &output,
73  const VdfMask &mask) override {
74  return _dataManager.TakeOutputValue(output, value, mask);
75  }
76 
77  /// Duplicates the output data associated with \p sourceOutput and copies
78  /// it to \p destOutput.
79  ///
80  virtual void DuplicateOutputData(
81  const VdfOutput &sourceOutput,
82  const VdfOutput &destOutput) override {
83  _dataManager.DuplicateOutputData(sourceOutput, destOutput);
84  }
85 
86  /// Returns \c true of the data manager is empty.
87  ///
88  virtual bool IsEmpty() const override {
89  return _dataManager.IsEmpty();
90  }
91 
92  /// Returns \c true, if the invalidation timestamps between the \p source
93  /// and \p dest outputs do not match, i.e. the source output should be
94  /// mung buffer locked.
96  const VdfOutput &source,
97  const VdfOutput &dest) const override {
98  return _dataManager.HasInvalidationTimestampMismatch(
99  _dataManager.GetDataHandle(source.GetId()),
100  _dataManager.GetDataHandle(dest.GetId()));
101  }
102 
103 protected:
104 
105  /// Returns value for the cache that flows across \p connection.
106  ///
107  virtual const VdfVector *_GetInputValue(
108  const VdfConnection &connection,
109  const VdfMask &mask) const override {
110  return _dataManager.GetInputValue(connection, mask);
111  }
112 
113  /// Returns an output value for reading.
114  ///
116  const VdfOutput &output,
117  const VdfMask &mask) const override {
118  return _dataManager.GetOutputValueForReading(
119  _dataManager.GetDataHandle(output.GetId()), mask);
120  }
121 
122  /// Returns an output value for writing.
123  ///
125  const VdfOutput &output) const override {
126  return _dataManager.GetOrCreateOutputValueForWriting(
127  output, _dataManager.GetDataHandle(output.GetId()));
128  }
129 
130  /// Clears the data for a specific output on this executor.
131  ///
133  const VdfId outputId, const VdfId nodeId) override {
134  _dataManager.ClearDataForOutput(outputId);
135  }
136 
137  /// Returns \c true if the output is already invalid for the given
138  /// \p invalidationMask.
139  ///
140  virtual bool _IsOutputInvalid(
141  const VdfId outputId,
142  const VdfMask &invalidationMask) const override {
143  return _dataManager.IsOutputInvalid(outputId, invalidationMask);
144  }
145 
146  /// Called during invalidation to mark outputs as invalid and determine
147  /// when the traversal can terminate early.
148  ///
149  /// \p incomingInput is the VdfInput by which this \p output was reached
150  /// during invalidation traversal, or NULL if \p output is one of the
151  /// first-traversed outputs.
152  ///
153  /// Returns \c true if there was anything to invalidate and \c false if
154  /// \p output was already invalid.
155  ///
156  virtual bool _InvalidateOutput(
157  const VdfOutput &output,
158  const VdfMask &invalidationMask) override
159  {
160  return _dataManager.InvalidateOutput(output, invalidationMask);
161  }
162 
163  /// Called before invalidation begins to update the timestamp that will be
164  /// written for every VdfOutput visited during invalidation. This timestamp
165  /// is later used to identify outputs for mung buffer locking.
166  ///
167  virtual void _UpdateInvalidationTimestamp() override
168  {
169  _dataManager.UpdateInvalidationTimestamp(
170  BaseClass::GetExecutorInvalidationTimestamp());
171  }
172 
173  /// Called to set destOutput's buffer output to be a reference to the
174  /// buffer output of sourceOutput.
175  ///
177  const VdfOutput &destOutput,
178  const VdfOutput &sourceOutput,
179  const VdfMask &sourceMask) const override {
180  // XXX: We are getting the cached output value from the executor, which
181  // may give us a pointer into the parent executor data manager. We
182  // cannot take ownership of values stored outside of this
183  // executor's data manager. We have to come up with a way to
184  // support reference outputs as a core concept!
185  const VdfVector *sourceValue =
186  _GetOutputValueForReading(sourceOutput, sourceMask);
187  _dataManager.SetReferenceOutputValue(sourceValue, destOutput.GetId());
188  }
189 
190  /// Mark the output as having been visited. This is only to be used by
191  /// the speculation engine to tell its parent executor that an output
192  /// has been visited and should be marked for invalidation.
193  ///
194  virtual void _TouchOutput(const VdfOutput &output) const override
195  {
196  _dataManager.DataManagerType::Base::Touch(output);
197  }
198 
199 
200 protected:
201 
202  // This object manages the data needed for this executor, including all
203  // the cached output values.
204  DataManagerType _dataManager;
205 };
206 
208 
209 #endif
virtual void _SetReferenceOutputValue(const VdfOutput &destOutput, const VdfOutput &sourceOutput, const VdfMask &sourceMask) const override
VdfDataManagerBasedExecutor(const VdfExecutorInterface *parentExecutor)
virtual bool TakeOutputValue(const VdfOutput &output, VdfVector *value, const VdfMask &mask) override
virtual const VdfVector * _GetInputValue(const VdfConnection &connection, const VdfMask &mask) const override
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
void _ClearDataForOutput(const VdfId outputId, const VdfId nodeId) override
VdfId GetId() const
Definition: output.h:100
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
virtual void SetOutputValue(const VdfOutput &output, const VdfVector &value, const VdfMask &mask) override
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
GLint GLuint mask
Definition: glcorearb.h:124
virtual void DuplicateOutputData(const VdfOutput &sourceOutput, const VdfOutput &destOutput) override
virtual bool HasInvalidationTimestampMismatch(const VdfOutput &source, const VdfOutput &dest) const override
virtual bool _InvalidateOutput(const VdfOutput &output, const VdfMask &invalidationMask) override
virtual const VdfVector * _GetOutputValueForReading(const VdfOutput &output, const VdfMask &mask) const override
virtual void Resize(const VdfNetwork &network) override
virtual void _UpdateInvalidationTimestamp() override
virtual void _TouchOutput(const VdfOutput &output) const override
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual bool IsEmpty() const override
virtual bool _IsOutputInvalid(const VdfId outputId, const VdfMask &invalidationMask) const override
Abstract base class for classes that execute a VdfNetwork to compute a requested set of values...
virtual VdfVector * _GetOutputValueForWriting(const VdfOutput &output) const override
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107