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