SkGradientShader extremly slow when CPU-based skia

134 views
Skip to first unread message

Mick Sam

unread,
Jul 19, 2022, 6:56:05 AM7/19/22
to skia-discuss
Hi,
We are trying to use SKIA as our backend renderer. Due to external limitations, we have to use the CPU renderer.
We are facing an extremely slow rendering when using gradients. Can we somehow optimize it?

Code snippet:

#define WIDTH 1280
#define HEIGHT 720

void* pixels;
sk_sp<SkSurface> surface;
SkCanvas* canvas = nullptr;

static void createCanvas(unsigned int width, unsigned int height) {
    static constexpr auto BPP = 4;

    if (pixels) free(pixels);
    pixels = (void*) malloc (width * height * BPP);

    static constexpr SkAlphaType at = kPremul_SkAlphaType;
    const SkImageInfo info = SkImageInfo::MakeN32(width, height, at);

    surface = SkSurface::MakeRasterDirect(info, pixels, width * BPP);

    canvas = surface->getCanvas();
}

void drawFrame() {
    clock_t t = clock();

    SkPoint points[2] = {SkPoint::Make(0.0f, 0.0f), SkPoint::Make(256.0f, 256.0f)};
    SkColor colors[2] = {SK_ColorBLUE, SK_ColorYELLOW};
    SkPaint paint;
    paint.setShader(SkGradientShader::MakeLinear(points, colors, nullptr, 2, SkTileMode::kClamp, 0, nullptr));
    canvas->drawPaint(paint);

    t = clock() - t;
    double time_taken = ((double)t)/CLOCKS_PER_SEC;
    printf("Frame rendering time %f sec\n", time_taken);
}

Frame rendering time 0.343467 sec

I am building skia using:

gn gen out/Shared --args=" \
    extra_cflags=[\"-fno-rtti\", \"-flto\", \"-O3\", \"-DSK_DISABLE_SKPICTURE\", \"-DSK_DISABLE_TEXT\", \"-DSK_DISABLE_LEGACY_SHADERCONTEXT\", \"-DSK_DISABLE_LOWP_RASTER_PIPELINE\", \"-DSK_FORCE_RASTER_PIPELINE_BLITTER\", \"-DSK_DISABLE_AAA\", \"-DSK_DISABLE_EFFECT_DESERIALIZATION\"] \
    is_official_build=true \
    skia_use_gl=false \
    skia_enable_gpu=false \
    skia_use_zlib=false \
    skia_enable_fontmgr_empty=false \
    skia_use_libpng_encode=false \
    skia_use_libpng_decode=false \
    skia_enable_skgpu_v1=false \
    skia_use_dng_sdk=false \
    skia_use_egl=false \
    skia_use_expat=false \
    skia_use_fontconfig=false \
    skia_use_freetype=false \
    skia_use_icu=false \
    skia_use_libheif=false \
    skia_use_system_libpng=false \
    skia_use_system_libjpeg_turbo=false \
    skia_use_libjpeg_turbo_encode=false \
    skia_use_libjpeg_turbo_decode=false \
    skia_use_libwebp_encode=false \
    skia_use_libwebp_decode=false \
    skia_use_system_libwebp=false \
    skia_use_lua=false \
    skia_use_piex=false \
    skia_use_vulkan=false \
    skia_use_metal=false \
    skia_use_angle=false \
    skia_use_system_zlib=false \
    skia_enable_spirv_validation=false \
    skia_enable_pdf=false \
    skia_enable_skottie=false \
    skia_enable_tools=false \
    skia_enable_skgpu_v2=false"

Brian Osman

unread,
Jul 19, 2022, 7:37:25 AM7/19/22
to skia-d...@googlegroups.com
Two things: What compiler are you using? (Much of Skia's CPU backend is only optimized well if you use clang). Second, it looks like you're trying to reduce code size, and most of the defines you're setting will do that without affecting performance. However, defining  SK_DISABLE_LOWP_RASTER_PIPELINEwill have an impact (assuming you're on an architecture with SIMD, and using clang). For something simple like a linear gradient, the LOWP pipeline is certainly faster (probably from 1.5x to 2x).

--
You received this message because you are subscribed to the Google Groups "skia-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to skia-discuss...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/skia-discuss/bc648a26-b6b3-43e7-9516-10af0ded6fbdn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages