Loading...
Searching...
No Matches
textureHandleRegistry.h
1//
2// Copyright 2020 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_ST_TEXTURE_HANDLE_REGISTRY_H
8#define PXR_IMAGING_HD_ST_TEXTURE_HANDLE_REGISTRY_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdSt/api.h"
12
13#include "pxr/imaging/hdSt/textureObject.h"
14
15#include "pxr/imaging/hd/enums.h"
16
17#include <tbb/concurrent_vector.h>
18
19#include <set>
20#include <memory>
21
22PXR_NAMESPACE_OPEN_SCOPE
23
27class HdSt_SamplerObjectRegistry;
28
29using HdStTextureHandlePtr =
30 std::weak_ptr<class HdStTextureHandle>;
31using HdStTextureHandleSharedPtr =
32 std::shared_ptr<class HdStTextureHandle>;
33using HdStTextureObjectPtr =
34 std::weak_ptr<class HdStTextureObject>;
35using HdStTextureObjectSharedPtr =
36 std::shared_ptr<class HdStTextureObject>;
37using HdStSamplerObjectSharedPtr =
38 std::shared_ptr<class HdStSamplerObject>;
39using HdStShaderCodePtr =
40 std::weak_ptr<class HdStShaderCode>;
41using HdStShaderCodeSharedPtr =
42 std::shared_ptr<class HdStShaderCode>;
43
55class HdSt_TextureHandleRegistry final
56{
57public:
58 HDST_API
59 explicit HdSt_TextureHandleRegistry(HdStResourceRegistry * registry);
60
61 HDST_API
62 ~HdSt_TextureHandleRegistry();
63
68 HDST_API
69 HdStTextureHandleSharedPtr AllocateTextureHandle(
70 const HdStTextureIdentifier &textureId,
71 HdStTextureType textureType,
72 const HdSamplerParameters &samplerParams,
74 size_t memoryRequest,
75 HdStShaderCodePtr const &shaderCode);
76
84 HDST_API
85 void MarkDirty(HdStTextureObjectPtr const &texture);
86
92 HDST_API
93 void MarkDirty(HdStShaderCodePtr const &shader);
94
98 HDST_API
99 void MarkSamplerGarbageCollectionNeeded();
100
103 HdSt_TextureObjectRegistry * GetTextureObjectRegistry() const {
104 return _textureObjectRegistry.get();
105 }
106
109 HdSt_SamplerObjectRegistry * GetSamplerObjectRegistry() const {
110 return _samplerObjectRegistry.get();
111 }
112
119 HDST_API
120 std::set<HdStShaderCodeSharedPtr> Commit();
121
129 HDST_API
130 void SetMemoryRequestForTextureType(HdStTextureType textureType, size_t memoryRequest);
131
132 HDST_API
133 size_t GetNumberOfTextureHandles() const;
134
135private:
136 void _ComputeMemoryRequest(HdStTextureObjectSharedPtr const &);
137 void _ComputeMemoryRequests(const std::set<HdStTextureObjectSharedPtr> &);
138 void _ComputeAllMemoryRequests();
139
140 bool _GarbageCollectHandlesAndComputeTargetMemory();
141 void _GarbageCollectAndComputeTargetMemory();
142 std::set<HdStShaderCodeSharedPtr> _Commit();
143
144 class _TextureToHandlesMap;
145
146 // Maps texture type to memory a single texture of that type can consume
147 // (in bytes).
148 // Will be taken into account when computing the maximum of all the
149 // memory requests of the texture handles.
150 std::map<HdStTextureType, size_t> _textureTypeToMemoryRequest;
151 // Has _textureTypeToMemoryRequest changed since the last commit.
152 bool _textureTypeToMemoryRequestChanged;
153
154 // Handles that are new or for which the underlying texture has
155 // changed: samplers might need to be (re-)allocated and the
156 // corresponding shader code might need to update the shader bar.
157 tbb::concurrent_vector<HdStTextureHandlePtr> _dirtyHandles;
158
159 // Textures whose set of associated handles and target memory
160 // might have changed.
161 tbb::concurrent_vector<HdStTextureObjectPtr> _dirtyTextures;
162
163 // Shaders that dropped a texture handle also need to be notified
164 // (for example because they re-allocated the shader bar after dropping
165 // the texture).
166 tbb::concurrent_vector<HdStShaderCodePtr> _dirtyShaders;
167
168 std::unique_ptr<class HdSt_SamplerObjectRegistry> _samplerObjectRegistry;
169 std::unique_ptr<class HdSt_TextureObjectRegistry> _textureObjectRegistry;
170 std::unique_ptr<_TextureToHandlesMap> _textureToHandlesMap;
171
172};
173
174PXR_NAMESPACE_CLOSE_SCOPE
175
176#endif
Collection of standard parameters such as wrap modes to sample a texture.
Definition: types.h:110
A central registry of all GPU resources.
Class to identify a texture file or a texture within the texture file (e.g., a frame in a movie).