Commit e6545fdf authored by Dmitry Kazakov's avatar Dmitry Kazakov

Optimize Sharp brushes by 5% more

When Fade is 100% and "Antialias Edges" option is off, there is no need
to calculate vNormFade term. Anyway the result will be +-inf :)
parent 282d2f0c
...@@ -60,19 +60,17 @@ void KisMaskGeneratorBenchmark::benchmarkCircle() ...@@ -60,19 +60,17 @@ void KisMaskGeneratorBenchmark::benchmarkCircle()
#include "krita_utils.h" #include "krita_utils.h"
void KisMaskGeneratorBenchmark::benchmarkSIMD() void benchmarkSIMD(qreal fade) {
{
#ifdef HAVE_VC
const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8(); const KoColorSpace * cs = KoColorSpaceRegistry::instance()->rgb8();
KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs); KisFixedPaintDeviceSP dev = new KisFixedPaintDevice(cs);
dev->setRect(QRect(0, 0, 100, 100)); dev->setRect(QRect(0, 0, 1000, 1000));
dev->initialize(); dev->initialize();
MaskProcessingData data(dev, cs, MaskProcessingData data(dev, cs,
0.0, 1.0, 0.0, 1.0,
50, 50, 0); 500, 500, 0);
KisCircleMaskGenerator gen(100, 0.5, 0.5, 0.5, 2, false); KisCircleMaskGenerator gen(1000, 1.0, fade, fade, 2, false);
KisBrushMaskApplicatorBase *applicator = gen.applicator(); KisBrushMaskApplicatorBase *applicator = gen.applicator();
applicator->initializeData(&data); applicator->initializeData(&data);
...@@ -84,7 +82,16 @@ void KisMaskGeneratorBenchmark::benchmarkSIMD() ...@@ -84,7 +82,16 @@ void KisMaskGeneratorBenchmark::benchmarkSIMD()
applicator->process(rc); applicator->process(rc);
} }
} }
#endif }
void KisMaskGeneratorBenchmark::benchmarkSIMD_SharpBrush()
{
benchmarkSIMD(1.0);
}
void KisMaskGeneratorBenchmark::benchmarkSIMD_FadedBrush()
{
benchmarkSIMD(0.5);
} }
void KisMaskGeneratorBenchmark::benchmarkSquare() void KisMaskGeneratorBenchmark::benchmarkSquare()
......
...@@ -26,7 +26,8 @@ class KisMaskGeneratorBenchmark : public QObject ...@@ -26,7 +26,8 @@ class KisMaskGeneratorBenchmark : public QObject
Q_OBJECT Q_OBJECT
private Q_SLOTS: private Q_SLOTS:
void benchmarkCircle(); void benchmarkCircle();
void benchmarkSIMD(); void benchmarkSIMD_SharpBrush();
void benchmarkSIMD_FadedBrush();
void benchmarkSquare(); void benchmarkSquare();
}; };
......
...@@ -61,6 +61,7 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i ...@@ -61,6 +61,7 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i
float centerX, float centerY) float centerX, float centerY)
{ {
const bool useSmoothing = d->copyOfAntialiasEdges; const bool useSmoothing = d->copyOfAntialiasEdges;
const bool noFading = d->noFading;
float y_ = y - centerY; float y_ = y - centerY;
float sinay_ = sina * y_; float sinay_ = sina * y_;
...@@ -84,7 +85,7 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i ...@@ -84,7 +85,7 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i
Vc::float_v vTransformedFadeX(d->transformedFadeX); Vc::float_v vTransformedFadeX(d->transformedFadeX);
Vc::float_v vTransformedFadeY(d->transformedFadeY); Vc::float_v vTransformedFadeY(d->transformedFadeY);
Vc::float_v vOne(1.0f); Vc::float_v vOne(Vc::One);
for (int i=0; i < width; i+= Vc::float_v::Size){ for (int i=0; i < width; i+= Vc::float_v::Size){
...@@ -98,6 +99,11 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i ...@@ -98,6 +99,11 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i
if (!outsideMask.isFull()) { if (!outsideMask.isFull()) {
if (noFading) {
Vc::float_v vFade(Vc::Zero);
vFade(outsideMask) = vOne;
vFade.store(bufferPointer, Vc::Aligned);
} else {
if (useSmoothing) { if (useSmoothing) {
xr = Vc::abs(xr) + vOne; xr = Vc::abs(xr) + vOne;
yr = Vc::abs(yr) + vOne; yr = Vc::abs(yr) + vOne;
...@@ -116,6 +122,7 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i ...@@ -116,6 +122,7 @@ FastRowProcessor::process<Vc::CurrentImplementation::current()>(float* buffer, i
vFade(outsideMask) = vOne; vFade(outsideMask) = vOne;
vFade.store(bufferPointer, Vc::Aligned); vFade.store(bufferPointer, Vc::Aligned);
}
} else { } else {
// Mask out everything outside the circle // Mask out everything outside the circle
vOne.store(bufferPointer, Vc::Aligned); vOne.store(bufferPointer, Vc::Aligned);
......
...@@ -70,6 +70,10 @@ void KisCircleMaskGenerator::setScale(qreal scaleX, qreal scaleY) ...@@ -70,6 +70,10 @@ void KisCircleMaskGenerator::setScale(qreal scaleX, qreal scaleY)
d->yfadecoef = (verticalFade() == 0) ? 1 : (2.0 / (verticalFade() * effectiveSrcHeight())); d->yfadecoef = (verticalFade() == 0) ? 1 : (2.0 / (verticalFade() * effectiveSrcHeight()));
d->transformedFadeX = KisMaskGenerator::softness() * d->xfadecoef; d->transformedFadeX = KisMaskGenerator::softness() * d->xfadecoef;
d->transformedFadeY = KisMaskGenerator::softness() * d->yfadecoef; d->transformedFadeY = KisMaskGenerator::softness() * d->yfadecoef;
d->noFading = !d->copyOfAntialiasEdges &&
qFuzzyCompare(d->xcoef, d->transformedFadeX) &&
qFuzzyCompare(d->ycoef, d->transformedFadeY);
} }
KisCircleMaskGenerator::~KisCircleMaskGenerator() KisCircleMaskGenerator::~KisCircleMaskGenerator()
......
...@@ -24,6 +24,7 @@ struct Q_DECL_HIDDEN KisCircleMaskGenerator::Private { ...@@ -24,6 +24,7 @@ struct Q_DECL_HIDDEN KisCircleMaskGenerator::Private {
double xfadecoef, yfadecoef; double xfadecoef, yfadecoef;
double transformedFadeX, transformedFadeY; double transformedFadeX, transformedFadeY;
bool copyOfAntialiasEdges; bool copyOfAntialiasEdges;
bool noFading;
KisBrushMaskApplicatorBase *applicator; KisBrushMaskApplicatorBase *applicator;
}; };
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment