7#ifndef PXR_IMAGING_HD_ST_RESOURCE_REGISTRY_H
8#define PXR_IMAGING_HD_ST_RESOURCE_REGISTRY_H
13#include "pxr/imaging/hdSt/api.h"
14#include "pxr/imaging/hdSt/bufferArrayRegistry.h"
15#include "pxr/imaging/hdSt/enums.h"
16#include "pxr/imaging/hdSt/renderBufferPool.h"
18#include "pxr/imaging/hgi/hgi.h"
20#include "pxr/imaging/hd/bufferArrayRange.h"
21#include "pxr/imaging/hd/bufferSource.h"
22#include "pxr/imaging/hd/bufferSpec.h"
23#include "pxr/imaging/hd/instanceRegistry.h"
24#include "pxr/imaging/hd/resourceRegistry.h"
26#include <tbb/concurrent_vector.h>
32#ifdef PXR_MATERIALX_SUPPORT_ENABLED
33#include <MaterialXCore/Library.h>
34MATERIALX_NAMESPACE_BEGIN
35 using ShaderPtr = std::shared_ptr<class Shader>;
36MATERIALX_NAMESPACE_END
39PXR_NAMESPACE_OPEN_SCOPE
41using HdStComputationSharedPtr = std::shared_ptr<class HdStComputation>;
42using HdStDispatchBufferSharedPtr = std::shared_ptr<class HdStDispatchBuffer>;
43using HdStGLSLProgramSharedPtr = std::shared_ptr<class HdStGLSLProgram>;
44using HioGlslfxSharedPtr = std::shared_ptr<class HioGlslfx>;
46using HdSt_BasisCurvesTopologySharedPtr =
47 std::shared_ptr<class HdSt_BasisCurvesTopology>;
49using HdStShaderCodePtr =
50 std::weak_ptr<class HdStShaderCode>;
51using HdSt_GeometricShaderSharedPtr =
52 std::shared_ptr<class HdSt_GeometricShader>;
53using HdStRenderPassShaderSharedPtr =
54 std::shared_ptr<class HdStRenderPassShader>;
56using HdStTextureHandleSharedPtr =
57 std::shared_ptr<class HdStTextureHandle>;
58using HdStTextureObjectSharedPtr =
59 std::shared_ptr<class HdStTextureObject>;
60using HdStBufferResourceSharedPtr =
61 std::shared_ptr<class HdStBufferResource>;
62using HdStResourceRegistrySharedPtr =
63 std::shared_ptr<class HdStResourceRegistry>;
64using HdSt_VertexAdjacencyBuilderSharedPtr =
65 std::shared_ptr<class HdSt_VertexAdjacencyBuilder>;
66using HdSt_MeshTopologySharedPtr =
67 std::shared_ptr<class HdSt_MeshTopology>;
68using HgiResourceBindingsSharedPtr =
69 std::shared_ptr<HgiResourceBindingsHandle>;
70using HgiGraphicsPipelineSharedPtr =
71 std::shared_ptr<HgiGraphicsPipelineHandle>;
72using HgiComputePipelineSharedPtr =
73 std::shared_ptr<HgiComputePipelineHandle>;
92enum HdStComputeQueue {
93 HdStComputeQueueZero=0,
96 HdStComputeQueueThree,
97 HdStComputeQueueCount};
99using HdStComputationComputeQueuePairVector =
100 std::vector<std::pair<HdStComputationSharedPtr, HdStComputeQueue>>;
110 HF_MALLOC_TAG_NEW(
"new HdStResourceRegistry");
123 std::string
const& path)
override;
150 HdStTextureType textureType,
158 size_t memoryRequest,
163 HdStShaderCodePtr
const &shaderCode);
177 HdStTextureType textureType);
202 HdStTextureType textureType,
203 size_t memoryRequest);
215 HdBufferSpecVector
const &bufferSpecs,
216 HdBufferArrayUsageHint usageHint);
219 HdBufferArrayRangeSharedPtr AllocateNonUniformImmutableBufferArrayRange(
221 HdBufferSpecVector
const &bufferSpecs,
222 HdBufferArrayUsageHint usageHint);
225 HdBufferArrayRangeSharedPtr AllocateUniformBufferArrayRange(
227 HdBufferSpecVector
const &bufferSpecs,
228 HdBufferArrayUsageHint usageHint);
231 HdBufferArrayRangeSharedPtr AllocateShaderStorageBufferArrayRange(
233 HdBufferSpecVector
const &bufferSpecs,
234 HdBufferArrayUsageHint usageHint);
237 HdBufferArrayRangeSharedPtr AllocateSingleBufferArrayRange(
239 HdBufferSpecVector
const &bufferSpecs,
240 HdBufferArrayUsageHint usageHint);
261 HdBufferArrayRangeSharedPtr
const& curRange,
262 HdBufferSpecVector
const &updatedOrAddedSpecs,
263 HdBufferSpecVector
const& removedSpecs,
264 HdBufferArrayUsageHint usageHint);
267 HdBufferArrayRangeSharedPtr UpdateNonUniformImmutableBufferArrayRange(
269 HdBufferArrayRangeSharedPtr
const& curRange,
270 HdBufferSpecVector
const &updatedOrAddedSpecs,
271 HdBufferSpecVector
const& removedSpecs,
272 HdBufferArrayUsageHint usageHint);
275 HdBufferArrayRangeSharedPtr UpdateUniformBufferArrayRange(
277 HdBufferArrayRangeSharedPtr
const& curRange,
278 HdBufferSpecVector
const &updatedOrAddedSpecs,
279 HdBufferSpecVector
const& removedSpecs,
280 HdBufferArrayUsageHint usageHint);
283 HdBufferArrayRangeSharedPtr UpdateShaderStorageBufferArrayRange(
285 HdBufferArrayRangeSharedPtr
const& curRange,
286 HdBufferSpecVector
const &updatedOrAddedSpecs,
287 HdBufferSpecVector
const& removedSpecs,
288 HdBufferArrayUsageHint usageHint);
297 HdBufferSourceSharedPtrVector &&sources);
301 void AddSource(HdBufferArrayRangeSharedPtr
const &range,
302 HdBufferSourceSharedPtr
const &source);
316 HdStComputationSharedPtr
const &computation,
317 HdStComputeQueue
const queue);
327 TfToken const &role,
int count,
int commandNumUints);
338 HgiBufferUsage bufferUsage,
339 std::string debugName =
"");
371 RegisterBasisCurvesTopology(
372 HdInstance<HdSt_BasisCurvesTopologySharedPtr>::ID
id);
376 RegisterVertexAdjacencyBuilder(
377 HdInstance<HdSt_VertexAdjacencyBuilderSharedPtr>::ID
id);
386 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
390 RegisterBasisCurvesIndexRange(
391 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
400 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
409 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
431#ifdef PXR_MATERIALX_SUPPORT_ENABLED
435 RegisterMaterialXShader(HdInstance<MaterialX::ShaderPtr>::ID
id);
466 const std::string& identifier,
467 const std::function<std::unique_ptr<HdResourceRegistry>()>& factory);
484 HgiComputeDispatch dispatchMethod = HgiComputeDispatchSerial);
515 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
516 _nonUniformAggregationStrategy = std::move(strategy);
523 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
524 _nonUniformImmutableAggregationStrategy = std::move(strategy);
530 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
531 _uniformUboAggregationStrategy = std::move(strategy);
537 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
538 _uniformSsboAggregationStrategy = std::move(strategy);
544 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
545 _singleAggregationStrategy = std::move(strategy);
559 void _CommitTextures();
561 HdBufferArrayRangeSharedPtr _AllocateBufferArrayRange(
565 HdBufferSpecVector
const &bufferSpecs,
566 HdBufferArrayUsageHint usageHint);
569 HdBufferArrayRangeSharedPtr _UpdateBufferArrayRange(
573 HdBufferArrayRangeSharedPtr
const& curRange,
574 HdBufferSpecVector
const &updatedOrAddedSpecs,
575 HdBufferSpecVector
const& removedSpecs,
576 HdBufferArrayUsageHint usageHint);
580 void _TallyResourceAllocation(
VtDictionary *result)
const;
584 struct _PendingSource {
585 _PendingSource(HdBufferArrayRangeSharedPtr
const &range)
591 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
592 HdBufferSourceSharedPtr
const &source)
598 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
599 HdBufferSourceSharedPtrVector && sources)
601 , sources(
std::move(sources))
605 HdBufferArrayRangeSharedPtr range;
606 HdBufferSourceSharedPtrVector sources;
611 using _PendingSourceList =
612 tbb::concurrent_vector<_PendingSource>;
614 _PendingSourceList _pendingSources;
616 using _PendingResolveList =
617 tbb::concurrent_vector<std::pair<HdBufferSourceSharedPtr,bool>>;
619 _PendingResolveList _pendingSourcesToResolve;
623 std::atomic_size_t _pendingStagingSize;
625 struct _PendingComputation{
626 _PendingComputation(HdBufferArrayRangeSharedPtr
const &range,
627 HdStComputationSharedPtr
const &computation)
628 : range(range), computation(computation) { }
629 HdBufferArrayRangeSharedPtr range;
630 HdStComputationSharedPtr computation;
636 typedef tbb::concurrent_vector<_PendingComputation> _PendingComputationList;
637 _PendingComputationList _pendingComputations[HdStComputeQueueCount];
647 std::unique_ptr<HdStAggregationStrategy> _nonUniformAggregationStrategy;
648 std::unique_ptr<HdStAggregationStrategy>
649 _nonUniformImmutableAggregationStrategy;
650 std::unique_ptr<HdStAggregationStrategy> _uniformUboAggregationStrategy;
651 std::unique_ptr<HdStAggregationStrategy> _uniformSsboAggregationStrategy;
652 std::unique_ptr<HdStAggregationStrategy> _singleAggregationStrategy;
654 typedef std::vector<HdStDispatchBufferSharedPtr>
655 _DispatchBufferRegistry;
656 _DispatchBufferRegistry _dispatchBufferRegistry;
658 typedef std::vector<HdStBufferResourceSharedPtr>
659 _BufferResourceRegistry;
660 _BufferResourceRegistry _bufferResourceRegistry;
664 _meshTopologyRegistry;
668 _basisCurvesTopologyRegistry;
672 _vertexAdjacencyBuilderRegistry;
676 _TopologyIndexRangeInstanceRegistry;
677 typedef tbb::concurrent_unordered_map<
TfToken,
678 _TopologyIndexRangeInstanceRegistry,
680 _TopologyIndexRangeInstanceRegMap;
682 _TopologyIndexRangeInstanceRegMap _meshTopologyIndexRangeRegistry;
683 _TopologyIndexRangeInstanceRegMap _basisCurvesTopologyIndexRangeRegistry;
687 _primvarRangeRegistry;
691 _extComputationDataRangeRegistry;
695 _geometricShaderRegistry;
699 _renderPassShaderRegistry;
703 _glslProgramRegistry;
709#ifdef PXR_MATERIALX_SUPPORT_ENABLED
715 std::unique_ptr<class HdSt_TextureHandleRegistry> _textureHandleRegistry;
719 _resourceBindingsRegistry;
723 _graphicsPipelineRegistry;
727 _computePipelineRegistry;
729 using _SubResourceRegistryMap =
730 tbb::concurrent_unordered_map<std::string,
731 std::unique_ptr<HdResourceRegistry>>;
732 _SubResourceRegistryMap _subResourceRegistries;
734 HgiBlitCmdsUniquePtr _blitCmds;
735 HgiComputeCmdsUniquePtr _computeCmds;
737 std::unique_ptr<HdStStagingBuffer> _stagingBuffer;
743PXR_NAMESPACE_CLOSE_SCOPE
Basic type for a vector of 2 int components.
This class is used as an interface to a shared instance in HdInstanceRegistry.
HdInstanceRegistry is a dictionary container of HdInstance.
A central registry for resources.
Collection of standard parameters such as wrap modes to sample a texture.
Aggregation strategy base class.
Manages the pool of buffer arrays.
System for re-using HdStRenderBuffers between tasks in different graphs that regenerate data per-fram...
A central registry of all GPU resources.
HDST_API HdResourceRegistry * FindOrCreateSubResourceRegistry(const std::string &identifier, const std::function< std::unique_ptr< HdResourceRegistry >()> &factory)
Finds a sub resource registry for the given identifier if it already exists or creates one by invokin...
HDST_API void SubmitComputeWork(HgiSubmitWaitType wait=HgiSubmitWaitTypeNoWait)
Submits compute work queued in global compute cmds for GPU execution.
HDST_API void AddSources(HdBufferArrayRangeSharedPtr const &range, HdBufferSourceSharedPtrVector &&sources)
Append source data for given range to be committed later.
HDST_API void AddSource(HdBufferArrayRangeSharedPtr const &range, HdBufferSourceSharedPtr const &source)
Append a source data for given range to be committed later.
HDST_API void AddSource(HdBufferSourceSharedPtr const &source)
Append a source data just to be resolved (used for cpu computations).
void SetShaderStorageAggregationStrategy(std::unique_ptr< HdStAggregationStrategy > &&strategy)
Set the aggregation strategy for SSBO (uniform primvars) Takes ownership of the passed in strategy ob...
HDST_API HdInstance< HdSt_MeshTopologySharedPtr > RegisterMeshTopology(HdInstance< HdSt_MeshTopologySharedPtr >::ID id)
These registries implement sharing and deduplication of data based on computed hash identifiers.
HDST_API HdStTextureObjectSharedPtr AllocateTextureObject(const HdStTextureIdentifier &textureId, HdStTextureType textureType)
Allocate texture object.
void SetNonUniformImmutableAggregationStrategy(std::unique_ptr< HdStAggregationStrategy > &&strategy)
Set the aggregation strategy for non uniform immutable parameters (vertex, varying,...
HDST_API HdInstance< HioGlslfxSharedPtr > RegisterGLSLFXFile(HdInstance< HioGlslfxSharedPtr >::ID id)
Register a GLSLFX file.
void _GarbageCollect() override
Hooks for derived registries to perform additional GC when GarbageCollect() is invoked.
HDST_API HdInstance< HdStGLSLProgramSharedPtr > RegisterGLSLProgram(HdInstance< HdStGLSLProgramSharedPtr >::ID id)
Register a GLSL program into the program registry.
HDST_API HdInstance< HdBufferArrayRangeSharedPtr > RegisterExtComputationDataRange(HdInstance< HdBufferArrayRangeSharedPtr >::ID id)
ExtComputation data array range instancing Returns the HdInstance pointing to shared HdBufferArrayRan...
HDST_API HgiBlitCmds * GetGlobalBlitCmds()
Returns the global hgi blit command queue for recording blitting work.
HDST_API void SetMemoryRequestForTextureType(HdStTextureType textureType, size_t memoryRequest)
Sets how much memory a single texture can consume in bytes by texture type.
HDST_API void AddComputation(HdBufferArrayRangeSharedPtr const &range, HdStComputationSharedPtr const &computation, HdStComputeQueue const queue)
Append a gpu computation into queue.
void SetSingleStorageAggregationStrategy(std::unique_ptr< HdStAggregationStrategy > &&strategy)
Set the aggregation strategy for single buffers (for nested instancer).
HDST_API HdStBufferResourceSharedPtr RegisterBufferResource(TfToken const &role, HdTupleType tupleType, HgiBufferUsage bufferUsage, std::string debugName="")
Register a misc buffer resource.
void SetUniformAggregationStrategy(std::unique_ptr< HdStAggregationStrategy > &&strategy)
Set the aggregation strategy for uniform (shader globals) Takes ownership of the passed in strategy o...
HDST_API HdBufferArrayRangeSharedPtr UpdateNonUniformBufferArrayRange(TfToken const &role, HdBufferArrayRangeSharedPtr const &curRange, HdBufferSpecVector const &updatedOrAddedSpecs, HdBufferSpecVector const &removedSpecs, HdBufferArrayUsageHint usageHint)
HDST_API friend std::ostream & operator<<(std::ostream &out, const HdStResourceRegistry &self)
Debug dump.
HDST_API HdInstance< HgiComputePipelineSharedPtr > RegisterComputePipeline(HdInstance< HgiComputePipelineSharedPtr >::ID id)
Register a Hgi compute pipeline into the registry.
HDST_API void GarbageCollectDispatchBuffers()
Remove any entries associated with expired dispatch buffers.
HDST_API HdStStagingBuffer * GetStagingBuffer()
Returns the staging buffer used when committing data to the GPU.
HDST_API HdInstance< HgiResourceBindingsSharedPtr > RegisterResourceBindings(HdInstance< HgiResourceBindingsSharedPtr >::ID id)
Register a Hgi resource bindings into the registry.
HDST_API void InvalidateShaderRegistry() override
Invalidate any shaders registered with this registry.
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 Hgi * GetHgi()
Returns Hgi used to create/destroy GPU resources.
HDST_API HdStPooledRenderBufferUniquePtr AllocateTempRenderBuffer(const SdfPath &graphPath, HdFormat fmt, GfVec2i dims, bool multiSampled, bool depth)
Allocate a RenderBuffer to be used only for this Render Graph's execution.
void _Commit() override
A hook for derived registries to perform additional resource commits.
HDST_API void SubmitBlitWork(HgiSubmitWaitType wait=HgiSubmitWaitTypeNoWait)
Submits blit work queued in global blit cmds for GPU execution.
HDST_API HdInstance< HdBufferArrayRangeSharedPtr > RegisterPrimvarRange(HdInstance< HdBufferArrayRangeSharedPtr >::ID id)
Primvar array range instancing Returns the HdInstance pointing to shared HdBufferArrayRange,...
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 HgiComputeCmds * GetGlobalComputeCmds(HgiComputeDispatch dispatchMethod=HgiComputeDispatchSerial)
Returns the global hgi compute cmd queue for recording compute work.
HDST_API HdStTextureHandleSharedPtr AllocateTextureHandle(const HdStTextureIdentifier &textureId, HdStTextureType textureType, const HdSamplerParameters &samplerParams, size_t memoryRequest, HdStShaderCodePtr const &shaderCode)
Allocate texture handle (encapsulates texture and sampler object, memory request and callback to shad...
HDST_API HdInstance< HdSt_GeometricShaderSharedPtr > RegisterGeometricShader(HdInstance< HdSt_GeometricShaderSharedPtr >::ID id)
Register a geometric shader.
HDST_API HdInstance< HdStRenderPassShaderSharedPtr > RegisterRenderPassShader(HdInstance< HdStRenderPassShaderSharedPtr >::ID id)
Register a render pass shader.
HDST_API void GarbageCollectBufferResources()
Remove any entries associated with expired misc buffers.
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 HdBufferArrayRangeSharedPtr AllocateNonUniformBufferArrayRange(TfToken const &role, HdBufferSpecVector const &bufferSpecs, HdBufferArrayUsageHint usageHint)
HDST_API HdInstance< HgiGraphicsPipelineSharedPtr > RegisterGraphicsPipeline(HdInstance< HgiGraphicsPipelineSharedPtr >::ID id)
Register a Hgi graphics pipeline into the registry.
void SetNonUniformAggregationStrategy(std::unique_ptr< HdStAggregationStrategy > &&strategy)
Set the aggregation strategy for non uniform parameters (vertex, varying, facevarying) Takes ownershi...
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...
Provides a staging buffer for CPU writes of triple-buffered resources.
Class to identify a texture file or a texture within the texture file (e.g., a frame in a movie).
A graphics API independent abstraction of resource copy commands.
A graphics API independent abstraction of compute commands.
Hydra Graphics Interface.
A path value used to locate objects in layers or scenegraphs.
Token for efficient comparison, assignment, and hashing of known strings.
A map with string keys and VtValue values.
HdTupleType represents zero, one, or more values of the same HdType.
Functor to use for hash maps from tokens to other things.