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

Commit 97fbc9a8 authored by Noelle Scobie's avatar Noelle Scobie
Browse files

Copy initial set of Graphite precompilation cases from upstream

This will be improved in the near future to be less brittle (e.g.
hardcoded external format metadata), and hopefully share helper code
with Skia more directly.

Credit to robertphillips@google.com for the actual work in this CL. :)

Bug: b/380159947
Test: manual analysis of pipeline precompilation
Flag: com.android.graphics.surfaceflinger.flags.graphite_renderengine
Change-Id: I3d1a352bcb88d3a1f8c54e2e7aceca348d7b0c40
parent ce3ed9d0
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -97,6 +97,7 @@ filegroup {
        "skia/compat/GaneshGpuContext.cpp",
        "skia/compat/GraphiteBackendTexture.cpp",
        "skia/compat/GraphiteGpuContext.cpp",
        "skia/compat/GraphitePipelineManager.cpp",
        "skia/debug/CaptureTimer.cpp",
        "skia/debug/CommonPool.cpp",
        "skia/debug/SkiaCapture.cpp",
+40 −0
Original line number Diff line number Diff line
@@ -22,9 +22,11 @@
#include <include/gpu/GpuTypes.h>
#include <include/gpu/graphite/BackendSemaphore.h>
#include <include/gpu/graphite/Context.h>
#include <include/gpu/graphite/PrecompileContext.h>
#include <include/gpu/graphite/Recording.h>
#include <include/gpu/graphite/vk/VulkanGraphiteTypes.h>

#include <android-base/properties.h>
#include <android-base/stringprintf.h>
#include <log/log_main.h>
#include <sync/sync.h>
@@ -32,6 +34,8 @@
#include <memory>
#include <vector>

#include "compat/GraphitePipelineManager.h"

namespace android::renderengine::skia {

using base::StringAppendF;
@@ -53,6 +57,42 @@ std::unique_ptr<GraphiteVkRenderEngine> GraphiteVkRenderEngine::create(
    }
}

GraphiteVkRenderEngine::~GraphiteVkRenderEngine() {
    // Ensure precompilation has finished accessing resources (e.g. context, RuntimeEffectManager).
    // TODO(b/380159947): interrupt precompilation loop on destruction, instead of waiting for it to
    // finish?
    if (mPrecompilePipelinesTask.joinable()) {
        mPrecompilePipelinesTask.join();
    }
}

std::future<void> GraphiteVkRenderEngine::primeCache(PrimeCacheConfig config) {
    std::future<void> ret = {};

    // Note: for local debugging only! Graphite's precompilation should stay ENABLED, and this
    // switch will be removed in the future without warning.
    if (base::GetBoolProperty("debug.renderengine.graphite.precompile", true)) {
        std::unique_ptr<graphite::PrecompileContext> precompileContext =
                mContext->graphiteContext()->makePrecompileContext();
        mPrecompilePipelinesTask =
                std::thread(GraphitePipelineManager::PrecompilePipelines,
                            std::move(precompileContext), std::ref(mRuntimeEffectManager));
    } else {
        ALOGW("Graphite's background shader / pipeline precompilation was disabled!");
    }

    // Note: for local debugging only! Legacy draw-based prewarming should stay DISABLED, and this
    // switch will be removed  in the future without warning. Enabling this may regress boot time
    // unnecessarily.
    // TODO(b/380159947): remove this option, and force precompilation to always be enabled.
    if (base::GetBoolProperty("debug.renderengine.graphite.prewarm", false)) {
        ALOGW("Legacy draw-based shader / pipeline prewarming was enabled, and may delay boot!");
        ret = SkiaVkRenderEngine::primeCache(config);
    }

    return ret;
}

// Graphite-specific function signature for fFinishedProc callback.
static void unref_semaphore(void* semaphore, skgpu::CallbackResult result) {
    if (result != skgpu::CallbackResult::kSuccess) {
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,9 @@ class GraphiteVkRenderEngine : public SkiaVkRenderEngine {
public:
    static std::unique_ptr<GraphiteVkRenderEngine> create(const RenderEngineCreationArgs& args);

    ~GraphiteVkRenderEngine() override;
    std::future<void> primeCache(PrimeCacheConfig config) override;

protected:
    std::unique_ptr<SkiaGpuContext> createContext(VulkanInterface& vulkanInterface) override;
    void waitFence(SkiaGpuContext* context, base::borrowed_fd fenceFd) override;
@@ -35,6 +38,7 @@ protected:
private:
    GraphiteVkRenderEngine(const RenderEngineCreationArgs& args) : SkiaVkRenderEngine(args) {}

    std::thread mPrecompilePipelinesTask;
    std::vector<graphite::BackendSemaphore> mStagedWaitSemaphores;
};

+8 −4
Original line number Diff line number Diff line
@@ -65,7 +65,7 @@ public:
    SkiaRenderEngine(Threaded, PixelFormat pixelFormat, BlurAlgorithm);
    ~SkiaRenderEngine() override;

    std::future<void> primeCache(PrimeCacheConfig config) override final;
    std::future<void> primeCache(PrimeCacheConfig config) override;
    void cleanupPostRender() override final;
    bool supportsBackgroundBlur() override final {
        return mBlurFilter != nullptr;
@@ -131,6 +131,12 @@ protected:
    SkSLCacheMonitor mSkSLCacheMonitor;
    RuntimeEffectManager mRuntimeEffectManager;

    // Graphics context used for creating surfaces and submitting commands.
    // Unlike mProtectedContext, mContext cannot be marked private because it
    // occasionally needs to be referenced by subclasses (e.g. for Graphite's
    // precompilation).
    unique_ptr<SkiaGpuContext> mContext;

private:
    void mapExternalTextureBuffer(const sp<GraphicBuffer>& buffer,
                                  bool isRenderable) override final;
@@ -204,9 +210,7 @@ private:
    // rendering that is potentially modified by multiple threads is guaranteed thread-safe.
    mutable std::mutex mRenderingMutex;

    // Graphics context used for creating surfaces and submitting commands
    unique_ptr<SkiaGpuContext> mContext;
    // Same as above, but for protected content (eg. DRM)
    // Same as mContext, but for protected content (eg. DRM)
    unique_ptr<SkiaGpuContext> mProtectedContext;
    bool mInProtectedContext = false;
};
+859 −0

File added.

Preview size limit exceeded, changes collapsed.

Loading