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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_ST_EXT_COMP_CPU_COMPUTATION_H
25 #define PXR_IMAGING_HD_ST_EXT_COMP_CPU_COMPUTATION_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 
31 
32 #include "pxr/usd/sdf/path.h"
33 
34 #include "pxr/base/tf/token.h"
35 #include "pxr/base/vt/value.h"
36 
37 #include <memory>
38 #include <vector>
39 
41 
42 
43 class HdSceneDelegate;
44 class HdExtComputation;
45 
47  std::shared_ptr<class HdStExtCompCpuComputation>;
49  std::shared_ptr<class HdSt_ExtCompInputSource>;
51  std::vector<HdSt_ExtCompInputSourceSharedPtr>;
52 
53 ///
54 /// A Buffer Source that represents a CPU implementation of a ExtComputation.
55 ///
56 /// The computation implements the basic: input->processing->output model
57 /// where the inputs are other buffer sources and processing happens during
58 /// resolve.
59 ///
60 /// As a computation may have many outputs, the outputs from the CPU
61 /// Computation can not be directly associated with a BAR. Instead
62 /// other buffer source computation bind the output to sources that can
63 /// be used in a BAR.
64 ///
65 /// Outputs to a computation are in SOA form, so a computation may have
66 /// many outputs, but each output has the same number of elements in it.
68 {
69 public:
70  HDST_API
71  static const size_t INVALID_OUTPUT_INDEX;
72 
73  /// Constructs a new Cpu ExtComputation source.
74  /// inputs provides a list of buffer sources that this computation
75  /// requires.
76  /// outputs is a list of outputs by names that the computation produces.
77  ///
78  /// Num elements specifies the number of elements in the output.
79  ///
80  /// sceneDelegate and id are used to callback to the scene delegate
81  /// in order to invoke computation processing.
83  const SdfPath &id,
85  const TfTokenVector &outputs,
86  int numElements,
87  HdSceneDelegate *sceneDelegate);
88 
89  HDST_API
90  ~HdStExtCompCpuComputation() override;
91 
92  /// Create a CPU computation implementing the given abstract computation.
93  /// The scene delegate identifies which delegate to pull scene inputs from.
94  HDST_API
96  CreateComputation(HdSceneDelegate *sceneDelegate,
97  const HdExtComputation &computation,
98  HdBufferSourceSharedPtrVector *computationSources);
99 
100  /// Returns the id for this computation as a token.
101  HDST_API
102  TfToken const &GetName() const override;
103 
104  /// Ask the scene delegate to run the computation and captures the output
105  /// signals.
106  HDST_API
107  bool Resolve() override;
108 
109  HDST_API
110  size_t GetNumElements() const override;
111 
112 
113  /// Converts a output name token into an index.
114  HDST_API
115  size_t GetOutputIndex(const TfToken &outputName) const;
116 
117  /// Returns the value of the specified output
118  /// (after the computations been Resolved).
119  HDST_API
120  const VtValue &GetOutputByIndex(size_t index) const;
121 
122 protected:
123  /// Returns if the computation is specified correctly.
124  HDST_API
125  bool _CheckValid() const override;
126 
127 private:
128  SdfPath _id;
130  TfTokenVector _outputs;
131  size_t _numElements;
132  HdSceneDelegate *_sceneDelegate;
133 
134  std::vector<VtValue> _outputValues;
135 
136  HdStExtCompCpuComputation() = delete;
138  const HdStExtCompCpuComputation &) = delete;
139  HdStExtCompCpuComputation &operator = (
140  const HdStExtCompCpuComputation &) = delete;
141 };
142 
143 
145 
146 #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:44
Definition: token.h:87
HDST_API const VtValue & GetOutputByIndex(size_t index) const
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
Definition: path.h:290
HDST_API bool Resolve() override
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
HDST_API size_t GetOutputIndex(const TfToken &outputName) const
Converts a output name token into an index.
#define HDST_API
Definition: api.h:40
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
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:164
HDST_API size_t GetNumElements() const override
std::shared_ptr< class HdStExtCompCpuComputation > HdStExtCompCpuComputationSharedPtr