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/hd/bufferArray.h" 31 #include "pxr/imaging/hd/bufferSpec.h" 32 #include "pxr/imaging/hd/bufferSource.h" 33 #include "pxr/imaging/hd/resource.h" 34 #include "pxr/imaging/hd/strategyBase.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> 45 PXR_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();
148 HdStBufferResourceSharedPtr
GetResource()
const override;
156 HdStBufferResourceNamedList
const&
GetResources()
const override;
164 void DebugDump(std::ostream &out)
const override;
173 _stripedBuffer =
nullptr;
183 _capacity = capacity;
192 enum { NOT_ALLOCATED = -1 };
193 _StripedInterleavedBuffer *_stripedBuffer;
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,
216 int bufferOffsetAlignment,
219 TfToken const &garbageCollectionPerfToken);
231 virtual void DebugDump(std::ostream &out)
const;
237 std::vector<HdBufferArrayRangeSharedPtr>
const &ranges,
238 HdBufferArraySharedPtr
const &curRangeOwner);
247 _needsCompaction =
true;
255 size_t GetElementStride()
const {
256 return _elementStride;
277 HdStBufferResourceNamedList
const&
GetResources()
const {
return _resourceList;}
290 void _DeallocateResources();
302 bool _needsCompaction;
304 int _bufferOffsetAlignment;
317 size_t _elementStride;
319 HdStBufferResourceNamedList _resourceList;
321 _StripedInterleavedBufferRangeSharedPtr _GetRangeSharedPtr(
size_t idx)
const {
322 return std::static_pointer_cast<_StripedInterleavedBufferRange>(
GetRange(idx).lock());
328 : _resourceRegistry(resourceRegistry) {}
335 HdBufferArraySharedPtr
const &bufferArray)
const override;
339 HdBufferArraySharedPtr
const &bufferArray,
355 HdBufferSpecVector
const &bufferSpecs,
361 HdBufferSpecVector
const &bufferSpecs,
375 HdBufferSpecVector
const &bufferSpecs,
381 HdBufferSpecVector
const &bufferSpecs,
385 PXR_NAMESPACE_CLOSE_SCOPE
387 #endif // PXR_IMAGING_HD_ST_INTERLEAVED_MEMORY_MANAGER_H HdBufferSpecVector GetBufferSpecs(HdBufferArraySharedPtr const &bufferArray) const override
Returns the buffer specs from a given buffer array.
size_t AggregationId
Aggregation ID.
The union provides a set of flags that provide hints to the memory management system about the proper...
Describes the properties needed to copy buffer data from CPU to GPU.
int GetElementOffset() const override
Returns the offset at which this range begins in the underlying.
HDST_API HdStBufferResourceSharedPtr _AddResource(TfToken const &name, HdTupleType tupleType, int offset, int stride)
Adds a new, named GPU resource and returns it.
HDST_API HdStBufferResourceNamedList const & GetResources() const override
Returns the list of all named GPU resources for this bufferArrayRange.
Similar to a VAO, this object is a bundle of coherent buffers.
void SetIndex(int index)
Set the relative offset for this range.
Aggregation strategy base class.
HD_API void IncrementVersion()
Increments the version of this buffer array.
HDST_API bool Resize(int numElements) override
Resize memory area for this range.
Interface class for representing range (subset) locator of HdBufferArray.
HdTupleType represents zero, one, or more values of the same HdType.
A map with string keys and VtValue values.
virtual HdBufferArraySharedPtr CreateBufferArray(TfToken const &role, HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint)=0
Factory for creating HdBufferArray.
HDST_API ~_StripedInterleavedBufferRange() override
Destructor.
_StripedInterleavedBufferRange(HdStResourceRegistry *resourceRegistry)
Constructor.
specialized buffer array range
HDST_API bool IsAssigned() const override
Returns true is the range has been assigned to a buffer.
HDST_API HdBufferSpecVector GetBufferSpecs() const
Reconstructs the bufferspecs and returns it (for buffer splitting)
#define TF_UNUSED(x)
Stops compiler from producing unused argument or variable warnings.
Interleaved memory manager (base class).
bool IsValid() const override
Returns true if this range is valid.
bool RequiresStaging() const override
Returns true if this needs a staging buffer for CPU to GPU copies.
virtual HDST_API void DebugDump(std::ostream &out) const
Debug output.
Token for efficient comparison, assignment, and hashing of known strings.
HDST_API HdStBufferResourceSharedPtr GetResource() const
TODO: We need to distinguish between the primvar types here, we should tag each HdBufferSource and Hd...
HDST_API VtValue ReadData(TfToken const &name) const override
Read back the buffer content.
#define TF_VERIFY(cond, format,...)
Checks a condition and reports an error if it evaluates false.
bool IsImmutable() const override
Returns true if this range is marked as immutable.
HDST_API HdStBufferResourceSharedPtr GetResource() const override
Returns the GPU resource.
A central registry of all GPU resources.
void SetNeedsReallocation()
Mark to perform reallocation on Reallocate()
int GetCapacity() const
Returns the capacity of allocated area.
HDST_API const void * _GetAggregation() const override
Returns the aggregation container.
HDST_API size_t GetMaxNumElements() const override
Returns the max number of elements.
void SetNeedsCompaction()
Mark to perform compaction on GarbageCollect()
void SetCapacity(int capacity)
Set the capacity of allocated area for this range.
HdStBufferResourceNamedList const & GetResources() const
Returns the list of all named GPU resources for this bufferArray.
HD_API HdBufferArrayRangePtr GetRange(size_t idx) const
Get the attached range at the specified index.
virtual AggregationId ComputeAggregationId(HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint) const =0
Returns id for given bufferSpecs to be used for aggregation.
HDST_API void SetBufferArray(HdBufferArray *bufferArray) override
Sets the buffer array associated with this buffer;.
size_t GetResourceAllocation(HdBufferArraySharedPtr const &bufferArray, VtDictionary &result) const override
Returns the size of the GPU memory used by the passed buffer array.
HDST_API void CopyData(HdBufferSourceSharedPtr const &bufferSource) override
Copy source data into buffer.
bool _needsReallocation
Dirty bit to set when the ranges attached to the buffer changes.
void Invalidate()
Make this range invalid.
HdBufferArrayRangeSharedPtr CreateBufferArrayRange() override
Factory for creating HdBufferArrayRange.
virtual HDST_API void Reallocate(std::vector< HdBufferArrayRangeSharedPtr > const &ranges, HdBufferArraySharedPtr const &curRangeOwner)
Performs reallocation.
HDST_API HdBufferArrayUsageHint GetUsageHint() const override
Returns the usage hint from the underlying buffer array.
size_t GetVersion() const override
Returns the version of the buffer array.
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.
size_t GetStride() const
Returns the stride.
void IncrementVersion() override
Increment the version of the buffer array.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
virtual HDST_API bool GarbageCollect()
perform compaction if necessary, returns true if it becomes empty.
HDST_API void DebugDump(std::ostream &out) const override
Debug dump.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
size_t GetVersion() const
Returns the version of this buffer array.
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...
size_t GetNumElements() const override
Returns the number of elements.
virtual HDST_API ~_StripedInterleavedBuffer()
Destructor. It invalidates _rangeList.