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
122 void GarbageCollect();
123
131 HDST_API
132 void SetMemoryRequestForTextureType(HdStTextureType textureType, size_t memoryRequest);
133
134 HDST_API
135 size_t GetNumberOfTextureHandles() const;
136
137private:
138 void _ComputeMemoryRequest(HdStTextureObjectSharedPtr const &);
139 void _ComputeMemoryRequests(const std::set<HdStTextureObjectSharedPtr> &);
140 void _ComputeAllMemoryRequests();
141
142 bool _GarbageCollectHandlesAndComputeTargetMemory();
143 std::set<HdStShaderCodeSharedPtr> _Commit();
144
145 class _TextureToHandlesMap;
146
147 // Maps texture type to memory a single texture of that type can consume
148 // (in bytes).
149 // Will be taken into account when computing the maximum of all the
150 // memory requests of the texture handles.
151 std::map<HdStTextureType, size_t> _textureTypeToMemoryRequest;
152 // Has _textureTypeToMemoryRequest changed since the last commit.
153 bool _textureTypeToMemoryRequestChanged;
154
155 // Handles that are new or for which the underlying texture has
156 // changed: samplers might need to be (re-)allocated and the
157 // corresponding shader code might need to update the shader bar.
158 tbb::concurrent_vector<HdStTextureHandlePtr> _dirtyHandles;
159
160 // Textures whose set of associated handles and target memory
161 // might have changed.
162 tbb::concurrent_vector<HdStTextureObjectPtr> _dirtyTextures;
163
164 // Shaders that dropped a texture handle also need to be notified
165 // (for example because they re-allocated the shader bar after dropping
166 // the texture).
167 tbb::concurrent_vector<HdStShaderCodePtr> _dirtyShaders;
168
169 std::unique_ptr<class HdSt_SamplerObjectRegistry> _samplerObjectRegistry;
170 std::unique_ptr<class HdSt_TextureObjectRegistry> _textureObjectRegistry;
171 std::unique_ptr<_TextureToHandlesMap> _textureToHandlesMap;
172
173};
174
175PXR_NAMESPACE_CLOSE_SCOPE
176
177#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).