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;
153 HdStTextureType textureType,
161 size_t memoryRequest,
166 HdStShaderCodePtr
const &shaderCode);
180 HdStTextureType textureType);
205 HdStTextureType textureType,
206 size_t memoryRequest);
218 HdBufferSpecVector
const &bufferSpecs,
219 HdBufferArrayUsageHint usageHint);
222 HdBufferArrayRangeSharedPtr AllocateNonUniformImmutableBufferArrayRange(
224 HdBufferSpecVector
const &bufferSpecs,
225 HdBufferArrayUsageHint usageHint);
228 HdBufferArrayRangeSharedPtr AllocateUniformBufferArrayRange(
230 HdBufferSpecVector
const &bufferSpecs,
231 HdBufferArrayUsageHint usageHint);
234 HdBufferArrayRangeSharedPtr AllocateShaderStorageBufferArrayRange(
236 HdBufferSpecVector
const &bufferSpecs,
237 HdBufferArrayUsageHint usageHint);
240 HdBufferArrayRangeSharedPtr AllocateSingleBufferArrayRange(
242 HdBufferSpecVector
const &bufferSpecs,
243 HdBufferArrayUsageHint usageHint);
264 HdBufferArrayRangeSharedPtr
const& curRange,
265 HdBufferSpecVector
const &updatedOrAddedSpecs,
266 HdBufferSpecVector
const& removedSpecs,
267 HdBufferArrayUsageHint usageHint);
270 HdBufferArrayRangeSharedPtr UpdateNonUniformImmutableBufferArrayRange(
272 HdBufferArrayRangeSharedPtr
const& curRange,
273 HdBufferSpecVector
const &updatedOrAddedSpecs,
274 HdBufferSpecVector
const& removedSpecs,
275 HdBufferArrayUsageHint usageHint);
278 HdBufferArrayRangeSharedPtr UpdateUniformBufferArrayRange(
280 HdBufferArrayRangeSharedPtr
const& curRange,
281 HdBufferSpecVector
const &updatedOrAddedSpecs,
282 HdBufferSpecVector
const& removedSpecs,
283 HdBufferArrayUsageHint usageHint);
286 HdBufferArrayRangeSharedPtr UpdateShaderStorageBufferArrayRange(
288 HdBufferArrayRangeSharedPtr
const& curRange,
289 HdBufferSpecVector
const &updatedOrAddedSpecs,
290 HdBufferSpecVector
const& removedSpecs,
291 HdBufferArrayUsageHint usageHint);
300 HdBufferSourceSharedPtrVector &&sources);
304 void AddSource(HdBufferArrayRangeSharedPtr
const &range,
305 HdBufferSourceSharedPtr
const &source);
319 HdStComputationSharedPtr
const &computation,
320 HdStComputeQueue
const queue);
330 TfToken const &role,
int count,
int commandNumUints);
341 HgiBufferUsage bufferUsage,
342 std::string debugName =
"");
374 RegisterBasisCurvesTopology(
375 HdInstance<HdSt_BasisCurvesTopologySharedPtr>::ID
id);
379 RegisterVertexAdjacencyBuilder(
380 HdInstance<HdSt_VertexAdjacencyBuilderSharedPtr>::ID
id);
389 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
393 RegisterBasisCurvesIndexRange(
394 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
398 RegisterImplicitPrimsIndexRange(
399 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id,
TfToken const &name);
408 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
417 HdInstance<HdBufferArrayRangeSharedPtr>::ID
id);
439#ifdef PXR_MATERIALX_SUPPORT_ENABLED
443 RegisterMaterialXShader(HdInstance<MaterialX::ShaderPtr>::ID
id);
474 const std::string& identifier,
475 const std::function<std::unique_ptr<HdResourceRegistry>()>& factory);
492 HgiComputeDispatch dispatchMethod = HgiComputeDispatchSerial);
523 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
524 _nonUniformAggregationStrategy = std::move(strategy);
531 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
532 _nonUniformImmutableAggregationStrategy = std::move(strategy);
538 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
539 _uniformUboAggregationStrategy = std::move(strategy);
545 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
546 _uniformSsboAggregationStrategy = std::move(strategy);
552 std::unique_ptr<HdStAggregationStrategy> &&strategy) {
553 _singleAggregationStrategy = std::move(strategy);
567 void _CommitTextures();
569 HdBufferArrayRangeSharedPtr _AllocateBufferArrayRange(
573 HdBufferSpecVector
const &bufferSpecs,
574 HdBufferArrayUsageHint usageHint);
577 HdBufferArrayRangeSharedPtr _UpdateBufferArrayRange(
581 HdBufferArrayRangeSharedPtr
const& curRange,
582 HdBufferSpecVector
const &updatedOrAddedSpecs,
583 HdBufferSpecVector
const& removedSpecs,
584 HdBufferArrayUsageHint usageHint);
588 void _TallyResourceAllocation(
VtDictionary *result)
const;
592 struct _PendingSource {
593 _PendingSource(HdBufferArrayRangeSharedPtr
const &range)
599 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
600 HdBufferSourceSharedPtr
const &source)
606 _PendingSource(HdBufferArrayRangeSharedPtr
const &range,
607 HdBufferSourceSharedPtrVector && sources)
609 , sources(
std::move(sources))
613 HdBufferArrayRangeSharedPtr range;
614 HdBufferSourceSharedPtrVector sources;
619 using _PendingSourceList =
620 tbb::concurrent_vector<_PendingSource>;
622 _PendingSourceList _pendingSources;
624 using _PendingResolveList =
625 tbb::concurrent_vector<std::pair<HdBufferSourceSharedPtr,bool>>;
627 _PendingResolveList _pendingSourcesToResolve;
631 std::atomic_size_t _pendingStagingSize;
633 struct _PendingComputation{
634 _PendingComputation(HdBufferArrayRangeSharedPtr
const &range,
635 HdStComputationSharedPtr
const &computation)
636 : range(range), computation(computation) { }
637 HdBufferArrayRangeSharedPtr range;
638 HdStComputationSharedPtr computation;
644 typedef tbb::concurrent_vector<_PendingComputation> _PendingComputationList;
645 _PendingComputationList _pendingComputations[HdStComputeQueueCount];
655 std::unique_ptr<HdStAggregationStrategy> _nonUniformAggregationStrategy;
656 std::unique_ptr<HdStAggregationStrategy>
657 _nonUniformImmutableAggregationStrategy;
658 std::unique_ptr<HdStAggregationStrategy> _uniformUboAggregationStrategy;
659 std::unique_ptr<HdStAggregationStrategy> _uniformSsboAggregationStrategy;
660 std::unique_ptr<HdStAggregationStrategy> _singleAggregationStrategy;
662 typedef std::vector<HdStDispatchBufferSharedPtr>
663 _DispatchBufferRegistry;
664 _DispatchBufferRegistry _dispatchBufferRegistry;
666 typedef std::vector<HdStBufferResourceSharedPtr>
667 _BufferResourceRegistry;
668 _BufferResourceRegistry _bufferResourceRegistry;
672 _meshTopologyRegistry;
676 _basisCurvesTopologyRegistry;
680 _vertexAdjacencyBuilderRegistry;
684 _TopologyIndexRangeInstanceRegistry;
685 typedef tbb::concurrent_unordered_map<
TfToken,
686 _TopologyIndexRangeInstanceRegistry,
688 _TopologyIndexRangeInstanceRegMap;
690 _TopologyIndexRangeInstanceRegMap _meshTopologyIndexRangeRegistry;
691 _TopologyIndexRangeInstanceRegMap _basisCurvesTopologyIndexRangeRegistry;
696 _TopologyIndexRangeInstanceRegMap _implicitPrimsTopologyIndexRangeRegistry;
700 _primvarRangeRegistry;
704 _extComputationDataRangeRegistry;
708 _geometricShaderRegistry;
712 _renderPassShaderRegistry;
716 _glslProgramRegistry;
722#ifdef PXR_MATERIALX_SUPPORT_ENABLED
728 std::unique_ptr<class HdSt_TextureHandleRegistry> _textureHandleRegistry;
732 _resourceBindingsRegistry;
736 _graphicsPipelineRegistry;
740 _computePipelineRegistry;
742 using _SubResourceRegistryMap =
743 tbb::concurrent_unordered_map<std::string,
744 std::unique_ptr<HdResourceRegistry>>;
745 _SubResourceRegistryMap _subResourceRegistries;
747 HgiBlitCmdsUniquePtr _blitCmds;
748 HgiComputeCmdsUniquePtr _computeCmds;
750 std::unique_ptr<HdStStagingBuffer> _stagingBuffer;
756PXR_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 VtDictionary GetDetailedResourceAllocation() const override
May return a more detailed report than GetResourceAllocation, at the expense of runtime.
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.