update/add benches to look at colorspace as well as alphatype

Example run:

  24/24  MB	14	332µs	338µs	337µs	341µs	gl	readpix_um_bgra_srgb
  24/24  MB	9	568µs	581µs	581µs	595µs	glsrgb	readpix_um_bgra_srgb
  29/29  MB	10	334µs	340µs	340µs	351µs	gl	readpix_um_bgra_null
  28/29  MB	8	553µs	593µs	592µs	626µs	glsrgb	readpix_um_bgra_null
  32/32  MB	15	334µs	338µs	344µs	388µs	gl	readpix_um_rgba_srgb
  31/32  MB	9	546µs	574µs	571µs	595µs	glsrgb	readpix_um_rgba_srgb
  32/32  MB	10	332µs	340µs	340µs	351µs	gl	readpix_um_rgba_null
  31/32  MB	8	553µs	587µs	589µs	629µs	glsrgb	readpix_um_rgba_null

  54/54  MB	14	364µs	369µs	370µs	383µs	gl	writepix_um_bgra_srgb
  24/54  MB	19	278µs	290µs	288µs	294µs	glsrgb	writepix_um_bgra_srgb
  58/58  MB	14	365µs	376µs	375µs	381µs	gl	writepix_um_bgra_null
  27/58  MB	19	280µs	291µs	291µs	314µs	glsrgb	writepix_um_bgra_null
  59/59  MB	14	368µs	374µs	375µs	382µs	gl	writepix_um_rgba_srgb
  27/59  MB	19	280µs	298µs	295µs	324µs	glsrgb	writepix_um_rgba_srgb
  62/62  MB	14	367µs	378µs	376µs	384µs	gl	writepix_um_rgba_null
  30/62  MB	16	289µs	293µs	296µs	310µs	glsrgb	writepix_um_rgba_null

Bug: skia:
Change-Id: I36e4f68e60a39087c07cf5ff63045a29b56da8f7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/202703
Reviewed-by: Brian Osman <brianosman@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Mike Reed <reed@google.com>
This commit is contained in:
Mike Reed 2019-03-21 15:55:05 -04:00 committed by Skia Commit-Bot
parent bc7402f30a
commit af990f3bb9
2 changed files with 55 additions and 66 deletions

View File

@ -8,61 +8,58 @@
#include "Benchmark.h"
#include "SkBitmap.h"
#include "SkCanvas.h"
#include "SkColorSpace.h"
/**
* This bench mark tests the use case where the user writes the a canvas
* and then reads small chunks from it repeatedly. This can cause trouble
* for the GPU as readbacks are very expensive.
*/
// Time variants of read-pixels
// [ colortype ][ alphatype ][ colorspace ]
// Different combinations can trigger fast or slow paths in the impls
//
class ReadPixBench : public Benchmark {
public:
ReadPixBench() {}
ReadPixBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
: fCT(ct), fAT(at), fCS(cs)
{
fName.printf("readpix_%s_%s_%s",
at == kPremul_SkAlphaType ? "pm" : "um",
ct == kRGBA_8888_SkColorType ? "rgba" : "bgra",
cs ? "srgb" : "null");
}
protected:
const char* onGetName() override {
return "readpix";
return fName.c_str();
}
void onDraw(int loops, SkCanvas* canvas) override {
canvas->clear(SK_ColorBLACK);
canvas->clear(0x80000000);
SkISize size = canvas->getBaseLayerSize();
int offX = (size.width() - kWindowSize) / kNumStepsX;
int offY = (size.height() - kWindowSize) / kNumStepsY;
SkPaint paint;
paint.setColor(SK_ColorBLUE);
canvas->drawCircle(SkIntToScalar(size.width()/2),
SkIntToScalar(size.height()/2),
SkIntToScalar(size.width()/2),
paint);
auto info = SkImageInfo::Make(size.width(), size.height(), fCT, fAT, fCS);
SkBitmap bitmap;
bitmap.allocPixels(SkImageInfo::MakeN32Premul(kWindowSize, kWindowSize));
bitmap.allocPixels(info);
for (int i = 0; i < loops; i++) {
for (int x = 0; x < kNumStepsX; ++x) {
for (int y = 0; y < kNumStepsY; ++y) {
canvas->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(),
x * offX, y * offY);
}
}
canvas->readPixels(bitmap.info(), bitmap.getPixels(), bitmap.rowBytes(), 0, 0);
}
}
private:
static const int kNumStepsX = 30;
static const int kNumStepsY = 30;
static const int kWindowSize = 5;
SkColorType fCT;
SkAlphaType fAT;
sk_sp<SkColorSpace> fCS;
SkString fName;
typedef Benchmark INHERITED;
};
DEF_BENCH( return new ReadPixBench(); )
DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr); )
DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr); )
DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
DEF_BENCH( return new ReadPixBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr); )
DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr); )
DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
DEF_BENCH( return new ReadPixBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB()); )
////////////////////////////////////////////////////////////////////////////////
#include "SkBitmap.h"

