24 #ifndef PXR_IMAGING_HD_ST_RESOURCE_REGISTRY_H
25 #define PXR_IMAGING_HD_ST_RESOURCE_REGISTRY_H
30 #include "pxr/imaging/hdSt/api.h"
32 #include "pxr/imaging/hgi/hgi.h"
34 #include "pxr/imaging/hd/bufferArrayRange.h"
35 #include "pxr/imaging/hd/bufferArrayRegistry.h"
36 #include "pxr/imaging/hd/bufferSource.h"
37 #include "pxr/imaging/hd/bufferSpec.h"
38 #include "pxr/imaging/hd/enums.h"
39 #include "pxr/imaging/hd/instanceRegistry.h"
40 #include "pxr/imaging/hd/resourceRegistry.h"
42 #include <tbb/concurrent_vector.h>
48 PXR_NAMESPACE_OPEN_SCOPE
50 using HdComputationSharedPtr = std::shared_ptr<class HdComputation>;
51 using HdStDispatchBufferSharedPtr = std::shared_ptr<class HdStDispatchBuffer>;
52 using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
53 using HioGlslfxSharedPtr = std::shared_ptr<class HioGlslfx>;
55 using HdSt_BasisCurvesTopologySharedPtr =
56 std::shared_ptr<class HdSt_BasisCurvesTopology>;
58 using HdStShaderCodePtr =
59 std::weak_ptr<class HdStShaderCode>;
60 using HdSt_GeometricShaderSharedPtr =
61 std::shared_ptr<class HdSt_GeometricShader>;
63 using HdStTextureHandleSharedPtr =
64 std::shared_ptr<class HdStTextureHandle>;
65 using HdStTextureObjectSharedPtr =
66 std::shared_ptr<class HdStTextureObject>;
67 using HdStBufferResourceSharedPtr =
68 std::shared_ptr<class HdStBufferResource>;
69 using HdStResourceRegistrySharedPtr =
70 std::shared_ptr<class HdStResourceRegistry>;
71 using Hd_VertexAdjacencySharedPtr =
72 std::shared_ptr<class Hd_VertexAdjacency>;
73 using HdSt_MeshTopologySharedPtr =
74 std::shared_ptr<class HdSt_MeshTopology>;
75 using HgiResourceBindingsSharedPtr =
76 std::shared_ptr<HgiResourceBindingsHandle>;
77 using HgiGraphicsPipelineSharedPtr =
78 std::shared_ptr<HgiGraphicsPipelineHandle>;
79 using HgiComputePipelineSharedPtr =
80 std::shared_ptr<HgiComputePipelineHandle>;
98 enum HdStComputeQueue {
99 HdStComputeQueueZero=0,
102 HdStComputeQueueThree,
103 HdStComputeQueueCount};
105 using HdStComputationSharedPtrVector =
106 std::vector<std::pair<HdComputationSharedPtr, HdStComputeQueue>>;
116 HF_MALLOC_TAG_NEW(
"new HdStResourceRegistry");
122 ~HdStResourceRegistry()
override;
129 std::string
const& path)
override;
157 HdTextureType textureType,
165 size_t memoryRequest,
168 bool createBindlessHandle,
173 HdStShaderCodePtr
const &shaderCode);
187 HdTextureType textureType);
198 HdTextureType textureType,
199 size_t memoryRequest);
211 HdBufferSpecVector
const &bufferSpecs,
215 HdBufferArrayRangeSharedPtr AllocateNonUniformImmutableBufferArrayRange(
217 HdBufferSpecVector
const &bufferSpecs,
221 HdBufferArrayRangeSharedPtr AllocateUniformBufferArrayRange(
223 HdBufferSpecVector
const &bufferSpecs,
227 HdBufferArrayRangeSharedPtr AllocateShaderStorageBufferArrayRange(
229 HdBufferSpecVector
const &bufferSpecs,
233 HdBufferArrayRangeSharedPtr AllocateSingleBufferArrayRange(
235 HdBufferSpecVector
const &bufferSpecs,
257 HdBufferArrayRangeSharedPtr
const& curRange,
258 HdBufferSpecVector
const &updatedOrAddedSpecs,
259 HdBufferSpecVector
const& removedSpecs,
263 HdBufferArrayRangeSharedPtr UpdateNonUniformImmutableBufferArrayRange(
265 HdBufferArrayRangeSharedPtr
const& curRange,
266 HdBufferSpecVector
const &updatedOrAddedSpecs,
267 HdBufferSpecVector
const& removedSpecs,
271 HdBufferArrayRangeSharedPtr UpdateUniformBufferArrayRange(
273 HdBufferArrayRangeSharedPtr
const& curRange,
274 HdBufferSpecVector
const &updatedOrAddedSpecs,
275 HdBufferSpecVector
const& removedSpecs,
279 HdBufferArrayRangeSharedPtr UpdateShaderStorageBufferArrayRange(
281 HdBufferArrayRangeSharedPtr
const& curRange,
282 HdBufferSpecVector
const &updatedOrAddedSpecs,
283 HdBufferSpecVector
const& removedSpecs,
292 void AddSources(HdBufferArrayRangeSharedPtr
const &range,
293 HdBufferSourceSharedPtrVector &&sources);
297 void AddSource(HdBufferArrayRangeSharedPtr
const &range,
298 HdBufferSourceSharedPtr
const &source);
302 void AddSource(HdBufferSourceSharedPtr
const &source);
312 HdComputationSharedPtr
const &computation,
313 HdStComputeQueue
const queue);
323 TfToken const &role,
int count,
int commandNumUints);
365 RegisterBasisCurvesTopology(
366 HdInstance<HdSt_BasisCurvesTopologySharedPtr>::ID
id);
370 RegisterVertexAdjacency(HdInstance<Hd_VertexAdjacencySharedPtr>::ID
id);
379 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
383 RegisterBasisCurvesIndexRange(
384 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
393 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
402 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
456 void SubmitBlitWork(HgiSubmitWaitType wait = HgiSubmitWaitTypeNoWait);
475 std::unique_ptr<HdAggregationStrategy> &&strategy) {
476 _nonUniformAggregationStrategy = std::move(strategy);
483 std::unique_ptr<HdAggregationStrategy> &&strategy) {
484 _nonUniformImmutableAggregationStrategy = std::move(strategy);
490 std::unique_ptr<HdAggregationStrategy> &&strategy) {
491 _uniformUboAggregationStrategy = std::move(strategy);
497 std::unique_ptr<HdAggregationStrategy> &&strategy) {
498 _uniformSsboAggregationStrategy = std::move(strategy);
504 std::unique_ptr<HdAggregationStrategy> &&strategy) {
505 _singleAggregationStrategy = std::move(strategy);
512 const HdStResourceRegistry&
self);
519 void _CommitTextures();
521 HdBufferArrayRangeSharedPtr _AllocateBufferArrayRange(
525 HdBufferSpecVector
const &bufferSpecs,
529 HdBufferArrayRangeSharedPtr _UpdateBufferArrayRange(
533 HdBufferArrayRangeSharedPtr
const& curRange,
534 HdBufferSpecVector
const &updatedOrAddedSpecs,
535 HdBufferSpecVector
const& removedSpecs,
540 void _TallyResourceAllocation(
VtDictionary *result)
const;
544 struct _PendingSource {
545 _PendingSource(HdBufferArrayRangeSharedPtr
const &range)
551 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
552 HdBufferSourceSharedPtr
const &source)
558 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
559 HdBufferSourceSharedPtrVector && sources)
561 , sources(std::move(sources))
565 HdBufferArrayRangeSharedPtr range;
566 HdBufferSourceSharedPtrVector sources;
571 typedef tbb::concurrent_vector<_PendingSource> _PendingSourceList;
572 _PendingSourceList _pendingSources;
573 std::atomic_size_t _numBufferSourcesToResolve;
575 struct _PendingComputation{
576 _PendingComputation(HdBufferArrayRangeSharedPtr
const &range,
577 HdComputationSharedPtr
const &computation)
578 : range(range), computation(computation) { }
579 HdBufferArrayRangeSharedPtr range;
580 HdComputationSharedPtr computation;
586 typedef tbb::concurrent_vector<_PendingComputation> _PendingComputationList;
587 _PendingComputationList _pendingComputations[HdStComputeQueueCount];
597 std::unique_ptr<HdAggregationStrategy> _nonUniformAggregationStrategy;
598 std::unique_ptr<HdAggregationStrategy>
599 _nonUniformImmutableAggregationStrategy;
600 std::unique_ptr<HdAggregationStrategy> _uniformUboAggregationStrategy;
601 std::unique_ptr<HdAggregationStrategy> _uniformSsboAggregationStrategy;
602 std::unique_ptr<HdAggregationStrategy> _singleAggregationStrategy;
604 typedef std::vector<HdStDispatchBufferSharedPtr>
605 _DispatchBufferRegistry;
606 _DispatchBufferRegistry _dispatchBufferRegistry;
608 typedef std::vector<HdStBufferResourceSharedPtr>
609 _BufferResourceRegistry;
610 _BufferResourceRegistry _bufferResourceRegistry;
614 _meshTopologyRegistry;
618 _basisCurvesTopologyRegistry;
622 _vertexAdjacencyRegistry;
626 _TopologyIndexRangeInstanceRegistry;
627 typedef tbb::concurrent_unordered_map<
TfToken,
628 _TopologyIndexRangeInstanceRegistry,
630 _TopologyIndexRangeInstanceRegMap;
632 _TopologyIndexRangeInstanceRegMap _meshTopologyIndexRangeRegistry;
633 _TopologyIndexRangeInstanceRegMap _basisCurvesTopologyIndexRangeRegistry;
637 _primvarRangeRegistry;
641 _extComputationDataRangeRegistry;
645 _geometricShaderRegistry;
649 _glslProgramRegistry;
656 std::unique_ptr<class HdSt_TextureHandleRegistry> _textureHandleRegistry;
660 _resourceBindingsRegistry;
664 _graphicsPipelineRegistry;
668 _computePipelineRegistry;
670 HgiBlitCmdsUniquePtr _blitCmds;
671 HgiComputeCmdsUniquePtr _computeCmds;
675 PXR_NAMESPACE_CLOSE_SCOPE
677 #endif //PXR_IMAGING_HD_ST_RESOURCE_REGISTRY_H
HDST_API HdInstance< HgiGraphicsPipelineSharedPtr > RegisterGraphicsPipeline(HdInstance< HgiGraphicsPipelineSharedPtr >::ID id)
Register a Hgi graphics pipeline into the registry.
The union provides a set of flags that provide hints to the memory management system about the proper...
HDST_API HdStTextureHandleSharedPtr AllocateTextureHandle(const HdStTextureIdentifier &textureId, HdTextureType textureType, const HdSamplerParameters &samplerParams, size_t memoryRequest, bool createBindlessHandle, HdStShaderCodePtr const &shaderCode)
Texture allocation API
Aggregation strategy base class.
HDST_API HdInstance< HdBufferArrayRangeSharedPtr > RegisterPrimvarRange(HdInstance< HdBufferArrayRangeSharedPtr >::ID id)
Primvar array range instancing Returns the HdInstance pointing to shared HdBufferArrayRange, distinguished by given ID.
HDST_API VtDictionary GetResourceAllocation() const override
Returns a report of resource allocation by role in bytes and a summary total allocation of GPU memory...
HDST_API HdStBufferResourceSharedPtr RegisterBufferResource(TfToken const &role, HdTupleType tupleType)
Register a misc buffer resource.
HdTupleType represents zero, one, or more values of the same HdType.
A map with string keys and VtValue values.
HDST_API void SubmitComputeWork(HgiSubmitWaitType wait=HgiSubmitWaitTypeNoWait)
Submits compute work queued in global compute cmds for GPU execution.
Functor to use for hash maps from tokens to other things.
HDST_API void GarbageCollectDispatchBuffers()
Remove any entries associated with expired dispatch buffers.
void SetNonUniformImmutableAggregationStrategy(std::unique_ptr< HdAggregationStrategy > &&strategy)
Set the aggregation strategy for non uniform immutable parameters (vertex, varying, facevarying) Takes ownership of the passed in strategy object.
Manages the pool of buffer arrays.
HDST_API void SetMemoryRequestForTextureType(HdTextureType textureType, size_t memoryRequest)
Sets how much memory a single texture can consume in bytes by texture type.
A graphics API independent abstraction of compute commands.
HDST_API void AddSources(HdBufferArrayRangeSharedPtr const &range, HdBufferSourceSharedPtrVector &&sources)
Resource update & computation queuing API
void SetNonUniformAggregationStrategy(std::unique_ptr< HdAggregationStrategy > &&strategy)
Set the aggregation strategy for non uniform parameters (vertex, varying, facevarying) Takes ownershi...
HDST_API Hgi * GetHgi()
Returns Hgi used to create/destroy GPU resources.
Class to identify a texture file or a texture within the texture file (e.g., a frame in a movie)...
HDST_API void AddSource(HdBufferArrayRangeSharedPtr const &range, HdBufferSourceSharedPtr const &source)
Append a source data for given range to be committed later.
Token for efficient comparison, assignment, and hashing of known strings.
HDST_API HdInstance< HioGlslfxSharedPtr > RegisterGLSLFXFile(HdInstance< HioGlslfxSharedPtr >::ID id)
Register a GLSLFX file.
A central registry of all GPU resources.
void _Commit() override
A hook for derived registries to perform additional resource commits.
A central registry for resources.
void SetUniformAggregationStrategy(std::unique_ptr< HdAggregationStrategy > &&strategy)
Set the aggregation strategy for uniform (shader globals) Takes ownership of the passed in strategy o...
HDST_API HgiBlitCmds * GetGlobalBlitCmds()
Returns the global hgi blit command queue for recording blitting work.
void SetSingleStorageAggregationStrategy(std::unique_ptr< HdAggregationStrategy > &&strategy)
Set the aggregation strategy for single buffers (for nested instancer).
HDST_API HdStDispatchBufferSharedPtr RegisterDispatchBuffer(TfToken const &role, int count, int commandNumUints)
Dispatch & buffer API
HDST_API HdInstance< HgiComputePipelineSharedPtr > RegisterComputePipeline(HdInstance< HgiComputePipelineSharedPtr >::ID id)
Register a Hgi compute pipeline into the registry.
Hydra Graphics Interface.
HDST_API HdStTextureObjectSharedPtr AllocateTextureObject(const HdStTextureIdentifier &textureId, HdTextureType textureType)
Allocate texture object.
HDST_API HdBufferArrayRangeSharedPtr UpdateNonUniformBufferArrayRange(TfToken const &role, HdBufferArrayRangeSharedPtr const &curRange, HdBufferSpecVector const &updatedOrAddedSpecs, HdBufferSpecVector const &removedSpecs, HdBufferArrayUsageHint usageHint)
BAR allocation/migration/update API
HDST_API HdInstance< HdBufferArrayRangeSharedPtr > RegisterExtComputationDataRange(HdInstance< HdBufferArrayRangeSharedPtr >::ID id)
ExtComputation data array range instancing Returns the HdInstance pointing to shared HdBufferArrayRan...
HDST_API HgiComputeCmds * GetGlobalComputeCmds()
Returns the global hgi compute cmd queue for recording compute work.
void SetShaderStorageAggregationStrategy(std::unique_ptr< HdAggregationStrategy > &&strategy)
Set the aggregation strategy for SSBO (uniform primvars) Takes ownership of the passed in strategy ob...
Collection of standard parameters such as wrap modes to sample a texture.
void _GarbageCollect() override
Hooks for derived registries to perform additional GC when GarbageCollect() is invoked.
HDST_API HdInstance< HdSt_GeometricShaderSharedPtr > RegisterGeometricShader(HdInstance< HdSt_GeometricShaderSharedPtr >::ID id)
Register a geometric shader.
HDST_API void GarbageCollectBufferResources()
Remove any entries associated with expired misc buffers.
HDST_API void SubmitBlitWork(HgiSubmitWaitType wait=HgiSubmitWaitTypeNoWait)
Submits blit work queued in global blit cmds for GPU execution.
HDST_API void ReloadResource(TfToken const &resourceType, std::string const &path) override
Generic method to inform RenderDelegate a resource needs to be reloaded.
HDST_API friend std::ostream & operator<<(std::ostream &out, const HdStResourceRegistry &self)
Debug dump.
HDST_API HdInstance< HdSt_MeshTopologySharedPtr > RegisterMeshTopology(HdInstance< HdSt_MeshTopologySharedPtr >::ID id)
Instance Registries
This class is used as an interface to a shared instance in HdInstanceRegistry.
A graphics API independent abstraction of resource copy commands.
HDST_API HdInstance< HgiResourceBindingsSharedPtr > RegisterResourceBindings(HdInstance< HgiResourceBindingsSharedPtr >::ID id)
Register a Hgi resource bindings into the registry.
HDST_API HdInstance< HdBufferArrayRangeSharedPtr > RegisterMeshIndexRange(HdInstance< HdBufferArrayRangeSharedPtr >::ID id, TfToken const &name)
Topology Index buffer array range instancing Returns the HdInstance points to shared HdBufferArrayRan...
HDST_API HdBufferArrayRangeSharedPtr AllocateNonUniformBufferArrayRange(TfToken const &role, HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint)
BAR allocation API
HDST_API HdInstance< HdStGLSLProgramSharedPtr > RegisterGLSLProgram(HdInstance< HdStGLSLProgramSharedPtr >::ID id)
Register a GLSL program into the program registry.
HDST_API void AddComputation(HdBufferArrayRangeSharedPtr const &range, HdComputationSharedPtr const &computation, HdStComputeQueue const queue)
Append a gpu computation into queue.
HDST_API void InvalidateShaderRegistry() override
Invalidate any shaders registered with this registry.