From eb18d41f9aba74d1e36f3e6bc3cdf4448166cc11 Mon Sep 17 00:00:00 2001 From: baldurk Date: Wed, 17 Oct 2018 16:09:53 +0100 Subject: [PATCH] Detect read-only GL persistent maps & skip intercepting them. Refs #1128 --- .../driver/gl/wrappers/gl_buffer_funcs.cpp | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/renderdoc/driver/gl/wrappers/gl_buffer_funcs.cpp b/renderdoc/driver/gl/wrappers/gl_buffer_funcs.cpp index d5aad0b6f..57e179538 100644 --- a/renderdoc/driver/gl/wrappers/gl_buffer_funcs.cpp +++ b/renderdoc/driver/gl/wrappers/gl_buffer_funcs.cpp @@ -449,7 +449,8 @@ void WrappedOpenGL::Common_glNamedBufferStorageEXT(ResourceId id, GLsizeiptr siz // because the user code isn't writing into them anyway and we're inserting invisible sync // points - so there's no need for it to be coherently mapped (and there's no requirement // that a buffer declared as coherent must ALWAYS be mapped as coherent). - if(flags & GL_MAP_PERSISTENT_BIT) + uint32_t persistentWriteFlags = GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT; + if((flags & persistentWriteFlags) == persistentWriteFlags) { record->Map.persistentPtr = (byte *)GL.glMapNamedBufferRangeEXT( record->Resource.name, 0, size, @@ -1900,14 +1901,20 @@ void *WrappedOpenGL::glMapNamedBufferRangeEXT(GLuint buffer, GLintptr offset, GL IsBackgroundCapturing(m_State)) directMap = true; - // persistent maps must ALWAYS be intercepted - if((access & GL_MAP_PERSISTENT_BIT) || record->Map.persistentPtr) + // read-only persistent maps can also be made directly + uint32_t persistentReadFlags = GL_MAP_PERSISTENT_BIT | GL_MAP_READ_BIT; + if((access & persistentReadFlags) == persistentReadFlags) + directMap = true; + + // persistent maps must ALWAYS be intercepted if they are writeable. if it's a read-only + // persistent map we never allocated a persistent pointer so we can skip this + if(record->Map.persistentPtr) directMap = false; bool verifyWrite = (RenderDoc::Inst().GetCaptureOptions().verifyMapWrites != 0); // must also intercept to verify writes - if(verifyWrite) + if(verifyWrite && (access & GL_MAP_WRITE_BIT)) directMap = false; if(directMap) @@ -1922,8 +1929,9 @@ void *WrappedOpenGL::glMapNamedBufferRangeEXT(GLuint buffer, GLintptr offset, GL record->Map.invalidate = invalidateMap; record->Map.verifyWrite = verifyWrite; - // store a list of all persistent maps, and subset of all coherent maps - if(access & GL_MAP_PERSISTENT_BIT) + // store a list of all persistent writing maps, and subset of all coherent maps + uint32_t persistentWriteFlags = GL_MAP_PERSISTENT_BIT | GL_MAP_WRITE_BIT; + if((access & persistentWriteFlags) == persistentWriteFlags) { Atomic::Inc64(&record->Map.persistentMaps); m_PersistentMaps.insert(record);