diff --git a/renderdoc/driver/gl/gl_driver.cpp b/renderdoc/driver/gl/gl_driver.cpp index cd239545d..841017dd5 100644 --- a/renderdoc/driver/gl/gl_driver.cpp +++ b/renderdoc/driver/gl/gl_driver.cpp @@ -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); diff --git a/renderdoc/driver/gl/gl_initstate.cpp b/renderdoc/driver/gl/gl_initstate.cpp index 294e62db5..1601b3bcc 100644 --- a/renderdoc/driver/gl/gl_initstate.cpp +++ b/renderdoc/driver/gl/gl_initstate.cpp @@ -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) diff --git a/renderdoc/driver/gl/gl_manager.h b/renderdoc/driver/gl/gl_manager.h index a4a844928..832bb8f24 100644 --- a/renderdoc/driver/gl/gl_manager.h +++ b/renderdoc/driver/gl/gl_manager.h @@ -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 bool Serialise_InitialState(SerialiserType &ser, ResourceId id, GLResourceRecord *record, const GLInitialContents *initial); diff --git a/renderdoc/driver/gl/gl_resources.h b/renderdoc/driver/gl/gl_resources.h index 7b412f72a..51a7e9c8d 100644 --- a/renderdoc/driver/gl/gl_resources.h +++ b/renderdoc/driver/gl/gl_resources.h @@ -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 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; diff --git a/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp b/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp index 6f5d2f4d3..a9d30411a 100644 --- a/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp +++ b/renderdoc/driver/gl/wrappers/gl_texture_funcs.cpp @@ -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(); } } }