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_EXT_COMP_CPU_COMPUTATION_H
25 #define PXR_IMAGING_HD_EXT_COMP_CPU_COMPUTATION_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
30 
31 #include "pxr/usd/sdf/path.h"
32 
33 #include "pxr/base/tf/token.h"
34 #include "pxr/base/vt/value.h"
35 
36 #include <memory>
37 
39 
40 class HdSceneDelegate;
41 class HdExtComputation;
43 
45  std::shared_ptr<HdExtCompCpuComputation>;
46 
47 ///
48 /// A Buffer Source that represents a CPU implementation of a ExtComputation.
49 ///
50 /// The computation implements the basic: input->processing->output model
51 /// where the inputs are other buffer sources and processing happens during
52 /// resolve.
53 ///
54 /// As a computation may have many outputs, the outputs from the CPU
55 /// Computation can not be directly associated with a BAR. Instead
56 /// other buffer source computation bind the output to sources that can
57 /// be used in a BAR.
58 ///
59 /// Outputs to a computation are in SOA form, so a computation may have
60 /// many outputs, but each output has the same number of elements in it.
62 public:
63  static const size_t INVALID_OUTPUT_INDEX;
64 
65  /// Constructs a new Cpu ExtComputation source.
66  /// inputs provides a list of buffer sources that this computation
67  /// requires.
68  /// outputs is a list of outputs by names that the computation produces.
69  ///
70  /// Num elements specifies the number of elements in the output.
71  ///
72  /// sceneDelegate and id are used to callback to the scene delegate
73  /// in order to invoke computation processing.
76  const TfTokenVector &outputs,
77  int numElements,
78  HdSceneDelegate *sceneDelegate);
79 
80  /// Create a CPU computation implementing the given abstract computation.
81  /// The scene delegate identifies which delegate to pull scene inputs from.
82  HD_API
84  CreateComputation(HdSceneDelegate *sceneDelegate,
85  const HdExtComputation &computation,
86  HdBufferSourceSharedPtrVector *computationSources);
87 
88  HD_API
89  virtual ~HdExtCompCpuComputation() = default;
90 
91  /// Returns the id for this computation as a token.
92  HD_API
93  virtual TfToken const &GetName() const override;
94 
95  /// Ask the scene delegate to run the computation and captures the output
96  /// signals.
97  HD_API
98  virtual bool Resolve() override;
99 
100  HD_API
101  virtual size_t GetNumElements() const override;
102 
103 
104  /// Converts a output name token into an index.
105  HD_API
106  size_t GetOutputIndex(const TfToken &outputName) const;
107 
108  /// Returns the value of the specified output
109  /// (after the computations been Resolved).
110  HD_API
111  const VtValue &GetOutputByIndex(size_t index) const;
112 
113 protected:
114  /// Returns if the computation is specified correctly.
115  HD_API
116  virtual bool _CheckValid() const override;
117 
118 private:
119  SdfPath _id;
121  TfTokenVector _outputs;
122  size_t _numElements;
123  HdSceneDelegate *_sceneDelegate;
124 
125  std::vector<VtValue> _outputValues;
126 
127  HdExtCompCpuComputation() = delete;
130  = delete;
131 };
132 
134 
135 #endif // PXR_IMAGING_HD_EXT_COMP_CPU_COMPUTATION_H
virtual HD_API TfToken const & GetName() const override
Returns the id for this computation as a token.
std::vector< Hd_ExtCompInputSourceSharedPtr > Hd_ExtCompInputSourceSharedPtrVector
virtual HD_API bool _CheckValid() const override
Returns if the computation is specified correctly.
#define HD_API
Definition: api.h:40
std::vector< HdBufferSourceSharedPtr > HdBufferSourceSharedPtrVector
Definition: bufferSource.h:44
Definition: token.h:87
virtual HD_API bool Resolve() override
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
static HD_API HdExtCompCpuComputationSharedPtr CreateComputation(HdSceneDelegate *sceneDelegate, const HdExtComputation &computation, HdBufferSourceSharedPtrVector *computationSources)
Definition: path.h:288
std::shared_ptr< HdExtCompCpuComputation > HdExtCompCpuComputationSharedPtr
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
GLuint index
Definition: glcorearb.h:785
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual HD_API ~HdExtCompCpuComputation()=default
Definition: value.h:168
HD_API size_t GetOutputIndex(const TfToken &outputName) const
Converts a output name token into an index.
HD_API const VtValue & GetOutputByIndex(size_t index) const
static const size_t INVALID_OUTPUT_INDEX
virtual HD_API size_t GetNumElements() const override