Invert tracking of texture views/texture buffers on GL

* Instead of the buffer/source texture tracking all the views of itself and
  checking to see if it should be force-included because any of its views were
  included, we instead track the underlying resource for each view or buffer
  texture.
* This means if e.g. a view or buffer texture gets dirtied, we can propagate
  that through to the underlying data store which needs to get dirtied so that
  we can fetch its initial states.
This commit is contained in:
baldurk
2019-11-20 22:58:08 +00:00
parent e353fd1a00
commit 7440497029
5 changed files with 32 additions and 53 deletions
-4
View File
@@ -2278,10 +2278,6 @@ bool WrappedOpenGL::EndFrameCapture(void *dev, void *wnd)
SERIALISE_ELEMENT(fbo);
}
RDCDEBUG("Forcing inclusion of views");
GetResourceManager()->Force_ReferenceViews();
RDCDEBUG("Inserting Resource Serialisers");
GetResourceManager()->InsertReferencedChunks(ser);
-33
View File
@@ -1030,39 +1030,6 @@ void GLResourceManager::PrepareTextureInitialContents(ResourceId liveid, Resourc
SetInitialContents(origid, initContents);
}
void GLResourceManager::Force_ReferenceViews()
{
// don't need to force anything if we're already including all resources
if(RenderDoc::Inst().GetCaptureOptions().refAllResources)
return;
for(auto recordit = m_ResourceRecords.begin(); recordit != m_ResourceRecords.end(); ++recordit)
{
GLResourceRecord *record = recordit->second;
// if this resource has some viewers, check to see if they were referenced by the frame but we
// weren't, and force our own reference as well so that our initial states are included
if(record && !record->viewTextures.empty())
{
// if this data resource was referenced already, just skip
if(m_FrameReferencedResources.find(record->GetResourceID()) != m_FrameReferencedResources.end())
continue;
// see if any of our viewers were referenced
for(auto it = record->viewTextures.begin(); it != record->viewTextures.end(); ++it)
{
// if so, return true to force our inclusion, for the benefit of the view
if(m_FrameReferencedResources.find(*it) != m_FrameReferencedResources.end())
{
RDCDEBUG("Forcing inclusion of %llu for %llu", record->GetResourceID(), *it);
MarkResourceFrameReferenced(record->GetResourceID(), eFrameRef_ReadBeforeWrite);
break;
}
}
}
}
}
uint64_t GLResourceManager::GetSize_InitialState(ResourceId resid, const GLInitialContents &initial)
{
if(initial.type == eResBuffer)
+21 -5
View File
@@ -204,17 +204,35 @@ public:
using ResourceManager::MarkResourceFrameReferenced;
void MarkResourceFrameReferenced(ResourceId id, FrameRefType refType)
{
GLResourceRecord *record = GetResourceRecord(id);
if(record && record->viewSource != ResourceId())
ResourceManager::MarkResourceFrameReferenced(record->viewSource, refType);
ResourceManager::MarkResourceFrameReferenced(id, refType);
}
void MarkResourceFrameReferenced(GLResource res, FrameRefType refType)
{
// we allow VAO 0 as a special case
if(res.name == 0 && res.Namespace != eResVertexArray)
return;
ResourceManager::MarkResourceFrameReferenced(GetID(res), refType);
GLResourceManager::MarkResourceFrameReferenced(GetID(res), refType);
}
using ResourceManager::MarkDirtyResource;
void MarkDirtyResource(ResourceId id)
{
GLResourceRecord *record = GetResourceRecord(id);
if(record && record->viewSource != ResourceId())
ResourceManager::MarkDirtyResource(record->viewSource);
void MarkDirtyResource(GLResource res) { return ResourceManager::MarkDirtyResource(GetID(res)); }
return ResourceManager::MarkDirtyResource(id);
}
void MarkDirtyResource(GLResource res)
{
return GLResourceManager::MarkDirtyResource(GetID(res));
}
// Mark resource as dirty and write-referenced.
// Write-referenced resources are used to track resource "age".
void MarkDirtyWithWriteReference(GLResource res)
@@ -249,8 +267,6 @@ public:
bool IsResourceTrackedForPersistency(const GLResource &res);
void Force_ReferenceViews();
template <typename SerialiserType>
bool Serialise_InitialState(SerialiserType &ser, ResourceId id, GLResourceRecord *record,
const GLInitialContents *initial);
+6 -6
View File
@@ -256,12 +256,12 @@ struct GLResourceRecord : public ResourceRecord
GLenum datatype;
GLenum usage;
// for texture buffers and texture views, this points from the data texture (or buffer)
// to the view texture. When preparing resource initial states, we force initial states
// for anything that is viewed if the viewer is frame referenced. Otherwise we might
// lose the underlying data for the view.
// Since it's 1-to-many, we keep a set here.
std::set<ResourceId> viewTextures;
// for texture buffers, this points from the texture to the real buffer, for texture views this
// points to the texture that's being viewed (the actual data source).
// When we mark a resource as dirty or frame referenced, we also mark the underlyingData resource
// the same, so that if we dirty the texture then we dirty the buffer/real texture, and so that if
// the texture is used then we bring the buffer/real texture into the frame.
ResourceId viewSource;
GLResource Resource;
@@ -750,7 +750,7 @@ void WrappedOpenGL::glTextureView(GLuint texture, GLenum target, GLuint origtext
record->AddChunk(scope.Get());
record->AddParent(origrecord);
origrecord->viewTextures.insert(record->GetResourceID());
record->viewSource = origrecord->GetResourceID();
// illegal to re-type textures
record->VerifyDataType(target);
@@ -6263,7 +6263,7 @@ void WrappedOpenGL::Common_glTextureBufferRangeEXT(ResourceId texId, GLenum targ
if(bufRecord)
{
record->AddParent(bufRecord);
bufRecord->viewTextures.insert(record->GetResourceID());
record->viewSource = bufRecord->GetResourceID();
}
}
@@ -6296,7 +6296,7 @@ void WrappedOpenGL::Common_glTextureBufferRangeEXT(ResourceId texId, GLenum targ
if(bufRecord)
{
record->AddParent(bufRecord);
bufRecord->viewTextures.insert(record->GetResourceID());
record->viewSource = bufRecord->GetResourceID();
}
}
}
@@ -6438,7 +6438,7 @@ void WrappedOpenGL::Common_glTextureBufferEXT(ResourceId texId, GLenum target,
if(bufRecord)
{
record->AddParent(bufRecord);
bufRecord->viewTextures.insert(record->GetResourceID());
record->viewSource = bufRecord->GetResourceID();
}
}
@@ -6472,7 +6472,7 @@ void WrappedOpenGL::Common_glTextureBufferEXT(ResourceId texId, GLenum target,
if(bufRecord)
{
record->AddParent(bufRecord);
bufRecord->viewTextures.insert(record->GetResourceID());
record->viewSource = bufRecord->GetResourceID();
}
}
}