Start moving SkRasterPipeline stages to SkOpts.
This lets them pick up runtime CPU specializations. Here I've plugged in SSE4.1. This is still one of the N prelude CLs to full 8-at-a-time AVX.
I've moved the union of the stages used by SkRasterPipelineBench and SkRasterPipelineBlitter to SkOpts... they'll all be used by the blitter eventually. Picking up SSE4.1 specialization here (even still just 4 pixels at a time) is a significant speedup, especially to store_srgb(), so much that it's no longer really interesting to compare against the fused-but-default-instruction-set version in the bench. So that's gone now.
That left the SkRasterPipeline unit test as the only other user of the EasyFn simplified interface to SkRasterPipeline. So I converted that back down to the bare-metal interface, and EasyFn and its friends became SkRasterPipeline_opts.h exclusive abbreviations (now called Kernel_Sk4f). This isn't really unexpected: SkXfermode also wanted to build up its own little abstractions, and once you build your own abstraction, the value of an additional EasyFn-like layer plummets to negative.
For simplicity I've left the SkXfermode stages alone, except srcover() which was always part of the blitter. No particular reason except keeping the churn down while I hack. These _can_ be in SkOpts, but don't have to be until we go 8-at-a-time.
BUG=skia:
GOLD_TRYBOT_URL= https://gold.skia.org/search?issue=2752
CQ_INCLUDE_TRYBOTS=master.client.skia:Test-Ubuntu-GCC-GCE-CPU-AVX2-x86_64-Release-SKNX_NO_SIMD-Trybot
Change-Id: I3b476b18232a1598d8977e425be2150059ab71dc
Reviewed-on: https://skia-review.googlesource.com/2752
Reviewed-by: Mike Klein <mtklein@chromium.org>
Commit-Queue: Mike Klein <mtklein@chromium.org>
diff --git a/src/core/SkRasterPipelineBlitter.cpp b/src/core/SkRasterPipelineBlitter.cpp
index 46820d3..2ada336 100644
--- a/src/core/SkRasterPipelineBlitter.cpp
+++ b/src/core/SkRasterPipelineBlitter.cpp
@@ -8,11 +8,10 @@
#include "SkBlitter.h"
#include "SkColor.h"
#include "SkColorFilter.h"
-#include "SkHalf.h"
+#include "SkOpts.h"
#include "SkPM4f.h"
#include "SkRasterPipeline.h"
#include "SkShader.h"
-#include "SkSRGB.h"
#include "SkXfermode.h"
@@ -57,200 +56,6 @@
return SkRasterPipelineBlitter::Create(dst, paint, alloc);
}
-// Clamp colors into [0,1] premul (e.g. just before storing back to memory).
-SK_RASTER_STAGE(clamp_01_premul) {
- a = Sk4f::Max(a, 0.0f);
- r = Sk4f::Max(r, 0.0f);
- g = Sk4f::Max(g, 0.0f);
- b = Sk4f::Max(b, 0.0f);
-
- a = Sk4f::Min(a, 1.0f);
- r = Sk4f::Min(r, a);
- g = Sk4f::Min(g, a);
- b = Sk4f::Min(b, a);
-}
-
-// The default shader produces a constant color (from the SkPaint).
-SK_RASTER_STAGE(constant_color) {
- auto color = (const SkPM4f*)ctx;
- r = color->r();
- g = color->g();
- b = color->b();
- a = color->a();
-}
-
-// The default transfer mode is srcover, s' = s + d*(1-sa).
-SK_RASTER_STAGE(srcover) {
- r += dr*(1.0f - a);
- g += dg*(1.0f - a);
- b += db*(1.0f - a);
- a += da*(1.0f - a);
-}
-
-static Sk4f lerp(const Sk4f& from, const Sk4f& to, const Sk4f& cov) {
- return from + (to-from)*cov;
-}
-
-// s' = d(1-c) + sc, for a constant c.
-SK_RASTER_STAGE(lerp_constant_float) {
- Sk4f c = *(const float*)ctx;
-
- r = lerp(dr, r, c);
- g = lerp(dg, g, c);
- b = lerp(db, b, c);
- a = lerp(da, a, c);
-}
-
-template <typename T>
-static SkNx<4,T> load_tail(size_t tail, const T* src) {
- if (tail) {
- return SkNx<4,T>(src[0], (tail>1 ? src[1] : 0), (tail>2 ? src[2] : 0), 0);
- }
- return SkNx<4,T>::Load(src);
-}
-
-template <typename T>
-static void store_tail(size_t tail, const SkNx<4,T>& v, T* dst) {
- switch(tail) {
- case 0: return v.store(dst);
- case 3: dst[2] = v[2];
- case 2: dst[1] = v[1];
- case 1: dst[0] = v[0];
- }
-}
-
-// s' = d(1-c) + sc for 8-bit c.
-SK_RASTER_STAGE(lerp_a8) {
- auto ptr = (const uint8_t*)ctx + x;
-
- Sk4f c = SkNx_cast<float>(load_tail(tail, ptr)) * (1/255.0f);
- r = lerp(dr, r, c);
- g = lerp(dg, g, c);
- b = lerp(db, b, c);
- a = lerp(da, a, c);
-}
-
-static void from_565(const Sk4h& _565, Sk4f* r, Sk4f* g, Sk4f* b) {
- Sk4i _32_bit = SkNx_cast<int>(_565);
-
- *r = SkNx_cast<float>(_32_bit & SK_R16_MASK_IN_PLACE) * (1.0f / SK_R16_MASK_IN_PLACE);
- *g = SkNx_cast<float>(_32_bit & SK_G16_MASK_IN_PLACE) * (1.0f / SK_G16_MASK_IN_PLACE);
- *b = SkNx_cast<float>(_32_bit & SK_B16_MASK_IN_PLACE) * (1.0f / SK_B16_MASK_IN_PLACE);
-}
-
-static Sk4h to_565(const Sk4f& r, const Sk4f& g, const Sk4f& b) {
- return SkNx_cast<uint16_t>( Sk4f_round(r * SK_R16_MASK) << SK_R16_SHIFT
- | Sk4f_round(g * SK_G16_MASK) << SK_G16_SHIFT
- | Sk4f_round(b * SK_B16_MASK) << SK_B16_SHIFT);
-}
-
-// s' = d(1-c) + sc for 565 c.
-SK_RASTER_STAGE(lerp_lcd16) {
- auto ptr = (const uint16_t*)ctx + x;
- Sk4f cr, cg, cb;
- from_565(load_tail(tail, ptr), &cr, &cg, &cb);
-
- r = lerp(dr, r, cr);
- g = lerp(dg, g, cg);
- b = lerp(db, b, cb);
- a = 1.0f;
-}
-
-SK_RASTER_STAGE(load_d_565) {
- auto ptr = (const uint16_t*)ctx + x;
- from_565(load_tail(tail, ptr), &dr,&dg,&db);
- da = 1.0f;
-}
-
-SK_RASTER_STAGE(store_565) {
- auto ptr = (uint16_t*)ctx + x;
- store_tail(tail, to_565(r,g,b), ptr);
-}
-
-SK_RASTER_STAGE(load_d_f16) {
- auto ptr = (const uint64_t*)ctx + x;
-
- if (tail) {
- auto p0 = SkHalfToFloat_finite_ftz(ptr[0]) ,
- p1 = tail>1 ? SkHalfToFloat_finite_ftz(ptr[1]) : Sk4f{0},
- p2 = tail>2 ? SkHalfToFloat_finite_ftz(ptr[2]) : Sk4f{0};
- dr = { p0[0],p1[0],p2[0],0 };
- dg = { p0[1],p1[1],p2[1],0 };
- db = { p0[2],p1[2],p2[2],0 };
- da = { p0[3],p1[3],p2[3],0 };
- return;
- }
-
- Sk4h rh, gh, bh, ah;
- Sk4h_load4(ptr, &rh, &gh, &bh, &ah);
- dr = SkHalfToFloat_finite_ftz(rh);
- dg = SkHalfToFloat_finite_ftz(gh);
- db = SkHalfToFloat_finite_ftz(bh);
- da = SkHalfToFloat_finite_ftz(ah);
-}
-
-SK_RASTER_STAGE(store_f16) {
- auto ptr = (uint64_t*)ctx + x;
-
- switch (tail) {
- case 0: return Sk4h_store4(ptr, SkFloatToHalf_finite_ftz(r), SkFloatToHalf_finite_ftz(g),
- SkFloatToHalf_finite_ftz(b), SkFloatToHalf_finite_ftz(a));
-
- case 3: SkFloatToHalf_finite_ftz({r[2], g[2], b[2], a[2]}).store(ptr+2);
- case 2: SkFloatToHalf_finite_ftz({r[1], g[1], b[1], a[1]}).store(ptr+1);
- case 1: SkFloatToHalf_finite_ftz({r[0], g[0], b[0], a[0]}).store(ptr+0);
- }
-}
-
-// Load 8-bit SkPMColor-order sRGB.
-SK_RASTER_STAGE(load_d_srgb) {
- auto ptr = (const uint32_t*)ctx + x;
-
- if (tail) {
- float rs[] = {0,0,0,0},
- gs[] = {0,0,0,0},
- bs[] = {0,0,0,0},
- as[] = {0,0,0,0};
- for (size_t i = 0; i < tail; i++) {
- rs[i] = sk_linear_from_srgb[(ptr[i] >> SK_R32_SHIFT) & 0xff];
- gs[i] = sk_linear_from_srgb[(ptr[i] >> SK_G32_SHIFT) & 0xff];
- bs[i] = sk_linear_from_srgb[(ptr[i] >> SK_B32_SHIFT) & 0xff];
- as[i] = (1/255.0f) * (ptr[i] >> SK_A32_SHIFT) ;
- }
- dr = Sk4f::Load(rs);
- dg = Sk4f::Load(gs);
- db = Sk4f::Load(bs);
- da = Sk4f::Load(as);
- return;
- }
-
- dr = { sk_linear_from_srgb[(ptr[0] >> SK_R32_SHIFT) & 0xff],
- sk_linear_from_srgb[(ptr[1] >> SK_R32_SHIFT) & 0xff],
- sk_linear_from_srgb[(ptr[2] >> SK_R32_SHIFT) & 0xff],
- sk_linear_from_srgb[(ptr[3] >> SK_R32_SHIFT) & 0xff] };
-
- dg = { sk_linear_from_srgb[(ptr[0] >> SK_G32_SHIFT) & 0xff],
- sk_linear_from_srgb[(ptr[1] >> SK_G32_SHIFT) & 0xff],
- sk_linear_from_srgb[(ptr[2] >> SK_G32_SHIFT) & 0xff],
- sk_linear_from_srgb[(ptr[3] >> SK_G32_SHIFT) & 0xff] };
-
- db = { sk_linear_from_srgb[(ptr[0] >> SK_B32_SHIFT) & 0xff],
- sk_linear_from_srgb[(ptr[1] >> SK_B32_SHIFT) & 0xff],
- sk_linear_from_srgb[(ptr[2] >> SK_B32_SHIFT) & 0xff],
- sk_linear_from_srgb[(ptr[3] >> SK_B32_SHIFT) & 0xff] };
-
- da = SkNx_cast<float>(Sk4u::Load(ptr) >> SK_A32_SHIFT) * (1/255.0f);
-}
-
-// Store 8-bit SkPMColor-order sRGB.
-SK_RASTER_STAGE(store_srgb) {
- auto ptr = (uint32_t*)ctx + x;
- store_tail(tail, ( sk_linear_to_srgb_noclamp(r) << SK_R32_SHIFT
- | sk_linear_to_srgb_noclamp(g) << SK_G32_SHIFT
- | sk_linear_to_srgb_noclamp(b) << SK_B32_SHIFT
- | Sk4f_round(255.0f * a) << SK_A32_SHIFT), (int*)ptr);
-}
-
static bool supported(const SkImageInfo& info) {
switch (info.colorType()) {
case kN32_SkColorType: return info.gammaCloseToSRGB();
@@ -297,10 +102,10 @@
color.premul());
if (!paint.getShader()) {
- blitter->fShader.append<constant_color>(&blitter->fPaintColor);
+ blitter->fShader.append(SkOpts::constant_color, &blitter->fPaintColor);
}
if (!paint.getXfermode()) {
- blitter->fXfermode.append<srcover>();
+ blitter->fXfermode.append(SkOpts::srcover);
}
return blitter;
@@ -312,41 +117,33 @@
switch (fDst.info().colorType()) {
case kN32_SkColorType:
if (fDst.info().gammaCloseToSRGB()) {
- p->append<load_d_srgb>(dst);
+ p->append(SkOpts::load_d_srgb_body, SkOpts::load_d_srgb_tail, dst);
}
break;
case kRGBA_F16_SkColorType:
- p->append<load_d_f16>(dst);
+ p->append(SkOpts::load_d_f16_body, SkOpts::load_d_f16_tail, dst);
break;
case kRGB_565_SkColorType:
- p->append<load_d_565>(dst);
+ p->append(SkOpts::load_d_565_body, SkOpts::load_d_565_tail, dst);
break;
default: break;
}
}
-template <SkRasterPipeline::EasyFn fn>
-static void clamp_01_premul_then(void* ctx, size_t x, size_t tail,
- Sk4f& r, Sk4f& g, Sk4f& b, Sk4f& a,
- Sk4f& dr, Sk4f& dg, Sk4f& db, Sk4f& da) {
- clamp_01_premul(nullptr, x,tail, r,g,b,a, dr,dg,db,da);
- fn( ctx, x,tail, r,g,b,a, dr,dg,db,da);
-}
-
void SkRasterPipelineBlitter::append_store(SkRasterPipeline* p, void* dst) const {
SkASSERT(supported(fDst.info()));
switch (fDst.info().colorType()) {
case kN32_SkColorType:
if (fDst.info().gammaCloseToSRGB()) {
- p->last<clamp_01_premul_then<store_srgb>>(dst);
+ p->append(SkOpts::store_srgb_body, SkOpts::store_srgb_tail, dst);
}
break;
case kRGBA_F16_SkColorType:
- p->last<clamp_01_premul_then<store_f16>>(dst);
+ p->append(SkOpts::store_f16_body, SkOpts::store_f16_tail, dst);
break;
case kRGB_565_SkColorType:
- p->last<clamp_01_premul_then<store_565>>(dst);
+ p->append(SkOpts::store_565_body, SkOpts::store_565_tail, dst);
break;
default: break;
}
@@ -374,7 +171,7 @@
p.extend(fColorFilter);
this->append_load_d(&p, dst);
p.extend(fXfermode);
- p.append<lerp_constant_float>(&coverage);
+ p.append(SkOpts::lerp_constant_float, &coverage);
this->append_store(&p, dst);
for (int16_t run = *runs; run > 0; run = *runs) {
@@ -404,10 +201,10 @@
p.extend(fXfermode);
switch (mask.fFormat) {
case SkMask::kA8_Format:
- p.append<lerp_a8>(mask.getAddr8(x,y)-x);
+ p.append(SkOpts::lerp_u8_body, SkOpts::lerp_u8_tail, mask.getAddr8(x,y)-x);
break;
case SkMask::kLCD16_Format:
- p.append<lerp_lcd16>(mask.getAddrLCD16(x,y)-x);
+ p.append(SkOpts::lerp_565_body, SkOpts::lerp_565_tail, mask.getAddrLCD16(x,y)-x);
break;
default: break;
}