Remove dashing from gpu veto

With new veto our new veto test results look like the following:
TP: true positive (picked to use gpu and gpu was faster)
I: inderminate, the raster time is withing 5% of gpu time

        TP  FP  TN  FN  I

old     21  9   15  12  3
new     29  12  11  6   3

There are three skps that tend to move from TN -> FP, however
the absolute difference in their run times are not huge between
them. The largest being desk_booking which is about 7.1 raster
and 8.8 gpu. The other two skps are desk_yahooanswers and
desk_linkedin

BUG=skia:
R=bsalomon@google.com, robertphillips@google.com

Author: egdaniel@google.com

Review URL: https://codereview.chromium.org/334053005
This commit is contained in:
egdaniel 2014-06-18 07:34:39 -07:00 committed by Commit bot
parent de10fdeee5
commit 12c2198535
4 changed files with 100 additions and 22 deletions

View File

@ -14,6 +14,10 @@
#include "SkTSort.h" #include "SkTSort.h"
#include "SkWriteBuffer.h" #include "SkWriteBuffer.h"
#if SK_SUPPORT_GPU
#include "GrContext.h"
#endif
template <typename T> int SafeCount(const T* obj) { template <typename T> int SafeCount(const T* obj) {
return obj ? obj->count() : 0; return obj ? obj->count() : 0;
} }
@ -1335,27 +1339,51 @@ void SkPicturePlayback::draw(SkCanvas& canvas, SkDrawPictureCallback* callback)
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
bool SkPicturePlayback::suitableForGpuRasterization(GrContext* context, const char **reason) const { bool SkPicturePlayback::suitableForGpuRasterization(GrContext* context, const char **reason,
int sampleCount) const {
// TODO: the heuristic used here needs to be refined // TODO: the heuristic used here needs to be refined
static const int kNumPaintWithPathEffectUsesTol = 1; static const int kNumPaintWithPathEffectUsesTol = 1;
static const int kNumAAConcavePaths = 5; static const int kNumAAConcavePaths = 5;
SkASSERT(fContentInfo.numAAHairlineConcavePaths() <= fContentInfo.numAAConcavePaths()); SkASSERT(fContentInfo.numAAHairlineConcavePaths() <= fContentInfo.numAAConcavePaths());
bool ret = fContentInfo.numPaintWithPathEffectUses() < kNumPaintWithPathEffectUsesTol && int numNonDashedPathEffects = fContentInfo.numPaintWithPathEffectUses() -
fContentInfo.numFastPathDashEffects();
bool suitableForDash = (0 == fContentInfo.numPaintWithPathEffectUses()) ||
(numNonDashedPathEffects < kNumPaintWithPathEffectUsesTol
&& 0 == sampleCount);
bool ret = suitableForDash &&
(fContentInfo.numAAConcavePaths() - fContentInfo.numAAHairlineConcavePaths()) (fContentInfo.numAAConcavePaths() - fContentInfo.numAAHairlineConcavePaths())
< kNumAAConcavePaths; < kNumAAConcavePaths;
if (!ret && NULL != reason) { if (!ret && NULL != reason) {
if (fContentInfo.numPaintWithPathEffectUses() >= kNumPaintWithPathEffectUsesTol) if (!suitableForDash) {
*reason = "Too many path effects."; if (0 != sampleCount) {
else if ((fContentInfo.numAAConcavePaths() - fContentInfo.numAAHairlineConcavePaths()) *reason = "Can't use multisample on dash effect.";
>= kNumAAConcavePaths) } else {
*reason = "Too many non dashed path effects.";
}
} else if ((fContentInfo.numAAConcavePaths() - fContentInfo.numAAHairlineConcavePaths())
>= kNumAAConcavePaths)
*reason = "Too many anti-aliased concave paths."; *reason = "Too many anti-aliased concave paths.";
else else
*reason = "Unknown reason for GPU unsuitability."; *reason = "Unknown reason for GPU unsuitability.";
} }
return ret; return ret;
} }
bool SkPicturePlayback::suitableForGpuRasterization(GrContext* context, const char **reason,
GrPixelConfig config, SkScalar dpi) const {
if (context != NULL) {
return this->suitableForGpuRasterization(context, reason,
context->getRecommendedSampleCount(config, dpi));
} else {
return this->suitableForGpuRasterization(NULL, reason);
}
}
#endif #endif
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -70,18 +70,21 @@ public:
void set(const SkPictureContentInfo& src) { void set(const SkPictureContentInfo& src) {
fNumPaintWithPathEffectUses = src.fNumPaintWithPathEffectUses; fNumPaintWithPathEffectUses = src.fNumPaintWithPathEffectUses;
fNumFastPathDashEffects = src.fNumFastPathDashEffects;
fNumAAConcavePaths = src.fNumAAConcavePaths; fNumAAConcavePaths = src.fNumAAConcavePaths;
fNumAAHairlineConcavePaths = src.fNumAAHairlineConcavePaths; fNumAAHairlineConcavePaths = src.fNumAAHairlineConcavePaths;
} }
void reset() { void reset() {
fNumPaintWithPathEffectUses = 0; fNumPaintWithPathEffectUses = 0;
fNumFastPathDashEffects = 0;
fNumAAConcavePaths = 0; fNumAAConcavePaths = 0;
fNumAAHairlineConcavePaths = 0; fNumAAHairlineConcavePaths = 0;
} }
void swap(SkPictureContentInfo* other) { void swap(SkPictureContentInfo* other) {
SkTSwap(fNumPaintWithPathEffectUses, other->fNumPaintWithPathEffectUses); SkTSwap(fNumPaintWithPathEffectUses, other->fNumPaintWithPathEffectUses);
SkTSwap(fNumFastPathDashEffects, other->fNumFastPathDashEffects);
SkTSwap(fNumAAConcavePaths, other->fNumAAConcavePaths); SkTSwap(fNumAAConcavePaths, other->fNumAAConcavePaths);
SkTSwap(fNumAAHairlineConcavePaths, other->fNumAAHairlineConcavePaths); SkTSwap(fNumAAHairlineConcavePaths, other->fNumAAHairlineConcavePaths);
} }
@ -89,6 +92,9 @@ public:
void incPaintWithPathEffectUses() { ++fNumPaintWithPathEffectUses; } void incPaintWithPathEffectUses() { ++fNumPaintWithPathEffectUses; }
int numPaintWithPathEffectUses() const { return fNumPaintWithPathEffectUses; } int numPaintWithPathEffectUses() const { return fNumPaintWithPathEffectUses; }
void incFastPathDashEffects() { ++fNumFastPathDashEffects; }
int numFastPathDashEffects() const { return fNumFastPathDashEffects; }
void incAAConcavePaths() { ++fNumAAConcavePaths; } void incAAConcavePaths() { ++fNumAAConcavePaths; }
int numAAConcavePaths() const { return fNumAAConcavePaths; } int numAAConcavePaths() const { return fNumAAConcavePaths; }
@ -102,6 +108,9 @@ private:
// This field is incremented every time a paint with a path effect is // This field is incremented every time a paint with a path effect is
// used (i.e., it is not a de-duplicated count) // used (i.e., it is not a de-duplicated count)
int fNumPaintWithPathEffectUses; int fNumPaintWithPathEffectUses;
// This field is incremented every time a paint with a path effect that is
// dashed, we are drawing a line, and we can use the gpu fast path
int fNumFastPathDashEffects;
// This field is incremented every time an anti-aliased drawPath call is // This field is incremented every time an anti-aliased drawPath call is
// issued with a concave path // issued with a concave path
int fNumAAConcavePaths; int fNumAAConcavePaths;
@ -269,7 +278,19 @@ public:
#endif #endif
#if SK_SUPPORT_GPU #if SK_SUPPORT_GPU
bool suitableForGpuRasterization(GrContext* context, const char **reason) const; /**
* sampleCount is the number of samples-per-pixel or zero if non-MSAA.
* It is defaulted to be zero.
*/
bool suitableForGpuRasterization(GrContext* context, const char **reason,
int sampleCount = 0) const;
/**
* Calls getRecommendedSampleCount with GrPixelConfig and dpi to calculate sampleCount
* and then calls the above version of suitableForGpuRasterization
*/
bool suitableForGpuRasterization(GrContext* context, const char **reason,
GrPixelConfig config, SkScalar dpi) const;
#endif #endif
private: // these help us with reading/writing private: // these help us with reading/writing

