VR-Forces 5.0.3 Developer's Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
DtGlTextureResidencyManager.h
Go to the documentation of this file.
1 /******************************************************************************
2 ** Copyright (c) 2023 MAK Technologies, Inc.
3 ** All rights reserved.
4 ******************************************************************************/
5 
9 
10 #pragma once
12 
13 #include <map>
14 #include <unordered_map>
15 
16 namespace makVrv
17 {
18  class DtGlTextureResidentMemoryTracker;
19 
22  {
23  public:
24  typedef std::map<unsigned int, int> TexIDToCount;
25  typedef std::map<void*, TexIDToCount> ContextToTexID;
26 
27  public:
30 
32  virtual ~DtGlTextureResidencyManager();
33 
36 
38  DtGlTextureResidencyManager& operator=(const DtGlTextureResidencyManager&) = delete;
39 
40  public:
42  virtual void makeResidentIfNecessary(void* gContext, GLuint textureID);
43 
47  virtual bool makeNonResidentIfNecessary(void* gContext, GLuint textureID, bool canDelete);
48 
50  virtual void deletingTexture(GLuint textureID);
51 
54  virtual bool ensureTextureIsResident(GLuint textureID, GLuint64 textureAddress);
55 
57  virtual GLuint64 gpuTextureAddress(GLuint textureID) const;
58 
60  virtual bool isTexture(GLuint textureID) const;
61 
65  virtual DtGlTextureResidentMemoryTracker* tracker() const;
66 
68  virtual void setAllowNvidiaBindlessFix(bool enable);
69 
70  protected:
72  virtual DtGlTextureResidentMemoryTracker* getOrCreateTracker(void* graphicsContext);
73  protected:
74  // Count of textures we've made resident *across all contexts*
75  // So 1 texture in 3 contexts will have a count of 3
76  // When this array goes to 0 then we call glDeleteTextures if the
77  // texture is also marked
79 
80  // So for pageable terrains, the textures can be shared between tiles
81  // However, when you releaseGLObjects and say glMakeTextureHandleNonResidentARB,
82  // other tiles which share the texture will not draw or have other problems
83  // since we removed the data from underneath them
84  // This is a basic (non-thread safe!) reference counting of textures by
85  // context ID
87 
88  std::unordered_map<void*, DtGlTextureResidentMemoryTracker*> myContextsToTrackers;
89 
90  // This is a work-around (HACK) for NVIDIA driver bug:
91  // https://jira.mak.com/browse/VRV-4620
92  // The work-around is to only ever make bindless textures resident and non-resident, once.
93  // In other words, don't try to make them resident and non-resident for each context.
94 
95  // I'm guessing because the texture is made resident in 1 context, then any other context
96  // can use that memory by getting the texture address. The work-around will fail if
97  // the driver starts doing proper ref-counting or something per context.
98 
99  // Note that NVIDIA does not seem to be following the bindless spec:
100  // This is from the spec (see issues section)
101  // "However, texture and image handle residency is managed per-context. If
102  // a texture or image handle is used in multiple contexts in a share group,
103  // the handle must be made resident in all such contexts."
104  std::unordered_map<GLuint, bool> myTextureIsResidentMap;
105 
106  // Also adding a way to disable the above work-around (HACK) for NVIDIA driver bug.
107  // The reason is that if NVIDIA fixes the driver, then vrv will most likely
108  // crash with the work-around. This will give a customer a way to disable it
109  // without us needed to provide a patch or update.
111  };
112 }
std::map< unsigned int, int > TexIDToCount
Definition: DtGlTextureResidencyManager.h:24
Dll export defines.
helper class to handle texture residency
Definition: DtGlTextureResidencyManager.h:21
std::map< void *, TexIDToCount > ContextToTexID
Definition: DtGlTextureResidencyManager.h:25
unsigned int GLuint
Definition: DtGlTextureBufferObject.h:17
DtGlTextureResidentMemoryTracker class is used to track resident memory of the textures in the system...
Definition: DtGlTextureResidentMemoryTracker.h:73
ContextToTexID myTextureCountByContext
Definition: DtGlTextureResidencyManager.h:78
std::unordered_map< GLuint, bool > myTextureIsResidentMap
Definition: DtGlTextureResidencyManager.h:104
#define DT_DLL_VRVGRAPHICSUTILS
Definition: vrvGraphicsUtils.h:18
bool myAllowNvidiaBindlessFix
Definition: DtGlTextureResidencyManager.h:110
TexIDToCount myTextureIdToRefCountAcrossContexts
Definition: DtGlTextureResidencyManager.h:86
std::unordered_map< void *, DtGlTextureResidentMemoryTracker * > myContextsToTrackers
Definition: DtGlTextureResidencyManager.h:88

Document ID: Generated on Thu Jun 1 17:58:13 EDT 2023 from SVN revision 255404
Copyright © 2005-2021 MAK Technologies. All Rights Reserved (www.mak.com)