HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extComputation.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_COMPUTATION_H
25 #define PXR_IMAGING_HD_EXT_COMPUTATION_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
30 #include "pxr/imaging/hd/sprim.h"
31 #include "pxr/imaging/hd/types.h"
32 #include "pxr/usd/sdf/path.h"
33 #include "pxr/base/vt/value.h"
34 #include <vector>
35 
37 
38 ///
39 /// Hydra Representation of a Client defined computation.
40 ///
41 /// A computation provides a way to procedurally generate a primvar.
42 ///
43 /// It represents a basic Input -> Processing -> Output model.
44 ///
45 /// Primarily inputs are provided by the scene delegate via the Get()
46 /// mechanism.
47 ///
48 /// Computations can also be chained together, such that the output from
49 /// one computation can be an input to another.
50 ///
51 /// The results of a computation is designed to be in SOA form (structure or
52 /// array), where each output is a member of the "structure" producing several
53 /// parallel arrays. While the type of the elements of the array is defined
54 /// by the output member, the number of elements in each array is the same
55 /// across all outputs.
56 ///
57 /// ExtComputations use a pull model, so processing is only triggered if
58 /// a downstream computation or prim pulls on one the computations outputs.
59 ///
60 class HdExtComputation : public HdSprim {
61 public:
62  /// Construct a new ExtComputation identified by id.
63  HD_API
64  HdExtComputation(SdfPath const &id);
65 
66  HD_API
67  virtual ~HdExtComputation() = default;
68 
69  ///
70  /// Change tracking
71  ///
73  Clean = 0,
74  DirtyInputDesc = 1 << 0, ///< The list of inputs or input
75  /// bindings changed
76  DirtyOutputDesc = 1 << 1, ///< The list of outputs changed
77  DirtyElementCount = 1 << 2, ///< The number of elements in the
78  /// output arrays changed
79  DirtySceneInput = 1 << 3, ///< A scene input changed value
80  DirtyCompInput = 1 << 4, ///< A computation input changed value
81  DirtyKernel = 1 << 5, ///< The compute kernel binding changed
82 
83  DirtyDispatchCount = 1 << 6, ///< The number of kernel
84  /// invocations to execute changed
85 
93  };
94 
95  HD_API
96  virtual void Sync(HdSceneDelegate *sceneDelegate,
97  HdRenderParam *renderParam,
98  HdDirtyBits *dirtyBits) override;
99 
100  HD_API
101  virtual HdDirtyBits GetInitialDirtyBitsMask() const override;
102 
103  HD_API
104  size_t GetDispatchCount() const;
105 
106  HD_API
107  size_t GetElementCount() const { return _elementCount; }
108 
109  HD_API
111  return _sceneInputNames;
112  }
113 
114  HD_API
116 
117  HD_API
120  return _computationInputs;
121  }
122 
123  HD_API
126  return _computationOutputs;
127  }
128 
129  HD_API
130  const std::string& GetGpuKernelSource() const { return _gpuKernelSource; }
131 
132  HD_API
133  bool IsInputAggregation() const;
134 
135 protected:
136  HD_API
137  void
138  _Sync(HdSceneDelegate *sceneDelegate,
139  HdRenderParam *renderParam,
140  HdDirtyBits *dirtyBits);
141 
142  HD_API
144 
145 private:
146  size_t _dispatchCount;
147  size_t _elementCount;
148  TfTokenVector _sceneInputNames;
149  HdExtComputationInputDescriptorVector _computationInputs;
150  HdExtComputationOutputDescriptorVector _computationOutputs;
151  std::string _gpuKernelSource;
152 
153  // No default construction or copying
154  HdExtComputation() = delete;
155  HdExtComputation(const HdExtComputation &) = delete;
156  HdExtComputation &operator =(const HdExtComputation &) = delete;
157 
158 };
159 
161 
162 #endif // PXR_IMAGING_HD_EXT_COMPUTATION_H
A computation input changed value.
HD_API size_t GetElementCount() const
uint32_t HdDirtyBits
Definition: types.h:127
HD_API size_t GetDispatchCount() const
std::vector< HdExtComputationInputDescriptor > HdExtComputationInputDescriptorVector
HD_API HdExtComputationOutputDescriptorVector const & GetComputationOutputs() const
#define HD_API
Definition: api.h:40
The compute kernel binding changed.
std::vector< HdExtComputationOutputDescriptor > HdExtComputationOutputDescriptorVector
HD_API TfTokenVector const & GetSceneInputNames() const
static HD_API bool _IsEnabledSharedExtComputationData()
virtual HD_API HdDirtyBits GetInitialDirtyBitsMask() const override
HD_API void _Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits)
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
virtual HD_API ~HdExtComputation()=default
virtual HD_API void Sync(HdSceneDelegate *sceneDelegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits) override
A scene input changed value.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:442
Definition: path.h:288
HD_API TfTokenVector GetOutputNames() const
The list of outputs changed.
Definition: sprim.h:52
HD_API bool IsInputAggregation() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
HD_API const std::string & GetGpuKernelSource() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HD_API HdExtComputationInputDescriptorVector const & GetComputationInputs() const