All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vboSimpleMemoryManager.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_VBO_SIMPLE_MEMORY_MANAGER_H
25 #define HDST_VBO_SIMPLE_MEMORY_MANAGER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdSt/api.h"
29 #include "pxr/imaging/hdSt/bufferArrayRangeGL.h"
30 #include "pxr/imaging/hd/version.h"
31 #include "pxr/imaging/hd/strategyBase.h"
32 #include "pxr/imaging/hd/bufferArray.h"
33 #include "pxr/imaging/hd/bufferSpec.h"
34 #include "pxr/imaging/hd/bufferSource.h"
35 
36 PXR_NAMESPACE_OPEN_SCOPE
37 
38 
46 public:
49  HDST_API
50  virtual HdBufferArraySharedPtr CreateBufferArray(
51  TfToken const &role,
52  HdBufferSpecVector const &bufferSpecs,
53  HdBufferArrayUsageHint usageHint);
54 
56  HDST_API
57  virtual HdBufferArrayRangeSharedPtr CreateBufferArrayRange();
58 
60  HDST_API
62  HdBufferSpecVector const &bufferSpecs,
63  HdBufferArrayUsageHint usageHint) const;
64 
66  virtual HdBufferSpecVector GetBufferSpecs(
67  HdBufferArraySharedPtr const &bufferArray) const;
68 
70  virtual size_t GetResourceAllocation(
71  HdBufferArraySharedPtr const &bufferArray,
72  VtDictionary &result) const;
73 
74 protected:
75  class _SimpleBufferArray;
76 
82  {
83  public:
86  _bufferArray(nullptr), _numElements(0) {
87  }
88 
90  virtual bool IsValid() const {
91  return (bool)_bufferArray;
92  }
93 
95  HDST_API
96  virtual bool IsAssigned() const;
97 
99  virtual bool IsImmutable() const;
100 
103  virtual bool Resize(int numElements) {
104  _numElements = numElements;
105  return _bufferArray->Resize(numElements);
106  }
107 
109  HDST_API
110  virtual void CopyData(HdBufferSourceSharedPtr const &bufferSource);
111 
113  HDST_API
114  virtual VtValue ReadData(TfToken const &name) const;
115 
117  virtual int GetOffset() const {
118  return 0;
119  }
120 
122  virtual int GetIndex() const {
123  return 0;
124  }
125 
127  virtual size_t GetNumElements() const {
128  return _numElements;
129  }
130 
132  virtual int GetCapacity() const {
133  return _bufferArray->GetCapacity();
134  }
135 
137  virtual size_t GetVersion() const {
138  return _bufferArray->GetVersion();
139  }
140 
142  virtual void IncrementVersion() {
143  _bufferArray->IncrementVersion();
144  }
145 
147  HDST_API
148  virtual size_t GetMaxNumElements() const;
149 
151  HDST_API
152  virtual HdBufferArrayUsageHint GetUsageHint() const override;
153 
156  HDST_API
157  virtual HdStBufferResourceGLSharedPtr GetResource() const;
158 
160  HDST_API
161  virtual HdStBufferResourceGLSharedPtr GetResource(TfToken const& name);
162 
164  HDST_API
165  virtual HdStBufferResourceGLNamedList const& GetResources() const;
166 
168  HDST_API
169  virtual void SetBufferArray(HdBufferArray *bufferArray);
170 
172  HDST_API
173  virtual void DebugDump(std::ostream &out) const;
174 
176  void Invalidate() {
177  _bufferArray = NULL;
178  }
179 
180  protected:
182  HDST_API
183  virtual const void *_GetAggregation() const;
184 
186  HDST_API
187  HdStBufferResourceGLSharedPtr _AddResource(TfToken const& name,
188  HdTupleType tupleType,
189  int offset,
190  int stride);
191 
192  private:
193  _SimpleBufferArray * _bufferArray;
194  size_t _numElements;
195  };
196 
197  typedef boost::shared_ptr<_SimpleBufferArray>
198  _SimpleBufferArraySharedPtr;
199  typedef boost::shared_ptr<_SimpleBufferArrayRange>
200  _SimpleBufferArrayRangeSharedPtr;
201  typedef boost::weak_ptr<_SimpleBufferArrayRange>
202  _SimpleBufferArrayRangePtr;
203 
209  {
210  public:
212  HDST_API
213  _SimpleBufferArray(TfToken const &role,
214  HdBufferSpecVector const &bufferSpecs,
215  HdBufferArrayUsageHint usageHint);
216 
218  HDST_API
219  virtual ~_SimpleBufferArray();
220 
222  HDST_API
223  virtual bool GarbageCollect();
224 
226  HDST_API
227  virtual void DebugDump(std::ostream &out) const;
228 
230  HDST_API
231  bool Resize(int numElements);
232 
235  HDST_API
236  virtual void Reallocate(
237  std::vector<HdBufferArrayRangeSharedPtr> const &ranges,
238  HdBufferArraySharedPtr const &curRangeOwner);
239 
241  HDST_API
242  virtual size_t GetMaxNumElements() const;
243 
245  int GetCapacity() const {
246  return _capacity;
247  }
248 
253 
256  HDST_API
257  HdStBufferResourceGLSharedPtr GetResource() const;
258 
263  HDST_API
264  HdStBufferResourceGLSharedPtr GetResource(TfToken const& name);
265 
267  HdStBufferResourceGLNamedList const& GetResources() const {return _resourceList;}
268 
270  HDST_API
271  HdBufferSpecVector GetBufferSpecs() const;
272 
273  protected:
274  HDST_API
275  void _DeallocateResources();
276 
278  HDST_API
279  HdStBufferResourceGLSharedPtr _AddResource(TfToken const& name,
280  HdTupleType tupleType,
281  int offset,
282  int stride);
283  private:
284  int _capacity;
285  size_t _maxBytesPerElement;
286 
287  HdStBufferResourceGLNamedList _resourceList;
288 
289  _SimpleBufferArrayRangeSharedPtr _GetRangeSharedPtr() const {
290  return GetRangeCount() > 0
291  ? boost::static_pointer_cast<_SimpleBufferArrayRange>(GetRange(0).lock())
292  : _SimpleBufferArrayRangeSharedPtr();
293  }
294  };
295 };
296 
297 PXR_NAMESPACE_CLOSE_SCOPE
298 
299 #endif // HDST_VBO_SIMPLE_MEMORY_MANAGER_H
virtual HDST_API const void * _GetAggregation() const
Returns the aggregation container.
size_t AggregationId
Aggregation ID.
Definition: strategyBase.h:51
The union provides a set of flags that provide hints to the memory management system about the proper...
Definition: bufferArray.h:74
virtual HDST_API size_t GetMaxNumElements() const
Returns the max number of elements.
virtual int GetIndex() const
Returns the index in aggregated buffer.
virtual bool IsValid() const
Returns true if this range is valid.
virtual HDST_API bool GarbageCollect()
perform compaction if necessary, returns true if it becomes empty.
virtual HDST_API HdBufferArrayRangeSharedPtr CreateBufferArrayRange()
Factory for creating HdBufferArrayRange.
virtual size_t GetResourceAllocation(HdBufferArraySharedPtr const &bufferArray, VtDictionary &result) const
Returns the size of the GPU memory used by the passed buffer array.
virtual HDST_API void DebugDump(std::ostream &out) const
Debug output.
virtual HDST_API void SetBufferArray(HdBufferArray *bufferArray)
Sets the buffer array associated with this buffer;.
Similar to a VAO, this object is a bundle of coherent buffers.
Definition: bufferArray.h:92
VBO simple memory manager.
Aggregation strategy base class.
Definition: strategyBase.h:48
HD_API void IncrementVersion()
Increments the version of this buffer array.
virtual HDST_API void CopyData(HdBufferSourceSharedPtr const &bufferSource)
Copy source data into buffer.
virtual HDST_API HdBufferArrayUsageHint GetUsageHint() const override
Returns the usage hint from the underlying buffer array.
virtual HDST_API ~_SimpleBufferArray()
Destructor. It invalidates _range.
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:239
A map with string keys and VtValue values.
Definition: dictionary.h:61
virtual HDST_API HdStBufferResourceGLSharedPtr GetResource() const
Returns the GPU resource.
virtual HDST_API HdBufferArraySharedPtr CreateBufferArray(TfToken const &role, HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint)
Factory for creating HdBufferArray managed by HdStVBOSimpleMemoryManager.
HD_API HdBufferArrayRangePtr GetRange(size_t idx) const
Get the attached range at the specified index.
virtual int GetCapacity() const
Returns the capacity of allocated area for this range.
HDST_API HdStBufferResourceGLSharedPtr _AddResource(TfToken const &name, HdTupleType tupleType, int offset, int stride)
Adds a new, named GPU resource and returns it.
virtual HDST_API void Reallocate(std::vector< HdBufferArrayRangeSharedPtr > const &ranges, HdBufferArraySharedPtr const &curRangeOwner)
Performs reallocation.
virtual void IncrementVersion()
Increment the version of the buffer array.
HdStBufferResourceGLNamedList const & GetResources() const
Returns the list of all named GPU resources for this bufferArray.
HDST_API HdStBufferResourceGLSharedPtr _AddResource(TfToken const &name, HdTupleType tupleType, int offset, int stride)
Adds a new, named GPU resource and returns it.
virtual HDST_API bool IsAssigned() const
Returns true is the range has been assigned to a buffer.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
virtual bool IsImmutable() const
Returns true if this range is marked as immutable.
HDST_API _SimpleBufferArray(TfToken const &role, HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint)
Constructor.
virtual int GetOffset() const
Returns the relative offset in aggregated buffer.
virtual size_t GetVersion() const
Returns the version of the buffer array.
virtual HdBufferSpecVector GetBufferSpecs(HdBufferArraySharedPtr const &bufferArray) const
Returns the buffer specs from a given buffer array.
size_t GetRangeCount() const
How many ranges are attached to the buffer array.
Definition: bufferArray.h:142
HDST_API HdBufferSpecVector GetBufferSpecs() const
Reconstructs the bufferspecs and returns it (for buffer splitting)
virtual HDST_API HdAggregationStrategy::AggregationId ComputeAggregationId(HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint) const
Returns id for given bufferSpecs to be used for aggregation.
Interface class for representing range (subset) locator of HdBufferArray.
virtual size_t GetNumElements() const
Returns the number of elements allocated.
HDST_API HdStBufferResourceGLSharedPtr GetResource() const
TODO: We need to distinguish between the primvar types here, we should tag each HdBufferSource and Hd...
HDST_API bool Resize(int numElements)
Set to resize buffers. Actual reallocation happens on Reallocate()
virtual HDST_API void DebugDump(std::ostream &out) const
Debug dump.
size_t GetVersion() const
Returns the version of this buffer array.
Definition: bufferArray.h:108
virtual HDST_API HdStBufferResourceGLNamedList const & GetResources() const
Returns the list of all named GPU resources for this bufferArrayRange.
virtual bool Resize(int numElements)
Resize memory area for this range.
int GetCapacity() const
Returns current capacity. It could be different from numElements.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
virtual HDST_API VtValue ReadData(TfToken const &name) const
Read back the buffer content.
virtual HDST_API size_t GetMaxNumElements() const
Returns the maximum number of elements capacity.
Simple buffer array (non-aggregated).
Specialized buffer array range for SimpleBufferArray.