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 #ifdef PXR_MATERIALX_SUPPORT_ENABLED 49 #include <MaterialXCore/Library.h> 50 MATERIALX_NAMESPACE_BEGIN
51 using ShaderPtr = std::shared_ptr<class Shader>;
52 MATERIALX_NAMESPACE_END
55 PXR_NAMESPACE_OPEN_SCOPE
57 using HdComputationSharedPtr = std::shared_ptr<class HdComputation>;
58 using HdStDispatchBufferSharedPtr = std::shared_ptr<class HdStDispatchBuffer>;
59 using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
60 using HioGlslfxSharedPtr = std::shared_ptr<class HioGlslfx>;
62 using HdSt_BasisCurvesTopologySharedPtr =
63 std::shared_ptr<class HdSt_BasisCurvesTopology>;
65 using HdStShaderCodePtr =
66 std::weak_ptr<class HdStShaderCode>;
67 using HdSt_GeometricShaderSharedPtr =
68 std::shared_ptr<class HdSt_GeometricShader>;
70 using HdStTextureHandleSharedPtr =
71 std::shared_ptr<class HdStTextureHandle>;
72 using HdStTextureObjectSharedPtr =
73 std::shared_ptr<class HdStTextureObject>;
74 using HdStBufferResourceSharedPtr =
75 std::shared_ptr<class HdStBufferResource>;
76 using HdStResourceRegistrySharedPtr =
77 std::shared_ptr<class HdStResourceRegistry>;
78 using Hd_VertexAdjacencySharedPtr =
79 std::shared_ptr<class Hd_VertexAdjacency>;
80 using HdSt_MeshTopologySharedPtr =
81 std::shared_ptr<class HdSt_MeshTopology>;
82 using HgiResourceBindingsSharedPtr =
83 std::shared_ptr<HgiResourceBindingsHandle>;
84 using HgiGraphicsPipelineSharedPtr =
85 std::shared_ptr<HgiGraphicsPipelineHandle>;
86 using HgiComputePipelineSharedPtr =
87 std::shared_ptr<HgiComputePipelineHandle>;
106 enum HdStComputeQueue {
107 HdStComputeQueueZero=0,
110 HdStComputeQueueThree,
111 HdStComputeQueueCount};
113 using HdStComputationSharedPtrVector =
114 std::vector<std::pair<HdComputationSharedPtr, HdStComputeQueue>>;
124 HF_MALLOC_TAG_NEW(
"new HdStResourceRegistry");
137 std::string
const& path)
override;
164 HdTextureType textureType,
172 size_t memoryRequest,
177 HdStShaderCodePtr
const &shaderCode);
191 HdTextureType textureType);
202 HdTextureType textureType,
203 size_t memoryRequest);
215 HdBufferSpecVector
const &bufferSpecs,
219 HdBufferArrayRangeSharedPtr AllocateNonUniformImmutableBufferArrayRange(
221 HdBufferSpecVector
const &bufferSpecs,
225 HdBufferArrayRangeSharedPtr AllocateUniformBufferArrayRange(
227 HdBufferSpecVector
const &bufferSpecs,
231 HdBufferArrayRangeSharedPtr AllocateShaderStorageBufferArrayRange(
233 HdBufferSpecVector
const &bufferSpecs,
237 HdBufferArrayRangeSharedPtr AllocateSingleBufferArrayRange(
239 HdBufferSpecVector
const &bufferSpecs,
261 HdBufferArrayRangeSharedPtr
const& curRange,
262 HdBufferSpecVector
const &updatedOrAddedSpecs,
263 HdBufferSpecVector
const& removedSpecs,
267 HdBufferArrayRangeSharedPtr UpdateNonUniformImmutableBufferArrayRange(
269 HdBufferArrayRangeSharedPtr
const& curRange,
270 HdBufferSpecVector
const &updatedOrAddedSpecs,
271 HdBufferSpecVector
const& removedSpecs,
275 HdBufferArrayRangeSharedPtr UpdateUniformBufferArrayRange(
277 HdBufferArrayRangeSharedPtr
const& curRange,
278 HdBufferSpecVector
const &updatedOrAddedSpecs,
279 HdBufferSpecVector
const& removedSpecs,
283 HdBufferArrayRangeSharedPtr UpdateShaderStorageBufferArrayRange(
285 HdBufferArrayRangeSharedPtr
const& curRange,
286 HdBufferSpecVector
const &updatedOrAddedSpecs,
287 HdBufferSpecVector
const& removedSpecs,
296 void AddSources(HdBufferArrayRangeSharedPtr
const &range,
297 HdBufferSourceSharedPtrVector &&sources);
301 void AddSource(HdBufferArrayRangeSharedPtr
const &range,
302 HdBufferSourceSharedPtr
const &source);
306 void AddSource(HdBufferSourceSharedPtr
const &source);
316 HdComputationSharedPtr
const &computation,
317 HdStComputeQueue
const queue);
327 TfToken const &role,
int count,
int commandNumUints);
369 RegisterBasisCurvesTopology(
370 HdInstance<HdSt_BasisCurvesTopologySharedPtr>::ID
id);
374 RegisterVertexAdjacency(HdInstance<Hd_VertexAdjacencySharedPtr>::ID
id);
383 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
387 RegisterBasisCurvesIndexRange(
388 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
397 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
406 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
423 #ifdef PXR_MATERIALX_SUPPORT_ENABLED 427 RegisterMaterialXShader(HdInstance<MaterialX::ShaderPtr>::ID
id);
460 HgiComputeDispatch dispatchMethod = HgiComputeDispatchSerial);
468 void SubmitBlitWork(HgiSubmitWaitType wait = HgiSubmitWaitTypeNoWait);
491 std::unique_ptr<HdAggregationStrategy> &&strategy) {
492 _nonUniformAggregationStrategy = std::move(strategy);
499 std::unique_ptr<HdAggregationStrategy> &&strategy) {
500 _nonUniformImmutableAggregationStrategy = std::move(strategy);
506 std::unique_ptr<HdAggregationStrategy> &&strategy) {
507 _uniformUboAggregationStrategy = std::move(strategy);
513 std::unique_ptr<HdAggregationStrategy> &&strategy) {
514 _uniformSsboAggregationStrategy = std::move(strategy);
520 std::unique_ptr<HdAggregationStrategy> &&strategy) {
521 _singleAggregationStrategy = std::move(strategy);
535 void _CommitTextures();
537 HdBufferArrayRangeSharedPtr _AllocateBufferArrayRange(
541 HdBufferSpecVector
const &bufferSpecs,
545 HdBufferArrayRangeSharedPtr _UpdateBufferArrayRange(
549 HdBufferArrayRangeSharedPtr
const& curRange,
550 HdBufferSpecVector
const &updatedOrAddedSpecs,
551 HdBufferSpecVector
const& removedSpecs,
556 void _TallyResourceAllocation(
VtDictionary *result)
const;
560 struct _PendingSource {
561 _PendingSource(HdBufferArrayRangeSharedPtr
const &range)
567 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
568 HdBufferSourceSharedPtr
const &source)
574 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
575 HdBufferSourceSharedPtrVector && sources)
577 , sources(std::move(sources))
581 HdBufferArrayRangeSharedPtr range;
582 HdBufferSourceSharedPtrVector sources;
587 typedef tbb::concurrent_vector<_PendingSource> _PendingSourceList;
588 _PendingSourceList _pendingSources;
589 std::atomic_size_t _numBufferSourcesToResolve;
591 struct _PendingComputation{
592 _PendingComputation(HdBufferArrayRangeSharedPtr
const &range,
593 HdComputationSharedPtr
const &computation)
594 : range(range), computation(computation) { }
595 HdBufferArrayRangeSharedPtr range;
596 HdComputationSharedPtr computation;
602 typedef tbb::concurrent_vector<_PendingComputation> _PendingComputationList;
603 _PendingComputationList _pendingComputations[HdStComputeQueueCount];
613 std::unique_ptr<HdAggregationStrategy> _nonUniformAggregationStrategy;
614 std::unique_ptr<HdAggregationStrategy>
615 _nonUniformImmutableAggregationStrategy;
616 std::unique_ptr<HdAggregationStrategy> _uniformUboAggregationStrategy;
617 std::unique_ptr<HdAggregationStrategy> _uniformSsboAggregationStrategy;
618 std::unique_ptr<HdAggregationStrategy> _singleAggregationStrategy;
620 typedef std::vector<HdStDispatchBufferSharedPtr>
621 _DispatchBufferRegistry;
622 _DispatchBufferRegistry _dispatchBufferRegistry;
624 typedef std::vector<HdStBufferResourceSharedPtr>
625 _BufferResourceRegistry;
626 _BufferResourceRegistry _bufferResourceRegistry;
630 _meshTopologyRegistry;
634 _basisCurvesTopologyRegistry;
638 _vertexAdjacencyRegistry;
642 _TopologyIndexRangeInstanceRegistry;
643 typedef tbb::concurrent_unordered_map<
TfToken,
644 _TopologyIndexRangeInstanceRegistry,
646 _TopologyIndexRangeInstanceRegMap;
648 _TopologyIndexRangeInstanceRegMap _meshTopologyIndexRangeRegistry;
649 _TopologyIndexRangeInstanceRegMap _basisCurvesTopologyIndexRangeRegistry;
653 _primvarRangeRegistry;
657 _extComputationDataRangeRegistry;
661 _geometricShaderRegistry;
665 _glslProgramRegistry;
671 #ifdef PXR_MATERIALX_SUPPORT_ENABLED 677 std::unique_ptr<class HdSt_TextureHandleRegistry> _textureHandleRegistry;
681 _resourceBindingsRegistry;
685 _graphicsPipelineRegistry;
689 _computePipelineRegistry;
691 HgiBlitCmdsUniquePtr _blitCmds;
692 HgiComputeCmdsUniquePtr _computeCmds;
694 std::unique_ptr<HdStStagingBuffer> _stagingBuffer;
698 PXR_NAMESPACE_CLOSE_SCOPE
700 #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.
HDST_API HgiComputeCmds * GetGlobalComputeCmds(HgiComputeDispatch dispatchMethod=HgiComputeDispatchSerial)
Returns the global hgi compute cmd queue for recording compute work.
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...
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.