summaryrefslogtreecommitdiff
path: root/vcl
diff options
context:
space:
mode:
authorTor Lillqvist <tml@collabora.com>2015-10-19 09:55:57 +0300
committerTor Lillqvist <tml@collabora.com>2015-10-19 17:53:13 +0300
commit7d84e3e08bdd06474cb7d9ef681492be5999d345 (patch)
treec0f2d84f744a83ebfe05438c46daf5a32625ef64 /vcl
parent7fb1b147507ad991de974c7c331816225dc5c088 (diff)
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
Diffstat (limited to 'vcl')
-rw-r--r--vcl/source/opengl/OpenGLContext.cxx22
1 files changed, 15 insertions, 7 deletions
diff --git a/vcl/source/opengl/OpenGLContext.cxx b/vcl/source/opengl/OpenGLContext.cxx
index c44b95b887e8..f389f88e92ad 100644
--- a/vcl/source/opengl/OpenGLContext.cxx
+++ b/vcl/source/opengl/OpenGLContext.cxx
@@ -1651,20 +1651,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();
}