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>;
99 enum HdStComputeQueue {
100 HdStComputeQueueZero=0,
103 HdStComputeQueueThree,
104 HdStComputeQueueCount};
106 using HdStComputationSharedPtrVector =
107 std::vector<std::pair<HdComputationSharedPtr, HdStComputeQueue>>;
117 HF_MALLOC_TAG_NEW(
"new HdStResourceRegistry");
130 std::string
const& path)
override;
157 HdTextureType textureType,
165 size_t memoryRequest,
170 HdStShaderCodePtr
const &shaderCode);
184 HdTextureType textureType);
195 HdTextureType textureType,
196 size_t memoryRequest);
208 HdBufferSpecVector
const &bufferSpecs,
212 HdBufferArrayRangeSharedPtr AllocateNonUniformImmutableBufferArrayRange(
214 HdBufferSpecVector
const &bufferSpecs,
218 HdBufferArrayRangeSharedPtr AllocateUniformBufferArrayRange(
220 HdBufferSpecVector
const &bufferSpecs,
224 HdBufferArrayRangeSharedPtr AllocateShaderStorageBufferArrayRange(
226 HdBufferSpecVector
const &bufferSpecs,
230 HdBufferArrayRangeSharedPtr AllocateSingleBufferArrayRange(
232 HdBufferSpecVector
const &bufferSpecs,
254 HdBufferArrayRangeSharedPtr
const& curRange,
255 HdBufferSpecVector
const &updatedOrAddedSpecs,
256 HdBufferSpecVector
const& removedSpecs,
260 HdBufferArrayRangeSharedPtr UpdateNonUniformImmutableBufferArrayRange(
262 HdBufferArrayRangeSharedPtr
const& curRange,
263 HdBufferSpecVector
const &updatedOrAddedSpecs,
264 HdBufferSpecVector
const& removedSpecs,
268 HdBufferArrayRangeSharedPtr UpdateUniformBufferArrayRange(
270 HdBufferArrayRangeSharedPtr
const& curRange,
271 HdBufferSpecVector
const &updatedOrAddedSpecs,
272 HdBufferSpecVector
const& removedSpecs,
276 HdBufferArrayRangeSharedPtr UpdateShaderStorageBufferArrayRange(
278 HdBufferArrayRangeSharedPtr
const& curRange,
279 HdBufferSpecVector
const &updatedOrAddedSpecs,
280 HdBufferSpecVector
const& removedSpecs,
289 void AddSources(HdBufferArrayRangeSharedPtr
const &range,
290 HdBufferSourceSharedPtrVector &&sources);
294 void AddSource(HdBufferArrayRangeSharedPtr
const &range,
295 HdBufferSourceSharedPtr
const &source);
299 void AddSource(HdBufferSourceSharedPtr
const &source);
309 HdComputationSharedPtr
const &computation,
310 HdStComputeQueue
const queue);
320 TfToken const &role,
int count,
int commandNumUints);
362 RegisterBasisCurvesTopology(
363 HdInstance<HdSt_BasisCurvesTopologySharedPtr>::ID
id);
367 RegisterVertexAdjacency(HdInstance<Hd_VertexAdjacencySharedPtr>::ID
id);
376 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
380 RegisterBasisCurvesIndexRange(
381 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
390 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
399 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
453 void SubmitBlitWork(HgiSubmitWaitType wait = HgiSubmitWaitTypeNoWait);
476 std::unique_ptr<HdAggregationStrategy> &&strategy) {
477 _nonUniformAggregationStrategy = std::move(strategy);
484 std::unique_ptr<HdAggregationStrategy> &&strategy) {
485 _nonUniformImmutableAggregationStrategy = std::move(strategy);
491 std::unique_ptr<HdAggregationStrategy> &&strategy) {
492 _uniformUboAggregationStrategy = std::move(strategy);
498 std::unique_ptr<HdAggregationStrategy> &&strategy) {
499 _uniformSsboAggregationStrategy = std::move(strategy);
505 std::unique_ptr<HdAggregationStrategy> &&strategy) {
506 _singleAggregationStrategy = std::move(strategy);
520 void _CommitTextures();
522 HdBufferArrayRangeSharedPtr _AllocateBufferArrayRange(
526 HdBufferSpecVector
const &bufferSpecs,
530 HdBufferArrayRangeSharedPtr _UpdateBufferArrayRange(
534 HdBufferArrayRangeSharedPtr
const& curRange,
535 HdBufferSpecVector
const &updatedOrAddedSpecs,
536 HdBufferSpecVector
const& removedSpecs,
541 void _TallyResourceAllocation(
VtDictionary *result)
const;
545 struct _PendingSource {
546 _PendingSource(HdBufferArrayRangeSharedPtr
const &range)
552 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
553 HdBufferSourceSharedPtr
const &source)
559 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
560 HdBufferSourceSharedPtrVector && sources)
562 , sources(std::move(sources))
566 HdBufferArrayRangeSharedPtr range;
567 HdBufferSourceSharedPtrVector sources;
572 typedef tbb::concurrent_vector<_PendingSource> _PendingSourceList;
573 _PendingSourceList _pendingSources;
574 std::atomic_size_t _numBufferSourcesToResolve;
576 struct _PendingComputation{
577 _PendingComputation(HdBufferArrayRangeSharedPtr
const &range,
578 HdComputationSharedPtr
const &computation)
579 : range(range), computation(computation) { }
580 HdBufferArrayRangeSharedPtr range;
581 HdComputationSharedPtr computation;
587 typedef tbb::concurrent_vector<_PendingComputation> _PendingComputationList;
588 _PendingComputationList _pendingComputations[HdStComputeQueueCount];
598 std::unique_ptr<HdAggregationStrategy> _nonUniformAggregationStrategy;
599 std::unique_ptr<HdAggregationStrategy>
600 _nonUniformImmutableAggregationStrategy;
601 std::unique_ptr<HdAggregationStrategy> _uniformUboAggregationStrategy;
602 std::unique_ptr<HdAggregationStrategy> _uniformSsboAggregationStrategy;
603 std::unique_ptr<HdAggregationStrategy> _singleAggregationStrategy;
605 typedef std::vector<HdStDispatchBufferSharedPtr>
606 _DispatchBufferRegistry;
607 _DispatchBufferRegistry _dispatchBufferRegistry;
609 typedef std::vector<HdStBufferResourceSharedPtr>
610 _BufferResourceRegistry;
611 _BufferResourceRegistry _bufferResourceRegistry;
615 _meshTopologyRegistry;
619 _basisCurvesTopologyRegistry;
623 _vertexAdjacencyRegistry;
627 _TopologyIndexRangeInstanceRegistry;
628 typedef tbb::concurrent_unordered_map<
TfToken,
629 _TopologyIndexRangeInstanceRegistry,
631 _TopologyIndexRangeInstanceRegMap;
633 _TopologyIndexRangeInstanceRegMap _meshTopologyIndexRangeRegistry;
634 _TopologyIndexRangeInstanceRegMap _basisCurvesTopologyIndexRangeRegistry;
638 _primvarRangeRegistry;
642 _extComputationDataRangeRegistry;
646 _geometricShaderRegistry;
650 _glslProgramRegistry;
657 std::unique_ptr<class HdSt_TextureHandleRegistry> _textureHandleRegistry;
661 _resourceBindingsRegistry;
665 _graphicsPipelineRegistry;
669 _computePipelineRegistry;
671 HgiBlitCmdsUniquePtr _blitCmds;
672 HgiComputeCmdsUniquePtr _computeCmds;
674 std::unique_ptr<HdStStagingBuffer> _stagingBuffer;
678 PXR_NAMESPACE_CLOSE_SCOPE
680 #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...
Aggregation strategy base class.
HDST_API HdInstance< HdBufferArrayRangeSharedPtr > RegisterPrimvarRange(HdInstance< HdBufferArrayRangeSharedPtr >::ID id)
Primvar array range instancing Returns the HdInstance pointing to shared HdBufferArrayRange,...
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.
HDST_API HdStTextureHandleSharedPtr AllocateTextureHandle(const HdStTextureIdentifier &textureId, HdTextureType textureType, const HdSamplerParameters &samplerParams, size_t memoryRequest, HdStShaderCodePtr const &shaderCode)
Allocate texture handle (encapsulates texture and sampler object, memory request and callback to shad...
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,...
HDST_API HdStStagingBuffer * GetStagingBuffer()
Returns the staging buffer used when committing data to the GPU.
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)
Append source data for given range to be committed later.
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)
Register a buffer allocated with count * commandNumUints * sizeof(uint32_t) to be used as an indirect...
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)
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.
Provides a staging buffer for CPU writes of triple-buffered resources.
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)
These registries implement sharing and deduplication of data based on computed hash identifiers.
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)
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.