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 
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 
23 PXR_NAMESPACE_OPEN_SCOPE
24 
26 class VdfSchedule;
27 
41 class EF_API_TYPE EfMaskedSubExecutor : public VdfDatalessExecutor
42 {
43  // Executor factory.
44  typedef
45  VdfExecutorFactory<
51  _Factory;
52 
53 public:
54 
60  EF_API
61  EfMaskedSubExecutor(const VdfExecutorInterface *parentExecutor);
62 
65  EF_API
66  virtual ~EfMaskedSubExecutor();
67 
70  const VdfExecutorFactoryBase &GetFactory() const override {
71  return _factory;
72  }
73 
77  EF_API
78  virtual void DuplicateOutputData(
79  const VdfOutput &sourceOutput,
80  const VdfOutput &destOutput) override;
81 
90  virtual bool IsEmpty() const override {
91  return false;
92  }
93 
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 
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 
177 PXR_NAMESPACE_CLOSE_SCOPE
178 
179 #endif
A client may instantiate an object of this class and set it in an executor, to collect errors that ma...
virtual void _Run(const VdfSchedule &schedule, const VdfRequest &computeRequest, VdfExecutorErrorLogger *errorLogger)=0
Run this executor with the given schedule and request.
const VdfExecutorFactoryBase & GetFactory() const override
Factory construction.
virtual bool IsEmpty() const override
Indicates whether this executor contains data.
VdfId GetId() const
The unique id of this output.
Definition: output.h:100
A VdfMask is placed on connections to specify the data flowing through them.
Definition: mask.h:36
An abstract base class for executors, which do not store any data at all.
Executor used in speculation.
const VdfExecutorInterface * GetParentExecutor() const
Returns the parent executor, if any.
This class is used to abstract away knowledge of the cache data used for each node.
Definition: vector.h:58
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
const VdfVector * GetOutputValue(const VdfOutput &output, const VdfMask &mask) const
Returns the cached value for a given output if it has a cache that contains all values specified by m...
virtual bool HasInvalidationTimestampMismatch(const VdfOutput &source, const VdfOutput &dest) const =0
Returns true, if the invalidation timestamps between the source and dest outputs do not match,...
virtual void DuplicateOutputData(const VdfOutput &sourceOutput, const VdfOutput &destOutput)=0
Duplicates the output data associated with sourceOutput and copies it to destOutput.
Deallocate in the background.
virtual bool _IsOutputInvalid(const VdfId outputId, const VdfMask &invalidationMask) const =0
Returns true if the output is already invalid for the given invalidationMask.
virtual bool HasInvalidationTimestampMismatch(const VdfOutput &source, const VdfOutput &dest) const override
Returns true if the invalidation timestamps mismatch between the source and dest outputs.
A VdfOutput represents an output on a node.
Definition: output.h:31
virtual bool _InvalidateOutput(const VdfOutput &output, const VdfMask &invalidationMask)=0
Called during invalidation to mark outputs as invalid and determine when the traversal can terminate ...
This sub-executor masks the parent executor.
virtual VDF_API void _ClearData()
Virtual implementation of ClearData, which can optionally be overridden by derived classes.
This class provides an executor engine to the speculation executor.
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
Returns an output value for reading.
uint64_t VdfId
The unique identifier type for Vdf objects.
Definition: types.h:107