2020-09-16 14:57:32 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2020 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "include/core/SkCanvas.h"
|
|
|
|
#include "include/core/SkDeferredDisplayListRecorder.h"
|
|
|
|
#include "include/core/SkSurfaceCharacterization.h"
|
2020-10-23 20:13:57 +00:00
|
|
|
#include "include/private/SkMalloc.h"
|
2020-10-26 17:50:57 +00:00
|
|
|
#include "include/utils/SkRandom.h"
|
2020-12-23 14:16:59 +00:00
|
|
|
#include "src/core/SkCanvasPriv.h"
|
2020-10-28 18:57:53 +00:00
|
|
|
#include "src/core/SkMessageBus.h"
|
2020-10-23 20:13:57 +00:00
|
|
|
#include "src/gpu/GrDefaultGeoProcFactory.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2020-10-23 20:13:57 +00:00
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "src/gpu/GrMemoryPool.h"
|
|
|
|
#include "src/gpu/GrOpFlushState.h"
|
2020-09-16 14:57:32 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2021-07-01 14:27:44 +00:00
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
2020-09-25 16:47:10 +00:00
|
|
|
#include "src/gpu/GrStyle.h"
|
2020-10-08 15:00:02 +00:00
|
|
|
#include "src/gpu/GrThreadSafeCache.h"
|
2021-08-11 19:43:50 +00:00
|
|
|
#include "src/gpu/ops/GrDrawOp.h"
|
2021-07-28 19:13:20 +00:00
|
|
|
#include "src/gpu/v1/SurfaceDrawContext_v1.h"
|
2020-09-16 14:57:32 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
#include "tests/TestUtils.h"
|
2020-10-23 20:13:57 +00:00
|
|
|
#include "tools/gpu/ProxyUtils.h"
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-09-22 21:34:51 +00:00
|
|
|
#include <thread>
|
|
|
|
|
2020-09-16 14:57:32 +00:00
|
|
|
static constexpr int kImageWH = 32;
|
|
|
|
static constexpr auto kImageOrigin = kBottomLeft_GrSurfaceOrigin;
|
2020-10-06 18:52:11 +00:00
|
|
|
static constexpr int kNoID = -1;
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
static SkImageInfo default_ii(int wh) {
|
|
|
|
return SkImageInfo::Make(wh, wh, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
}
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
static std::unique_ptr<skgpu::v1::SurfaceDrawContext> new_SDC(GrRecordingContext* rContext,
|
|
|
|
int wh) {
|
|
|
|
return skgpu::v1::SurfaceDrawContext::Make(rContext,
|
|
|
|
GrColorType::kRGBA_8888,
|
|
|
|
nullptr,
|
|
|
|
SkBackingFit::kExact,
|
|
|
|
{wh, wh},
|
|
|
|
SkSurfaceProps(),
|
|
|
|
1,
|
|
|
|
GrMipMapped::kNo,
|
|
|
|
GrProtected::kNo,
|
|
|
|
kImageOrigin,
|
|
|
|
SkBudgeted::kYes);
|
2020-09-25 16:47:10 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
static void create_view_key(GrUniqueKey* key, int wh, int id) {
|
|
|
|
static const GrUniqueKey::Domain kViewDomain = GrUniqueKey::GenerateDomain();
|
|
|
|
GrUniqueKey::Builder builder(key, kViewDomain, 1);
|
2020-09-16 14:57:32 +00:00
|
|
|
builder[0] = wh;
|
|
|
|
builder.finish();
|
2020-10-06 18:52:11 +00:00
|
|
|
|
|
|
|
if (id != kNoID) {
|
|
|
|
key->setCustomData(SkData::MakeWithCopy(&id, sizeof(id)));
|
|
|
|
}
|
2020-10-23 20:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void create_vert_key(GrUniqueKey* key, int wh, int id) {
|
|
|
|
static const GrUniqueKey::Domain kVertDomain = GrUniqueKey::GenerateDomain();
|
|
|
|
GrUniqueKey::Builder builder(key, kVertDomain, 1);
|
|
|
|
builder[0] = wh;
|
|
|
|
builder.finish();
|
|
|
|
|
|
|
|
if (id != kNoID) {
|
|
|
|
key->setCustomData(SkData::MakeWithCopy(&id, sizeof(id)));
|
|
|
|
}
|
|
|
|
}
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-11-02 13:57:39 +00:00
|
|
|
static bool default_is_newer_better(SkData* incumbent, SkData* challenger) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
// When testing views we create a bitmap that covers the entire screen and has an inset blue rect
|
|
|
|
// atop a field of white.
|
|
|
|
// When testing verts we clear the background to white and simply draw an inset blur rect.
|
2020-09-25 16:47:10 +00:00
|
|
|
static SkBitmap create_bitmap(int wh) {
|
2020-09-16 14:57:32 +00:00
|
|
|
SkBitmap bitmap;
|
|
|
|
|
|
|
|
bitmap.allocPixels(default_ii(wh));
|
|
|
|
|
|
|
|
SkCanvas tmp(bitmap);
|
|
|
|
tmp.clear(SK_ColorWHITE);
|
|
|
|
|
|
|
|
SkPaint blue;
|
|
|
|
blue.setColor(SK_ColorBLUE);
|
2020-09-25 16:47:10 +00:00
|
|
|
blue.setAntiAlias(false);
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-09-25 16:47:10 +00:00
|
|
|
tmp.drawRect({10, 10, wh-10.0f, wh-10.0f}, blue);
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-09-25 19:25:46 +00:00
|
|
|
bitmap.setImmutable();
|
2020-09-16 14:57:32 +00:00
|
|
|
return bitmap;
|
|
|
|
}
|
|
|
|
|
2020-11-02 13:57:39 +00:00
|
|
|
class GrThreadSafeVertexTestOp;
|
|
|
|
|
2020-09-16 14:57:32 +00:00
|
|
|
class TestHelper {
|
|
|
|
public:
|
|
|
|
struct Stats {
|
|
|
|
int fCacheHits = 0;
|
|
|
|
int fCacheMisses = 0;
|
|
|
|
|
|
|
|
int fNumSWCreations = 0;
|
2020-09-25 16:47:10 +00:00
|
|
|
int fNumLazyCreations = 0;
|
2020-09-16 14:57:32 +00:00
|
|
|
int fNumHWCreations = 0;
|
|
|
|
};
|
|
|
|
|
2020-11-02 13:57:39 +00:00
|
|
|
TestHelper(GrDirectContext* dContext,
|
|
|
|
GrThreadSafeCache::IsNewerBetter isNewerBetter = default_is_newer_better)
|
|
|
|
: fDContext(dContext)
|
|
|
|
, fIsNewerBetter(isNewerBetter) {
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
fDst = SkSurface::MakeRenderTarget(dContext, SkBudgeted::kNo, default_ii(kImageWH));
|
|
|
|
SkAssertResult(fDst);
|
|
|
|
|
|
|
|
SkSurfaceCharacterization characterization;
|
|
|
|
SkAssertResult(fDst->characterize(&characterization));
|
|
|
|
|
|
|
|
fRecorder1 = std::make_unique<SkDeferredDisplayListRecorder>(characterization);
|
2020-10-23 20:13:57 +00:00
|
|
|
this->ddlCanvas1()->clear(SkColors::kWhite);
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
fRecorder2 = std::make_unique<SkDeferredDisplayListRecorder>(characterization);
|
2020-10-23 20:13:57 +00:00
|
|
|
this->ddlCanvas2()->clear(SkColors::kWhite);
|
|
|
|
|
|
|
|
fDst->getCanvas()->clear(SkColors::kWhite);
|
2020-09-16 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
~TestHelper() {
|
2020-09-22 16:18:16 +00:00
|
|
|
fDContext->flush();
|
|
|
|
fDContext->submit(true);
|
2020-09-16 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Stats* stats() { return &fStats; }
|
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
int numCacheEntries() const { return this->threadSafeCache()->numEntries(); }
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
GrDirectContext* dContext() { return fDContext; }
|
|
|
|
|
|
|
|
SkCanvas* liveCanvas() { return fDst ? fDst->getCanvas() : nullptr; }
|
|
|
|
SkCanvas* ddlCanvas1() { return fRecorder1 ? fRecorder1->getCanvas() : nullptr; }
|
2020-09-18 18:07:43 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> snap1() {
|
|
|
|
if (fRecorder1) {
|
|
|
|
sk_sp<SkDeferredDisplayList> tmp = fRecorder1->detach();
|
|
|
|
fRecorder1 = nullptr;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-09-16 14:57:32 +00:00
|
|
|
SkCanvas* ddlCanvas2() { return fRecorder2 ? fRecorder2->getCanvas() : nullptr; }
|
2020-09-18 18:07:43 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> snap2() {
|
|
|
|
if (fRecorder2) {
|
|
|
|
sk_sp<SkDeferredDisplayList> tmp = fRecorder2->detach();
|
|
|
|
fRecorder2 = nullptr;
|
|
|
|
return tmp;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nullptr;
|
|
|
|
}
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
GrThreadSafeCache* threadSafeCache() { return fDContext->priv().threadSafeCache(); }
|
|
|
|
const GrThreadSafeCache* threadSafeCache() const { return fDContext->priv().threadSafeCache(); }
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
typedef void (TestHelper::*addAccessFP)(SkCanvas*, int wh, int id,
|
|
|
|
bool failLookUp, bool failFillingIn);
|
|
|
|
typedef bool (TestHelper::*checkFP)(SkCanvas*, int wh,
|
|
|
|
int expectedHits, int expectedMisses,
|
|
|
|
int expectedNumRefs, int expectedID);
|
|
|
|
|
2020-09-16 14:57:32 +00:00
|
|
|
// Add a draw on 'canvas' that will introduce a ref on the 'wh' view
|
2020-10-23 20:13:57 +00:00
|
|
|
void addViewAccess(SkCanvas* canvas,
|
|
|
|
int wh,
|
|
|
|
int id = kNoID,
|
|
|
|
bool failLookup = false,
|
|
|
|
bool failFillingIn = false) {
|
|
|
|
auto rContext = canvas->recordingContext();
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
auto view = AccessCachedView(rContext, this->threadSafeCache(),
|
2020-10-06 18:52:11 +00:00
|
|
|
wh, failLookup, failFillingIn, id, &fStats);
|
2020-09-16 14:57:32 +00:00
|
|
|
SkASSERT(view);
|
|
|
|
|
2020-12-23 14:16:59 +00:00
|
|
|
auto sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(canvas);
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-12-23 14:16:59 +00:00
|
|
|
sdc->drawTexture(nullptr,
|
2020-09-16 14:57:32 +00:00
|
|
|
view,
|
|
|
|
kPremul_SkAlphaType,
|
|
|
|
GrSamplerState::Filter::kNearest,
|
|
|
|
GrSamplerState::MipmapMode::kNone,
|
|
|
|
SkBlendMode::kSrcOver,
|
2020-09-25 19:25:46 +00:00
|
|
|
{1.0f, 1.0f, 1.0f, 1.0f},
|
2020-09-16 14:57:32 +00:00
|
|
|
SkRect::MakeWH(wh, wh),
|
|
|
|
SkRect::MakeWH(wh, wh),
|
|
|
|
GrAA::kNo,
|
|
|
|
GrQuadAAFlags::kNone,
|
|
|
|
SkCanvas::kFast_SrcRectConstraint,
|
|
|
|
SkMatrix::I(),
|
|
|
|
nullptr);
|
|
|
|
}
|
|
|
|
|
2020-09-18 18:07:43 +00:00
|
|
|
// Besides checking that the number of refs and cache hits and misses are as expected, this
|
|
|
|
// method also validates that the unique key doesn't appear in any of the other caches.
|
2020-10-23 20:13:57 +00:00
|
|
|
bool checkView(SkCanvas* canvas, int wh,
|
|
|
|
int expectedHits, int expectedMisses, int expectedNumRefs, int expectedID) {
|
|
|
|
if (fStats.fCacheHits != expectedHits || fStats.fCacheMisses != expectedMisses) {
|
2020-09-22 16:18:16 +00:00
|
|
|
SkDebugf("Hits E: %d A: %d --- Misses E: %d A: %d\n",
|
2020-10-23 20:13:57 +00:00
|
|
|
expectedHits, fStats.fCacheHits, expectedMisses, fStats.fCacheMisses);
|
2020-09-16 14:57:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrUniqueKey key;
|
2020-10-23 20:13:57 +00:00
|
|
|
create_view_key(&key, wh, kNoID);
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
auto threadSafeCache = this->threadSafeCache();
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
auto [view, xtraData] = threadSafeCache->findWithData(key);
|
2020-09-22 16:18:16 +00:00
|
|
|
if (!view.proxy()) {
|
|
|
|
return false;
|
|
|
|
}
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-06 18:52:11 +00:00
|
|
|
if (expectedID < 0) {
|
2020-10-23 20:13:57 +00:00
|
|
|
if (xtraData) {
|
2020-10-06 18:52:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
2020-10-23 20:13:57 +00:00
|
|
|
if (!xtraData) {
|
2020-10-06 18:52:11 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
const int* cachedID = static_cast<const int*>(xtraData->data());
|
2020-10-06 18:52:11 +00:00
|
|
|
if (*cachedID != expectedID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
if (!view.proxy()->refCntGreaterThan(expectedNumRefs+1) || // +1 for 'view's ref
|
|
|
|
view.proxy()->refCntGreaterThan(expectedNumRefs+2)) {
|
2020-09-16 14:57:32 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2020-09-18 18:07:43 +00:00
|
|
|
if (canvas) {
|
|
|
|
GrRecordingContext* rContext = canvas->recordingContext();
|
2020-09-16 14:57:32 +00:00
|
|
|
GrProxyProvider* recordingProxyProvider = rContext->priv().proxyProvider();
|
|
|
|
sk_sp<GrTextureProxy> result = recordingProxyProvider->findProxyByUniqueKey(key);
|
|
|
|
if (result) {
|
|
|
|
// views in this cache should never appear in the recorder's cache
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
GrProxyProvider* directProxyProvider = fDContext->priv().proxyProvider();
|
|
|
|
sk_sp<GrTextureProxy> result = directProxyProvider->findProxyByUniqueKey(key);
|
|
|
|
if (result) {
|
|
|
|
// views in this cache should never appear in the main proxy cache
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto resourceProvider = fDContext->priv().resourceProvider();
|
|
|
|
sk_sp<GrSurface> surf = resourceProvider->findByUniqueKey<GrSurface>(key);
|
|
|
|
if (surf) {
|
|
|
|
// the textures backing the views in this cache should never be discoverable in the
|
|
|
|
// resource cache
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-11-02 13:57:39 +00:00
|
|
|
void addVertAccess(SkCanvas* canvas,
|
|
|
|
int wh,
|
|
|
|
int id,
|
|
|
|
bool failLookup,
|
|
|
|
bool failFillingIn,
|
|
|
|
GrThreadSafeVertexTestOp** createdOp);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
// Add a draw on 'canvas' that will introduce a ref on a 'wh' vertex data
|
|
|
|
void addVertAccess(SkCanvas* canvas,
|
|
|
|
int wh,
|
|
|
|
int id = kNoID,
|
|
|
|
bool failLookup = false,
|
2020-11-02 13:57:39 +00:00
|
|
|
bool failFillingIn = false) {
|
|
|
|
this->addVertAccess(canvas, wh, id, failLookup, failFillingIn, nullptr);
|
|
|
|
}
|
2020-10-23 20:13:57 +00:00
|
|
|
|
|
|
|
bool checkVert(SkCanvas* canvas, int wh,
|
|
|
|
int expectedHits, int expectedMisses, int expectedNumRefs, int expectedID) {
|
|
|
|
if (fStats.fCacheHits != expectedHits || fStats.fCacheMisses != expectedMisses) {
|
|
|
|
SkDebugf("Hits E: %d A: %d --- Misses E: %d A: %d\n",
|
|
|
|
expectedHits, fStats.fCacheHits, expectedMisses, fStats.fCacheMisses);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrUniqueKey key;
|
|
|
|
create_vert_key(&key, wh, kNoID);
|
|
|
|
|
|
|
|
auto threadSafeCache = this->threadSafeCache();
|
|
|
|
|
|
|
|
auto [vertData, xtraData] = threadSafeCache->findVertsWithData(key);
|
|
|
|
if (!vertData) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (expectedID < 0) {
|
|
|
|
if (xtraData) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (!xtraData) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
const int* cachedID = static_cast<const int*>(xtraData->data());
|
|
|
|
if (*cachedID != expectedID) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!vertData->refCntGreaterThan(expectedNumRefs+1) || // +1 for 'vertData's ref
|
|
|
|
vertData->refCntGreaterThan(expectedNumRefs+2)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
auto resourceProvider = fDContext->priv().resourceProvider();
|
|
|
|
sk_sp<GrGpuBuffer> buffer = resourceProvider->findByUniqueKey<GrGpuBuffer>(key);
|
|
|
|
if (buffer) {
|
|
|
|
// the buffer holding the vertex data in this cache should never be discoverable
|
|
|
|
// in the resource cache
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-09-25 19:25:46 +00:00
|
|
|
bool checkImage(skiatest::Reporter* reporter, sk_sp<SkSurface> s) {
|
|
|
|
SkBitmap actual;
|
|
|
|
|
|
|
|
actual.allocPixels(default_ii(kImageWH));
|
|
|
|
|
|
|
|
if (!s->readPixels(actual, 0, 0)) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SkBitmap expected = create_bitmap(kImageWH);
|
|
|
|
|
|
|
|
const float tols[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
|
|
|
|
|
|
|
|
auto error = std::function<ComparePixmapsErrorReporter>(
|
|
|
|
[reporter](int x, int y, const float diffs[4]) {
|
|
|
|
SkASSERT(x >= 0 && y >= 0);
|
|
|
|
ERRORF(reporter, "mismatch at %d, %d (%f, %f, %f %f)",
|
|
|
|
x, y, diffs[0], diffs[1], diffs[2], diffs[3]);
|
|
|
|
});
|
|
|
|
|
|
|
|
return ComparePixels(expected.pixmap(), actual.pixmap(), tols, error);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool checkImage(skiatest::Reporter* reporter) {
|
|
|
|
return this->checkImage(reporter, fDst);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool checkImage(skiatest::Reporter* reporter, sk_sp<SkDeferredDisplayList> ddl) {
|
|
|
|
sk_sp<SkSurface> tmp = SkSurface::MakeRenderTarget(fDContext,
|
|
|
|
SkBudgeted::kNo,
|
|
|
|
default_ii(kImageWH));
|
|
|
|
if (!tmp) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!tmp->draw(std::move(ddl))) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return this->checkImage(reporter, std::move(tmp));
|
|
|
|
}
|
|
|
|
|
2020-09-22 16:18:16 +00:00
|
|
|
size_t gpuSize(int wh) const {
|
|
|
|
GrBackendFormat format = fDContext->defaultBackendFormat(kRGBA_8888_SkColorType,
|
|
|
|
GrRenderable::kNo);
|
|
|
|
|
2020-10-01 17:46:00 +00:00
|
|
|
return GrSurface::ComputeSize(format, {wh, wh}, /*colorSamplesPerPixel=*/1,
|
|
|
|
GrMipMapped::kNo, /*binSize=*/false);
|
2020-09-22 16:18:16 +00:00
|
|
|
}
|
|
|
|
|
2020-09-16 14:57:32 +00:00
|
|
|
private:
|
|
|
|
static GrSurfaceProxyView AccessCachedView(GrRecordingContext*,
|
2020-10-08 15:00:02 +00:00
|
|
|
GrThreadSafeCache*,
|
2020-09-22 16:18:16 +00:00
|
|
|
int wh,
|
2020-10-06 18:52:11 +00:00
|
|
|
bool failLookup, bool failFillingIn, int id,
|
2020-09-25 16:47:10 +00:00
|
|
|
Stats*);
|
2020-09-16 14:57:32 +00:00
|
|
|
static GrSurfaceProxyView CreateViewOnCpu(GrRecordingContext*, int wh, Stats*);
|
2020-09-25 16:47:10 +00:00
|
|
|
static bool FillInViewOnGpu(GrDirectContext*, int wh, Stats*,
|
|
|
|
const GrSurfaceProxyView& lazyView,
|
2020-10-08 15:00:02 +00:00
|
|
|
sk_sp<GrThreadSafeCache::Trampoline>);
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
Stats fStats;
|
|
|
|
GrDirectContext* fDContext = nullptr;
|
2020-11-02 13:57:39 +00:00
|
|
|
GrThreadSafeCache::IsNewerBetter fIsNewerBetter;
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
sk_sp<SkSurface> fDst;
|
|
|
|
std::unique_ptr<SkDeferredDisplayListRecorder> fRecorder1;
|
|
|
|
std::unique_ptr<SkDeferredDisplayListRecorder> fRecorder2;
|
|
|
|
};
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
class GrThreadSafeVertexTestOp : public GrDrawOp {
|
|
|
|
public:
|
|
|
|
DEFINE_OP_CLASS_ID
|
|
|
|
|
2020-10-07 20:46:15 +00:00
|
|
|
static GrOp::Owner Make(GrRecordingContext* rContext, TestHelper::Stats* stats,
|
2020-11-02 13:57:39 +00:00
|
|
|
int wh, int id, bool failLookup, bool failFillingIn,
|
|
|
|
GrThreadSafeCache::IsNewerBetter isNewerBetter) {
|
2020-10-23 20:13:57 +00:00
|
|
|
|
2020-10-07 20:46:15 +00:00
|
|
|
return GrOp::Make<GrThreadSafeVertexTestOp>(
|
2020-11-02 13:57:39 +00:00
|
|
|
rContext, rContext, stats, wh, id, failLookup, failFillingIn, isNewerBetter);
|
2020-10-23 20:13:57 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 13:57:39 +00:00
|
|
|
const GrThreadSafeCache::VertexData* vertexData() const { return fVertexData.get(); }
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
private:
|
2020-10-07 20:46:15 +00:00
|
|
|
friend class GrOp; // for ctor
|
2020-10-23 20:13:57 +00:00
|
|
|
|
|
|
|
GrThreadSafeVertexTestOp(GrRecordingContext* rContext, TestHelper::Stats* stats, int wh, int id,
|
2020-11-02 13:57:39 +00:00
|
|
|
bool failLookup, bool failFillingIn,
|
|
|
|
GrThreadSafeCache::IsNewerBetter isNewerBetter)
|
2020-10-23 20:13:57 +00:00
|
|
|
: INHERITED(ClassID())
|
|
|
|
, fStats(stats)
|
|
|
|
, fWH(wh)
|
|
|
|
, fID(id)
|
2020-11-02 13:57:39 +00:00
|
|
|
, fFailFillingIn(failFillingIn)
|
|
|
|
, fIsNewerBetter(isNewerBetter) {
|
2020-10-23 20:13:57 +00:00
|
|
|
this->setBounds(SkRect::MakeIWH(fWH, fWH), HasAABloat::kNo, IsHairline::kNo);
|
|
|
|
|
|
|
|
// Normally we wouldn't add a ref to the vertex data at this point. However, it is
|
|
|
|
// needed in this unit test to get the ref counts on the uniquely keyed resources
|
|
|
|
// to be as expected.
|
|
|
|
this->findOrCreateVertices(rContext, failLookup, fFailFillingIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* name() const override { return "GrThreadSafeVertexTestOp"; }
|
|
|
|
FixedFunctionFlags fixedFunctionFlags() const override { return FixedFunctionFlags::kNone; }
|
2021-04-22 18:57:28 +00:00
|
|
|
GrProcessorSet::Analysis finalize(const GrCaps&, const GrAppliedClip*, GrClampType) override {
|
2020-10-23 20:13:57 +00:00
|
|
|
return GrProcessorSet::EmptySetAnalysis();
|
|
|
|
}
|
|
|
|
|
|
|
|
GrProgramInfo* createProgramInfo(const GrCaps* caps,
|
|
|
|
SkArenaAlloc* arena,
|
2020-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2021-08-26 16:05:11 +00:00
|
|
|
bool usesMSAASurface,
|
2020-10-23 20:13:57 +00:00
|
|
|
GrAppliedClip&& appliedClip,
|
2021-06-02 15:58:05 +00:00
|
|
|
const GrDstProxyView& dstProxyView,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
|
|
|
GrLoadOp colorLoadOp) const {
|
2020-10-23 20:13:57 +00:00
|
|
|
using namespace GrDefaultGeoProcFactory;
|
|
|
|
|
|
|
|
Color color({ 0.0f, 0.0f, 1.0f, 1.0f });
|
|
|
|
|
|
|
|
auto gp = MakeForDeviceSpace(arena, color,
|
|
|
|
Coverage::kSolid_Type,
|
|
|
|
LocalCoords::kUnused_Type,
|
|
|
|
SkMatrix::I());
|
|
|
|
|
2021-08-26 16:05:11 +00:00
|
|
|
return sk_gpu_test::CreateProgramInfo(caps, arena, writeView, usesMSAASurface,
|
2020-10-23 20:13:57 +00:00
|
|
|
std::move(appliedClip), dstProxyView,
|
|
|
|
gp, SkBlendMode::kSrcOver,
|
|
|
|
GrPrimitiveType::kTriangleStrip,
|
2020-11-20 15:22:43 +00:00
|
|
|
renderPassXferBarriers, colorLoadOp);
|
2020-10-23 20:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
GrProgramInfo* createProgramInfo(GrOpFlushState* flushState) const {
|
|
|
|
return this->createProgramInfo(&flushState->caps(),
|
|
|
|
flushState->allocator(),
|
|
|
|
flushState->writeView(),
|
2021-08-26 16:05:11 +00:00
|
|
|
flushState->usesMSAASurface(),
|
2020-10-23 20:13:57 +00:00
|
|
|
flushState->detachAppliedClip(),
|
|
|
|
flushState->dstProxyView(),
|
2020-11-20 15:22:43 +00:00
|
|
|
flushState->renderPassBarriers(),
|
|
|
|
flushState->colorLoadOp());
|
2020-10-23 20:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void findOrCreateVertices(GrRecordingContext* rContext, bool failLookup, bool failFillingIn) {
|
|
|
|
|
|
|
|
if (!fVertexData) {
|
|
|
|
auto threadSafeViewCache = rContext->priv().threadSafeCache();
|
|
|
|
|
|
|
|
if (rContext->asDirectContext()) {
|
|
|
|
// The vertex variant doesn't have a correlate to lazyProxies but increment this
|
|
|
|
// here to make the unit tests happy.
|
|
|
|
++fStats->fNumLazyCreations;
|
|
|
|
}
|
|
|
|
|
|
|
|
GrUniqueKey key;
|
|
|
|
create_vert_key(&key, fWH, fID);
|
|
|
|
|
|
|
|
// We can "fail the lookup" to simulate a threaded race condition
|
|
|
|
auto [cachedVerts, data] = threadSafeViewCache->findVertsWithData(key);
|
|
|
|
if (cachedVerts && !failLookup) {
|
|
|
|
fVertexData = cachedVerts;
|
|
|
|
++fStats->fCacheHits;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
++fStats->fCacheMisses;
|
|
|
|
if (!rContext->asDirectContext()) {
|
|
|
|
++fStats->fNumSWCreations;
|
|
|
|
}
|
|
|
|
|
|
|
|
constexpr size_t kVertSize = sizeof(SkPoint);
|
|
|
|
SkPoint* verts = static_cast<SkPoint*>(sk_malloc_throw(4 * kVertSize));
|
|
|
|
|
|
|
|
verts[0].set(10.0f, 10.0f);
|
|
|
|
verts[1].set(fWH-10.0f, 10.0f);
|
|
|
|
verts[2].set(10.0f, fWH-10.0f);
|
|
|
|
verts[3].set(fWH-10.0f, fWH-10.0f);
|
|
|
|
|
|
|
|
fVertexData = GrThreadSafeCache::MakeVertexData(verts, 4, kVertSize);
|
|
|
|
|
2020-11-02 13:57:39 +00:00
|
|
|
auto [tmpV, tmpD] = threadSafeViewCache->addVertsWithData(key, fVertexData,
|
|
|
|
fIsNewerBetter);
|
2020-10-23 20:13:57 +00:00
|
|
|
if (tmpV != fVertexData) {
|
|
|
|
// Someone beat us to creating the vertex data. Use that version.
|
|
|
|
fVertexData = tmpV;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (auto dContext = rContext->asDirectContext(); dContext && !fVertexData->gpuBuffer()) {
|
|
|
|
auto rp = dContext->priv().resourceProvider();
|
|
|
|
|
|
|
|
if (!failFillingIn) {
|
|
|
|
++fStats->fNumHWCreations;
|
|
|
|
|
|
|
|
sk_sp<GrGpuBuffer> tmp = rp->createBuffer(fVertexData->size(),
|
|
|
|
GrGpuBufferType::kVertex,
|
|
|
|
kStatic_GrAccessPattern,
|
|
|
|
fVertexData->vertices());
|
|
|
|
fVertexData->setGpuBuffer(std::move(tmp));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void onPrePrepare(GrRecordingContext* rContext,
|
2020-11-19 18:41:26 +00:00
|
|
|
const GrSurfaceProxyView& writeView,
|
2020-10-23 20:13:57 +00:00
|
|
|
GrAppliedClip* clip,
|
2021-06-02 15:58:05 +00:00
|
|
|
const GrDstProxyView& dstProxyView,
|
2020-11-20 15:22:43 +00:00
|
|
|
GrXferBarrierFlags renderPassXferBarriers,
|
|
|
|
GrLoadOp colorLoadOp) override {
|
2020-10-23 20:13:57 +00:00
|
|
|
SkArenaAlloc* arena = rContext->priv().recordTimeAllocator();
|
|
|
|
|
2021-08-26 16:05:11 +00:00
|
|
|
// DMSAA is not supported on DDL.
|
|
|
|
bool usesMSAASurface = writeView.asRenderTargetProxy()->numSamples() > 1;
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
// This is equivalent to a GrOpFlushState::detachAppliedClip
|
|
|
|
GrAppliedClip appliedClip = clip ? std::move(*clip) : GrAppliedClip::Disabled();
|
|
|
|
|
|
|
|
fProgramInfo = this->createProgramInfo(rContext->priv().caps(), arena, writeView,
|
2021-08-26 16:05:11 +00:00
|
|
|
usesMSAASurface, std::move(appliedClip),
|
|
|
|
dstProxyView, renderPassXferBarriers, colorLoadOp);
|
2020-10-23 20:13:57 +00:00
|
|
|
|
|
|
|
rContext->priv().recordProgramInfo(fProgramInfo);
|
|
|
|
|
|
|
|
// This is now a noop (bc it is always called in the ctor) but is where we would normally
|
|
|
|
// create the vertices.
|
|
|
|
this->findOrCreateVertices(rContext, false, fFailFillingIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onPrepare(GrOpFlushState* flushState) override {
|
|
|
|
auto dContext = flushState->gpu()->getContext();
|
|
|
|
|
|
|
|
// This call site is not a noop bc this op could've been created on with DDL context
|
|
|
|
// and, therefore, could be lacking a gpu-side buffer
|
|
|
|
this->findOrCreateVertices(dContext, false, fFailFillingIn);
|
|
|
|
}
|
|
|
|
|
|
|
|
void onExecute(GrOpFlushState* flushState, const SkRect& chainBounds) override {
|
|
|
|
if (!fVertexData || !fVertexData->gpuBuffer()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!fProgramInfo) {
|
|
|
|
fProgramInfo = this->createProgramInfo(flushState);
|
|
|
|
}
|
|
|
|
|
|
|
|
flushState->bindPipeline(*fProgramInfo, SkRect::MakeIWH(fWH, fWH));
|
|
|
|
flushState->bindBuffers(nullptr, nullptr, fVertexData->refGpuBuffer());
|
|
|
|
flushState->draw(4, 0);
|
|
|
|
}
|
|
|
|
|
2020-11-02 13:57:39 +00:00
|
|
|
TestHelper::Stats* fStats;
|
|
|
|
int fWH;
|
|
|
|
int fID;
|
|
|
|
bool fFailFillingIn;
|
|
|
|
GrThreadSafeCache::IsNewerBetter fIsNewerBetter;
|
2020-10-23 20:13:57 +00:00
|
|
|
|
|
|
|
sk_sp<GrThreadSafeCache::VertexData> fVertexData;
|
2020-11-02 13:57:39 +00:00
|
|
|
GrProgramInfo* fProgramInfo = nullptr;
|
2020-10-23 20:13:57 +00:00
|
|
|
|
|
|
|
using INHERITED = GrDrawOp;
|
|
|
|
};
|
|
|
|
|
|
|
|
void TestHelper::addVertAccess(SkCanvas* canvas,
|
|
|
|
int wh, int id,
|
2020-11-02 13:57:39 +00:00
|
|
|
bool failLookup, bool failFillingIn,
|
|
|
|
GrThreadSafeVertexTestOp** createdOp) {
|
2020-10-23 20:13:57 +00:00
|
|
|
auto rContext = canvas->recordingContext();
|
2020-12-23 14:16:59 +00:00
|
|
|
auto sdc = SkCanvasPriv::TopDeviceSurfaceDrawContext(canvas);
|
2020-10-23 20:13:57 +00:00
|
|
|
|
2020-11-02 13:57:39 +00:00
|
|
|
GrOp::Owner op = GrThreadSafeVertexTestOp::Make(rContext, &fStats,
|
|
|
|
wh, id,
|
|
|
|
failLookup, failFillingIn,
|
|
|
|
fIsNewerBetter);
|
|
|
|
if (createdOp) {
|
|
|
|
*createdOp = (GrThreadSafeVertexTestOp*) op.get();
|
|
|
|
}
|
|
|
|
|
2020-12-23 14:16:59 +00:00
|
|
|
sdc->addDrawOp(std::move(op));
|
2020-10-23 20:13:57 +00:00
|
|
|
}
|
|
|
|
|
2020-09-16 14:57:32 +00:00
|
|
|
GrSurfaceProxyView TestHelper::CreateViewOnCpu(GrRecordingContext* rContext,
|
|
|
|
int wh,
|
|
|
|
Stats* stats) {
|
|
|
|
GrProxyProvider* proxyProvider = rContext->priv().proxyProvider();
|
|
|
|
|
2020-09-25 16:47:10 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->createProxyFromBitmap(create_bitmap(wh),
|
2020-09-16 14:57:32 +00:00
|
|
|
GrMipmapped::kNo,
|
|
|
|
SkBackingFit::kExact,
|
|
|
|
SkBudgeted::kYes);
|
|
|
|
if (!proxy) {
|
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
GrSwizzle swizzle = rContext->priv().caps()->getReadSwizzle(proxy->backendFormat(),
|
|
|
|
GrColorType::kRGBA_8888);
|
|
|
|
++stats->fNumSWCreations;
|
|
|
|
return {std::move(proxy), kImageOrigin, swizzle};
|
|
|
|
}
|
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
bool TestHelper::FillInViewOnGpu(GrDirectContext* dContext, int wh, Stats* stats,
|
|
|
|
const GrSurfaceProxyView& lazyView,
|
|
|
|
sk_sp<GrThreadSafeCache::Trampoline> trampoline) {
|
2020-09-25 16:47:10 +00:00
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
std::unique_ptr<skgpu::v1::SurfaceDrawContext> sdc = new_SDC(dContext, wh);
|
2020-09-25 16:47:10 +00:00
|
|
|
|
|
|
|
GrPaint paint;
|
|
|
|
paint.setColor4f({0.0f, 0.0f, 1.0f, 1.0f});
|
|
|
|
|
2021-07-28 19:13:20 +00:00
|
|
|
sdc->clear(SkPMColor4f{1.0f, 1.0f, 1.0f, 1.0f});
|
|
|
|
sdc->drawRect(nullptr, std::move(paint), GrAA::kNo, SkMatrix::I(),
|
2020-09-25 16:47:10 +00:00
|
|
|
{ 10, 10, wh-10.0f, wh-10.0f }, &GrStyle::SimpleFill());
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-09-16 14:57:32 +00:00
|
|
|
++stats->fNumHWCreations;
|
2021-07-28 19:13:20 +00:00
|
|
|
auto view = sdc->readSurfaceView();
|
2020-09-25 16:47:10 +00:00
|
|
|
|
|
|
|
SkASSERT(view.swizzle() == lazyView.swizzle());
|
|
|
|
SkASSERT(view.origin() == lazyView.origin());
|
|
|
|
trampoline->fProxy = view.asTextureProxyRef();
|
|
|
|
|
|
|
|
return true;
|
2020-09-16 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
GrSurfaceProxyView TestHelper::AccessCachedView(GrRecordingContext* rContext,
|
|
|
|
GrThreadSafeCache* threadSafeCache,
|
|
|
|
int wh,
|
|
|
|
bool failLookup, bool failFillingIn, int id,
|
|
|
|
Stats* stats) {
|
2020-09-16 14:57:32 +00:00
|
|
|
GrUniqueKey key;
|
2020-10-23 20:13:57 +00:00
|
|
|
create_view_key(&key, wh, id);
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-09-25 16:47:10 +00:00
|
|
|
if (GrDirectContext* dContext = rContext->asDirectContext()) {
|
|
|
|
// The gpu thread gets priority over the recording threads. If the gpu thread is first,
|
|
|
|
// it crams a lazy proxy into the cache and then fills it in later.
|
2020-10-08 15:00:02 +00:00
|
|
|
auto [lazyView, trampoline] = GrThreadSafeCache::CreateLazyView(
|
2020-10-07 19:33:43 +00:00
|
|
|
dContext, GrColorType::kRGBA_8888, {wh, wh}, kImageOrigin, SkBackingFit::kExact);
|
2020-10-06 20:44:18 +00:00
|
|
|
++stats->fNumLazyCreations;
|
2020-09-25 16:47:10 +00:00
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
auto [view, data] = threadSafeCache->findOrAddWithData(key, lazyView);
|
2020-09-25 16:47:10 +00:00
|
|
|
if (view != lazyView) {
|
|
|
|
++stats->fCacheHits;
|
|
|
|
return view;
|
2020-10-06 18:52:11 +00:00
|
|
|
} else if (id != kNoID) {
|
|
|
|
// Make sure, in this case, that the customData stuck
|
|
|
|
SkASSERT(data);
|
|
|
|
SkDEBUGCODE(const int* cachedID = static_cast<const int*>(data->data());)
|
|
|
|
SkASSERT(*cachedID == id);
|
2020-09-25 16:47:10 +00:00
|
|
|
}
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-09-25 16:47:10 +00:00
|
|
|
++stats->fCacheMisses;
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-09-25 16:47:10 +00:00
|
|
|
if (failFillingIn) {
|
|
|
|
// Simulate something going horribly wrong at flush-time so no GrTexture is
|
|
|
|
// available to fulfill the lazy proxy.
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!FillInViewOnGpu(dContext, wh, stats, lazyView, std::move(trampoline))) {
|
|
|
|
// In this case something has gone disastrously wrong so set up to drop the draw
|
|
|
|
// that needed this resource and reduce future pollution of the cache.
|
2020-10-08 15:00:02 +00:00
|
|
|
threadSafeCache->remove(key);
|
2020-09-25 16:47:10 +00:00
|
|
|
return {};
|
|
|
|
}
|
|
|
|
|
|
|
|
return view;
|
2020-09-16 14:57:32 +00:00
|
|
|
} else {
|
2020-09-25 16:47:10 +00:00
|
|
|
GrSurfaceProxyView view;
|
|
|
|
|
|
|
|
// We can "fail the lookup" to simulate a threaded race condition
|
2020-10-08 15:00:02 +00:00
|
|
|
if (view = threadSafeCache->find(key); !failLookup && view) {
|
2020-09-25 16:47:10 +00:00
|
|
|
++stats->fCacheHits;
|
|
|
|
return view;
|
|
|
|
}
|
|
|
|
|
|
|
|
++stats->fCacheMisses;
|
|
|
|
|
2020-09-16 14:57:32 +00:00
|
|
|
view = CreateViewOnCpu(rContext, wh, stats);
|
2020-09-25 16:47:10 +00:00
|
|
|
SkASSERT(view);
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
auto [newView, data] = threadSafeCache->addWithData(key, view);
|
2020-10-06 18:52:11 +00:00
|
|
|
if (view == newView && id != kNoID) {
|
|
|
|
// Make sure, in this case, that the customData stuck
|
|
|
|
SkASSERT(data);
|
|
|
|
SkDEBUGCODE(const int* cachedID = static_cast<const int*>(data->data());)
|
|
|
|
SkASSERT(*cachedID == id);
|
|
|
|
}
|
|
|
|
return newView;
|
2020-09-25 16:47:10 +00:00
|
|
|
}
|
2020-09-16 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
// Case 1: ensure two DDL recorders share the view/vertexData
|
|
|
|
static void test_1(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, 1, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, /*id*/ 1));
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), kImageWH, 2, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas2(), kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 2, /*id*/ 1));
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
2020-09-25 16:47:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 0);
|
2020-09-16 14:57:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 0);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 1);
|
2020-09-25 19:25:46 +00:00
|
|
|
|
|
|
|
helper.checkImage(reporter, helper.snap1());
|
|
|
|
helper.checkImage(reporter, helper.snap2());
|
2020-09-16 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache1View, reporter, ctxInfo) {
|
|
|
|
test_1(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache1Verts, reporter, ctxInfo) {
|
|
|
|
test_1(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Case 2: ensure that, if the direct context version wins, its result is reused by the
|
|
|
|
// DDL recorders
|
|
|
|
static void test_2(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.liveCanvas(), kImageWH, 1, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, /*id*/ 1));
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, 2, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 2, /*id*/ 1));
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), kImageWH, 3, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas2(), kImageWH,
|
|
|
|
/*hits*/ 2, /*misses*/ 1, /*refs*/ 3, /*id*/ 1));
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
2020-09-25 16:47:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 1);
|
2020-09-16 14:57:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 0);
|
2020-09-25 19:25:46 +00:00
|
|
|
|
|
|
|
helper.checkImage(reporter);
|
|
|
|
helper.checkImage(reporter, helper.snap1());
|
|
|
|
helper.checkImage(reporter, helper.snap2());
|
2020-09-16 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache2View, reporter, ctxInfo) {
|
|
|
|
test_2(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache2Verts, reporter, ctxInfo) {
|
|
|
|
test_2(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
// Case 3: ensure that, if the cpu-version wins, its result is reused by the direct context
|
|
|
|
static void test_3(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, 1, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, /*id*/ 1));
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.liveCanvas(), kImageWH, 2, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 2, /*id*/ 1));
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
2020-09-25 16:47:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 1);
|
2020-09-16 14:57:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 0);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 1);
|
2020-09-25 19:25:46 +00:00
|
|
|
|
|
|
|
helper.checkImage(reporter);
|
|
|
|
helper.checkImage(reporter, helper.snap1());
|
2020-09-16 14:57:32 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache3View, reporter, ctxInfo) {
|
|
|
|
test_3(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache3Verts, reporter, ctxInfo) {
|
|
|
|
test_3(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Case 4: ensure that, if two DDL recorders get in a race, they still end up sharing a single
|
|
|
|
// view/vertexData
|
|
|
|
static void test_4(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-16 14:57:32 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, 1, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, /*id*/ 1));
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
static const bool kFailLookup = true;
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), kImageWH, 2, kFailLookup, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas2(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 2, /*id*/ 1));
|
2020-09-16 14:57:32 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
2020-09-25 16:47:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 0);
|
2020-09-16 14:57:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 0);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 2);
|
2020-09-25 19:25:46 +00:00
|
|
|
|
|
|
|
helper.checkImage(reporter, helper.snap1());
|
|
|
|
helper.checkImage(reporter, helper.snap2());
|
2020-09-16 14:57:32 +00:00
|
|
|
}
|
2020-09-18 16:28:59 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache4View, reporter, ctxInfo) {
|
|
|
|
test_4(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache4Verts, reporter, ctxInfo) {
|
|
|
|
test_4(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
2020-09-25 16:47:10 +00:00
|
|
|
// Case 4.5: check that, if a live rendering and a DDL recording get into a race, the live
|
2020-10-23 20:13:57 +00:00
|
|
|
// rendering takes precedence.
|
|
|
|
static void test_4_5(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-25 16:47:10 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.liveCanvas(), kImageWH, 1, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, /*id*/ 1));
|
2020-09-25 16:47:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 0);
|
|
|
|
|
|
|
|
static const bool kFailLookup = true;
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, 2, kFailLookup, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 2, /*id*/ 1));
|
2020-09-25 16:47:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 1);
|
2020-09-25 19:25:46 +00:00
|
|
|
|
|
|
|
helper.checkImage(reporter);
|
|
|
|
helper.checkImage(reporter, helper.snap1());
|
2020-09-25 16:47:10 +00:00
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache4_5View, reporter, ctxInfo) {
|
|
|
|
test_4_5(ctxInfo.directContext(), reporter,
|
|
|
|
&TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache4_5Verts, reporter, ctxInfo) {
|
|
|
|
test_4_5(ctxInfo.directContext(), reporter,
|
|
|
|
&TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
2020-09-25 16:47:10 +00:00
|
|
|
// Case 4.75: check that, if a live rendering fails to generate the content needed to instantiate
|
|
|
|
// its lazy proxy, life goes on
|
2020-10-23 20:13:57 +00:00
|
|
|
static void test_4_75(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-25 16:47:10 +00:00
|
|
|
|
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
|
|
|
static const bool kFailFillingIn = true;
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.liveCanvas(), kImageWH, kNoID, false, kFailFillingIn);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
2020-09-25 16:47:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 0);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 0);
|
|
|
|
|
|
|
|
dContext->flush();
|
|
|
|
dContext->submit(true);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 0, kNoID));
|
2020-09-25 16:47:10 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 0);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 0);
|
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache4_75View, reporter, ctxInfo) {
|
|
|
|
test_4_75(ctxInfo.directContext(), reporter,
|
|
|
|
&TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache4_75Verts, reporter, ctxInfo) {
|
|
|
|
test_4_75(ctxInfo.directContext(), reporter,
|
|
|
|
&TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
2020-10-06 18:52:11 +00:00
|
|
|
// Case 5: ensure that expanding the map works (esp. wrt custom data)
|
2020-10-23 20:13:57 +00:00
|
|
|
static void test_5(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
|
|
|
|
|
|
|
TestHelper helper(dContext);
|
2020-09-18 16:28:59 +00:00
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
auto threadSafeCache = helper.threadSafeCache();
|
2020-09-18 16:28:59 +00:00
|
|
|
|
|
|
|
int size = 16;
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), size, /*id*/ size, false, false);
|
2020-09-18 16:28:59 +00:00
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
size_t initialSize = threadSafeCache->approxBytesUsedForHash();
|
2020-09-18 16:28:59 +00:00
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
while (initialSize == threadSafeCache->approxBytesUsedForHash()) {
|
2020-09-18 16:28:59 +00:00
|
|
|
size *= 2;
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), size, /*id*/ size, false, false);
|
2020-10-06 18:52:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
for (int i = 16; i <= size; i *= 2) {
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(),
|
|
|
|
/*wh*/ i,
|
|
|
|
/*hits*/ 0,
|
|
|
|
/*misses*/ threadSafeCache->numEntries(),
|
|
|
|
/*refs*/ 1,
|
|
|
|
/*id*/ i));
|
2020-09-18 16:28:59 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache5View, reporter, ctxInfo) {
|
|
|
|
test_5(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache5Verts, reporter, ctxInfo) {
|
|
|
|
test_5(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
2020-09-25 19:25:46 +00:00
|
|
|
// Case 6: Check on dropping refs. In particular, that the cache has its own ref to keep
|
2020-10-23 20:13:57 +00:00
|
|
|
// the backing resource alive and locked.
|
|
|
|
static void test_6(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
|
|
|
|
|
|
|
TestHelper helper(dContext);
|
2020-09-18 18:07:43 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, kNoID, false, false);
|
2020-09-18 18:07:43 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = helper.snap1();
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(nullptr, kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
2020-09-18 18:07:43 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), kImageWH, kNoID, false, false);
|
2020-09-18 18:07:43 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl2 = helper.snap2();
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(nullptr, kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 2, kNoID));
|
2020-09-18 18:07:43 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
|
|
|
|
ddl1 = nullptr;
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(nullptr, kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 1, kNoID));
|
2020-09-18 18:07:43 +00:00
|
|
|
|
|
|
|
ddl2 = nullptr;
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(nullptr, kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 0, kNoID));
|
2020-09-18 18:07:43 +00:00
|
|
|
|
|
|
|
// The cache still has its ref
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(nullptr, kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 0, kNoID));
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache6View, reporter, ctxInfo) {
|
|
|
|
test_6(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache6Verts, reporter, ctxInfo) {
|
|
|
|
test_6(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
2020-09-18 18:07:43 +00:00
|
|
|
}
|
2020-09-18 20:16:33 +00:00
|
|
|
|
2020-09-25 19:25:46 +00:00
|
|
|
// Case 7: Check that invoking dropAllRefs and dropUniqueRefs directly works as expected; i.e.,
|
2020-10-23 20:13:57 +00:00
|
|
|
// dropAllRefs removes everything while dropUniqueRefs is more measured.
|
|
|
|
static void test_7(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-18 20:16:33 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, kNoID, false, false);
|
2020-09-18 20:16:33 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = helper.snap1();
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(nullptr, kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
2020-09-18 20:16:33 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), 2*kImageWH, kNoID, false, false);
|
2020-09-18 20:16:33 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl2 = helper.snap2();
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(nullptr, 2*kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 1, kNoID));
|
2020-09-18 20:16:33 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 2);
|
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
helper.threadSafeCache()->dropUniqueRefs(nullptr);
|
2020-09-18 20:16:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 2);
|
|
|
|
|
|
|
|
ddl1 = nullptr;
|
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
helper.threadSafeCache()->dropUniqueRefs(nullptr);
|
2020-09-18 20:16:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(nullptr, 2*kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 1, kNoID));
|
2020-09-18 20:16:33 +00:00
|
|
|
|
2020-10-08 15:00:02 +00:00
|
|
|
helper.threadSafeCache()->dropAllRefs();
|
2020-09-18 20:16:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 0);
|
|
|
|
|
|
|
|
ddl2 = nullptr;
|
|
|
|
}
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache7View, reporter, ctxInfo) {
|
|
|
|
test_7(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache7Verts, reporter, ctxInfo) {
|
|
|
|
test_7(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
2020-09-22 16:18:16 +00:00
|
|
|
// Case 8: This checks that GrContext::abandonContext works as expected wrt the thread
|
|
|
|
// safe cache. This simulates the case where we have one DDL that has finished
|
|
|
|
// recording but one still recording when the abandonContext fires.
|
2020-10-23 20:13:57 +00:00
|
|
|
static void test_8(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
TestHelper helper(dContext);
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.liveCanvas(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, kNoID, false, false);
|
2020-09-22 16:18:16 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = helper.snap1();
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 2, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas2(), kImageWH,
|
|
|
|
/*hits*/ 2, /*misses*/ 1, /*refs*/ 3, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
2020-09-25 16:47:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 1);
|
2020-09-22 16:18:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 0);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
dContext->abandonContext(); // This should exercise dropAllRefs
|
2020-09-22 16:18:16 +00:00
|
|
|
|
|
|
|
sk_sp<SkDeferredDisplayList> ddl2 = helper.snap2();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 0);
|
|
|
|
|
|
|
|
ddl1 = nullptr;
|
|
|
|
ddl2 = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache8View, reporter, ctxInfo) {
|
|
|
|
test_8(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache8Verts, reporter, ctxInfo) {
|
|
|
|
test_8(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
2020-09-22 16:18:16 +00:00
|
|
|
// Case 9: This checks that GrContext::releaseResourcesAndAbandonContext works as expected wrt
|
|
|
|
// the thread safe cache. This simulates the case where we have one DDL that has finished
|
|
|
|
// recording but one still recording when the releaseResourcesAndAbandonContext fires.
|
2020-10-23 20:13:57 +00:00
|
|
|
static void test_9(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.liveCanvas(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, kNoID, false, false);
|
2020-09-22 16:18:16 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = helper.snap1();
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 2, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas2(), kImageWH,
|
|
|
|
/*hits*/ 2, /*misses*/ 1, /*refs*/ 3, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
2020-09-25 16:47:10 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumLazyCreations == 1);
|
2020-09-22 16:18:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumHWCreations == 1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.stats()->fNumSWCreations == 0);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
dContext->releaseResourcesAndAbandonContext(); // This should hit dropAllRefs
|
2020-09-22 16:18:16 +00:00
|
|
|
|
|
|
|
sk_sp<SkDeferredDisplayList> ddl2 = helper.snap2();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 0);
|
|
|
|
|
|
|
|
ddl1 = nullptr;
|
|
|
|
ddl2 = nullptr;
|
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache9View, reporter, ctxInfo) {
|
|
|
|
test_9(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache9Verts, reporter, ctxInfo) {
|
|
|
|
test_9(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
2020-09-22 16:18:16 +00:00
|
|
|
// Case 10: This checks that the GrContext::purgeUnlockedResources(size_t) variant works as
|
|
|
|
// expected wrt the thread safe cache. It, in particular, tests out the MRU behavior
|
|
|
|
// of the shared cache.
|
2020-10-23 20:13:57 +00:00
|
|
|
static void test_10(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2021-06-28 13:20:44 +00:00
|
|
|
|
|
|
|
if (GrBackendApi::kOpenGL != dContext->backend()) {
|
|
|
|
// The lower-level backends have too much going on for the following simple purging
|
|
|
|
// test to work
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2020-09-22 16:18:16 +00:00
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.liveCanvas(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, kNoID, false, false);
|
2020-09-22 16:18:16 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = helper.snap1();
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 2, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.liveCanvas(), 2*kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), 2*kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 2, /*refs*/ 1, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), 2*kImageWH, kNoID, false, false);
|
2020-09-22 16:18:16 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl2 = helper.snap2();
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas2(), 2*kImageWH,
|
|
|
|
/*hits*/ 2, /*misses*/ 2, /*refs*/ 2, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
|
|
|
dContext->flush();
|
|
|
|
dContext->submit(true);
|
|
|
|
|
|
|
|
// This should clear out everything but the textures locked in the thread-safe cache
|
|
|
|
dContext->purgeUnlockedResources(false);
|
|
|
|
|
|
|
|
ddl1 = nullptr;
|
|
|
|
ddl2 = nullptr;
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 2);
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 2, /*misses*/ 2, /*refs*/ 0, kNoID));
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), 2*kImageWH,
|
|
|
|
/*hits*/ 2, /*misses*/ 2, /*refs*/ 0, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
|
|
|
|
// Regardless of which image is MRU, this should force the other out
|
|
|
|
size_t desiredBytes = helper.gpuSize(2*kImageWH) + helper.gpuSize(kImageWH)/2;
|
|
|
|
|
|
|
|
auto cache = dContext->priv().getResourceCache();
|
|
|
|
size_t currentBytes = cache->getResourceBytes();
|
|
|
|
|
|
|
|
SkASSERT(currentBytes >= desiredBytes);
|
|
|
|
size_t amountToPurge = currentBytes - desiredBytes;
|
|
|
|
|
|
|
|
// The 2*kImageWH texture should be MRU.
|
|
|
|
dContext->purgeUnlockedResources(amountToPurge, true);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), 2*kImageWH,
|
|
|
|
/*hits*/ 2, /*misses*/ 2, /*refs*/ 0, kNoID));
|
2020-09-22 16:18:16 +00:00
|
|
|
}
|
2020-09-22 19:20:01 +00:00
|
|
|
|
2021-06-28 13:20:44 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache10View, reporter, ctxInfo) {
|
|
|
|
test_10(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
2020-10-23 20:13:57 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// To enable test_10 with verts would require a bit more work, namely:
|
|
|
|
// have a different # of verts based on size
|
|
|
|
// also pass in a gpuSize function to 'test_10'
|
|
|
|
//DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache10Verts, reporter, ctxInfo) {
|
|
|
|
// test_10(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
//}
|
|
|
|
|
2020-09-22 19:20:01 +00:00
|
|
|
// Case 11: This checks that scratch-only variant of GrContext::purgeUnlockedResources works as
|
2020-09-25 19:25:46 +00:00
|
|
|
// expected wrt the thread safe cache. In particular, that when 'scratchResourcesOnly'
|
|
|
|
// is true, the call has no effect on the cache.
|
2020-10-23 20:13:57 +00:00
|
|
|
static void test_11(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-22 19:20:01 +00:00
|
|
|
|
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.liveCanvas(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
2020-09-22 19:20:01 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.liveCanvas(), 2*kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), 2*kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 1, kNoID));
|
2020-09-22 19:20:01 +00:00
|
|
|
|
|
|
|
dContext->flush();
|
|
|
|
dContext->submit(true);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 2);
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 0, kNoID));
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), 2*kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 0, kNoID));
|
2020-09-22 19:20:01 +00:00
|
|
|
|
|
|
|
// This shouldn't remove anything from the cache
|
|
|
|
dContext->purgeUnlockedResources(/* scratchResourcesOnly */ true);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 2);
|
|
|
|
|
|
|
|
dContext->purgeUnlockedResources(/* scratchResourcesOnly */ false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 0);
|
|
|
|
}
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache11View, reporter, ctxInfo) {
|
|
|
|
test_11(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache11Verts, reporter, ctxInfo) {
|
|
|
|
test_11(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
2020-09-25 19:25:46 +00:00
|
|
|
// Case 12: Test out purges caused by resetting the cache budget to 0. Note that, due to
|
|
|
|
// the how the cache operates (i.e., not directly driven by ref/unrefs) there
|
|
|
|
// needs to be an explicit kick to purge the cache.
|
2020-10-23 20:13:57 +00:00
|
|
|
static void test_12(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-22 19:20:01 +00:00
|
|
|
|
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.liveCanvas(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, kNoID, false, false);
|
2020-09-22 19:20:01 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = helper.snap1();
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 1, /*refs*/ 2, kNoID));
|
2020-09-22 19:20:01 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.liveCanvas(), 2*kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), 2*kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 2, /*refs*/ 1, kNoID));
|
2020-09-22 19:20:01 +00:00
|
|
|
|
|
|
|
dContext->flush();
|
|
|
|
dContext->submit(true);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 2);
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 2, /*refs*/ 1, kNoID));
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), 2*kImageWH,
|
|
|
|
/*hits*/ 1, /*misses*/ 2, /*refs*/ 0, kNoID));
|
2020-09-22 19:20:01 +00:00
|
|
|
|
|
|
|
dContext->setResourceCacheLimit(0);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
|
|
|
|
ddl1 = nullptr;
|
|
|
|
|
2020-09-25 19:25:46 +00:00
|
|
|
// Explicitly kick off the purge - it won't happen automatically on unref
|
2020-09-22 19:20:01 +00:00
|
|
|
dContext->performDeferredCleanup(std::chrono::milliseconds(0));
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 0);
|
|
|
|
}
|
2020-09-22 21:34:51 +00:00
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache12View, reporter, ctxInfo) {
|
|
|
|
test_12(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache12Verts, reporter, ctxInfo) {
|
|
|
|
test_12(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
|
|
|
}
|
|
|
|
|
2020-09-22 21:34:51 +00:00
|
|
|
// Case 13: Test out the 'msNotUsed' parameter to GrContext::performDeferredCleanup.
|
2020-10-23 20:13:57 +00:00
|
|
|
static void test_13(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check) {
|
2020-09-22 21:34:51 +00:00
|
|
|
|
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
2020-09-22 21:34:51 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = helper.snap1();
|
|
|
|
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
|
|
auto firstTime = GrStdSteadyClock::now();
|
|
|
|
std::this_thread::sleep_for(std::chrono::milliseconds(5));
|
|
|
|
|
2020-10-23 20:13:57 +00:00
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), 2*kImageWH, kNoID, false, false);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas2(), 2*kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 1, kNoID));
|
2020-09-22 21:34:51 +00:00
|
|
|
sk_sp<SkDeferredDisplayList> ddl2 = helper.snap2();
|
|
|
|
|
|
|
|
ddl1 = nullptr;
|
|
|
|
ddl2 = nullptr;
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 2);
|
|
|
|
|
|
|
|
auto secondTime = GrStdSteadyClock::now();
|
|
|
|
|
|
|
|
auto msecs = std::chrono::duration_cast<std::chrono::milliseconds>(secondTime - firstTime);
|
|
|
|
dContext->performDeferredCleanup(msecs);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
2020-10-23 20:13:57 +00:00
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.liveCanvas(), 2*kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 0, kNoID));
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache13View, reporter, ctxInfo) {
|
|
|
|
test_13(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache13Verts, reporter, ctxInfo) {
|
|
|
|
test_13(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert);
|
2020-09-22 21:34:51 +00:00
|
|
|
}
|
2020-10-26 17:50:57 +00:00
|
|
|
|
|
|
|
// Case 14: Test out mixing & matching view & vertex data w/ recycling of the cache entries to
|
|
|
|
// wring out the anonymous union code. This is mainly for the MSAN bot's consumption.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache14, reporter, ctxInfo) {
|
|
|
|
constexpr int kBestPrimeNumber = 73; // palindromic in binary
|
|
|
|
SkRandom rand(kBestPrimeNumber);
|
|
|
|
|
|
|
|
TestHelper helper(ctxInfo.directContext());
|
|
|
|
|
|
|
|
for (int i = 0; i < 2; ++i) {
|
|
|
|
SkCanvas* ddlCanvas = (!i) ? helper.ddlCanvas1() : helper.ddlCanvas2();
|
|
|
|
|
|
|
|
for (int j = 0; j < 10; ++j) {
|
|
|
|
int numResources = 10*i + j + 1;
|
|
|
|
int wh = numResources;
|
|
|
|
|
|
|
|
if (rand.nextBool()) {
|
|
|
|
helper.addViewAccess(ddlCanvas, wh, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, helper.checkView(ddlCanvas, wh,
|
|
|
|
/*hits*/ 0, /*misses*/ numResources,
|
|
|
|
/*refs*/ 1, kNoID));
|
|
|
|
} else {
|
|
|
|
helper.addVertAccess(ddlCanvas, wh, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, helper.checkVert(ddlCanvas, wh,
|
|
|
|
/*hits*/ 0, /*misses*/ numResources,
|
|
|
|
/*refs*/ 1, kNoID));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!i) {
|
|
|
|
// Drop all the accumulated resources from the thread-safe cache
|
|
|
|
helper.snap1();
|
|
|
|
ctxInfo.directContext()->purgeUnlockedResources(/* scratchResourcesOnly */ false);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-10-28 18:57:53 +00:00
|
|
|
|
|
|
|
// Case 15: Test out posting invalidation messages that involve the thread safe cache
|
|
|
|
static void test_15(GrDirectContext* dContext, skiatest::Reporter* reporter,
|
|
|
|
TestHelper::addAccessFP addAccess,
|
|
|
|
TestHelper::checkFP check,
|
|
|
|
void (*create_key)(GrUniqueKey*, int wh, int id)) {
|
|
|
|
|
|
|
|
TestHelper helper(dContext);
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.ddlCanvas1(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = helper.snap1();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
|
|
|
|
GrUniqueKey key;
|
|
|
|
(*create_key)(&key, kImageWH, kNoID);
|
|
|
|
|
|
|
|
GrUniqueKeyInvalidatedMessage msg(key, dContext->priv().contextID(),
|
|
|
|
/* inThreadSafeCache */ true);
|
|
|
|
|
2021-03-11 19:44:42 +00:00
|
|
|
SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t>::Post(msg);
|
2020-10-28 18:57:53 +00:00
|
|
|
|
|
|
|
// This purge call is needed to process the invalidation messages
|
|
|
|
dContext->purgeUnlockedResources(/* scratchResourcesOnly */ true);
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 0);
|
|
|
|
|
|
|
|
(helper.*addAccess)(helper.ddlCanvas2(), kImageWH, kNoID, false, false);
|
|
|
|
REPORTER_ASSERT(reporter, (helper.*check)(helper.ddlCanvas2(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 1, kNoID));
|
|
|
|
sk_sp<SkDeferredDisplayList> ddl2 = helper.snap2();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
|
|
|
|
helper.checkImage(reporter, std::move(ddl1));
|
|
|
|
helper.checkImage(reporter, std::move(ddl2));
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache15View, reporter, ctxInfo) {
|
|
|
|
test_15(ctxInfo.directContext(), reporter, &TestHelper::addViewAccess, &TestHelper::checkView,
|
|
|
|
create_view_key);
|
|
|
|
}
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache15Verts, reporter, ctxInfo) {
|
|
|
|
test_15(ctxInfo.directContext(), reporter, &TestHelper::addVertAccess, &TestHelper::checkVert,
|
|
|
|
create_vert_key);
|
|
|
|
}
|
2020-11-02 13:57:39 +00:00
|
|
|
|
|
|
|
// Case 16: Test out pre-emption of an existing vertex-data cache entry. This test simulates
|
|
|
|
// the case where there is a race to create vertex data. However, the second one
|
|
|
|
// to finish is better and usurps the first's position in the cache.
|
|
|
|
//
|
|
|
|
// This capability isn't available for views.
|
|
|
|
|
|
|
|
static bool newer_is_always_better(SkData* /* incumbent */, SkData* /* challenger */) {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(GrThreadSafeCache16Verts, reporter, ctxInfo) {
|
|
|
|
GrUniqueKey key;
|
|
|
|
create_vert_key(&key, kImageWH, kNoID);
|
|
|
|
|
|
|
|
TestHelper helper(ctxInfo.directContext(), newer_is_always_better);
|
|
|
|
|
|
|
|
GrThreadSafeVertexTestOp* op1 = nullptr, *op2 = nullptr;
|
|
|
|
|
|
|
|
helper.addVertAccess(helper.ddlCanvas1(), kImageWH, kNoID, false, false, &op1);
|
|
|
|
REPORTER_ASSERT(reporter, helper.checkVert(helper.ddlCanvas1(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 1, /*refs*/ 1, kNoID));
|
|
|
|
sk_sp<SkDeferredDisplayList> ddl1 = helper.snap1();
|
|
|
|
|
|
|
|
{
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
auto [vertexData, xtraData] = helper.threadSafeCache()->findVertsWithData(key);
|
|
|
|
REPORTER_ASSERT(reporter, vertexData.get() == op1->vertexData());
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.addVertAccess(helper.ddlCanvas2(), kImageWH, kNoID, /* failLookup */ true, false, &op2);
|
|
|
|
REPORTER_ASSERT(reporter, helper.checkVert(helper.ddlCanvas2(), kImageWH,
|
|
|
|
/*hits*/ 0, /*misses*/ 2, /*refs*/ 1, kNoID));
|
|
|
|
sk_sp<SkDeferredDisplayList> ddl2 = helper.snap2();
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, op1->vertexData() != op2->vertexData());
|
|
|
|
|
|
|
|
{
|
|
|
|
REPORTER_ASSERT(reporter, helper.numCacheEntries() == 1);
|
|
|
|
auto [vertexData, xtraData] = helper.threadSafeCache()->findVertsWithData(key);
|
|
|
|
REPORTER_ASSERT(reporter, vertexData.get() == op2->vertexData());
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.checkImage(reporter, std::move(ddl1));
|
|
|
|
helper.checkImage(reporter, std::move(ddl2));
|
|
|
|
}
|