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 HDST_API
39 explicit HdSt_TextureObjectRegistry(HdStResourceRegistry * registry);
40 HDST_API
41 ~HdSt_TextureObjectRegistry();
42
48 HDST_API
49 HdStTextureObjectSharedPtr AllocateTextureObject(
50 const HdStTextureIdentifier &textureId,
51 HdStTextureType textureType);
52
56 HDST_API
57 std::set<HdStTextureObjectSharedPtr> Commit();
58
61 HDST_API
62 void GarbageCollect();
63
67 HDST_API
68 void MarkTextureFilePathDirty(const TfToken &filePath);
69
73 HDST_API
74 void MarkTextureObjectDirty(
75 HdStTextureObjectPtr const &textureObject);
76
79 HDST_API
80 HdStResourceRegistry * GetResourceRegistry() const {
81 return _resourceRegistry;
82 }
83
86 int64_t GetTotalTextureMemory() const {
87 return _totalTextureMemory;
88 }
89
93 HDST_API
94 void AdjustTotalTextureMemory(int64_t memDiff);
95
97 size_t GetNumberOfTextureObjects() const {
98 return _textureObjectRegistry.size();
99 }
100
101private:
102 HdStTextureObjectSharedPtr _MakeTextureObject(
103 const HdStTextureIdentifier &textureId,
104 HdStTextureType textureType);
105
106 std::atomic<int64_t> _totalTextureMemory;
107
108 // Registry for texture and sampler objects.
110 _textureObjectRegistry;
111
112 // Map file paths to texture objects for quick invalidation
113 // by file path.
114 std::unordered_map<TfToken, HdStTextureObjectPtrVector,
116 _filePathToTextureObjects;
117
118 // File paths for which GPU resources need to be (re-)loaded
119 tbb::concurrent_vector<TfToken> _dirtyFilePaths;
120
121 // Texture for which GPU resources need to be (re-)loaded
122 tbb::concurrent_vector<HdStTextureObjectPtr> _dirtyTextures;
123
124 HdStResourceRegistry *_resourceRegistry;
125};
126
127PXR_NAMESPACE_CLOSE_SCOPE
128
129#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