Loading...
Searching...
No Matches
textureObjectRegistry.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_OBJECT_REGISTRY_H
8#define PXR_IMAGING_HD_ST_TEXTURE_OBJECT_REGISTRY_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hdSt/api.h"
12#include "pxr/imaging/hdSt/enums.h"
13#include "pxr/imaging/hd/instanceRegistry.h"
14
15#include <tbb/concurrent_vector.h>
16#include <vector>
17#include <atomic>
18
19PXR_NAMESPACE_OPEN_SCOPE
20
21using HdStTextureObjectSharedPtr =
22 std::shared_ptr<class HdStTextureObject>;
23using HdStTextureObjectPtr =
24 std::weak_ptr<class HdStTextureObject>;
25using HdStTextureObjectPtrVector =
26 std::vector<HdStTextureObjectPtr>;
29
30
35class HdSt_TextureObjectRegistry final
36{
37public:
38 explicit HdSt_TextureObjectRegistry(HdStResourceRegistry * registry);
39 ~HdSt_TextureObjectRegistry();
40
46 HDST_API
47 HdStTextureObjectSharedPtr AllocateTextureObject(
48 const HdStTextureIdentifier &textureId,
49 HdStTextureType textureType);
50
54 HDST_API
55 std::set<HdStTextureObjectSharedPtr> Commit();
56
59 HDST_API
60 void GarbageCollect();
61
65 HDST_API
66 void MarkTextureFilePathDirty(const TfToken &filePath);
67
71 HDST_API
72 void MarkTextureObjectDirty(
73 HdStTextureObjectPtr const &textureObject);
74
77 HDST_API
78 HdStResourceRegistry * GetResourceRegistry() const {
79 return _resourceRegistry;
80 }
81
84 int64_t GetTotalTextureMemory() const {
85 return _totalTextureMemory;
86 }
87
91 HDST_API
92 void AdjustTotalTextureMemory(int64_t memDiff);
93
95 size_t GetNumberOfTextureObjects() const {
96 return _textureObjectRegistry.size();
97 }
98
99private:
100 HdStTextureObjectSharedPtr _MakeTextureObject(
101 const HdStTextureIdentifier &textureId,
102 HdStTextureType textureType);
103
104 std::atomic<int64_t> _totalTextureMemory;
105
106 // Registry for texture and sampler objects.
108 _textureObjectRegistry;
109
110 // Map file paths to texture objects for quick invalidation
111 // by file path.
112 std::unordered_map<TfToken, HdStTextureObjectPtrVector,
114 _filePathToTextureObjects;
115
116 // File paths for which GPU resources need to be (re-)loaded
117 tbb::concurrent_vector<TfToken> _dirtyFilePaths;
118
119 // Texture for which GPU resources need to be (re-)loaded
120 tbb::concurrent_vector<HdStTextureObjectPtr> _dirtyTextures;
121
122 HdStResourceRegistry *_resourceRegistry;
123};
124
125PXR_NAMESPACE_CLOSE_SCOPE
126
127#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:71
Functor to use for hash maps from tokens to other things.
Definition: token.h:149