SSE2 implementation of RGBA box blurs. This yields ~2X perf improvement on Xeon ES-2690.
R=mtklein@google.com Review URL: https://codereview.chromium.org/61643011 git-svn-id: http://skia.googlecode.com/svn/trunk@12204 2bbb7eff-a529-9590-31e7-b0007b416f81
This commit is contained in:
parent
11e5b972a9
commit
27eec46d69
@ -84,6 +84,10 @@ private:
|
||||
typedef SkBenchmark INHERITED;
|
||||
};
|
||||
|
||||
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, 0, false);)
|
||||
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, 0, false);)
|
||||
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_LARGE, false);)
|
||||
DEF_BENCH(return new BlurImageFilterBench(0, BLUR_SIGMA_SMALL, false);)
|
||||
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, true);)
|
||||
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_SMALL, BLUR_SIGMA_SMALL, false);)
|
||||
DEF_BENCH(return new BlurImageFilterBench(BLUR_SIGMA_LARGE, BLUR_SIGMA_LARGE, true);)
|
||||
|
@ -51,6 +51,7 @@
|
||||
'../src/opts/SkBitmapFilter_opts_SSE2.cpp',
|
||||
'../src/opts/SkBlitRow_opts_SSE2.cpp',
|
||||
'../src/opts/SkBlitRect_opts_SSE2.cpp',
|
||||
'../src/opts/SkBlurImage_opts_SSE2.cpp',
|
||||
'../src/opts/SkMorphology_opts_SSE2.cpp',
|
||||
'../src/opts/SkUtils_opts_SSE2.cpp',
|
||||
'../src/opts/SkXfermode_opts_none.cpp',
|
||||
@ -78,6 +79,7 @@
|
||||
'../src/opts/SkBlitMask_opts_arm.cpp',
|
||||
'../src/opts/SkBlitRow_opts_arm.cpp',
|
||||
'../src/opts/SkBlitRow_opts_arm.h',
|
||||
'../src/opts/SkBlurImage_opts_none.cpp',
|
||||
'../src/opts/SkMorphology_opts_none.cpp',
|
||||
'../src/opts/SkXfermode_opts_arm.cpp',
|
||||
],
|
||||
@ -102,6 +104,7 @@
|
||||
'../src/opts/SkBitmapProcState_opts_none.cpp',
|
||||
'../src/opts/SkBlitMask_opts_none.cpp',
|
||||
'../src/opts/SkBlitRow_opts_none.cpp',
|
||||
'../src/opts/SkBlurImage_opts_none.cpp',
|
||||
'../src/opts/SkMorphology_opts_none.cpp',
|
||||
'../src/opts/SkUtils_opts_none.cpp',
|
||||
'../src/opts/SkXfermode_opts_none.cpp',
|
||||
|
@ -10,6 +10,7 @@
|
||||
#include "SkColorPriv.h"
|
||||
#include "SkFlattenableBuffers.h"
|
||||
#include "SkGpuBlurUtils.h"
|
||||
#include "SkBlurImage_opts.h"
|
||||
#if SK_SUPPORT_GPU
|
||||
#include "GrContext.h"
|
||||
#include "SkImageFilterUtils.h"
|
||||
@ -125,26 +126,6 @@ static void boxBlur(const SkPMColor* src, int srcStride, SkPMColor* dst, int ker
|
||||
}
|
||||
}
|
||||
|
||||
static void boxBlurX(const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize,
|
||||
int leftOffset, int rightOffset, int width, int height)
|
||||
{
|
||||
boxBlur<kX, kX>(src, srcStride, dst, kernelSize, leftOffset, rightOffset, width, height);
|
||||
}
|
||||
|
||||
#ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
|
||||
static void boxBlurXY(const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize,
|
||||
int leftOffset, int rightOffset, int width, int height)
|
||||
{
|
||||
boxBlur<kX, kY>(src, srcStride, dst, kernelSize, leftOffset, rightOffset, width, height);
|
||||
}
|
||||
#endif
|
||||
|
||||
static void boxBlurY(const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize,
|
||||
int topOffset, int bottomOffset, int width, int height)
|
||||
{
|
||||
boxBlur<kY, kY>(src, srcStride, dst, kernelSize, topOffset, bottomOffset, width, height);
|
||||
}
|
||||
|
||||
static void getBox3Params(SkScalar s, int *kernelSize, int* kernelSize3, int *lowOffset,
|
||||
int *highOffset)
|
||||
{
|
||||
@ -212,6 +193,13 @@ bool SkBlurImageFilter::onFilterImage(Proxy* proxy,
|
||||
SkPMColor* d = dst->getAddr32(0, 0);
|
||||
int w = dstBounds.width(), h = dstBounds.height();
|
||||
int sw = src.rowBytesAsPixels();
|
||||
SkBoxBlurProc boxBlurX, boxBlurY, boxBlurXY;
|
||||
if (!SkBoxBlurGetPlatformProcs(&boxBlurX, &boxBlurY, &boxBlurXY)) {
|
||||
boxBlurX = boxBlur<kX, kX>;
|
||||
boxBlurY = boxBlur<kY, kY>;
|
||||
boxBlurXY = boxBlur<kX, kY>;
|
||||
}
|
||||
|
||||
if (kernelSizeX > 0 && kernelSizeY > 0) {
|
||||
#ifndef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
|
||||
boxBlurX(s, sw, t, kernelSizeX, lowOffsetX, highOffsetX, w, h);
|
||||
|
19
src/opts/SkBlurImage_opts.h
Normal file
19
src/opts/SkBlurImage_opts.h
Normal file
@ -0,0 +1,19 @@
|
||||
/*
|
||||
* Copyright 2013 The Android Open Source Project
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#ifndef SkBlurImage_opts_DEFINED
|
||||
#define SkBlurImage_opts_DEFINED
|
||||
|
||||
#include "SkColorPriv.h"
|
||||
|
||||
typedef void (*SkBoxBlurProc)(const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize,
|
||||
int leftOffset, int rightOffset, int width, int height);
|
||||
|
||||
bool SkBoxBlurGetPlatformProcs(SkBoxBlurProc* boxBlurX,
|
||||
SkBoxBlurProc* boxBlurY,
|
||||
SkBoxBlurProc* boxBlurXY);
|
||||
#endif
|
115
src/opts/SkBlurImage_opts_SSE2.cpp
Normal file
115
src/opts/SkBlurImage_opts_SSE2.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
/*
|
||||
* Copyright 2013 The Android Open Source Project
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
|
||||
#include "SkBitmap.h"
|
||||
#include "SkColorPriv.h"
|
||||
#include "SkBlurImage_opts_SSE2.h"
|
||||
#include "SkRect.h"
|
||||
|
||||
#include <emmintrin.h>
|
||||
|
||||
namespace {
|
||||
|
||||
enum BlurDirection {
|
||||
kX, kY
|
||||
};
|
||||
|
||||
/**
|
||||
* Helper function to spread the components of a 32-bit integer into the
|
||||
* lower 8 bits of each 32-bit element of an SSE register.
|
||||
*/
|
||||
|
||||
inline __m128i expand(int a) {
|
||||
const __m128i zero = _mm_setzero_si128();
|
||||
|
||||
// 0 0 0 0 0 0 0 0 0 0 0 0 A R G B
|
||||
__m128i result = _mm_cvtsi32_si128(a);
|
||||
|
||||
// 0 0 0 0 0 0 0 0 0 A 0 R 0 G 0 B
|
||||
result = _mm_unpacklo_epi8(result, zero);
|
||||
|
||||
// 0 0 0 A 0 0 0 R 0 0 0 G 0 0 0 B
|
||||
return _mm_unpacklo_epi16(result, zero);
|
||||
}
|
||||
|
||||
template<BlurDirection srcDirection, BlurDirection dstDirection>
|
||||
void SkBoxBlur_SSE2(const SkPMColor* src, int srcStride, SkPMColor* dst, int kernelSize,
|
||||
int leftOffset, int rightOffset, int width, int height)
|
||||
{
|
||||
const int rightBorder = SkMin32(rightOffset + 1, width);
|
||||
const int srcStrideX = srcDirection == kX ? 1 : srcStride;
|
||||
const int dstStrideX = dstDirection == kX ? 1 : height;
|
||||
const int srcStrideY = srcDirection == kX ? srcStride : 1;
|
||||
const int dstStrideY = dstDirection == kX ? width : 1;
|
||||
const __m128i scale = _mm_set1_epi32((1 << 24) / kernelSize);
|
||||
const __m128i half = _mm_set1_epi32(1 << 23);
|
||||
const __m128i zero = _mm_setzero_si128();
|
||||
for (int y = 0; y < height; ++y) {
|
||||
__m128i sum = zero;
|
||||
const SkPMColor* p = src;
|
||||
for (int i = 0; i < rightBorder; ++i) {
|
||||
sum = _mm_add_epi32(sum, expand(*p));
|
||||
p += srcStrideX;
|
||||
}
|
||||
|
||||
const SkPMColor* sptr = src;
|
||||
SkColor* dptr = dst;
|
||||
for (int x = 0; x < width; ++x) {
|
||||
#if 0
|
||||
// In SSE4.1, this would be
|
||||
__m128i result = _mm_mullo_epi32(sum, scale);
|
||||
#else
|
||||
// But SSE2 has no PMULLUD, so we must do AG and RB separately.
|
||||
__m128i tmp1 = _mm_mul_epu32(sum, scale);
|
||||
__m128i tmp2 = _mm_mul_epu32(_mm_srli_si128(sum, 4),
|
||||
_mm_srli_si128(scale, 4));
|
||||
__m128i result = _mm_unpacklo_epi32(_mm_shuffle_epi32(tmp1, _MM_SHUFFLE(0,0,2,0)),
|
||||
_mm_shuffle_epi32(tmp2, _MM_SHUFFLE(0,0,2,0)));
|
||||
#endif
|
||||
// sumA*scale+.5 sumB*scale+.5 sumG*scale+.5 sumB*scale+.5
|
||||
result = _mm_add_epi32(result, half);
|
||||
|
||||
// 0 0 0 A 0 0 0 R 0 0 0 G 0 0 0 B
|
||||
result = _mm_srli_epi32(result, 24);
|
||||
|
||||
// 0 0 0 0 0 0 0 0 0 A 0 R 0 G 0 B
|
||||
result = _mm_packs_epi32(result, zero);
|
||||
|
||||
// 0 0 0 0 0 0 0 0 0 0 0 0 A R G B
|
||||
result = _mm_packus_epi16(result, zero);
|
||||
*dptr = _mm_cvtsi128_si32(result);
|
||||
if (x >= leftOffset) {
|
||||
SkColor l = *(sptr - leftOffset * srcStrideX);
|
||||
sum = _mm_sub_epi32(sum, expand(l));
|
||||
}
|
||||
if (x + rightOffset + 1 < width) {
|
||||
SkColor r = *(sptr + (rightOffset + 1) * srcStrideX);
|
||||
sum = _mm_add_epi32(sum, expand(r));
|
||||
}
|
||||
sptr += srcStrideX;
|
||||
if (srcDirection == kY) {
|
||||
_mm_prefetch(reinterpret_cast<const char*>(sptr + (rightOffset + 1) * srcStrideX),
|
||||
_MM_HINT_T0);
|
||||
}
|
||||
dptr += dstStrideX;
|
||||
}
|
||||
src += srcStrideY;
|
||||
dst += dstStrideY;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool SkBoxBlurGetPlatformProcs_SSE2(SkBoxBlurProc* boxBlurX,
|
||||
SkBoxBlurProc* boxBlurY,
|
||||
SkBoxBlurProc* boxBlurXY) {
|
||||
*boxBlurX = SkBoxBlur_SSE2<kX, kX>;
|
||||
*boxBlurY = SkBoxBlur_SSE2<kY, kY>;
|
||||
*boxBlurXY = SkBoxBlur_SSE2<kX, kY>;
|
||||
return true;
|
||||
}
|
12
src/opts/SkBlurImage_opts_SSE2.h
Normal file
12
src/opts/SkBlurImage_opts_SSE2.h
Normal file
@ -0,0 +1,12 @@
|
||||
/*
|
||||
* Copyright 2013 The Android Open Source Project
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkBlurImage_opts.h"
|
||||
|
||||
bool SkBoxBlurGetPlatformProcs_SSE2(SkBoxBlurProc* boxBlurX,
|
||||
SkBoxBlurProc* boxBlurY,
|
||||
SkBoxBlurProc* boxBlurXY);
|
14
src/opts/SkBlurImage_opts_none.cpp
Normal file
14
src/opts/SkBlurImage_opts_none.cpp
Normal file
@ -0,0 +1,14 @@
|
||||
/*
|
||||
* Copyright 2013 The Android Open Source Project
|
||||
*
|
||||
* Use of this source code is governed by a BSD-style license that can be
|
||||
* found in the LICENSE file.
|
||||
*/
|
||||
|
||||
#include "SkBlurImage_opts.h"
|
||||
|
||||
bool SkBoxBlurGetPlatformProcs(SkBoxBlurProc* boxBlurX,
|
||||
SkBoxBlurProc* boxBlurY,
|
||||
SkBoxBlurProc* boxBlurXY) {
|
||||
return false;
|
||||
}
|
@ -12,6 +12,7 @@
|
||||
#include "SkBlitRow.h"
|
||||
#include "SkBlitRect_opts_SSE2.h"
|
||||
#include "SkBlitRow_opts_SSE2.h"
|
||||
#include "SkBlurImage_opts_SSE2.h"
|
||||
#include "SkUtils_opts_SSE2.h"
|
||||
#include "SkUtils.h"
|
||||
#include "SkMorphology_opts.h"
|
||||
@ -268,6 +269,19 @@ SkMorphologyProc SkMorphologyGetPlatformProc(SkMorphologyProcType type) {
|
||||
}
|
||||
}
|
||||
|
||||
bool SkBoxBlurGetPlatformProcs(SkBoxBlurProc* boxBlurX,
|
||||
SkBoxBlurProc* boxBlurY,
|
||||
SkBoxBlurProc* boxBlurXY) {
|
||||
#ifdef SK_DISABLE_BLUR_DIVISION_OPTIMIZATION
|
||||
return false;
|
||||
#else
|
||||
if (!cachedHasSSE2()) {
|
||||
return false;
|
||||
}
|
||||
return SkBoxBlurGetPlatformProcs_SSE2(boxBlurX, boxBlurY, boxBlurXY);
|
||||
#endif
|
||||
}
|
||||
|
||||
SkBlitRow::ColorRectProc PlatformColorRectProcFactory(); // suppress warning
|
||||
|
||||
SkBlitRow::ColorRectProc PlatformColorRectProcFactory() {
|
||||
|
Loading…
Reference in New Issue
Block a user