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

Commit d1359d56 authored by Noelle Scobie's avatar Noelle Scobie Committed by Android (Google) Code Review
Browse files

Merge changes I3d1a352b,I00755d5a into main

* changes:
  Copy initial set of Graphite precompilation cases from upstream
  Centralize all SkRuntimeEffect creation and make them easily accessible
parents 6dd98803 97fbc9a8
Loading
Loading
Loading
Loading
+3 −2
Original line number Diff line number Diff line
@@ -97,20 +97,21 @@ 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",
        "skia/debug/SkiaMemoryReporter.cpp",
        "skia/filters/BlurFilter.cpp",
        "skia/filters/EdgeExtensionShaderFactory.cpp",
        "skia/filters/GainmapFactory.cpp",
        "skia/filters/GaussianBlurFilter.cpp",
        "skia/filters/KawaseBlurDualFilter.cpp",
        "skia/filters/KawaseBlurFilter.cpp",
        "skia/filters/LinearEffect.cpp",
        "skia/filters/LutShader.cpp",
        "skia/filters/MouriMap.cpp",
        "skia/filters/RuntimeEffectManager.cpp",
        "skia/filters/StretchShaderFactory.cpp",
        "skia/filters/EdgeExtensionShaderFactory.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;
};

+0 −1
Original line number Diff line number Diff line
@@ -38,7 +38,6 @@
#include "android-base/macros.h"
#include "debug/SkiaCapture.h"
#include "filters/BlurFilter.h"
#include "filters/LinearEffect.h"
#include "filters/StretchShaderFactory.h"

class SkData;
+21 −34
Original line number Diff line number Diff line
@@ -81,8 +81,9 @@
#include "filters/GaussianBlurFilter.h"
#include "filters/KawaseBlurDualFilter.h"
#include "filters/KawaseBlurFilter.h"
#include "filters/LinearEffect.h"
#include "filters/LutShader.h"
#include "filters/MouriMap.h"
#include "filters/RuntimeEffectManager.h"
#include "log/log_main.h"
#include "skia/compat/SkiaBackendTexture.h"
#include "skia/debug/SkiaCapture.h"
@@ -292,17 +293,17 @@ SkiaRenderEngine::SkiaRenderEngine(Threaded threaded, PixelFormat pixelFormat,
    switch (blurAlgorithm) {
        case BlurAlgorithm::GAUSSIAN: {
            ALOGD("Background Blurs Enabled (Gaussian algorithm)");
            mBlurFilter = new GaussianBlurFilter();
            mBlurFilter = new GaussianBlurFilter(mRuntimeEffectManager);
            break;
        }
        case BlurAlgorithm::KAWASE: {
            ALOGD("Background Blurs Enabled (Kawase algorithm)");
            mBlurFilter = new KawaseBlurFilter();
            mBlurFilter = new KawaseBlurFilter(mRuntimeEffectManager);
            break;
        }
        case BlurAlgorithm::KAWASE_DUAL_FILTER: {
            ALOGD("Background Blurs Enabled (Kawase dual-filtering algorithm)");
            mBlurFilter = new KawaseBlurDualFilter();
            mBlurFilter = new KawaseBlurDualFilter(mRuntimeEffectManager);
            break;
        }
        default: {
@@ -525,6 +526,7 @@ void SkiaRenderEngine::cleanupPostRender() {

sk_sp<SkShader> SkiaRenderEngine::createRuntimeEffectShader(
        const RuntimeEffectShaderParameters& parameters) {
    SFTRACE_CALL();
    // The given surface will be stretched by HWUI via matrix transformation
    // which gets similar results for most surfaces
    // Determine later on if we need to leverage the stretch shader within
@@ -585,14 +587,8 @@ sk_sp<SkShader> SkiaRenderEngine::createRuntimeEffectShader(
                                      .undoPremultipliedAlpha = parameters.undoPremultipliedAlpha,
                                      .fakeOutputDataspace = parameters.fakeOutputDataspace};

        auto effectIter = mRuntimeEffects.find(effect);
        sk_sp<SkRuntimeEffect> runtimeEffect = nullptr;
        if (effectIter == mRuntimeEffects.end()) {
            runtimeEffect = buildRuntimeEffect(effect);
            mRuntimeEffects.insert({effect, runtimeEffect});
        } else {
            runtimeEffect = effectIter->second;
        }
        sk_sp<SkRuntimeEffect> runtimeEffect =
                mRuntimeEffectManager.getOrCreateLinearRuntimeEffect(effect);

        mat4 colorTransform = parameters.layer.colorTransform;

@@ -603,19 +599,23 @@ sk_sp<SkShader> SkiaRenderEngine::createRuntimeEffectShader(
        }

        const auto hardwareBuffer = graphicBuffer ? graphicBuffer->toAHardwareBuffer() : nullptr;
        return createLinearEffectShader(shader, effect, runtimeEffect, std::move(colorTransform),
        return RuntimeEffectManager::createLinearEffectShader(shader, effect, runtimeEffect,
                                                              std::move(colorTransform),
                                                              parameters.display.maxLuminance,
                                        parameters.display.currentLuminanceNits,
                                        parameters.layer.source.buffer.maxLuminanceNits,
                                        hardwareBuffer, parameters.display.renderIntent);
                                                              parameters.display
                                                                      .currentLuminanceNits,
                                                              parameters.layer.source.buffer
                                                                      .maxLuminanceNits,
                                                              hardwareBuffer,
                                                              parameters.display.renderIntent);
    }
    return shader;
}

sk_sp<SkShader> SkiaRenderEngine::localTonemap(sk_sp<SkShader> shader, float inputMultiplier,
                                               float targetHdrSdrRatio) {
    static MouriMap kMapper;
    return kMapper.mouriMap(getActiveContext(), shader, inputMultiplier, targetHdrSdrRatio);
    return mLocalTonemapper.mouriMap(getActiveContext(), shader, inputMultiplier,
                                     targetHdrSdrRatio);
}

void SkiaRenderEngine::initCanvas(SkCanvas* canvas, const DisplaySettings& display) {
@@ -1353,9 +1353,8 @@ void SkiaRenderEngine::tonemapAndDrawGainmapInternal(

    const auto tonemappedShader = localTonemap(hdrShader, 1.0f, 1.0f);

    static GainmapFactory kGainmapFactory;
    const auto gainmapShader =
            kGainmapFactory.createSkShader(tonemappedShader, hdrShader, hdrSdrRatio);
            mGainmapFactory.createSkShader(tonemappedShader, hdrShader, hdrSdrRatio);

    sp<Fence> drawFence;

@@ -1501,19 +1500,7 @@ void SkiaRenderEngine::dump(std::string& result) {
        gpuProtectedReporter.logOutput(result, true);

        StringAppendF(&result, "\n");
        StringAppendF(&result, "RenderEngine runtime effects: %zu\n", mRuntimeEffects.size());
        for (const auto& [linearEffect, unused] : mRuntimeEffects) {
            StringAppendF(&result, "- inputDataspace: %s\n",
                          dataspaceDetails(
                                  static_cast<android_dataspace>(linearEffect.inputDataspace))
                                  .c_str());
            StringAppendF(&result, "- outputDataspace: %s\n",
                          dataspaceDetails(
                                  static_cast<android_dataspace>(linearEffect.outputDataspace))
                                  .c_str());
            StringAppendF(&result, "undoPremultipliedAlpha: %s\n",
                          linearEffect.undoPremultipliedAlpha ? "true" : "false");
        }
        mRuntimeEffectManager.dump(result);
    }
    StringAppendF(&result, "\n");
}
Loading