24#ifndef PXR_IMAGING_HD_ST_INTERLEAVED_MEMORY_MANAGER_H
25#define PXR_IMAGING_HD_ST_INTERLEAVED_MEMORY_MANAGER_H
28#include "pxr/imaging/hdSt/api.h"
29#include "pxr/imaging/hdSt/bufferArrayRange.h"
30#include "pxr/imaging/hdSt/strategyBase.h"
32#include "pxr/imaging/hd/bufferArray.h"
33#include "pxr/imaging/hd/bufferSpec.h"
34#include "pxr/imaging/hd/bufferSource.h"
35#include "pxr/imaging/hd/tokens.h"
36#include "pxr/imaging/hd/version.h"
37#include "pxr/imaging/hgi/buffer.h"
43#include <unordered_map>
45PXR_NAMESPACE_OPEN_SCOPE
65 , _stripedBuffer(nullptr)
66 , _index(NOT_ALLOCATED)
77 return (
bool)_stripedBuffer;
93 bool Resize(
int numElements)
override;
97 void CopyData(HdBufferSourceSharedPtr
const &bufferSource)
override;
114 !
TF_VERIFY(_index != NOT_ALLOCATED))
return 0;
115 return _stripedBuffer->
GetStride() * _index;
128 int GetElementStride()
const override {
129 return _stripedBuffer->GetElementStride();
173 _stripedBuffer =
nullptr;
183 _capacity = capacity;
192 enum { NOT_ALLOCATED = -1 };
199 using _StripedInterleavedBufferSharedPtr =
200 std::shared_ptr<_StripedInterleavedBuffer>;
201 using _StripedInterleavedBufferRangeSharedPtr =
202 std::shared_ptr<_StripedInterleavedBufferRange>;
203 using _StripedInterleavedBufferRangePtr =
204 std::weak_ptr<_StripedInterleavedBufferRange>;
214 HdBufferSpecVector
const &bufferSpecs,
215 HdBufferArrayUsageHint usageHint,
216 int bufferOffsetAlignment,
219 TfToken const &garbageCollectionPerfToken);
237 std::vector<HdBufferArrayRangeSharedPtr>
const &ranges,
238 HdBufferArraySharedPtr
const &curRangeOwner);
247 _needsCompaction =
true;
255 size_t GetElementStride()
const {
256 return _elementStride;
272 HdStBufferResourceNamedList
const&
GetResources()
const {
return _resourceList;}
285 void _DeallocateResources();
297 bool _needsCompaction;
299 int _bufferOffsetAlignment;
312 size_t _elementStride;
314 HgiBufferUsage _bufferUsage;
316 HdStBufferResourceNamedList _resourceList;
318 _StripedInterleavedBufferRangeSharedPtr _GetRangeSharedPtr(
size_t idx)
const {
319 return std::static_pointer_cast<_StripedInterleavedBufferRange>(
GetRange(idx).lock());
325 : _resourceRegistry(resourceRegistry) {}
332 HdBufferArraySharedPtr
const &bufferArray)
const override;
336 HdBufferArraySharedPtr
const &bufferArray,
352 HdBufferSpecVector
const &bufferSpecs,
353 HdBufferArrayUsageHint usageHint);
358 HdBufferSpecVector
const &bufferSpecs,
359 HdBufferArrayUsageHint usageHint)
const;
372 HdBufferSpecVector
const &bufferSpecs,
373 HdBufferArrayUsageHint usageHint);
378 HdBufferSpecVector
const &bufferSpecs,
379 HdBufferArrayUsageHint usageHint)
const;
382PXR_NAMESPACE_CLOSE_SCOPE
Similar to a VAO, this object is a bundle of coherent buffers.
bool _needsReallocation
Dirty bit to set when the ranges attached to the buffer changes.
HD_API void IncrementVersion()
Increments the version of this buffer array.
HD_API HdBufferArrayRangePtr GetRange(size_t idx) const
Get the attached range at the specified index.
size_t GetVersion() const
Returns the version of this buffer array.
Aggregation strategy base class.
size_t AggregationId
Aggregation ID.
virtual HdBufferArraySharedPtr CreateBufferArray(TfToken const &role, HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint)=0
Factory for creating HdBufferArray.
virtual AggregationId ComputeAggregationId(HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint) const =0
Returns id for given bufferSpecs to be used for aggregation.
Interface class for representing range (subset) locator of HdBufferArray.
size_t GetStride() const
Returns the stride.
void SetNeedsCompaction()
Mark to perform compaction on GarbageCollect()
HDST_API HdStBufferResourceSharedPtr _AddResource(TfToken const &name, HdTupleType tupleType, int offset, int stride)
Adds a new, named GPU resource and returns it.
HDST_API HdStBufferResourceSharedPtr GetResource(TfToken const &name)
Returns the named GPU resource.
void SetNeedsReallocation()
Mark to perform reallocation on Reallocate()
virtual HDST_API bool GarbageCollect()
perform compaction if necessary, returns true if it becomes empty.
HDST_API HdStBufferResourceSharedPtr GetResource() const
Returns the GPU resource.
virtual HDST_API ~_StripedInterleavedBuffer()
Destructor. It invalidates _rangeList.
virtual HDST_API void DebugDump(std::ostream &out) const
Debug output.
HdStBufferResourceNamedList const & GetResources() const
Returns the list of all named GPU resources for this bufferArray.
HDST_API _StripedInterleavedBuffer(HdStInterleavedMemoryManager *mgr, HdStResourceRegistry *resourceRegistry, TfToken const &role, HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint, int bufferOffsetAlignment, int structAlignment, size_t maxSize, TfToken const &garbageCollectionPerfToken)
Constructor.
virtual HDST_API void Reallocate(std::vector< HdBufferArrayRangeSharedPtr > const &ranges, HdBufferArraySharedPtr const &curRangeOwner)
Performs reallocation.
HDST_API HdBufferSpecVector GetBufferSpecs() const
Reconstructs the bufferspecs and returns it (for buffer splitting)
specialized buffer array range
HDST_API void CopyData(HdBufferSourceSharedPtr const &bufferSource) override
Copy source data into buffer.
size_t GetNumElements() const override
Returns the number of elements.
HDST_API HdBufferArrayUsageHint GetUsageHint() const override
Returns the usage hint from the underlying buffer array.
HDST_API void SetBufferArray(HdBufferArray *bufferArray) override
Sets the buffer array associated with this buffer;.
int GetCapacity() const
Returns the capacity of allocated area.
void IncrementVersion() override
Increment the version of the buffer array.
bool IsValid() const override
Returns true if this range is valid.
HDST_API bool IsAssigned() const override
Returns true is the range has been assigned to a buffer.
HDST_API ~_StripedInterleavedBufferRange() override
Destructor.
int GetElementOffset() const override
Returns the offset at which this range begins in the underlying buffer array in terms of elements.
HDST_API void DebugDump(std::ostream &out) const override
Debug dump.
bool IsImmutable() const override
Returns true if this range is marked as immutable.
HDST_API size_t GetMaxNumElements() const override
Returns the max number of elements.
HDST_API HdStBufferResourceNamedList const & GetResources() const override
Returns the list of all named GPU resources for this bufferArrayRange.
size_t GetVersion() const override
Returns the version of the buffer array.
void Invalidate()
Make this range invalid.
bool RequiresStaging() const override
Returns true if this needs a staging buffer for CPU to GPU copies.
HDST_API HdStBufferResourceSharedPtr GetResource(TfToken const &name) override
Returns the named GPU resource.
HDST_API HdStBufferResourceSharedPtr GetResource() const override
Returns the GPU resource.
void SetIndex(int index)
Set the relative offset for this range.
HDST_API VtValue ReadData(TfToken const &name) const override
Read back the buffer content.
void SetCapacity(int capacity)
Set the capacity of allocated area for this range.
HDST_API const void * _GetAggregation() const override
Returns the aggregation container.
_StripedInterleavedBufferRange(HdStResourceRegistry *resourceRegistry)
Constructor.
HDST_API bool Resize(int numElements) override
Resize memory area for this range.
int GetByteOffset(TfToken const &resourceName) const override
Returns the byte offset at which this range begins in the underlying buffer array for the given resou...
Interleaved memory manager (base class).
size_t GetResourceAllocation(HdBufferArraySharedPtr const &bufferArray, VtDictionary &result) const override
Returns the size of the GPU memory used by the passed buffer array.
HdBufferSpecVector GetBufferSpecs(HdBufferArraySharedPtr const &bufferArray) const override
Returns the buffer specs from a given buffer array.
HdBufferArrayRangeSharedPtr CreateBufferArrayRange() override
Factory for creating HdBufferArrayRange.
A central registry of all GPU resources.
Token for efficient comparison, assignment, and hashing of known strings.
A map with string keys and VtValue values.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
#define TF_UNUSED(x)
Stops compiler from producing unused argument or variable warnings.
HdTupleType represents zero, one, or more values of the same HdType.
Describes the properties needed to copy buffer data from CPU to GPU.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...