HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
maskedSubExecutor.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_EF_MASKED_SUB_EXECUTOR_H
8 #define PXR_EXEC_EF_MASKED_SUB_EXECUTOR_H
9 
10 ///\file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/ef/api.h"
15 
19 #include "pxr/exec/vdf/types.h"
20 
21 #include <tbb/concurrent_unordered_map.h>
22 
24 
26 class VdfSchedule;
27 
28 ///////////////////////////////////////////////////////////////////////////////
29 ///
30 /// \class EfMaskedSubExecutor.
31 ///
32 /// \brief This sub-executor masks the parent executor. It is a dataless
33 /// executor, i.e. it does not hold on to any data caches. It does, however,
34 /// support invalidation and locally trackes invalidation state. If an output is
35 /// invalid on this executor, the call to GetOutputValue() will not look
36 /// up the data cache on the parent executor, and will instead return NULL.
37 /// Thus, the EfMaskedSubExecutor allows for correctly tracking invalidation
38 /// without affecting the invalidation state on the parent executor, potentially
39 /// messing with mung buffer locking, or stomping on existing buffers.
40 ///
42 {
43  // Executor factory.
44  typedef
51  _Factory;
52 
53 public:
54 
55  /// Constructor
56  ///
57  /// Note, this executor must be constructed with a parent executor present,
58  /// because it dispatches the calls to GetOutputValue to the parent.
59  ///
60  EF_API
61  EfMaskedSubExecutor(const VdfExecutorInterface *parentExecutor);
62 
63  /// Destructor
64  ///
65  EF_API
66  virtual ~EfMaskedSubExecutor();
67 
68  /// Factory construction.
69  ///
70  const VdfExecutorFactoryBase &GetFactory() const override {
71  return _factory;
72  }
73 
74  /// Duplicates the output data associated with \p sourceOutput and copies
75  /// it to \p destOutput.
76  ///
77  EF_API
78  virtual void DuplicateOutputData(
79  const VdfOutput &sourceOutput,
80  const VdfOutput &destOutput) override;
81 
82  /// Indicates whether this executor contains data.
83  ///
84  /// Note, that this method always returns \c false on this executor. We do
85  /// this in order to trick invalidation into thinking that there is always
86  /// data living on this executor. This allows us to push invalidation
87  /// through the entire network and record the invalidation state, without
88  /// regard for what state the parent executor is in.
89  ///
90  virtual bool IsEmpty() const override {
91  return false;
92  }
93 
94  /// Returns \c true if the invalidation timestamps mismatch between the
95  /// \p source and \p dest outputs. This information is used to determine
96  /// whether to lock the source output for mung buffer locking.
97  ///
98  /// Although, this executor does store invalidation state, we refer to the
99  /// parent executor to look up invalidation timestamps.
100  ///
102  const VdfOutput &source,
103  const VdfOutput &dest) const override {
104  const VdfExecutorInterface *parentExecutor = GetParentExecutor();
105  return
106  parentExecutor &&
107  parentExecutor->HasInvalidationTimestampMismatch(source, dest);
108  }
109 
110 protected:
111 
112  // This executor supports invalidation. Any invalid output will not be
113  // read from the parent executor.
114  //
115  virtual bool _InvalidateOutput(
116  const VdfOutput &output,
117  const VdfMask &invalidationMask) override;
118 
119  // This executor does not store temporary data caches, instead the locally
120  // stored invalidation state will be cleared out.
121  //
122  virtual void _ClearData() override;
123 
124 private:
125 
126  // Running this executor is not supported.
127  //
128  virtual void _Run(
129  const VdfSchedule &schedule,
130  const VdfRequest &computeRequest,
131  VdfExecutorErrorLogger *errorLogger) override;
132 
133  // Returns an output value for reading.
134  //
135  inline virtual const VdfVector *_GetOutputValueForReading(
136  const VdfOutput &output,
137  const VdfMask &mask) const override;
138 
139  // Returns \c true if the output is already invalid for the given
140  // \p invalidationMask.
141  //
142  virtual bool _IsOutputInvalid(
143  const VdfId outputId,
144  const VdfMask &invalidationMask) const override;
145 
146  // The factory shared amongst executors of this type.
147  //
148  static const _Factory _factory;
149 
150  // A set of invalid outputs. Note, that after creating this executor, all
151  // outputs are considered valid. As outputs become invalid, they are added
152  // to the set of invalid outputs.
153  //
154  using _InvalidOutputs = tbb::concurrent_unordered_map<VdfId, VdfMask>;
155  _InvalidOutputs _invalidOutputs;
156 };
157 
158 ///////////////////////////////////////////////////////////////////////////////
159 
160 const VdfVector *
161 EfMaskedSubExecutor::_GetOutputValueForReading(
162  const VdfOutput &output,
163  const VdfMask &mask) const
164 {
165  // If the output has not been invalidated on this executor, return the
166  // value stored at the parent executor. Otherwise, return NULL.
167  const VdfExecutorInterface *parentExecutor = GetParentExecutor();
168  _InvalidOutputs::const_iterator it =
169  _invalidOutputs.find(output.GetId());
170  if (parentExecutor &&
171  (it == _invalidOutputs.end() || !it->second.Overlaps(mask))) {
172  return parentExecutor->GetOutputValue(output, mask);
173  }
174  return NULL;
175 }
176 
178 
179 #endif
virtual bool _InvalidateOutput(const VdfOutput &output, const VdfMask &invalidationMask)=0
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
friend class VdfSpeculationExecutorEngine
VdfId GetId() const
Definition: output.h:100
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
#define EF_API_TYPE
Definition: api.h:26
An abstract base class for executors, which do not store any data at all. This class mainly serves th...
Executor used in speculation.
virtual void _Run(const VdfSchedule &schedule, const VdfRequest &computeRequest, VdfExecutorErrorLogger *errorLogger)=0
This is a data manager for executors that uses data stored in a vector indexed by output ids...
Contains a specification of how to execute a particular VdfNetwork.
Definition: schedule.h:40
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
GLint GLuint mask
Definition: glcorearb.h:124
virtual void _ClearData() override
const VdfExecutorFactoryBase & GetFactory() const override
virtual bool IsEmpty() const override
virtual bool HasInvalidationTimestampMismatch(const VdfOutput &source, const VdfOutput &dest) const =0
This sub-executor masks the parent executor. It is a dataless executor, i.e. it does not hold on to a...
const VdfVector * GetOutputValue(const VdfOutput &output, const VdfMask &mask) const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
virtual bool _IsOutputInvalid(const VdfId outputId, const VdfMask &invalidationMask) const =0
Abstract base class for classes that execute a VdfNetwork to compute a requested set of values...
virtual const VdfVector * _GetOutputValueForReading(const VdfOutput &output, const VdfMask &mask) const override
virtual void DuplicateOutputData(const VdfOutput &sourceOutput, const VdfOutput &destOutput)=0
const VdfExecutorInterface * GetParentExecutor() const
virtual bool HasInvalidationTimestampMismatch(const VdfOutput &source, const VdfOutput &dest) const override
#define EF_API
Definition: api.h:25
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107