Kaydet (Commit) 7d84e3e0 authored tarafından Tor Lillqvist's avatar Tor Lillqvist

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
üst 7fb1b147
...@@ -1651,20 +1651,28 @@ OpenGLProgram* OpenGLContext::GetProgram( const OUString& rVertexShader, const O ...@@ -1651,20 +1651,28 @@ OpenGLProgram* OpenGLContext::GetProgram( const OUString& rVertexShader, const O
{ {
OpenGLZone aZone; OpenGLZone aZone;
rtl::OString aKey = OpenGLHelper::GetDigest( rVertexShader, rFragmentShader, preamble ); // We cache the shader programs in a per-process run-time cache
// based on only the names and the preamble. We don't expect
if( !aKey.isEmpty() ) // shader source files to change during the lifetime of a
{ // LibreOffice process.
ProgramCollection::iterator it = maPrograms.find( aKey ); rtl::OString aNameBasedKey = OUStringToOString(rVertexShader + "+" + rFragmentShader, RTL_TEXTENCODING_UTF8) + "+" + preamble;
if( !aNameBasedKey.isEmpty() )
{
ProgramCollection::iterator it = maPrograms.find( aNameBasedKey );
if( it != maPrograms.end() ) if( it != maPrograms.end() )
return it->second.get(); 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>(); 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; return NULL;
maPrograms.insert(std::make_pair(aKey, pProgram)); maPrograms.insert(std::make_pair(aNameBasedKey, pProgram));
return pProgram.get(); return pProgram.get();
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment