HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
inputValueBlock.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_INPUT_VALUE_BLOCK_H
8 #define PXR_EXEC_EF_INPUT_VALUE_BLOCK_H
9 
10 ///\file
11 
12 #include "pxr/pxr.h"
13 
14 #include "pxr/exec/ef/api.h"
15 
19 
20 #include <vector>
21 #include <utility>
22 
24 
25 /// Forward declarations
27 
28 ///////////////////////////////////////////////////////////////////////////////
29 ///
30 /// \class EfInputValueBlock
31 ///
32 /// \brief An input value block is a vector of (output, value) pairs, each
33 /// of which will be used to initialize a network before execution.
34 ///
36 {
37 
38 private:
39 
40  // The type representing the vector of (output, value) pairs.
41  typedef std::vector< std::pair<VdfMaskedOutput, VdfVector *> > _VectorType;
42 
43 public:
44 
45  /// Constructs an empty input value block.
46  ///
47  EfInputValueBlock() = default;
48 
49  /// Copy constructor.
50  ///
51  EF_API
53 
54  /// Move constructor.
55  ///
56  EfInputValueBlock(EfInputValueBlock &&rhs) = default;
57 
58  /// Destructor.
59  ///
60  EF_API
62 
63  /// Copy assignment operator.
64  ///
65  EF_API
66  EfInputValueBlock &operator=(const EfInputValueBlock &rhs);
67 
68  /// Move assignment operator.
69  ///
70  EfInputValueBlock &operator=(EfInputValueBlock &&rhs) = default;
71 
72  /// Adds an (output, value) pair to this block.
73  ///
74  /// Note that this API currently only supports single valued outputs and
75  /// does not yet support vectorized outputs.
76  ///
77  template <typename T>
78  void AddOutputValuePair(const VdfMaskedOutput &output, const T &value)
79  {
80  _values.push_back(std::make_pair( output, new VdfTypedVector<T>()));
81  _values.back().second->Set(value);
82  }
83 
84  /// Adds an (output, VdfVector) pair to this block.
85  ///
86  void AddOutputVectorPair(const VdfMaskedOutput &output,
87  const VdfVector &value)
88  {
89  _values.push_back(std::make_pair( output, new VdfVector(value) ) );
90  }
91 
92  /// Applies the input value block to an executor, by setting the output
93  /// values and pushing through invalidation for each one of the output
94  /// values set.
95  ///
96  /// \p invalidationRequest is an output parameter, which will return the
97  /// request used for invalidation.
98  ///
99  EF_API
100  void Apply(VdfExecutorInterface *executor,
101  VdfMaskedOutputVector *invalidationRequest = NULL) const;
102 
103  /// Pushes invalidation into the \p executor using the supplied
104  /// \p invalidationRequest. Contrary to the Apply method, this method does
105  /// not infer the invalidation request from the set input values. Instead,
106  /// the \p invalidationRequest may be specified by the caller.
107  ///
108  EF_API
110  const VdfMaskedOutputVector &invalidationRequest) const;
111 
112  /// A const iterator into a block vector.
113  ///
114  typedef _VectorType::const_iterator const_iterator;
115 
116  /// Returns a const_iterator to the beginning of the values vector.
117  ///
119  return _values.begin();
120  }
121 
122  /// Returns a const_iterator to the end of the values vector.
123  ///
124  const_iterator end() const {
125  return _values.end();
126  }
127 
128  /// Returns the number of outputs in this block.
129  ///
130  size_t GetSize() const {
131  return _values.size();
132  }
133 
134 private:
135 
136  // Push invalidation on to the executor.
137  //
138  void _Invalidate(VdfExecutorInterface *executor,
139  const VdfMaskedOutputVector &invalidationRequest) const;
140 
141  // Sets the output values on the executor.
142  //
143  void _SetValues(VdfExecutorInterface *executor) const;
144 
145  // Clears the input value block.
146  //
147  void _Clear();
148 
149  // Appends the contents of \p to this object.
150  //
151  void _Append(const EfInputValueBlock &rhs);
152 
153 private:
154 
155  // The value pairs that make up this block.
156  _VectorType _values;
157 
158 };
159 
160 /// A vector of EfInputValueBlocks.
161 ///
162 typedef std::vector< EfInputValueBlock > EfInputValueBlockVector;
163 
165 
166 #endif
void AddOutputVectorPair(const VdfMaskedOutput &output, const VdfVector &value)
const_iterator begin() const
#define PXR_NAMESPACE_OPEN_SCOPE
Definition: pxr.h:73
GLsizei const GLfloat * value
Definition: glcorearb.h:824
const_iterator end() const
size_t GetSize() const
EF_API void Apply(VdfExecutorInterface *executor, VdfMaskedOutputVector *invalidationRequest=NULL) const
EF_API ~EfInputValueBlock()
std::vector< EfInputValueBlock > EfInputValueBlockVector
EF_API void InvalidateAndApply(VdfExecutorInterface *executor, const VdfMaskedOutputVector &invalidationRequest) const
Class to hold on to an externally owned output and a mask.
Definition: maskedOutput.h:31
An input value block is a vector of (output, value) pairs, each of which will be used to initialize a...
EfInputValueBlock()=default
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
EF_API EfInputValueBlock & operator=(const EfInputValueBlock &rhs)
void AddOutputValuePair(const VdfMaskedOutput &output, const T &value)
_VectorType::const_iterator const_iterator
Abstract base class for classes that execute a VdfNetwork to compute a requested set of values...
std::vector< VdfMaskedOutput > VdfMaskedOutputVector
#define EF_API
Definition: api.h:25