diff options
| author | 2021-03-22 10:42:47 -0400 | |
|---|---|---|
| committer | 2021-03-23 17:44:45 +0000 | |
| commit | 9f3072c7ae6ff575811e35fd5248b2396c878b3d (patch) | |
| tree | d47bcdc5690693982feaf291237a5b0bbb1f4a76 | |
| parent | b552167471c48a22eec834b6c0ad0d5d623ab4e5 (diff) | |
SkiaGLRE caching: monitor the caching of shaders
Bug: 178661709
Test: adb shell setprop debug.renderengine.backend skiagl
adb shell stop && adb shell start
adb shell dumpsys SurfaceFlinger
Add an implementation of PersistentCache that allows us to monitor
whether a shader was generated when we expected one to be. This can be
repurposed in the future (i.e. once we've generated all the shaders we
expect) to verify that we do *not* generate shaders after primeCache
finishes.
Add the number of recently cached shaders (i.e. since the last call, or
primeCache, if this is the first call) to the output of dumpsys.
Change-Id: I6f177b7ad78fef166d529e918447395629673f47
| -rw-r--r-- | libs/renderengine/skia/Cache.cpp | 4 | ||||
| -rw-r--r-- | libs/renderengine/skia/SkiaGLRenderEngine.cpp | 20 | ||||
| -rw-r--r-- | libs/renderengine/skia/SkiaGLRenderEngine.h | 25 | ||||
| -rw-r--r-- | libs/renderengine/skia/SkiaRenderEngine.h | 1 |
4 files changed, 50 insertions, 0 deletions
diff --git a/libs/renderengine/skia/Cache.cpp b/libs/renderengine/skia/Cache.cpp index 4fdae74a5a..f8dd7f52e0 100644 --- a/libs/renderengine/skia/Cache.cpp +++ b/libs/renderengine/skia/Cache.cpp @@ -55,6 +55,7 @@ static void drawShadowLayer(SkiaRenderEngine* renderengine, const DisplaySetting // generate the slower (more general case) version. If we also need a // slow version without color correction, we should use this matrix with // display.outputDataspace set to SRGB. + bool identity = true; for (const mat4 transform : { mat4(), mat4(0.728872f, 0.f, 0.f, 0.f, 0.f, 0.727627f, 0.f, 0.f, 0.f, 0.f, 1.f, 0.f, @@ -62,6 +63,8 @@ static void drawShadowLayer(SkiaRenderEngine* renderengine, const DisplaySetting layer.geometry.positionTransform = transform; renderengine->drawLayers(display, layers, dstBuffer, false /* useFrameBufferCache*/, base::unique_fd(), nullptr); + renderengine->assertShadersCompiled(identity ? 1 : 2); + identity = false; } } @@ -105,6 +108,7 @@ static void drawImageLayers(SkiaRenderEngine* renderengine, const DisplaySetting renderengine->drawLayers(display, layers, dstBuffer, false /* useFrameBufferCache*/, base::unique_fd(), nullptr); + renderengine->assertShadersCompiled(1); } } } diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.cpp b/libs/renderengine/skia/SkiaGLRenderEngine.cpp index afdcd76552..7d711c19c6 100644 --- a/libs/renderengine/skia/SkiaGLRenderEngine.cpp +++ b/libs/renderengine/skia/SkiaGLRenderEngine.cpp @@ -268,6 +268,23 @@ EGLConfig SkiaGLRenderEngine::chooseEglConfig(EGLDisplay display, int format, bo return config; } +sk_sp<SkData> SkiaGLRenderEngine::SkSLCacheMonitor::load(const SkData& key) { + // This "cache" does not actually cache anything. It just allows us to + // monitor Skia's internal cache. So this method always returns null. + return nullptr; +} + +void SkiaGLRenderEngine::SkSLCacheMonitor::store(const SkData& key, const SkData& data, + const SkString& description) { + mShadersCachedSinceLastCall++; +} + +void SkiaGLRenderEngine::assertShadersCompiled(int numShaders) { + const int cached = mSkSLCacheMonitor.shadersCachedSinceLastCall(); + LOG_ALWAYS_FATAL_IF(cached != numShaders, "Attempted to cache %i shaders; cached %i", + numShaders, cached); +} + SkiaGLRenderEngine::SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGLDisplay display, EGLContext ctxt, EGLSurface placeholder, EGLContext protectedContext, EGLSurface protectedPlaceholder) @@ -284,6 +301,7 @@ SkiaGLRenderEngine::SkiaGLRenderEngine(const RenderEngineCreationArgs& args, EGL GrContextOptions options; options.fPreferExternalImagesOverES3 = true; options.fDisableDistanceFieldPaths = true; + options.fPersistentCache = &mSkSLCacheMonitor; mGrContext = GrDirectContext::MakeGL(glInterface, options); if (useProtectedContext(true)) { mProtectedGrContext = GrDirectContext::MakeGL(glInterface, options); @@ -1168,6 +1186,8 @@ void SkiaGLRenderEngine::dump(std::string& result) { StringAppendF(&result, "RenderEngine supports protected context: %d\n", supportsProtectedContent()); StringAppendF(&result, "RenderEngine is in protected context: %d\n", mInProtectedContext); + StringAppendF(&result, "RenderEngine shaders cached since last dump/primeCache: %d\n", + mSkSLCacheMonitor.shadersCachedSinceLastCall()); { std::lock_guard<std::mutex> lock(mRenderingMutex); diff --git a/libs/renderengine/skia/SkiaGLRenderEngine.h b/libs/renderengine/skia/SkiaGLRenderEngine.h index 15d834db21..7605df942c 100644 --- a/libs/renderengine/skia/SkiaGLRenderEngine.h +++ b/libs/renderengine/skia/SkiaGLRenderEngine.h @@ -31,6 +31,7 @@ #include "AutoBackendTexture.h" #include "EGL/egl.h" +#include "GrContextOptions.h" #include "SkImageInfo.h" #include "SkiaRenderEngine.h" #include "android-base/macros.h" @@ -63,6 +64,7 @@ public: bool supportsProtectedContent() const override; bool useProtectedContext(bool useProtectedContext) override; bool supportsBackgroundBlur() override { return mBlurFilter != nullptr; } + void assertShadersCompiled(int numShaders) override; protected: void dump(std::string& result) override; @@ -131,6 +133,29 @@ private: bool mInProtectedContext = false; // Object to capture commands send to Skia. std::unique_ptr<SkiaCapture> mCapture; + + // Implements PersistentCache as a way to monitor what SkSL shaders Skia has + // cached. + class SkSLCacheMonitor : public GrContextOptions::PersistentCache { + public: + SkSLCacheMonitor() = default; + ~SkSLCacheMonitor() override = default; + + sk_sp<SkData> load(const SkData& key) override; + + void store(const SkData& key, const SkData& data, const SkString& description) override; + + int shadersCachedSinceLastCall() { + const int shadersCachedSinceLastCall = mShadersCachedSinceLastCall; + mShadersCachedSinceLastCall = 0; + return shadersCachedSinceLastCall; + } + + private: + int mShadersCachedSinceLastCall = 0; + }; + + SkSLCacheMonitor mSkSLCacheMonitor; }; } // namespace skia diff --git a/libs/renderengine/skia/SkiaRenderEngine.h b/libs/renderengine/skia/SkiaRenderEngine.h index f4037257ee..59d7e2ff89 100644 --- a/libs/renderengine/skia/SkiaRenderEngine.h +++ b/libs/renderengine/skia/SkiaRenderEngine.h @@ -58,6 +58,7 @@ public: }; virtual bool cleanupPostRender(CleanupMode) override { return true; }; virtual int getContextPriority() override { return 0; } + virtual void assertShadersCompiled(int numShaders) {} }; } // namespace skia |