diff options
author | Riley Andrews <riandrews@google.com> | 2014-09-29 13:29:40 -0700 |
---|---|---|
committer | Riley Andrews <riandrews@google.com> | 2014-10-02 01:30:28 +0000 |
commit | a51fafc4d83ab1d1582c1c870c31be44b057aa95 (patch) | |
tree | 132d602ea94840d2138d24410ed3e314e73d6b25 /services | |
parent | db57cfbd6f9d5795846ef237fd297cb81e429679 (diff) | |
download | frameworks_native-a51fafc4d83ab1d1582c1c870c31be44b057aa95.zip frameworks_native-a51fafc4d83ab1d1582c1c870c31be44b057aa95.tar.gz frameworks_native-a51fafc4d83ab1d1582c1c870c31be44b057aa95.tar.bz2 |
Generate the SurfaceFlinger shader cache on initialization
Blobcache is not yet enabled for surfaceflinger (as it should be).
As a temporary workaround, generate all needed shaders during
surfaceflinger initialization instead of doing the compilation
on-demand during ui transitions.
Change-Id: I14455b20a3f85f177d85c9c8b76d8ccc35379b39
Diffstat (limited to 'services')
-rw-r--r-- | services/surfaceflinger/RenderEngine/ProgramCache.cpp | 33 | ||||
-rw-r--r-- | services/surfaceflinger/RenderEngine/ProgramCache.h | 2 |
2 files changed, 34 insertions, 1 deletions
diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.cpp b/services/surfaceflinger/RenderEngine/ProgramCache.cpp index d130506..0de5cca 100644 --- a/services/surfaceflinger/RenderEngine/ProgramCache.cpp +++ b/services/surfaceflinger/RenderEngine/ProgramCache.cpp @@ -77,13 +77,44 @@ Formatter& dedent(Formatter& f) { ANDROID_SINGLETON_STATIC_INSTANCE(ProgramCache) - ProgramCache::ProgramCache() { + // Until surfaceflinger has a dependable blob cache on the filesystem, + // generate shaders on initialization so as to avoid jank. + primeCache(); } ProgramCache::~ProgramCache() { } +void ProgramCache::primeCache() { + uint32_t shaderCount = 0; + uint32_t keyMask = Key::BLEND_MASK | Key::OPACITY_MASK | + Key::PLANE_ALPHA_MASK | Key::TEXTURE_MASK; + // Prime the cache for all combinations of the above masks, + // leaving off the experimental color matrix mask options. + + nsecs_t timeBefore = systemTime(); + for (uint32_t keyVal = 0; keyVal <= keyMask; keyVal++) { + Key shaderKey; + shaderKey.set(keyMask, keyVal); + uint32_t tex = shaderKey.getTextureTarget(); + if (tex != Key::TEXTURE_OFF && + tex != Key::TEXTURE_EXT && + tex != Key::TEXTURE_2D) { + continue; + } + Program* program = mCache.valueFor(shaderKey); + if (program == NULL) { + program = generateProgram(shaderKey); + mCache.add(shaderKey, program); + shaderCount++; + } + } + nsecs_t timeAfter = systemTime(); + float compileTimeMs = static_cast<float>(timeAfter - timeBefore) / 1.0E6; + ALOGD("shader cache generated - %u shaders in %f ms\n", shaderCount, compileTimeMs); +} + ProgramCache::Key ProgramCache::computeKey(const Description& description) { Key needs; needs.set(Key::TEXTURE_MASK, diff --git a/services/surfaceflinger/RenderEngine/ProgramCache.h b/services/surfaceflinger/RenderEngine/ProgramCache.h index e8b9dcd..1fa53d3 100644 --- a/services/surfaceflinger/RenderEngine/ProgramCache.h +++ b/services/surfaceflinger/RenderEngine/ProgramCache.h @@ -112,6 +112,8 @@ public: void useProgram(const Description& description); private: + // Generate shaders to populate the cache + void primeCache(); // compute a cache Key from a Description static Key computeKey(const Description& description); // generates a program from the Key |