View File

@ -988,6 +988,14 @@ void SkPictureRecord::drawPoints(PointMode mode, size_t count, const SkPoint pts
size_t initialOffset = this->addDraw(DRAW_POINTS, &size); size_t initialOffset = this->addDraw(DRAW_POINTS, &size);
SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWritten()); SkASSERT(initialOffset+getPaintOffset(DRAW_POINTS, size) == fWriter.bytesWritten());
this->addPaint(paint); this->addPaint(paint);
if (paint.getPathEffect() != NULL) {
SkPathEffect::DashInfo info;
SkPathEffect::DashType dashType = paint.getPathEffect()->asADash(&info);
if (2 == count && SkPaint::kRound_Cap != paint.getStrokeCap() &&
SkPathEffect::kDash_DashType == dashType && 2 == info.fCount) {
fContentInfo.incFastPathDashEffects();
}
}
this->addInt(mode); this->addInt(mode);
this->addInt(SkToInt(count)); this->addInt(SkToInt(count));
fWriter.writeMul4(pts, count * sizeof(SkPoint)); fWriter.writeMul4(pts, count * sizeof(SkPoint));

51
tools/test_gpuveto.py Normal file → Executable file
View File

@ -57,9 +57,11 @@ class GpuVeto(object):
def __init__(self): def __init__(self):
self.bench_pictures = find_run_binary.find_path_to_program( self.bench_pictures = find_run_binary.find_path_to_program(
'bench_pictures') 'bench_pictures')
sys.stdout.write('Running: %s\n' % (self.bench_pictures))
self.gpuveto = find_run_binary.find_path_to_program('gpuveto') self.gpuveto = find_run_binary.find_path_to_program('gpuveto')
assert os.path.isfile(self.bench_pictures) assert os.path.isfile(self.bench_pictures)
assert os.path.isfile(self.gpuveto) assert os.path.isfile(self.gpuveto)
self.indeterminate = 0
self.truePositives = 0 self.truePositives = 0
self.falsePositives = 0 self.falsePositives = 0
self.trueNegatives = 0 self.trueNegatives = 0
@ -69,14 +71,16 @@ class GpuVeto(object):
for skp in enumerate(dir_or_file): for skp in enumerate(dir_or_file):
self.process_skp(skp[1]) self.process_skp(skp[1])
sys.stdout.write('TP %d FP %d TN %d FN %d\n' % (self.truePositives, sys.stdout.write('TP %d FP %d TN %d FN %d IND %d\n' % (self.truePositives,
self.falsePositives, self.falsePositives,
self.trueNegatives, self.trueNegatives,
self.falseNegatives)) self.falseNegatives,
self.indeterminate))
def process_skp(self, skp_file): def process_skp(self, skp_file):
assert os.path.isfile(skp_file) assert os.path.isfile(skp_file)
#print skp_file
# run gpuveto on the skp # run gpuveto on the skp
args = [self.gpuveto, '-r', skp_file] args = [self.gpuveto, '-r', skp_file]
@ -92,46 +96,63 @@ class GpuVeto(object):
# run raster config # run raster config
args = [self.bench_pictures, '-r', skp_file, args = [self.bench_pictures, '-r', skp_file,
'--repeat', '20', '--repeat', '20',
'--timers', 'w',
'--config', '8888'] '--config', '8888']
returncode, output = execute_program(args) returncode, output = execute_program(args)
if (returncode != 0): if (returncode != 0):
return return
matches = re.findall('[\d.]+', output) matches = re.findall('[\d]+\.[\d]+', output)
if len(matches) != 4: if len(matches) != 1:
return return
rasterTime = float(matches[3]) rasterTime = float(matches[0])
# run gpu config # run gpu config
args2 = [self.bench_pictures, '-r', skp_file, args2 = [self.bench_pictures, '-r', skp_file,
'--repeat', '20', '--repeat', '20',
'--timers', 'w',
'--config', 'gpu'] '--config', 'gpu']
returncode, output = execute_program(args2) returncode, output = execute_program(args2)
if (returncode != 0): if (returncode != 0):
return return
matches = re.findall('[\d.]+', output) matches = re.findall('[\d]+\.[\d]+', output)
if len(matches) != 4: if len(matches) != 1:
return return
gpuTime = float(matches[3]) gpuTime = float(matches[0])
sys.stdout.write('%s: gpuveto: %d raster %.2f gpu: %.2f\n' % ( # happens if page is too big it will not render
skp_file, suitable, rasterTime, gpuTime)) if 0 == gpuTime:
return
if suitable: tolerance = 0.05
tol_range = tolerance * gpuTime
if rasterTime > gpuTime - tol_range and rasterTime < gpuTime + tol_range:
result = "NONE"
self.indeterminate += 1
elif suitable:
if gpuTime < rasterTime: if gpuTime < rasterTime:
self.truePositives += 1 self.truePositives += 1
result = "TP"
else: else:
self.falsePositives += 1 self.falsePositives += 1
result = "FP"
else: else:
if gpuTime < rasterTime: if gpuTime < rasterTime:
self.falseNegatives += 1 self.falseNegatives += 1
result = "FN"
else: else:
self.trueNegatives += 1 self.trueNegatives += 1
result = "TN"
sys.stdout.write('%s: gpuveto: %d raster %.2f gpu: %.2f Result: %s\n' % (
skp_file, suitable, rasterTime, gpuTime, result))
def main(main_argv): def main(main_argv):
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()