View File

@ -10,35 +10,21 @@
#include "SkCanvas.h"
#include "SkString.h"
// Time variants of write-pixels
// [ colortype ][ alphatype ][ colorspace ]
// Different combinations can trigger fast or slow paths in the impls
//
class WritePixelsBench : public Benchmark {
public:
WritePixelsBench(SkColorType ct, SkAlphaType at)
WritePixelsBench(SkColorType ct, SkAlphaType at, sk_sp<SkColorSpace> cs)
: fColorType(ct)
, fAlphaType(at)
, fName("writepix")
, fCS(cs)
{
switch (ct) {
case kRGBA_8888_SkColorType:
fName.append("_RGBA");
break;
case kBGRA_8888_SkColorType:
fName.append("_BGRA");
break;
default:
SkASSERT(0);
break;
}
switch (at) {
case kPremul_SkAlphaType:
fName.append("_PM");
break;
case kUnpremul_SkAlphaType:
fName.append("_UPM");
break;
default:
SkASSERT(0);
break;
}
fName.printf("writepix_%s_%s_%s",
at == kPremul_SkAlphaType ? "pm" : "um",
ct == kRGBA_8888_SkColorType ? "rgba" : "bgra",
cs ? "srgb" : "null");
}
protected:
@ -49,13 +35,11 @@ protected:
void onDraw(int loops, SkCanvas* canvas) override {
SkISize size = canvas->getBaseLayerSize();
canvas->clear(0xFFFF0000);
SkImageInfo info = SkImageInfo::Make(size.width(), size.height(), fColorType, fAlphaType,
fCS);
SkBitmap bmp;
bmp.allocN32Pixels(size.width(), size.height());
canvas->readPixels(bmp, 0, 0);
SkImageInfo info = SkImageInfo::Make(bmp.width(), bmp.height(), fColorType, fAlphaType);
bmp.allocPixels(info);
bmp.eraseColor(SK_ColorBLACK);
for (int loop = 0; loop < loops; ++loop) {
canvas->writePixels(info, bmp.getPixels(), bmp.rowBytes(), 0, 0);
@ -65,6 +49,7 @@ protected:
private:
SkColorType fColorType;
SkAlphaType fAlphaType;
sk_sp<SkColorSpace> fCS;
SkString fName;
typedef Benchmark INHERITED;
@ -72,5 +57,12 @@ private:
//////////////////////////////////////////////////////////////////////////////
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType);)
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType);)
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
DEF_BENCH(return new WritePixelsBench(kRGBA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, nullptr);)
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, nullptr);)
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kPremul_SkAlphaType, SkColorSpace::MakeSRGB());)
DEF_BENCH(return new WritePixelsBench(kBGRA_8888_SkColorType, kUnpremul_SkAlphaType, SkColorSpace::MakeSRGB());)