2013-11-21 06:21:58 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2013 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
2014-11-10 18:19:06 +00:00
|
|
|
#include "Benchmark.h"
|
|
|
|
|
2013-11-21 06:21:58 +00:00
|
|
|
#if SK_SUPPORT_GPU
|
|
|
|
|
2014-07-25 15:35:45 +00:00
|
|
|
#include "GrGpuResource.h"
|
2015-02-13 22:20:05 +00:00
|
|
|
#include "GrGpuResourcePriv.h"
|
2014-06-19 19:32:29 +00:00
|
|
|
#include "GrContext.h"
|
2014-10-08 15:40:09 +00:00
|
|
|
#include "GrGpu.h"
|
2015-02-11 18:49:59 +00:00
|
|
|
#include "GrResourceCache.h"
|
2013-11-21 06:21:58 +00:00
|
|
|
#include "SkCanvas.h"
|
|
|
|
|
|
|
|
enum {
|
2014-11-25 13:52:06 +00:00
|
|
|
CACHE_SIZE_COUNT = 4096,
|
2013-11-21 06:21:58 +00:00
|
|
|
};
|
|
|
|
|
2014-11-25 13:52:06 +00:00
|
|
|
class BenchResource : public GrGpuResource {
|
2013-11-21 06:21:58 +00:00
|
|
|
public:
|
2014-11-25 13:52:06 +00:00
|
|
|
BenchResource (GrGpu* gpu)
|
Refactor to separate backend object lifecycle and GpuResource budget decision
Refactor GrGpuResource to contain two different pieces of state:
a) instance is budgeted or not budgeted
b) instance references wrapped backend objects or not
The "object lifecycle" was also attached to backend object
handles (ids), which made the code a bit unclear. Backend objects
would be associated with GrGpuResource::LifeCycle, even though
GrGpuResource::LifeCycle refers to the GpuResource, and individual
backend objects in one GpuResource might be governed with different
"lifecycle".
Mark the budgeted/not budgeted with SkBudgeted::kYes, SkBudgeted::kNo.
This was previously GrGpuResource::kCached_LifeCycle,
GrGpuResource::kUncached_LifeCycle.
Mark the "references wrapped object" with boolean. This was previously
GrGpuResource::kBorrowed_LifeCycle,
GrGpuResource::kAdopted_LifeCycle for GrGpuResource.
Associate the backend object ownership status with
GrBackendObjectOwnership for the backend object handles.
The resource type leaf constuctors, such has GrGLTexture or
GrGLTextureRenderTarget take "budgeted" parameter. This parameter
is passed to GrGpuResource::registerWithCache().
The resource type intermediary constructors, such as GrGLTexture
constructors for class GrGLTextureRenderTarget do not take "budgeted"
parameters, intermediary construtors do not call registerWithCache.
Removes the need for tagging GrGpuResource -derived subclass
constructors with "Derived" parameter.
Makes instances that wrap backend objects be registered with
a new function GrGpuResource::registerWithCacheWrapped().
Removes "budgeted" parameter from classes such as StencilAttahment, as
they are always cached and never wrap any external backend objects.
Removes the use of concept "external" from the member function names.
The API refers to the objects as "wrapped", so make all related
functions use the term consistently.
No change in functionality. Resources referencing wrapped objects are
always inserted to the cache with budget decision kNo.
BUG=594928
GOLD_TRYBOT_URL= https://gold.skia.org/search2?unt=true&query=source_type%3Dgm&master=false&issue=1862043002
Review URL: https://codereview.chromium.org/1862043002
2016-04-22 08:48:29 +00:00
|
|
|
: INHERITED(gpu) {
|
|
|
|
this->registerWithCache(SkBudgeted::kYes);
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-05-19 05:47:33 +00:00
|
|
|
static void ComputeKey(int i, int keyData32Count, GrUniqueKey* key) {
|
2015-02-19 15:24:21 +00:00
|
|
|
static GrUniqueKey::Domain kDomain = GrUniqueKey::GenerateDomain();
|
2015-05-19 05:47:33 +00:00
|
|
|
GrUniqueKey::Builder builder(key, kDomain, keyData32Count);
|
|
|
|
for (int j = 0; j < keyData32Count; ++j) {
|
|
|
|
builder[j] = i + j;
|
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-03-26 01:17:31 +00:00
|
|
|
size_t onGpuMemorySize() const override { return 100; }
|
2014-07-25 15:35:45 +00:00
|
|
|
typedef GrGpuResource INHERITED;
|
2013-11-21 06:21:58 +00:00
|
|
|
};
|
|
|
|
|
2015-05-19 05:47:33 +00:00
|
|
|
static void populate_cache(GrGpu* gpu, int resourceCount, int keyData32Count) {
|
2013-11-21 06:21:58 +00:00
|
|
|
for (int i = 0; i < resourceCount; ++i) {
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key;
|
2015-05-19 05:47:33 +00:00
|
|
|
BenchResource::ComputeKey(i, keyData32Count, &key);
|
2015-08-26 20:07:48 +00:00
|
|
|
GrGpuResource* resource = new BenchResource(gpu);
|
2015-02-19 15:24:21 +00:00
|
|
|
resource->resourcePriv().setUniqueKey(key);
|
2013-11-21 06:21:58 +00:00
|
|
|
resource->unref();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class GrResourceCacheBenchAdd : public Benchmark {
|
2013-11-21 06:21:58 +00:00
|
|
|
public:
|
2015-05-19 05:47:33 +00:00
|
|
|
GrResourceCacheBenchAdd(int keyData32Count)
|
|
|
|
: fFullName("grresourcecache_add")
|
|
|
|
, fKeyData32Count(keyData32Count) {
|
|
|
|
if (keyData32Count > 1) {
|
|
|
|
fFullName.appendf("_%d", fKeyData32Count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2014-11-10 18:19:06 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2015-05-19 05:47:33 +00:00
|
|
|
return fFullName.c_str();
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2017-07-25 14:05:01 +00:00
|
|
|
sk_sp<GrContext> context(GrContext::MakeMock(nullptr));
|
2015-08-27 14:41:13 +00:00
|
|
|
if (nullptr == context) {
|
2014-11-10 18:19:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Set the cache budget to be very large so no purging occurs.
|
2014-11-25 13:52:06 +00:00
|
|
|
context->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30);
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = context->getResourceCache();
|
2014-11-10 18:19:06 +00:00
|
|
|
|
|
|
|
// Make sure the cache is empty.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes());
|
2014-11-10 18:19:06 +00:00
|
|
|
|
|
|
|
GrGpu* gpu = context->getGpu();
|
2013-11-21 06:21:58 +00:00
|
|
|
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2015-05-19 05:47:33 +00:00
|
|
|
populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count);
|
2015-02-11 18:49:59 +00:00
|
|
|
SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount());
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2015-05-19 05:47:33 +00:00
|
|
|
SkString fFullName;
|
|
|
|
int fKeyData32Count;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-11-21 06:21:58 +00:00
|
|
|
};
|
|
|
|
|
2014-06-19 19:32:29 +00:00
|
|
|
class GrResourceCacheBenchFind : public Benchmark {
|
2013-11-21 06:21:58 +00:00
|
|
|
public:
|
2015-05-19 05:47:33 +00:00
|
|
|
GrResourceCacheBenchFind(int keyData32Count)
|
|
|
|
: fFullName("grresourcecache_find")
|
|
|
|
, fKeyData32Count(keyData32Count) {
|
|
|
|
if (keyData32Count > 1) {
|
|
|
|
fFullName.appendf("_%d", fKeyData32Count);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-03-26 01:17:31 +00:00
|
|
|
bool isSuitableFor(Backend backend) override {
|
2014-11-10 18:19:06 +00:00
|
|
|
return backend == kNonRendering_Backend;
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
protected:
|
2015-03-26 01:17:31 +00:00
|
|
|
const char* onGetName() override {
|
2015-05-19 05:47:33 +00:00
|
|
|
return fFullName.c_str();
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
|
2015-09-30 19:11:07 +00:00
|
|
|
void onDelayedSetup() override {
|
2017-07-25 14:05:01 +00:00
|
|
|
fContext = GrContext::MakeMock(nullptr);
|
2014-11-25 13:52:06 +00:00
|
|
|
if (!fContext) {
|
2014-11-10 18:19:06 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
// Set the cache budget to be very large so no purging occurs.
|
2014-11-25 13:52:06 +00:00
|
|
|
fContext->setResourceCacheLimits(CACHE_SIZE_COUNT, 1 << 30);
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = fContext->getResourceCache();
|
2014-11-10 18:19:06 +00:00
|
|
|
|
|
|
|
// Make sure the cache is empty.
|
2015-02-11 18:49:59 +00:00
|
|
|
cache->purgeAllUnlocked();
|
|
|
|
SkASSERT(0 == cache->getResourceCount() && 0 == cache->getResourceBytes());
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2014-11-25 13:52:06 +00:00
|
|
|
GrGpu* gpu = fContext->getGpu();
|
2014-11-10 18:19:06 +00:00
|
|
|
|
2015-05-19 05:47:33 +00:00
|
|
|
populate_cache(gpu, CACHE_SIZE_COUNT, fKeyData32Count);
|
2014-11-25 13:52:06 +00:00
|
|
|
}
|
2013-11-21 06:21:58 +00:00
|
|
|
|
2015-10-01 16:43:39 +00:00
|
|
|
void onDraw(int loops, SkCanvas* canvas) override {
|
2014-11-25 13:52:06 +00:00
|
|
|
if (!fContext) {
|
|
|
|
return;
|
|
|
|
}
|
2015-02-11 18:49:59 +00:00
|
|
|
GrResourceCache* cache = fContext->getResourceCache();
|
|
|
|
SkASSERT(CACHE_SIZE_COUNT == cache->getResourceCount());
|
2013-12-03 18:17:16 +00:00
|
|
|
for (int i = 0; i < loops; ++i) {
|
2014-11-25 13:52:06 +00:00
|
|
|
for (int k = 0; k < CACHE_SIZE_COUNT; ++k) {
|
2015-02-19 15:24:21 +00:00
|
|
|
GrUniqueKey key;
|
2015-05-19 05:47:33 +00:00
|
|
|
BenchResource::ComputeKey(k, fKeyData32Count, &key);
|
2016-11-04 17:02:54 +00:00
|
|
|
sk_sp<GrGpuResource> resource(cache->findAndRefUniqueResource(key));
|
2014-11-25 13:52:06 +00:00
|
|
|
SkASSERT(resource);
|
2013-11-21 06:21:58 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-11-04 17:02:54 +00:00
|
|
|
sk_sp<GrContext> fContext;
|
2015-05-19 05:47:33 +00:00
|
|
|
SkString fFullName;
|
|
|
|
int fKeyData32Count;
|
2014-06-19 19:32:29 +00:00
|
|
|
typedef Benchmark INHERITED;
|
2013-11-21 06:21:58 +00:00
|
|
|
};
|
|
|
|
|
2015-05-19 05:47:33 +00:00
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(1); )
|
|
|
|
#ifdef SK_RELEASE
|
|
|
|
// Only on release because on debug the SkTDynamicHash validation is too slow.
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(2); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(3); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(4); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(5); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(10); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(25); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(54); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(55); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchAdd(56); )
|
|
|
|
#endif
|
|
|
|
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(1); )
|
|
|
|
#ifdef SK_RELEASE
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(2); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(3); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(4); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(5); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(10); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(25); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(54); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(55); )
|
|
|
|
DEF_BENCH( return new GrResourceCacheBenchFind(56); )
|
|
|
|
#endif
|
2013-11-21 06:21:58 +00:00
|
|
|
|
|
|
|
#endif
|