[Libreoffice-commits] core.git: Branch 'feature/fixes11' - vcl/source

Tor Lillqvist tml at collabora.com
Mon Oct 19 00:14:04 PDT 2015


 vcl/source/opengl/OpenGLContext.cxx |   22 +++++++++++++++-------
 1 file changed, 15 insertions(+), 7 deletions(-)

New commits:
commit 552183f691dcdbdb4466d77be66e55312980a20d
Author: Tor Lillqvist <tml at collabora.com>
Date:   Mon Oct 19 09:55:57 2015 +0300

    Speed up in-process caching of OpenGL shader programs
    
    It seems to be fairly CPU intensive to calculate the MD5 digest of
    shader program source code. But we don't need to use that to look up a
    corrresponding program in the run-time in-process cache anyway. The
    shader names are unique, so it is enough to use that as key.
    
    Change-Id: I8fd9f5f875be14a82cd53daf8a2ca72bfd23beb6

diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index ca53bc0..3246cfc 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -1739,20 +1739,28 @@ OpenGLProgram* OpenGLContext::GetProgram( const OUString& rVertexShader, const O
 {
     OpenGLZone aZone;
 
-    rtl::OString aKey = OpenGLHelper::GetDigest( rVertexShader, rFragmentShader, preamble );
-
-    if( !aKey.isEmpty() )
-    {
-        ProgramCollection::iterator it = maPrograms.find( aKey );
+    // We cache the shader programs in a per-process run-time cache
+    // based on only the names and the preamble. We don't expect
+    // shader source files to change during the lifetime of a
+    // LibreOffice process.
+    rtl::OString aNameBasedKey = OUStringToOString(rVertexShader + "+" + rFragmentShader, RTL_TEXTENCODING_UTF8) + "+" + preamble;
+    if( !aNameBasedKey.isEmpty() )
+    {
+        ProgramCollection::iterator it = maPrograms.find( aNameBasedKey );
         if( it != maPrograms.end() )
             return it->second.get();
     }
 
+    // Binary shader programs are cached persistently (between
+    // LibreOffice process instances) based on a hash of their source
+    // code, as the source code can and will change between
+    // LibreOffice versions even if the shader names don't change.
+    rtl::OString aPersistentKey = OpenGLHelper::GetDigest( rVertexShader, rFragmentShader, preamble );
     std::shared_ptr<OpenGLProgram> pProgram = std::make_shared<OpenGLProgram>();
-    if( !pProgram->Load( rVertexShader, rFragmentShader, preamble, aKey ) )
+    if( !pProgram->Load( rVertexShader, rFragmentShader, preamble, aPersistentKey ) )
         return NULL;
 
-    maPrograms.insert(std::make_pair(aKey, pProgram));
+    maPrograms.insert(std::make_pair(aNameBasedKey, pProgram));
 
     return pProgram.get();
 }


More information about the Libreoffice-commits mailing list