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"
15
16#include <tbb/concurrent_vector.h>
17#include <vector>
18#include <atomic>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
22using HdStTextureObjectSharedPtr =
23 std::shared_ptr<class HdStTextureObject>;
24using HdStTextureObjectPtr =
25 std::weak_ptr<class HdStTextureObject>;
26using HdStTextureObjectPtrVector =
27 std::vector<HdStTextureObjectPtr>;
30
31
36class HdSt_TextureObjectRegistry final
37{
38public:
39 HDST_API
40 explicit HdSt_TextureObjectRegistry(HdStResourceRegistry * registry);
41 HDST_API
42 ~HdSt_TextureObjectRegistry();
43
49 HDST_API
50 HdStTextureObjectSharedPtr AllocateTextureObject(
51 const HdStTextureIdentifier &textureId,
52 HdStTextureType textureType);
53
57 HDST_API
58 std::set<HdStTextureObjectSharedPtr> Commit();
59
62 HDST_API
63 void GarbageCollect();
64
68 HDST_API
69 void MarkTextureFilePathDirty(const TfToken &filePath);
70
74 HDST_API
75 void MarkTextureObjectDirty(
76 HdStTextureObjectPtr const &textureObject);
77
80 HDST_API
81 HdStResourceRegistry * GetResourceRegistry() const {
82 return _resourceRegistry;
83 }
84
87 int64_t GetTotalTextureMemory() const {
88 return _totalTextureMemory;
89 }
90
94 HDST_API
95 void AdjustTotalTextureMemory(int64_t memDiff);
96
98 size_t GetNumberOfTextureObjects() const {
99 return _textureObjectRegistry.size();
100 }
101
105 HDST_API
106 std::vector<VtDictionary> GetAllocInfo() const;
107
108private:
109 HdStTextureObjectSharedPtr _MakeTextureObject(
110 const HdStTextureIdentifier &textureId,
111 HdStTextureType textureType);
112
113 std::atomic<int64_t> _totalTextureMemory;
114
115 // Registry for texture and sampler objects.
117 _textureObjectRegistry;
118
119 // Map file paths to texture objects for quick invalidation
120 // by file path.
121 std::unordered_map<TfToken, HdStTextureObjectPtrVector,
123 _filePathToTextureObjects;
124
125 // File paths for which GPU resources need to be (re-)loaded
126 tbb::concurrent_vector<TfToken> _dirtyFilePaths;
127
128 // Texture for which GPU resources need to be (re-)loaded
129 tbb::concurrent_vector<HdStTextureObjectPtr> _dirtyTextures;
130
131 HdStResourceRegistry *_resourceRegistry;
132};
133
134PXR_NAMESPACE_CLOSE_SCOPE
135
136#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:81
Functor to use for hash maps from tokens to other things.
Definition token.h:176