Loading...
Searching...
No Matches
textureObjectRegistry.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_OBJECT_REGISTRY_H
25#define PXR_IMAGING_HD_ST_TEXTURE_OBJECT_REGISTRY_H
26
27#include "pxr/pxr.h"
28#include "pxr/imaging/hdSt/api.h"
29#include "pxr/imaging/hd/enums.h"
30#include "pxr/imaging/hd/instanceRegistry.h"
31
32#include <tbb/concurrent_vector.h>
33#include <vector>
34#include <atomic>
35
36PXR_NAMESPACE_OPEN_SCOPE
37
38using HdStTextureObjectSharedPtr =
39 std::shared_ptr<class HdStTextureObject>;
40using HdStTextureObjectPtr =
41 std::weak_ptr<class HdStTextureObject>;
42using HdStTextureObjectPtrVector =
43 std::vector<HdStTextureObjectPtr>;
46
47
52class HdSt_TextureObjectRegistry final
53{
54public:
55 explicit HdSt_TextureObjectRegistry(HdStResourceRegistry * registry);
56 ~HdSt_TextureObjectRegistry();
57
63 HDST_API
64 HdStTextureObjectSharedPtr AllocateTextureObject(
65 const HdStTextureIdentifier &textureId,
66 HdTextureType textureType);
67
71 HDST_API
72 std::set<HdStTextureObjectSharedPtr> Commit();
73
76 HDST_API
77 void GarbageCollect();
78
82 HDST_API
83 void MarkTextureFilePathDirty(const TfToken &filePath);
84
88 HDST_API
89 void MarkTextureObjectDirty(
90 HdStTextureObjectPtr const &textureObject);
91
94 HDST_API
95 HdStResourceRegistry * GetResourceRegistry() const {
96 return _resourceRegistry;
97 }
98
101 int64_t GetTotalTextureMemory() const {
102 return _totalTextureMemory;
103 }
104
108 HDST_API
109 void AdjustTotalTextureMemory(int64_t memDiff);
110
112 size_t GetNumberOfTextureObjects() const {
113 return _textureObjectRegistry.size();
114 }
115
116private:
117 HdStTextureObjectSharedPtr _MakeTextureObject(
118 const HdStTextureIdentifier &textureId,
119 HdTextureType textureType);
120
121 std::atomic<int64_t> _totalTextureMemory;
122
123 // Registry for texture and sampler objects.
125 _textureObjectRegistry;
126
127 // Map file paths to texture objects for quick invalidation
128 // by file path.
129 std::unordered_map<TfToken, HdStTextureObjectPtrVector,
131 _filePathToTextureObjects;
132
133 // File paths for which GPU resources need to be (re-)loaded
134 tbb::concurrent_vector<TfToken> _dirtyFilePaths;
135
136 // Texture for which GPU resources need to be (re-)loaded
137 tbb::concurrent_vector<HdStTextureObjectPtr> _dirtyTextures;
138
139 HdStResourceRegistry *_resourceRegistry;
140};
141
142PXR_NAMESPACE_CLOSE_SCOPE
143
144#endif
HdInstanceRegistry is a dictionary container of HdInstance.
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).
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:88
Functor to use for hash maps from tokens to other things.
Definition: token.h:166