Use infix syntax from skvm
Nothing should draw differently, just wanting to make the code
more readable.
Change-Id: I139f673cd7b28536e91cb2a3c793c86c5fb143cc
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/280819
Commit-Queue: Mike Reed <reed@google.com>
Reviewed-by: Mike Klein <mtklein@google.com>
diff --git a/src/core/SkColorFilter.cpp b/src/core/SkColorFilter.cpp
index 6a18c94..d0e7d75 100644
--- a/src/core/SkColorFilter.cpp
+++ b/src/core/SkColorFilter.cpp
@@ -218,7 +218,7 @@
skvm::Color onProgram(skvm::Builder* p, skvm::Color c, SkColorSpace* dstCS,
skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const override {
- return p->premul(fSteps.program(p, uniforms, p->unpremul(c)));
+ return premul(fSteps.program(p, uniforms, unpremul(c)));
}
protected:
@@ -310,7 +310,7 @@
skvm::Color c0 = fCF0->program(p, c, dstCS, uniforms, alloc);
skvm::Color c1 = fCF1 ? fCF1->program(p, c, dstCS, uniforms, alloc) : c;
return (c0 && c1)
- ? p->lerp(c0, c1, p->uniformF(uniforms->pushF(fWeight)))
+ ? lerp(c0, c1, p->uniformF(uniforms->pushF(fWeight)))
: skvm::Color{};
}
diff --git a/src/core/SkColorFilter_Matrix.cpp b/src/core/SkColorFilter_Matrix.cpp
index 882dfe0..8954418 100644
--- a/src/core/SkColorFilter_Matrix.cpp
+++ b/src/core/SkColorFilter_Matrix.cpp
@@ -87,13 +87,13 @@
skvm::Uniforms* uniforms, SkArenaAlloc*) const {
auto apply_matrix = [&](auto xyzw) {
auto dot = [&](int j) {
- auto mad = [&](float f, skvm::F32 m, skvm::F32 a) {
+ auto custom_mad = [&](float f, skvm::F32 m, skvm::F32 a) {
// skvm::Builder won't fold f*0 == 0, but we shouldn't encounter NaN here.
// While looking, also simplify f == ±1. Anything else becomes a uniform.
return f == 0.0f ? a
- : f == +1.0f ? p->add(m,a)
- : f == -1.0f ? p->sub(a,m)
- : p->mad(p->uniformF(uniforms->pushF(f)), m, a);
+ : f == +1.0f ? a + m
+ : f == -1.0f ? a - m
+ : m * p->uniformF(uniforms->pushF(f)) + a;
};
// Similarly, let skvm::Builder fold away the additive bias when zero.
@@ -102,15 +102,15 @@
: p->uniformF(uniforms->pushF(b));
auto [x,y,z,w] = xyzw;
- return mad(fMatrix[0+j*5], x,
- mad(fMatrix[1+j*5], y,
- mad(fMatrix[2+j*5], z,
- mad(fMatrix[3+j*5], w, bias))));
+ return custom_mad(fMatrix[0+j*5], x,
+ custom_mad(fMatrix[1+j*5], y,
+ custom_mad(fMatrix[2+j*5], z,
+ custom_mad(fMatrix[3+j*5], w, bias))));
};
return std::make_tuple(dot(0), dot(1), dot(2), dot(3));
};
- c = p->unpremul(c);
+ c = unpremul(c);
if (fDomain == Domain::kHSLA) {
auto [h,s,l,a] = apply_matrix(p->to_hsla(c));
@@ -120,7 +120,7 @@
c = {r,g,b,a};
}
- return p->premul(c); // note: rasterpipeline version does clamp01 first
+ return premul(c); // note: rasterpipeline version does clamp01 first
}
#if SK_SUPPORT_GPU
diff --git a/src/core/SkColorSpaceXformSteps.cpp b/src/core/SkColorSpaceXformSteps.cpp
index 67cb62d..4ff8c97 100644
--- a/src/core/SkColorSpaceXformSteps.cpp
+++ b/src/core/SkColorSpaceXformSteps.cpp
@@ -208,7 +208,7 @@
skvm::Color SkColorSpaceXformSteps::program(skvm::Builder* p, skvm::Uniforms* uniforms,
skvm::Color c) const {
if (flags.unpremul) {
- c = p->unpremul(c);
+ c = unpremul(c);
}
if (flags.linearize) {
c = sk_program_transfer_fn(p, uniforms, srcTF, c);
@@ -227,7 +227,7 @@
c = sk_program_transfer_fn(p, uniforms, dstTFInv, c);
}
if (flags.premul) {
- c = p->premul(c);
+ c = premul(c);
}
return c;
}
diff --git a/src/effects/SkHighContrastFilter.cpp b/src/effects/SkHighContrastFilter.cpp
index 83ba5cf..4e0934b 100644
--- a/src/effects/SkHighContrastFilter.cpp
+++ b/src/effects/SkHighContrastFilter.cpp
@@ -147,9 +147,9 @@
c = sk_program_transfer_fn(p, uniforms, tf, c);
if (fConfig.fGrayscale) {
- skvm::F32 gray = p->mad(p->splat(SK_LUM_COEFF_R),c.r,
- p->mad(p->splat(SK_LUM_COEFF_G),c.g,
- p->mul(p->splat(SK_LUM_COEFF_B),c.b)));
+ skvm::F32 gray = c.r * SK_LUM_COEFF_R
+ + c.g * SK_LUM_COEFF_G
+ + c.b * SK_LUM_COEFF_B;
c = {gray, gray, gray, c.a};
}
@@ -165,10 +165,14 @@
const float b = (-0.5f * m + 0.5f);
skvm::F32 M = p->uniformF(uniforms->pushF(m));
skvm::F32 B = p->uniformF(uniforms->pushF(b));
- c = {p->mad(M,c.r, B), p->mad(M,c.g, B), p->mad(M,c.b, B), c.a};
+ c.r = c.r * M + B;
+ c.g = c.g * M + B;
+ c.b = c.b * M + B;
}
- c = {p->clamp01(c.r), p->clamp01(c.g), p->clamp01(c.b), c.a};
+ c.r = clamp01(c.r);
+ c.g = clamp01(c.g);
+ c.b = clamp01(c.b);
// Re-encode back from linear.
if (dstCS) {
diff --git a/src/effects/SkLumaColorFilter.cpp b/src/effects/SkLumaColorFilter.cpp
index 5c15001..13efc75 100644
--- a/src/effects/SkLumaColorFilter.cpp
+++ b/src/effects/SkLumaColorFilter.cpp
@@ -29,12 +29,12 @@
skvm::Color SkLumaColorFilter::onProgram(skvm::Builder* p, skvm::Color c,
SkColorSpace* dstCS,
skvm::Uniforms* uniforms, SkArenaAlloc* alloc) const {
- auto a = p->mad(c.r, p->splat(0.2126f),
- p->mad(c.g, p->splat(0.7152f),
- p->mul(c.b, p->splat(0.0722f))));
- c.a = p->clamp(a, p->splat(0.0f), p->splat(1.0f));
- c.r = c.g = c.b = p->splat(0.0f);
- return c;
+ return {
+ p->splat(0.0f),
+ p->splat(0.0f),
+ p->splat(0.0f),
+ clamp01(c.r * 0.2126f + c.g * 0.7152f + c.b * 0.0722f),
+ };
}
sk_sp<SkColorFilter> SkLumaColorFilter::Make() {
diff --git a/src/effects/SkOverdrawColorFilter.cpp b/src/effects/SkOverdrawColorFilter.cpp
index 13b0e48..d290cc4 100644
--- a/src/effects/SkOverdrawColorFilter.cpp
+++ b/src/effects/SkOverdrawColorFilter.cpp
@@ -76,8 +76,8 @@
skvm::Color SkOverdrawColorFilter::onProgram(skvm::Builder* p, skvm::Color c,
SkColorSpace* /*dstCS*/, skvm::Uniforms* uniforms,
SkArenaAlloc* alloc) const {
- skvm::I32 index = p->min(p->to_unorm(8,c.a), p->splat(kNumColors - 1));
- c = p->unpack_8888(p->gather32(uniforms->pushPtr(fColors), index));
+ skvm::I32 index = min(to_unorm(8,c.a), kNumColors - 1);
+ c = unpack_8888(gather32(uniforms->pushPtr(fColors), index));
std::swap(c.r, c.b); // The SkColors in fColors are BGRA, but we want RGBA
return c;
}
diff --git a/src/effects/SkTableColorFilter.cpp b/src/effects/SkTableColorFilter.cpp
index 8978bb9..87e0bd2 100644
--- a/src/effects/SkTableColorFilter.cpp
+++ b/src/effects/SkTableColorFilter.cpp
@@ -128,15 +128,12 @@
skvm::Uniforms* uniforms, SkArenaAlloc*) const override {
auto apply_table_to_component = [&](skvm::F32 c, const uint8_t* bytePtr) -> skvm::F32 {
- c = p->clamp(c, p->splat(0.f), p->splat(1.0f));
- skvm::I32 index = p->to_unorm(8, c);
-
+ skvm::I32 index = to_unorm(8, clamp01(c));
skvm::Uniform table = uniforms->pushPtr(bytePtr);
- skvm::I32 byte = p->gather8(table, index);
- return p->from_unorm(8, byte);
+ return from_unorm(8, gather8(table, index));
};
- c = p->unpremul(c);
+ c = unpremul(c);
const uint8_t* ptr = fStorage;
if (fFlags & kA_Flag) {
@@ -154,7 +151,7 @@
if (fFlags & kB_Flag) {
c.b = apply_table_to_component(c.b, ptr);
}
- return p->premul(c);
+ return premul(c);
}
protected:
diff --git a/src/shaders/SkImageShader.cpp b/src/shaders/SkImageShader.cpp
index 2d95fa2..e85f0b4 100755
--- a/src/shaders/SkImageShader.cpp
+++ b/src/shaders/SkImageShader.cpp
@@ -691,17 +691,16 @@
auto repeat = [&](skvm::F32 v, float scale) {
skvm::F32 S = p->uniformF(uniforms->pushF( scale)),
I = p->uniformF(uniforms->pushF(1.0f/scale));
- // v - floor(v/scale)*scale
- return p->sub(v, p->mul(p->floor(p->mul(v,I)), S));
+ return v - floor(v * I) * S;
};
auto mirror = [&](skvm::F32 v, float scale) {
skvm::F32 S = p->uniformF(uniforms->pushF( scale)),
I2 = p->uniformF(uniforms->pushF(0.5f/scale));
// abs( (v-scale) - (2*scale)*floor((v-scale)*(0.5f/scale)) - scale )
// {---A---} {------------------B------------------}
- skvm::F32 A = p->sub(v,S),
- B = p->mul(p->add(S,S), p->floor(p->mul(A,I2)));
- return p->abs(p->sub(p->sub(A,B), S));
+ skvm::F32 A = v - S,
+ B = (S + S) * floor(A * I2);
+ return abs(A - B - S);
};
switch (fTileModeX) {
case SkTileMode::kDecal: /* handled after gather */ break;
@@ -718,47 +717,46 @@
// Always clamp sample coordinates to [0,width), [0,height), both for memory
// safety and to handle the clamps still needed by kClamp, kRepeat, and kMirror.
- auto clamp = [&](skvm::F32 v, float limit) {
+ auto clamp0x = [&](skvm::F32 v, float limit) {
// Subtract an ulp so the upper clamp limit excludes limit itself.
int bits;
memcpy(&bits, &limit, 4);
- return p->clamp(v, p->splat(0.0f), p->uniformF(uniforms->push(bits-1)));
+ return clamp(v, 0.0f, p->uniformF(uniforms->push(bits-1)));
};
- skvm::F32 clamped_x = clamp(sx, pm. width()),
- clamped_y = clamp(sy, pm.height());
+ skvm::F32 clamped_x = clamp0x(sx, pm. width()),
+ clamped_y = clamp0x(sy, pm.height());
// Load pixels from pm.addr()[(int)sx + (int)sy*stride].
skvm::Uniform img = uniforms->pushPtr(pm.addr());
- skvm::I32 index = p->add(p->trunc(clamped_x),
- p->mul(p->trunc(clamped_y),
- p->uniform32(uniforms->push(pm.rowBytesAsPixels()))));
+ skvm::I32 index = trunc(clamped_x) +
+ trunc(clamped_y) * p->uniform32(uniforms->push(pm.rowBytesAsPixels()));
skvm::Color c;
switch (pm.colorType()) {
default: SkUNREACHABLE;
- case kGray_8_SkColorType: c.r = c.g = c.b = p->from_unorm(8, p->gather8(img, index));
+ case kGray_8_SkColorType: c.r = c.g = c.b = from_unorm(8, gather8(img, index));
c.a = p->splat(1.0f);
break;
case kAlpha_8_SkColorType: c.r = c.g = c.b = p->splat(0.0f);
- c.a = p->from_unorm(8, p->gather8(img, index));
+ c.a = from_unorm(8, gather8(img, index));
break;
- case kRGB_565_SkColorType: c = p->unpack_565 (p->gather16(img, index)); break;
+ case kRGB_565_SkColorType: c = unpack_565 (gather16(img, index)); break;
case kRGB_888x_SkColorType: [[fallthrough]];
- case kRGBA_8888_SkColorType: c = p->unpack_8888(p->gather32(img, index));
+ case kRGBA_8888_SkColorType: c = unpack_8888(gather32(img, index));
break;
- case kBGRA_8888_SkColorType: c = p->unpack_8888(p->gather32(img, index));
+ case kBGRA_8888_SkColorType: c = unpack_8888(gather32(img, index));
std::swap(c.r, c.b);
break;
case kRGB_101010x_SkColorType: [[fallthrough]];
- case kRGBA_1010102_SkColorType: c = p->unpack_1010102(p->gather32(img, index));
+ case kRGBA_1010102_SkColorType: c = unpack_1010102(gather32(img, index));
break;
case kBGR_101010x_SkColorType: [[fallthrough]];
- case kBGRA_1010102_SkColorType: c = p->unpack_1010102(p->gather32(img, index));
+ case kBGRA_1010102_SkColorType: c = unpack_1010102(gather32(img, index));
std::swap(c.r, c.b);
break;
}
@@ -770,12 +768,12 @@
// Mask away any pixels that we tried to sample outside the bounds in kDecal.
if (fTileModeX == SkTileMode::kDecal || fTileModeY == SkTileMode::kDecal) {
skvm::I32 mask = p->splat(~0);
- if (fTileModeX == SkTileMode::kDecal) { mask = p->bit_and(mask, p->eq(sx, clamped_x)); }
- if (fTileModeY == SkTileMode::kDecal) { mask = p->bit_and(mask, p->eq(sy, clamped_y)); }
- c.r = p->bit_cast(p->bit_and(mask, p->bit_cast(c.r)));
- c.g = p->bit_cast(p->bit_and(mask, p->bit_cast(c.g)));
- c.b = p->bit_cast(p->bit_and(mask, p->bit_cast(c.b)));
- c.a = p->bit_cast(p->bit_and(mask, p->bit_cast(c.a)));
+ if (fTileModeX == SkTileMode::kDecal) { mask &= (sx == clamped_x); }
+ if (fTileModeY == SkTileMode::kDecal) { mask &= (sy == clamped_y); }
+ c.r = bit_cast(p->bit_and(mask, bit_cast(c.r)));
+ c.g = bit_cast(p->bit_and(mask, bit_cast(c.g)));
+ c.b = bit_cast(p->bit_and(mask, bit_cast(c.b)));
+ c.a = bit_cast(p->bit_and(mask, bit_cast(c.a)));
// Notice that even if input_is_opaque, c.a might now be 0.
}
@@ -789,67 +787,61 @@
} else if (quality == kLow_SkFilterQuality) {
// Our four sample points are the corners of a logical 1x1 pixel
// box surrounding (x,y) at (0.5,0.5) off-center.
- skvm::F32 left = p->sub(x, p->splat(0.5f)),
- top = p->sub(y, p->splat(0.5f)),
- right = p->add(x, p->splat(0.5f)),
- bottom = p->add(y, p->splat(0.5f));
+ skvm::F32 left = x - 0.5f,
+ top = y - 0.5f,
+ right = x + 0.5f,
+ bottom = y + 0.5f;
// The fractional parts of right and bottom are our lerp factors in x and y respectively.
- skvm::F32 fx = p->fract(right ),
- fy = p->fract(bottom);
+ skvm::F32 fx = fract(right ),
+ fy = fract(bottom);
- c = p->lerp(p->lerp(sample(left,top ), sample(right,top ), fx),
- p->lerp(sample(left,bottom), sample(right,bottom), fx), fy);
+ c = lerp(lerp(sample(left,top ), sample(right,top ), fx),
+ lerp(sample(left,bottom), sample(right,bottom), fx), fy);
} else {
SkASSERT(quality == kHigh_SkFilterQuality);
// All bicubic samples have the same fractional offset (fx,fy) from the center.
// They're either the 16 corners of a 3x3 grid/ surrounding (x,y) at (0.5,0.5) off-center.
- skvm::F32 fx = p->fract(p->add(x, p->splat(0.5f))),
- fy = p->fract(p->add(y, p->splat(0.5f)));
+ skvm::F32 fx = fract(x + 0.5f),
+ fy = fract(y + 0.5f);
// See GrCubicEffect for details of these weights.
// TODO: these maybe don't seem right looking at gm/bicubic and GrBicubicEffect.
auto near = [&](skvm::F32 t) {
// 1/18 + 9/18t + 27/18t^2 - 21/18t^3 == t ( t ( -21/18t + 27/18) + 9/18) + 1/18
- return p->mad(t,
- p->mad(t,
- p->mad(t, p->splat(-21/18.0f),
- p->splat( 27/18.0f)),
- p->splat( 9/18.0f)),
- p->splat( 1/18.0f));
+ return t * (t * (t * (-21/18.0f) + 27/18.0f) + 9/18.0f) + 1/18.0f;
};
auto far = [&](skvm::F32 t) {
// 0/18 + 0/18*t - 6/18t^2 + 7/18t^3 == t^2 (7/18t - 6/18)
- return p->mul(p->mul(t,t), p->mad(t, p->splat( 7/18.0f),
- p->splat(-6/18.0f)));
+ return t * t * (t * (7/18.0f) - 6/18.0f);
};
const skvm::F32 wx[] = {
- far (p->sub(p->splat(1.0f), fx)),
- near(p->sub(p->splat(1.0f), fx)),
- near( fx ),
- far ( fx ),
+ far (1.0f - fx),
+ near(1.0f - fx),
+ near( fx),
+ far ( fx),
};
const skvm::F32 wy[] = {
- far (p->sub(p->splat(1.0f), fy)),
- near(p->sub(p->splat(1.0f), fy)),
- near( fy ),
- far ( fy ),
+ far (1.0f - fy),
+ near(1.0f - fy),
+ near( fy),
+ far ( fy),
};
c.r = c.g = c.b = c.a = p->splat(0.0f);
- skvm::F32 sy = p->add(y, p->splat(-1.5f));
- for (int j = 0; j < 4; j++, sy = p->add(sy, p->splat(1.0f))) {
- skvm::F32 sx = p->add(x, p->splat(-1.5f));
- for (int i = 0; i < 4; i++, sx = p->add(sx, p->splat(1.0f))) {
+ skvm::F32 sy = y - 1.5f;
+ for (int j = 0; j < 4; j++, sy += 1.0f) {
+ skvm::F32 sx = x - 1.5f;
+ for (int i = 0; i < 4; i++, sx += 1.0f) {
skvm::Color s = sample(sx,sy);
- skvm::F32 w = p->mul(wx[i], wy[j]);
+ skvm::F32 w = wx[i] * wy[j];
- c.r = p->mad(s.r,w, c.r);
- c.g = p->mad(s.g,w, c.g);
- c.b = p->mad(s.b,w, c.b);
- c.a = p->mad(s.a,w, c.a);
+ c.r += s.r * w;
+ c.g += s.g * w;
+ c.b += s.b * w;
+ c.a += s.a * w;
}
}
}
@@ -876,14 +868,14 @@
if (quality == kHigh_SkFilterQuality) {
// Bicubic filtering naturally produces out of range values on both sides of [0,1].
- c.a = p->clamp(c.a, p->splat(0.0f), p->splat(1.0f));
+ c.a = clamp01(c.a);
skvm::F32 limit = (at == kUnpremul_SkAlphaType || fClampAsIfUnpremul)
? p->splat(1.0f)
: c.a;
- c.r = p->clamp(c.r, p->splat(0.0f), limit);
- c.g = p->clamp(c.g, p->splat(0.0f), limit);
- c.b = p->clamp(c.b, p->splat(0.0f), limit);
+ c.r = clamp(c.r, 0.0f, limit);
+ c.g = clamp(c.g, 0.0f, limit);
+ c.b = clamp(c.b, 0.0f, limit);
}
SkColorSpaceXformSteps steps{cs,at, dst.colorSpace(),kPremul_SkAlphaType};
diff --git a/src/utils/SkShadowUtils.cpp b/src/utils/SkShadowUtils.cpp
index 9d272e1..ae9249a 100644
--- a/src/utils/SkShadowUtils.cpp
+++ b/src/utils/SkShadowUtils.cpp
@@ -62,13 +62,11 @@
// exp(-x * x * 4) - 0.018f;
// ... now approximate with quartic
//
- skvm::F32 c4 = p->splat(-2.26661229133605957031f);
- skvm::F32 c3 = p->splat( 2.89795351028442382812f);
- skvm::F32 c2 = p->splat( 0.21345567703247070312f);
- skvm::F32 c1 = p->splat( 0.15489584207534790039f);
- skvm::F32 c0 = p->splat( 0.00030726194381713867f);
- skvm::F32 x = c.a;
- x = p->mad(x, p->mad(x, p->mad(x, p->mad(x, c4, c3), c2), c1), c0);
+ skvm::F32 x = p->splat(-2.26661229133605957031f);
+ x = c.a * x + 2.89795351028442382812f;
+ x = c.a * x + 0.21345567703247070312f;
+ x = c.a * x + 0.15489584207534790039f;
+ x = c.a * x + 0.00030726194381713867f;
return {x, x, x, x};
}