All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
resourceRegistry.h
1 //
2 // Copyright 2016 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 HDST_RESOURCE_REGISTRY_H
25 #define HDST_RESOURCE_REGISTRY_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hdSt/shaderKey.h"
30 #include "pxr/imaging/hdSt/glslProgram.h"
31 #include "pxr/imaging/hd/resourceRegistry.h"
32 
33 PXR_NAMESPACE_OPEN_SCOPE
34 
35 typedef boost::shared_ptr<class HdStDispatchBuffer>
36  HdStDispatchBufferSharedPtr;
37 typedef boost::shared_ptr<class HdStPersistentBuffer>
38  HdStPersistentBufferSharedPtr;
39 typedef boost::shared_ptr<class HdStResourceRegistry>
40  HdStResourceRegistrySharedPtr;
41 typedef boost::shared_ptr<class HdStTextureResourceHandle>
42  HdStTextureResourceHandleSharedPtr;
43 typedef boost::shared_ptr<class HdSt_GeometricShader>
44  HdSt_GeometricShaderSharedPtr;
45 typedef boost::shared_ptr<class HdStGLSLProgram> HdStGLSLProgramSharedPtr;
46 
52 public:
53  HF_MALLOC_TAG_NEW("new HdStResourceRegistry");
54 
55  HDST_API
57 
58  HDST_API
59  virtual ~HdStResourceRegistry();
60 
63  HDST_API
64  HdStDispatchBufferSharedPtr RegisterDispatchBuffer(
65  TfToken const &role, int count, int commandNumUints);
66 
69  HDST_API
70  HdStPersistentBufferSharedPtr RegisterPersistentBuffer(
71  TfToken const &role, size_t dataSize, void *data);
72 
74  HDST_API
76 
78  HDST_API
80 
85  HDST_API
86  HdBufferArrayRangeSharedPtr MergeBufferArrayRange(
87  HdAggregationStrategy *strategy,
88  HdBufferArrayRegistry &bufferArrayRegistry,
89  TfToken const &role,
90  HdBufferSpecVector const &newBufferSpecs,
91  HdBufferArrayUsageHint newUsageHint,
92  HdBufferArrayRangeSharedPtr const &range);
93 
95  HDST_API
96  HdBufferArrayRangeSharedPtr MergeNonUniformBufferArrayRange(
97  TfToken const &role,
98  HdBufferSpecVector const &newBufferSpecs,
99  HdBufferArrayUsageHint newUsageHint,
100  HdBufferArrayRangeSharedPtr const &range);
101 
103  HDST_API
104  HdBufferArrayRangeSharedPtr MergeNonUniformImmutableBufferArrayRange(
105  TfToken const &role,
106  HdBufferSpecVector const &newBufferSpecs,
107  HdBufferArrayUsageHint newUsageHint,
108  HdBufferArrayRangeSharedPtr const &range);
109 
111  HDST_API
112  HdBufferArrayRangeSharedPtr MergeUniformBufferArrayRange(
113  TfToken const &role,
114  HdBufferSpecVector const &newBufferSpecs,
115  HdBufferArrayUsageHint newUsageHint,
116  HdBufferArrayRangeSharedPtr const &range);
117 
119  HDST_API
120  HdBufferArrayRangeSharedPtr MergeShaderStorageBufferArrayRange(
121  TfToken const &role,
122  HdBufferSpecVector const &newBufferSpecs,
123  HdBufferArrayUsageHint newUsageHint,
124  HdBufferArrayRangeSharedPtr const &range);
125 
127  HDST_API
128  std::unique_lock<std::mutex> RegisterGeometricShader(HdStShaderKey::ID id,
130 
133  HDST_API
134  std::unique_lock<std::mutex> RegisterGLSLProgram(HdStGLSLProgram::ID id,
136 
138  HDST_API
139  std::unique_lock<std::mutex> RegisterTextureResourceHandle(
140  HdStShaderKey::ID id,
142 
143  HDST_API
144  std::unique_lock<std::mutex> FindTextureResourceHandle(
145  TextureKey id,
147  *instance, bool *found);
148 
149  void InvalidateShaderRegistry() override;
150 
151 protected:
152  virtual void _GarbageCollect() override;
153  virtual void _TallyResourceAllocation(VtDictionary *result) const override;
154 
155 private:
156 
157  typedef std::vector<HdStDispatchBufferSharedPtr>
158  _DispatchBufferRegistry;
159  _DispatchBufferRegistry _dispatchBufferRegistry;
160 
161  typedef std::vector<HdStPersistentBufferSharedPtr>
162  _PersistentBufferRegistry;
163  _PersistentBufferRegistry _persistentBufferRegistry;
164 
165  // geometric shader registry
168  HdInstanceRegistry<_GeometricShaderInstance> _geometricShaderRegistry;
169 
170  // glsl shader program registry
173  HdInstanceRegistry<_GLSLProgramInstance> _glslProgramRegistry;
174 
177  HdInstanceRegistry<_TextureResourceHandleInstance> _textureResourceHandleRegistry;
178 
179 };
180 
181 
182 PXR_NAMESPACE_CLOSE_SCOPE
183 
184 #endif //HDST_RESOURCE_REGISTRY_H
The union provides a set of flags that provide hints to the memory management system about the proper...
Definition: bufferArray.h:74
void InvalidateShaderRegistry() override
Invalidate any shaders registered with this registry.
HDST_API std::unique_lock< std::mutex > RegisterGeometricShader(HdStShaderKey::ID id, HdInstance< HdStShaderKey::ID, HdSt_GeometricShaderSharedPtr > *pInstance)
Register a geometric shader.
Aggregation strategy base class.
Definition: strategyBase.h:48
A map with string keys and VtValue values.
Definition: dictionary.h:61
HDST_API void GarbageCollectDispatchBuffers()
Remove any entries associated with expired dispatch buffers.
Manages the pool of buffer arrays.
HDST_API HdBufferArrayRangeSharedPtr MergeUniformBufferArrayRange(TfToken const &role, HdBufferSpecVector const &newBufferSpecs, HdBufferArrayUsageHint newUsageHint, HdBufferArrayRangeSharedPtr const &range)
MergeBufferArrayRange of uniform buffer.
HdInstanceRegistry is a dictionary container of HdInstance.
virtual void _GarbageCollect() override
A hook for derived registries to perform additional GC when GarbageCollect() is invoked.
HDST_API void GarbageCollectPersistentBuffers()
Remove any entries associated with expired persistently mapped buffers.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
virtual void _TallyResourceAllocation(VtDictionary *result) const override
A hook for derived registries to tally their resources by key into the given dictionary.
HDST_API HdBufferArrayRangeSharedPtr MergeNonUniformBufferArrayRange(TfToken const &role, HdBufferSpecVector const &newBufferSpecs, HdBufferArrayUsageHint newUsageHint, HdBufferArrayRangeSharedPtr const &range)
MergeBufferArrayRange of non uniform buffer.
HDST_API HdBufferArrayRangeSharedPtr MergeShaderStorageBufferArrayRange(TfToken const &role, HdBufferSpecVector const &newBufferSpecs, HdBufferArrayUsageHint newUsageHint, HdBufferArrayRangeSharedPtr const &range)
MergeBufferArrayRange of shader storage buffer.
A central registry of all GPU resources.
HDST_API HdStPersistentBufferSharedPtr RegisterPersistentBuffer(TfToken const &role, size_t dataSize, void *data)
Register a buffer initialized with dataSize bytes of data to be used as a persistently mapped shader ...
A central registry of all GPU resources.
HDST_API HdBufferArrayRangeSharedPtr MergeNonUniformImmutableBufferArrayRange(TfToken const &role, HdBufferSpecVector const &newBufferSpecs, HdBufferArrayUsageHint newUsageHint, HdBufferArrayRangeSharedPtr const &range)
MergeBufferArrayRange of non uniform immutable buffer.
HDST_API HdStDispatchBufferSharedPtr RegisterDispatchBuffer(TfToken const &role, int count, int commandNumUints)
Register a buffer allocated with count * commandNumUints * sizeof(GLuint) to be used as an indirect d...
HDST_API HdBufferArrayRangeSharedPtr MergeBufferArrayRange(HdAggregationStrategy *strategy, HdBufferArrayRegistry &bufferArrayRegistry, TfToken const &role, HdBufferSpecVector const &newBufferSpecs, HdBufferArrayUsageHint newUsageHint, HdBufferArrayRangeSharedPtr const &range)
Check if range is compatible with newBufferSpecs.
HDST_API std::unique_lock< std::mutex > RegisterTextureResourceHandle(HdStShaderKey::ID id, HdInstance< HdStShaderKey::ID, HdStTextureResourceHandleSharedPtr > *pInstance)
Register a texture resource handle.
size_t TextureKey
Globally unique id for texture, see RegisterTextureResource() for details.
HDST_API std::unique_lock< std::mutex > RegisterGLSLProgram(HdStGLSLProgram::ID id, HdInstance< HdStGLSLProgram::ID, HdStGLSLProgramSharedPtr > *pInstance)
Register a GLSL program into the program registry.
This class is used as a pointer to the shared instance in HdInstanceRegistry.