Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9a51086 authored by Derek Sollenberger's avatar Derek Sollenberger
Browse files

Reduce size of buffer used to prime the RenderEngine shader cache.

In local testing on Pixel 3XL the same shaders were produced when
compared to the old value and time spent in primeCache was reduced by ~200ms.

Test: atest librenderengine_test
Bug: 182658261
Change-Id: Id08db5822b05681876780225f92bf4601dc46c76
parent b1f5ee4a
Loading
Loading
Loading
Loading
+55 −48
Original line number Diff line number Diff line
@@ -238,9 +238,14 @@ void Cache::primeShaderCache(SkiaRenderEngine* renderengine) {
    if (previousCount) {
        ALOGD("%d Shaders already compiled before Cache::primeShaderCache ran\n", previousCount);
    }

    // The loop is beneficial for debugging and should otherwise be optimized out by the compiler.
    // Adding additional bounds to the loop is useful for verifying that the size of the dst buffer
    // does not impact the shader compilation counts by triggering different behaviors in RE/Skia.
    for (SkSize bounds : {SkSize::Make(128, 128), /*SkSize::Make(1080, 2340)*/}) {
        const nsecs_t timeBefore = systemTime();
        // The dimensions should not matter, so long as we draw inside them.
    const Rect displayRect(0, 0, 1080, 2340);
        const Rect displayRect(0, 0, bounds.fWidth, bounds.fHeight);
        DisplaySettings display{
                .physicalDisplay = displayRect,
                .clip = displayRect,
@@ -251,18 +256,19 @@ void Cache::primeShaderCache(SkiaRenderEngine* renderengine) {
        const int64_t usage = GRALLOC_USAGE_HW_RENDER | GRALLOC_USAGE_HW_TEXTURE;

        sp<GraphicBuffer> dstBuffer =
            new GraphicBuffer(displayRect.width(), displayRect.height(), PIXEL_FORMAT_RGBA_8888, 1,
                              usage, "primeShaderCache_dst");
                new GraphicBuffer(displayRect.width(), displayRect.height(), PIXEL_FORMAT_RGBA_8888,
                                  1, usage, "primeShaderCache_dst");

    const auto dstTexture = std::make_shared<ExternalTexture>(dstBuffer, *renderengine,
        const auto dstTexture =
                std::make_shared<ExternalTexture>(dstBuffer, *renderengine,
                                                  ExternalTexture::Usage::WRITEABLE);
        // This buffer will be the source for the call to drawImageLayers. Draw
        // something to it as a placeholder for what an app draws. We should draw
        // something, but the details are not important. Make use of the shadow layer drawing step
        // to populate it.
        sp<GraphicBuffer> srcBuffer =
            new GraphicBuffer(displayRect.width(), displayRect.height(), PIXEL_FORMAT_RGBA_8888, 1,
                              usage, "drawImageLayer_src");
                new GraphicBuffer(displayRect.width(), displayRect.height(), PIXEL_FORMAT_RGBA_8888,
                                  1, usage, "drawImageLayer_src");

        const auto srcTexture =
                std::make_shared<ExternalTexture>(srcBuffer, *renderengine,
@@ -279,8 +285,8 @@ void Cache::primeShaderCache(SkiaRenderEngine* renderengine) {
        const int64_t usageExternal = GRALLOC_USAGE_HW_TEXTURE;

        sp<GraphicBuffer> externalBuffer =
            new GraphicBuffer(displayRect.width(), displayRect.height(), PIXEL_FORMAT_RGBA_8888, 1,
                              usageExternal, "primeShaderCache_external");
                new GraphicBuffer(displayRect.width(), displayRect.height(), PIXEL_FORMAT_RGBA_8888,
                                  1, usageExternal, "primeShaderCache_external");
        const auto externalTexture =
                std::make_shared<ExternalTexture>(externalBuffer, *renderengine,
                                                  ExternalTexture::Usage::READABLE);
@@ -296,5 +302,6 @@ void Cache::primeShaderCache(SkiaRenderEngine* renderengine) {
        const int shadersCompiled = renderengine->reportShadersCompiled();
        ALOGD("Shader cache generated %d shaders in %f ms\n", shadersCompiled, compileTimeMs);
    }
}

} // namespace android::renderengine::skia