HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extCompCpuComputation.h
Go to the documentation of this file.
1 //
2 // Copyright 2017 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_IMAGING_HD_ST_EXT_COMP_CPU_COMPUTATION_H
8 #define PXR_IMAGING_HD_ST_EXT_COMP_CPU_COMPUTATION_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
12 
14 
15 #include "pxr/usd/sdf/path.h"
16 
17 #include "pxr/base/tf/token.h"
18 #include "pxr/base/vt/value.h"
19 
20 #include <memory>
21 #include <vector>
22 
24 
25 
26 class HdSceneDelegate;
27 class HdExtComputation;
28 
30  std::shared_ptr<class HdStExtCompCpuComputation>;
32  std::shared_ptr<class HdSt_ExtCompInputSource>;
34  std::vector<HdSt_ExtCompInputSourceSharedPtr>;
35 
36 ///
37 /// A Buffer Source that represents a CPU implementation of a ExtComputation.
38 ///
39 /// The computation implements the basic: input->processing->output model
40 /// where the inputs are other buffer sources and processing happens during
41 /// resolve.
42 ///
43 /// As a computation may have many outputs, the outputs from the CPU
44 /// Computation can not be directly associated with a BAR. Instead
45 /// other buffer source computation bind the output to sources that can
46 /// be used in a BAR.
47 ///
48 /// Outputs to a computation are in SOA form, so a computation may have
49 /// many outputs, but each output has the same number of elements in it.
51 {
52 public:
53  HDST_API
54  static const size_t INVALID_OUTPUT_INDEX;
55 
56  /// Constructs a new Cpu ExtComputation source.
57  /// inputs provides a list of buffer sources that this computation
58  /// requires.
59  /// outputs is a list of outputs by names that the computation produces.
60  ///
61  /// Num elements specifies the number of elements in the output.
62  ///
63  /// sceneDelegate and id are used to callback to the scene delegate
64  /// in order to invoke computation processing.
66  const SdfPath &id,
68  const TfTokenVector &outputs,
69  int numElements,
70  HdSceneDelegate *sceneDelegate);
71 
72  HDST_API
73  ~HdStExtCompCpuComputation() override;
74 
75  /// Create a CPU computation implementing the given abstract computation.
76  /// The scene delegate identifies which delegate to pull scene inputs from.
77  HDST_API
79  CreateComputation(HdSceneDelegate *sceneDelegate,
80  const HdExtComputation &computation,
81  HdBufferSourceSharedPtrVector *computationSources);
82 
83  /// Returns the id for this computation as a token.
84  HDST_API
85  TfToken const &GetName() const override;
86 
87  /// Ask the scene delegate to run the computation and captures the output
88  /// signals.
89  HDST_API
90  bool Resolve() override;
91 
92  HDST_API
93  size_t GetNumElements() const override;
94 
95 
96  /// Converts a output name token into an index.
97  HDST_API
98  size_t GetOutputIndex(const TfToken &outputName) const;
99 
100  /// Returns the value of the specified output
101  /// (after the computations been Resolved).
102  HDST_API
103  const VtValue &GetOutputByIndex(size_t index) const;
104 
105 protected:
106  /// Returns if the computation is specified correctly.
107  HDST_API
108  bool _CheckValid() const override;
109 
110 private:
111  SdfPath _id;
113  TfTokenVector _outputs;
114  size_t _numElements;
115  HdSceneDelegate *_sceneDelegate;
116 
117  std::vector<VtValue> _outputValues;
118 
119  HdStExtCompCpuComputation() = delete;
121  const HdStExtCompCpuComputation &) = delete;
122  HdStExtCompCpuComputation &operator = (
123  const HdStExtCompCpuComputation &) = delete;
124 };
125 
126 
128 
129 #endif // PXR_IMAGING_HD_ST_EXT_COMP_CPU_COMPUTATION_H
HDST_API bool _CheckValid() const override
Returns if the computation is specified correctly.
std::shared_ptr< class HdSt_ExtCompInputSource > HdSt_ExtCompInputSourceSharedPtr
static HDST_API const size_t INVALID_OUTPUT_INDEX
std::vector< HdBufferSourceSharedPtr > HdBufferSourceSharedPtrVector
Definition: bufferSource.h:27
Definition: token.h:70
HDST_API const VtValue & GetOutputByIndex(size_t index) const
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
Definition: path.h:273
HDST_API bool Resolve() override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HDST_API size_t GetOutputIndex(const TfToken &outputName) const
Converts a output name token into an index.
#define HDST_API
Definition: api.h:23
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::vector< HdSt_ExtCompInputSourceSharedPtr > HdSt_ExtCompInputSourceSharedPtrVector
static HDST_API HdStExtCompCpuComputationSharedPtr CreateComputation(HdSceneDelegate *sceneDelegate, const HdExtComputation &computation, HdBufferSourceSharedPtrVector *computationSources)
HDST_API TfToken const & GetName() const override
Returns the id for this computation as a token.
HDST_API ~HdStExtCompCpuComputation() override
Definition: value.h:146
HDST_API size_t GetNumElements() const override
std::shared_ptr< class HdStExtCompCpuComputation > HdStExtCompCpuComputationSharedPtr