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
64 void Flush()
override;
71 class _BufferFlushListEntry {
73 _BufferFlushListEntry(
81 using _BufferFlushMap =
82 std::unordered_map<class HgiBuffer*, _BufferFlushListEntry>;
91 , _stripedBuffer(nullptr)
92 , _index(NOT_ALLOCATED)
102 return (
bool)_stripedBuffer;
115 bool Resize(
int numElements)
override;
119 void CopyData(HdBufferSourceSharedPtr
const &bufferSource)
override;
136 !
TF_VERIFY(_index != NOT_ALLOCATED))
return 0;
137 return _stripedBuffer->
GetStride() * _index;
166 HdStBufferResourceSharedPtr
GetResource()
const override;
174 HdStBufferResourceNamedList
const&
GetResources()
const override;
182 void DebugDump(std::ostream &out)
const override;
191 _stripedBuffer =
nullptr;
200 enum { NOT_ALLOCATED = -1 };
201 _StripedInterleavedBuffer *_stripedBuffer;
206 using _StripedInterleavedBufferSharedPtr =
207 std::shared_ptr<_StripedInterleavedBuffer>;
208 using _StripedInterleavedBufferRangeSharedPtr =
209 std::shared_ptr<_StripedInterleavedBufferRange>;
210 using _StripedInterleavedBufferRangePtr =
211 std::weak_ptr<_StripedInterleavedBufferRange>;
221 HdBufferSpecVector
const &bufferSpecs,
223 int bufferOffsetAlignment,
226 TfToken const &garbageCollectionPerfToken);
238 virtual void DebugDump(std::ostream &out)
const;
244 std::vector<HdBufferArrayRangeSharedPtr>
const &ranges,
245 HdBufferArraySharedPtr
const &curRangeOwner);
254 _needsCompaction =
true;
280 HdStBufferResourceNamedList
const&
GetResources()
const {
return _resourceList;}
293 void _DeallocateResources();
305 bool _needsCompaction;
307 int _bufferOffsetAlignment;
310 HdStBufferResourceNamedList _resourceList;
312 _StripedInterleavedBufferRangeSharedPtr _GetRangeSharedPtr(
size_t idx)
const {
313 return std::static_pointer_cast<_StripedInterleavedBufferRange>(
GetRange(idx).lock());
319 : _resourceRegistry(resourceRegistry) {}
326 HdBufferArraySharedPtr
const &bufferArray)
const override;
330 HdBufferArraySharedPtr
const &bufferArray,
334 _BufferFlushMap _queuedBuffers;
347 HdBufferSpecVector
const &bufferSpecs,
353 HdBufferSpecVector
const &bufferSpecs,
367 HdBufferSpecVector
const &bufferSpecs,
373 HdBufferSpecVector
const &bufferSpecs,
377 PXR_NAMESPACE_CLOSE_SCOPE
379 #endif // PXR_IMAGING_HD_ST_INTERLEAVED_MEMORY_MANAGER_H
void Flush() override
Flush the staging buffer to GPU.
HdBufferSpecVector GetBufferSpecs(HdBufferArraySharedPtr const &bufferArray) const override
Returns the buffer specs from a given buffer array.
HDST_API HdBufferSpecVector GetBufferSpecs() const
Reconstructs the bufferspecs and returns it (for buffer splitting)
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.
virtual HDST_API void DebugDump(std::ostream &out) const
Debug output.
int GetElementOffset() const override
Returns the offset at which this range begins in the underlying buffer array in terms of elements...
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.
HD_API HdBufferArrayRangePtr GetRange(size_t idx) const
Get the attached range at the specified index.
_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.
#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.
Token for efficient comparison, assignment, and hashing of known strings.
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.
int GetStride() const
Returns the stride.
void SetNeedsReallocation()
Mark to perform reallocation on Reallocate()
HDST_API const void * _GetAggregation() const override
Returns the aggregation container.
HDST_API HdStBufferResourceSharedPtr GetResource() const
TODO: We need to distinguish between the primvar types here, we should tag each HdBufferSource and Hd...
HDST_API size_t GetMaxNumElements() const override
Returns the max number of elements.
HdStBufferResourceNamedList const & GetResources() const
Returns the list of all named GPU resources for this bufferArray.
void SetNeedsCompaction()
Mark to perform compaction on GarbageCollect()
size_t GetVersion() const
Returns the version of this buffer array.
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.
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...
void StageBufferCopy(HgiBufferCpuToGpuOp const ©Op)
Copy new data from CPU into staging buffer.
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.