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 terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_EXT_COMPUTATION_H
8 #define PXR_IMAGING_HD_EXT_COMPUTATION_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
13 #include "pxr/imaging/hd/sprim.h"
14 
16 
17 ///
18 /// Hydra Representation of a Client defined computation.
19 ///
20 /// A computation provides a way to procedurally generate a primvar.
21 ///
22 /// It represents a basic Input -> Processing -> Output model.
23 ///
24 /// Primarily inputs are provided by the scene delegate via the Get()
25 /// mechanism.
26 ///
27 /// Computations can also be chained together, such that the output from
28 /// one computation can be an input to another.
29 ///
30 /// The results of a computation is designed to be in SOA form (structure or
31 /// array), where each output is a member of the "structure" producing several
32 /// parallel arrays. While the type of the elements of the array is defined
33 /// by the output member, the number of elements in each array is the same
34 /// across all outputs.
35 ///
36 /// ExtComputations use a pull model, so processing is only triggered if
37 /// a downstream computation or prim pulls on one the computations outputs.
38 ///
39 class HdExtComputation : public HdSprim
40 {
41 public:
42  /// Construct a new ExtComputation identified by id.
43  HD_API
44  HdExtComputation(SdfPath const &id);
45 
46  HD_API
47  ~HdExtComputation() override;
48 
49  ///
50  /// Change tracking
51  ///
53  Clean = 0,
54  DirtyInputDesc = 1 << 0, ///< The list of inputs or input
55  /// bindings changed
56  DirtyOutputDesc = 1 << 1, ///< The list of outputs changed
57  DirtyElementCount = 1 << 2, ///< The number of elements in the
58  /// output arrays changed
59  DirtySceneInput = 1 << 3, ///< A scene input changed value
60  DirtyCompInput = 1 << 4, ///< A computation input changed value
61  DirtyKernel = 1 << 5, ///< The compute kernel binding changed
62 
63  DirtyDispatchCount = 1 << 6, ///< The number of kernel
64  /// invocations to execute changed
65 
73  };
74 
75  HD_API
76  void Sync(HdSceneDelegate *sceneDelegate,
77  HdRenderParam *renderParam,
78  HdDirtyBits *dirtyBits) override;
79 
80  HD_API
81  HdDirtyBits GetInitialDirtyBitsMask() const override;
82 
83  HD_API
84  size_t GetDispatchCount() const;
85 
86  HD_API
87  size_t GetElementCount() const { return _elementCount; }
88 
89  HD_API
91  return _sceneInputNames;
92  }
93 
94  HD_API
96 
97  HD_API
100  return _computationInputs;
101  }
102 
103  HD_API
106  return _computationOutputs;
107  }
108 
109  HD_API
110  const std::string& GetGpuKernelSource() const { return _gpuKernelSource; }
111 
112  HD_API
113  bool IsInputAggregation() const;
114 
115 protected:
116  HD_API
117  void
118  _Sync(HdSceneDelegate *sceneDelegate,
119  HdRenderParam *renderParam,
120  HdDirtyBits *dirtyBits);
121 
122  HD_API
124 
125 private:
126  size_t _dispatchCount;
127  size_t _elementCount;
128  TfTokenVector _sceneInputNames;
129  HdExtComputationInputDescriptorVector _computationInputs;
130  HdExtComputationOutputDescriptorVector _computationOutputs;
131  std::string _gpuKernelSource;
132 
133  // No default construction or copying
134  HdExtComputation() = delete;
135  HdExtComputation(const HdExtComputation &) = delete;
136  HdExtComputation &operator =(const HdExtComputation &) = delete;
137 
138 };
139 
141 
142 #endif // PXR_IMAGING_HD_EXT_COMPUTATION_H
A computation input changed value.
HD_API size_t GetElementCount() const
uint32_t HdDirtyBits
Definition: types.h:143
HD_API size_t GetDispatchCount() const
std::vector< HdExtComputationInputDescriptor > HdExtComputationInputDescriptorVector
HD_API HdExtComputationOutputDescriptorVector const & GetComputationOutputs() const
#define HD_API
Definition: api.h:23
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:440
Definition: path.h:273
HD_API ~HdExtComputation() override
HD_API TfTokenVector GetOutputNames() const
The list of outputs changed.
Definition: sprim.h:34
HD_API bool IsInputAggregation() const
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
HD_API const std::string & GetGpuKernelSource() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HD_API HdExtComputationInputDescriptorVector const & GetComputationInputs() const
HD_API HdDirtyBits GetInitialDirtyBitsMask() const override