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