HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
extCompGpuComputationResource.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_ST_EXT_COMP_GPU_COMPUTATION_RESOURCE_H
8 #define PXR_IMAGING_HD_ST_EXT_COMP_GPU_COMPUTATION_RESOURCE_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdSt/api.h"
13 #include "pxr/imaging/hdSt/resourceBinder.h"
14 #include "pxr/imaging/hdSt/extCompComputeShader.h"
16 
17 #include <vector>
18 
20 
22  std::shared_ptr<class HdStExtCompGpuComputationResource>;
23 using HdStGLSLProgramSharedPtr= std::shared_ptr<class HdStGLSLProgram>;
25  std::vector<HdBufferArrayRangeSharedPtr>;
26 
27 /// \class HdStExtCompGpuComputationResource
28 ///
29 /// A resource that represents the persistent GPU resources of an ExtComputation.
30 ///
31 /// All program and binding data required for compiling and loading HdRprim and
32 /// internal primvar data is held by this object. The companion source and
33 /// computation appeal to this object to access the GPU resources.
34 ///
35 /// \see HdStExtCompGpuComputation
37 public:
38  /// Creates a GPU computation resource that can bind resources matching
39  /// the layout of the compute kernel.
40  /// The registry passed is the registry that the kernel program will
41  /// be shared amongst. De-duplication of the compiled and linked program
42  /// for runtime execution happens on a per-registry basis.
43  ///
44  /// Memory for the input computation buffers must be provided
45  /// This must be done prior to a HdResourceRegistry::Commit in
46  /// which the computation has been added.
47  /// Note that the Resource allocates no memory on its own and can be
48  /// speculatively created and later de-duplicated, or discarded,
49  /// without wasting resources.
50  ///
51  /// \param[in] outputBufferSpecs the buffer specs that the computation is
52  /// expecting to output.
53  /// \param[in] kernel the compute kernel source to run as the computation.
54  /// \param[in] registry the registry that the internal computation
55  /// will cache and de-duplicate its compute shader instance with.
57  HdBufferSpecVector const &outputBufferSpecs,
58  HdSt_ExtCompComputeShaderSharedPtr const &kernel,
60  HdStResourceRegistrySharedPtr const &registry
61  );
62 
63  virtual ~HdStExtCompGpuComputationResource() = default;
64 
65  /// Gets the HdBufferArrayRange that inputs should be loaded into using the
66  /// resource binder.
68  return _inputs;
69  }
70 
71  /// Gets the GPU HdStGLSLProgram to run to execute the computation.
72  /// This may have been shared with many other instances in the same
73  /// registry.
74  /// The program is only valid for execution after Resolve has been called.
76  if (!_computeProgram) {
77  _Resolve();
78  }
79  return _computeProgram;
80  }
81 
82  /// Gets the resource binder that matches the layout of the compute program.
83  /// The binder is only valid for resolving layouts after Resolve has been
84  /// called.
85  HdSt_ResourceBinder const &GetResourceBinder() {
86  if (!_computeProgram) {
87  _Resolve();
88  }
89  return _resourceBinder;
90  }
91 
92 private:
93  /// Resolve the resource bindings and program for use by a computation.
94  /// The compute program is resolved and linked against the input and output
95  /// resource bindings and the kernel source in this step.
96  bool _Resolve();
97 
98  HdBufferSpecVector _outputBufferSpecs;
99  HdSt_ExtCompComputeShaderSharedPtr _kernel;
101 
102  size_t _shaderSourceHash;
104  HdStGLSLProgramSharedPtr _computeProgram;
105  HdSt_ResourceBinder _resourceBinder;
106 
109  const HdStExtCompGpuComputationResource &) = delete;
111  const HdStExtCompGpuComputationResource &) = delete;
112 };
113 
115 
116 #endif // PXR_IMAGING_HD_ST_EXT_COMP_GPU_COMPUTATION_RESOURCE_H
117 
std::shared_ptr< class HdStExtCompGpuComputationResource > HdStExtCompGpuComputationResourceSharedPtr
virtual ~HdStExtCompGpuComputationResource()=default
HdSt_ResourceBinder const & GetResourceBinder()
HdStGLSLProgramSharedPtr const & GetProgram()
std::vector< struct HdBufferSpec > HdBufferSpecVector
std::shared_ptr< class HdStGLSLProgram > HdStGLSLProgramSharedPtr
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HdBufferArrayRangeSharedPtrVector const & GetInputs() const
std::vector< HdBufferArrayRangeSharedPtr > HdBufferArrayRangeSharedPtrVector
std::shared_ptr< class HdStResourceRegistry > HdStResourceRegistrySharedPtr
Definition: commandBuffer.h:30