Loading...
Searching...
No Matches
textureHandleRegistry.h
1//
2// Copyright 2020 Pixar
3//
4// Licensed under the Apache License, Version 2.0 (the "Apache License")
5// with the following modification; you may not use this file except in
6// compliance with the Apache License and the following modification to it:
7// Section 6. Trademarks. is deleted and replaced with:
8//
9// 6. Trademarks. This License does not grant permission to use the trade
10// names, trademarks, service marks, or product names of the Licensor
11// and its affiliates, except as required to comply with Section 4(c) of
12// the License and to reproduce the content of the NOTICE file.
13//
14// You may obtain a copy of the Apache License at
15//
16// http://www.apache.org/licenses/LICENSE-2.0
17//
18// Unless required by applicable law or agreed to in writing, software
19// distributed under the Apache License with the above modification is
20// distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21// KIND, either express or implied. See the Apache License for the specific
22// language governing permissions and limitations under the Apache License.
23//
24#ifndef PXR_IMAGING_HD_ST_TEXTURE_HANDLE_REGISTRY_H
25#define PXR_IMAGING_HD_ST_TEXTURE_HANDLE_REGISTRY_H
26
27#include "pxr/pxr.h"
28#include "pxr/imaging/hdSt/api.h"
29
30#include "pxr/imaging/hdSt/textureObject.h"
31
32#include "pxr/imaging/hd/enums.h"
33
34#include <tbb/concurrent_vector.h>
35
36#include <set>
37#include <memory>
38
39PXR_NAMESPACE_OPEN_SCOPE
40
44class HdSt_SamplerObjectRegistry;
45
46using HdStTextureHandlePtr =
47 std::weak_ptr<class HdStTextureHandle>;
48using HdStTextureHandleSharedPtr =
49 std::shared_ptr<class HdStTextureHandle>;
50using HdStTextureObjectPtr =
51 std::weak_ptr<class HdStTextureObject>;
52using HdStTextureObjectSharedPtr =
53 std::shared_ptr<class HdStTextureObject>;
54using HdStSamplerObjectSharedPtr =
55 std::shared_ptr<class HdStSamplerObject>;
56using HdStShaderCodePtr =
57 std::weak_ptr<class HdStShaderCode>;
58using HdStShaderCodeSharedPtr =
59 std::shared_ptr<class HdStShaderCode>;
60
72class HdSt_TextureHandleRegistry final
73{
74public:
75 HDST_API
76 explicit HdSt_TextureHandleRegistry(HdStResourceRegistry * registry);
77
78 HDST_API
79 ~HdSt_TextureHandleRegistry();
80
85 HDST_API
86 HdStTextureHandleSharedPtr AllocateTextureHandle(
87 const HdStTextureIdentifier &textureId,
88 HdTextureType textureType,
89 const HdSamplerParameters &samplerParams,
91 size_t memoryRequest,
92 HdStShaderCodePtr const &shaderCode);
93
101 HDST_API
102 void MarkDirty(HdStTextureObjectPtr const &texture);
103
109 HDST_API
110 void MarkDirty(HdStShaderCodePtr const &shader);
111
115 HDST_API
116 void MarkSamplerGarbageCollectionNeeded();
117
120 HdSt_TextureObjectRegistry * GetTextureObjectRegistry() const {
121 return _textureObjectRegistry.get();
122 }
123
126 HdSt_SamplerObjectRegistry * GetSamplerObjectRegistry() const {
127 return _samplerObjectRegistry.get();
128 }
129
136 HDST_API
137 std::set<HdStShaderCodeSharedPtr> Commit();
138
146 HDST_API
147 void SetMemoryRequestForTextureType(HdTextureType textureType, size_t memoryRequest);
148
149 HDST_API
150 size_t GetNumberOfTextureHandles() const;
151
152private:
153 void _ComputeMemoryRequest(HdStTextureObjectSharedPtr const &);
154 void _ComputeMemoryRequests(const std::set<HdStTextureObjectSharedPtr> &);
155 void _ComputeAllMemoryRequests();
156
157 bool _GarbageCollectHandlesAndComputeTargetMemory();
158 void _GarbageCollectAndComputeTargetMemory();
159 std::set<HdStShaderCodeSharedPtr> _Commit();
160
161 class _TextureToHandlesMap;
162
163 // Maps texture type to memory a single texture of that type can consume
164 // (in bytes).
165 // Will be taken into account when computing the maximum of all the
166 // memory requests of the texture handles.
167 std::map<HdTextureType, size_t> _textureTypeToMemoryRequest;
168 // Has _textureTypeToMemoryRequest changed since the last commit.
169 bool _textureTypeToMemoryRequestChanged;
170
171 // Handles that are new or for which the underlying texture has
172 // changed: samplers might need to be (re-)allocated and the
173 // corresponding shader code might need to update the shader bar.
174 tbb::concurrent_vector<HdStTextureHandlePtr> _dirtyHandles;
175
176 // Textures whose set of associated handles and target memory
177 // might have changed.
178 tbb::concurrent_vector<HdStTextureObjectPtr> _dirtyTextures;
179
180 // Shaders that dropped a texture handle also need to be notified
181 // (for example because they re-allocated the shader bar after dropping
182 // the texture).
183 tbb::concurrent_vector<HdStShaderCodePtr> _dirtyShaders;
184
185 std::unique_ptr<class HdSt_SamplerObjectRegistry> _samplerObjectRegistry;
186 std::unique_ptr<class HdSt_TextureObjectRegistry> _textureObjectRegistry;
187 std::unique_ptr<_TextureToHandlesMap> _textureToHandlesMap;
188
189};
190
191PXR_NAMESPACE_CLOSE_SCOPE
192
193#endif
Collection of standard parameters such as wrap modes to sample a texture.
Definition: types.h:127
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).