2017-09-21 12:26:08 +00:00
|
|
|
/*
|
|
|
|
* Copyright 2017 Google Inc.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
|
|
* found in the LICENSE file.
|
|
|
|
*/
|
|
|
|
|
|
|
|
// This is a GPU-backend specific test.
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
|
|
|
|
2020-12-23 15:11:33 +00:00
|
|
|
#include "include/core/SkBitmap.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "include/core/SkImage.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrBackendSurface.h"
|
2020-07-06 14:56:46 +00:00
|
|
|
#include "include/gpu/GrDirectContext.h"
|
2020-10-14 15:23:11 +00:00
|
|
|
#include "src/gpu/GrDirectContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
2020-07-23 17:54:35 +00:00
|
|
|
#include "src/gpu/GrRecordingContextPriv.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/GrResourceCache.h"
|
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
2020-03-05 19:14:18 +00:00
|
|
|
#include "src/gpu/GrTexture.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "src/gpu/SkGr.h"
|
2020-10-13 00:45:06 +00:00
|
|
|
#include "tools/gpu/ManagedBackendTexture.h"
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2020-07-15 13:17:59 +00:00
|
|
|
#ifdef SK_DAWN
|
|
|
|
#include "src/gpu/dawn/GrDawnGpu.h"
|
|
|
|
#endif
|
|
|
|
|
2018-01-08 18:40:32 +00:00
|
|
|
int GrProxyProvider::numUniqueKeyProxies_TestOnly() const {
|
2017-09-21 12:26:08 +00:00
|
|
|
return fUniquelyKeyedProxies.count();
|
|
|
|
}
|
|
|
|
|
2019-08-05 16:58:39 +00:00
|
|
|
static constexpr auto kColorType = GrColorType::kRGBA_8888;
|
|
|
|
static constexpr auto kSize = SkISize::Make(64, 64);
|
2017-09-21 12:26:08 +00:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Basic test
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter,
|
|
|
|
GrRecordingContext* rContext,
|
|
|
|
GrProxyProvider* proxyProvider,
|
|
|
|
SkBackingFit fit) {
|
|
|
|
const GrCaps* caps = rContext->priv().caps();
|
2019-07-30 16:49:10 +00:00
|
|
|
|
2019-08-05 16:58:39 +00:00
|
|
|
GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kNo);
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2020-02-14 15:47:18 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy =
|
2020-07-21 13:27:25 +00:00
|
|
|
proxyProvider->createProxy(format, kSize, GrRenderable::kNo, 1, GrMipmapped::kNo, fit,
|
2020-03-27 00:37:01 +00:00
|
|
|
SkBudgeted::kYes, GrProtected::kNo);
|
2017-09-21 12:26:08 +00:00
|
|
|
// Only budgeted & wrapped external proxies get to carry uniqueKeys
|
2017-09-26 16:49:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
|
|
|
|
return proxy;
|
2017-09-21 12:26:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter,
|
|
|
|
GrRecordingContext* rContext,
|
|
|
|
GrProxyProvider* proxyProvider,
|
|
|
|
SkBackingFit fit) {
|
|
|
|
const GrCaps* caps = rContext->priv().caps();
|
2019-07-30 16:49:10 +00:00
|
|
|
|
2019-08-05 16:58:39 +00:00
|
|
|
GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2020-02-14 15:47:18 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy =
|
2020-07-21 13:27:25 +00:00
|
|
|
proxyProvider->createProxy(format, kSize, GrRenderable::kYes, 1, GrMipmapped::kNo, fit,
|
2020-03-27 00:37:01 +00:00
|
|
|
SkBudgeted::kYes, GrProtected::kNo);
|
2017-09-21 12:26:08 +00:00
|
|
|
// Only budgeted & wrapped external proxies get to carry uniqueKeys
|
2017-09-26 16:49:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
|
|
|
|
return proxy;
|
|
|
|
}
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrRecordingContext*,
|
2018-01-17 18:35:46 +00:00
|
|
|
GrProxyProvider* proxyProvider, SkBackingFit fit) {
|
2018-09-27 15:28:03 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
|
2020-02-14 15:47:18 +00:00
|
|
|
kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
|
2018-01-16 13:06:32 +00:00
|
|
|
// Only budgeted & wrapped external proxies get to carry uniqueKeys
|
2017-09-26 16:49:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
|
|
|
|
return proxy;
|
2017-09-21 12:26:08 +00:00
|
|
|
}
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrRecordingContext*,
|
2018-01-17 18:35:46 +00:00
|
|
|
GrProxyProvider* proxyProvider, SkBackingFit fit) {
|
2017-09-26 16:49:26 +00:00
|
|
|
static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
|
|
|
|
static int kUniqueKeyData = 0;
|
|
|
|
|
|
|
|
GrUniqueKey key;
|
|
|
|
|
|
|
|
GrUniqueKey::Builder builder(&key, d, 1, nullptr);
|
|
|
|
builder[0] = kUniqueKeyData++;
|
|
|
|
builder.finish();
|
|
|
|
|
2018-01-17 18:35:46 +00:00
|
|
|
// Only budgeted & wrapped external proxies get to carry uniqueKeys
|
2018-09-27 15:28:03 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
|
2020-02-14 15:47:18 +00:00
|
|
|
kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
|
2018-01-17 18:35:46 +00:00
|
|
|
SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
|
2017-09-26 16:49:26 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid());
|
|
|
|
return proxy;
|
2017-09-21 12:26:08 +00:00
|
|
|
}
|
|
|
|
|
2020-10-13 00:45:06 +00:00
|
|
|
static sk_sp<GrTextureProxy> create_wrapped_backend(GrDirectContext* dContext) {
|
|
|
|
auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
|
|
|
|
dContext,
|
|
|
|
kSize.width(),
|
|
|
|
kSize.height(),
|
|
|
|
GrColorTypeToSkColorType(kColorType),
|
|
|
|
GrMipmapped::kNo,
|
|
|
|
GrRenderable::kNo,
|
|
|
|
GrProtected::kNo);
|
|
|
|
if (!mbet) {
|
2017-09-21 12:26:08 +00:00
|
|
|
return nullptr;
|
|
|
|
}
|
2020-10-13 00:45:06 +00:00
|
|
|
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
|
|
|
|
return proxyProvider->wrapBackendTexture(mbet->texture(),
|
|
|
|
kBorrow_GrWrapOwnership,
|
|
|
|
GrWrapCacheable::kYes,
|
|
|
|
kRead_GrIOType,
|
|
|
|
mbet->refCountedCallback());
|
2017-09-21 12:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
|
|
|
|
// and looking them up work, etc.
|
2020-07-23 17:54:35 +00:00
|
|
|
static void basic_test(GrDirectContext* dContext,
|
2017-09-21 12:26:08 +00:00
|
|
|
skiatest::Reporter* reporter,
|
2021-03-12 21:29:40 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy,
|
|
|
|
int cacheEntriesPerProxy) {
|
2017-09-21 12:26:08 +00:00
|
|
|
static int id = 1;
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
|
|
|
|
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
|
|
|
|
GrResourceCache* cache = dContext->priv().getResourceCache();
|
2017-09-21 12:26:08 +00:00
|
|
|
|
|
|
|
int startCacheCount = cache->getResourceCount();
|
|
|
|
|
|
|
|
GrUniqueKey key;
|
2017-09-26 16:49:26 +00:00
|
|
|
if (proxy->getUniqueKey().isValid()) {
|
|
|
|
key = proxy->getUniqueKey();
|
|
|
|
} else {
|
|
|
|
GrMakeKeyFromImageID(&key, id, SkIRect::MakeWH(64, 64));
|
|
|
|
++id;
|
|
|
|
|
|
|
|
// Assigning the uniqueKey adds the proxy to the hash but doesn't force instantiation
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
|
2018-01-17 18:35:46 +00:00
|
|
|
SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
|
2017-09-26 16:49:26 +00:00
|
|
|
}
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2017-09-21 12:26:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, startCacheCount == cache->getResourceCount());
|
|
|
|
|
|
|
|
// setUniqueKey had better stick
|
|
|
|
REPORTER_ASSERT(reporter, key == proxy->getUniqueKey());
|
|
|
|
|
|
|
|
// We just added it, surely we can find it
|
2020-03-27 00:37:01 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(key));
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2021-03-05 22:50:08 +00:00
|
|
|
int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : cacheEntriesPerProxy);
|
2018-09-10 18:10:19 +00:00
|
|
|
|
2017-09-21 12:26:08 +00:00
|
|
|
// Once instantiated, the backing resource should have the same key
|
2018-01-08 18:40:32 +00:00
|
|
|
SkAssertResult(proxy->instantiate(resourceProvider));
|
2019-01-24 17:18:33 +00:00
|
|
|
const GrUniqueKey texKey = proxy->peekSurface()->getUniqueKey();
|
2017-09-21 12:26:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, texKey.isValid());
|
|
|
|
REPORTER_ASSERT(reporter, key == texKey);
|
|
|
|
|
2019-01-24 17:18:33 +00:00
|
|
|
// An Unbudgeted-cacheable resource will not get purged when a proxy with the same key is
|
|
|
|
// deleted.
|
|
|
|
bool expectResourceToOutliveProxy = proxy->peekSurface()->resourcePriv().budgetedType() ==
|
|
|
|
GrBudgetedType::kUnbudgetedCacheable;
|
|
|
|
|
|
|
|
// An Unbudgeted-uncacheable resource is never kept alive if it's ref cnt reaches zero even if
|
|
|
|
// it has a key.
|
|
|
|
bool expectDeletingProxyToDeleteResource =
|
|
|
|
proxy->peekSurface()->resourcePriv().budgetedType() ==
|
|
|
|
GrBudgetedType::kUnbudgetedUncacheable;
|
|
|
|
|
2017-09-21 12:26:08 +00:00
|
|
|
// deleting the proxy should delete it from the hash but not the cache
|
|
|
|
proxy = nullptr;
|
2019-01-24 17:18:33 +00:00
|
|
|
if (expectDeletingProxyToDeleteResource) {
|
2021-03-05 22:50:08 +00:00
|
|
|
expectedCacheCount -= cacheEntriesPerProxy;
|
2019-01-24 17:18:33 +00:00
|
|
|
}
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2018-09-10 18:10:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
|
2017-09-21 12:26:08 +00:00
|
|
|
|
|
|
|
// If the proxy was cached refinding it should bring it back to life
|
2020-03-27 00:37:01 +00:00
|
|
|
proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
|
2018-09-10 18:10:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, proxy);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
|
|
|
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
|
2017-09-21 12:26:08 +00:00
|
|
|
|
|
|
|
// Mega-purging it should remove it from both the hash and the cache
|
|
|
|
proxy = nullptr;
|
2021-06-10 00:49:48 +00:00
|
|
|
cache->purgeUnlockedResources();
|
2019-01-24 17:18:33 +00:00
|
|
|
if (!expectResourceToOutliveProxy) {
|
2021-03-05 22:50:08 +00:00
|
|
|
expectedCacheCount -= cacheEntriesPerProxy;
|
2019-01-24 17:18:33 +00:00
|
|
|
}
|
2018-09-10 18:10:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2019-01-24 17:18:33 +00:00
|
|
|
// If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
|
|
|
|
// be.
|
2020-03-27 00:37:01 +00:00
|
|
|
proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
|
2019-01-24 17:18:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
|
2018-09-10 18:10:19 +00:00
|
|
|
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
|
2019-01-24 17:18:33 +00:00
|
|
|
|
|
|
|
if (expectResourceToOutliveProxy) {
|
|
|
|
proxy.reset();
|
2020-07-23 17:54:35 +00:00
|
|
|
GrUniqueKeyInvalidatedMessage msg(texKey, dContext->priv().contextID());
|
2021-03-11 19:44:42 +00:00
|
|
|
SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t>::Post(msg);
|
2019-01-24 17:18:33 +00:00
|
|
|
cache->purgeAsNeeded();
|
2021-03-05 22:50:08 +00:00
|
|
|
expectedCacheCount -= cacheEntriesPerProxy;
|
2020-03-27 00:37:01 +00:00
|
|
|
proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
|
2019-01-24 17:18:33 +00:00
|
|
|
REPORTER_ASSERT(reporter, !proxy);
|
|
|
|
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
|
|
|
|
}
|
2017-09-21 12:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Invalidation test
|
|
|
|
|
|
|
|
// Test if invalidating unique ids operates as expected for texture proxies.
|
2021-03-12 21:29:40 +00:00
|
|
|
static void invalidation_test(GrDirectContext* dContext,
|
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
int cacheEntriesPerProxy) {
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
|
|
|
|
GrResourceCache* cache = dContext->priv().getResourceCache();
|
2017-09-21 12:26:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
|
|
|
|
sk_sp<SkImage> rasterImg;
|
|
|
|
|
|
|
|
{
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(64, 64, kRGBA_8888_SkColorType, kOpaque_SkAlphaType);
|
|
|
|
|
|
|
|
SkBitmap bm;
|
|
|
|
bm.allocPixels(ii);
|
|
|
|
|
2020-12-23 16:50:36 +00:00
|
|
|
rasterImg = bm.asImage();
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2017-09-21 12:26:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
}
|
|
|
|
|
2020-07-15 13:17:59 +00:00
|
|
|
// Some of our backends use buffers to do uploads that will live in our resource cache. So we
|
|
|
|
// need to account for those extra resources here.
|
|
|
|
int bufferResources = 0;
|
2020-07-23 17:54:35 +00:00
|
|
|
if (dContext->backend() == GrBackendApi::kDawn ||
|
|
|
|
dContext->backend() == GrBackendApi::kVulkan ||
|
2020-07-31 13:47:08 +00:00
|
|
|
dContext->backend() == GrBackendApi::kDirect3D ||
|
|
|
|
dContext->backend() == GrBackendApi::kMetal) {
|
2020-07-15 13:17:59 +00:00
|
|
|
bufferResources = 1;
|
|
|
|
}
|
|
|
|
|
2020-07-23 17:54:35 +00:00
|
|
|
sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(dContext);
|
2020-03-18 14:06:13 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2021-03-12 21:29:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, cacheEntriesPerProxy + bufferResources == cache->getResourceCount());
|
2017-09-21 12:26:08 +00:00
|
|
|
|
|
|
|
rasterImg = nullptr; // this invalidates the uniqueKey
|
|
|
|
|
|
|
|
// this forces the cache to respond to the inval msg
|
2020-07-23 17:54:35 +00:00
|
|
|
size_t maxBytes = dContext->getResourceCacheLimit();
|
|
|
|
dContext->setResourceCacheLimit(maxBytes-1);
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2021-03-12 21:29:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, cacheEntriesPerProxy + bufferResources == cache->getResourceCount());
|
2017-09-21 12:26:08 +00:00
|
|
|
|
|
|
|
textureImg = nullptr;
|
2020-07-15 13:17:59 +00:00
|
|
|
|
|
|
|
// For backends that use buffers to upload lets make sure that work has been submit and done
|
|
|
|
// before we try to purge all resources.
|
2020-07-23 17:54:35 +00:00
|
|
|
dContext->submit(true);
|
2020-07-15 13:17:59 +00:00
|
|
|
|
|
|
|
#ifdef SK_DAWN
|
|
|
|
// The forced cpu sync in dawn doesn't actually mean the async map will finish thus we may
|
|
|
|
// still have a ref on the GrGpuBuffer and it will not get purged by the call below. We dig
|
|
|
|
// deep into the dawn gpu to make sure we wait for the async map to finish.
|
2020-07-23 17:54:35 +00:00
|
|
|
if (dContext->backend() == GrBackendApi::kDawn) {
|
|
|
|
GrDawnGpu* gpu = static_cast<GrDawnGpu*>(dContext->priv().getGpu());
|
2020-07-15 13:17:59 +00:00
|
|
|
gpu->waitOnAllBusyStagingBuffers();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-06-10 00:49:48 +00:00
|
|
|
dContext->priv().getResourceCache()->purgeUnlockedResources();
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2017-09-21 12:26:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
}
|
|
|
|
|
2017-09-27 17:11:16 +00:00
|
|
|
// Test if invalidating unique ids prior to instantiating operates as expected
|
2020-07-23 17:54:35 +00:00
|
|
|
static void invalidation_and_instantiation_test(GrDirectContext* dContext,
|
2021-03-12 21:29:40 +00:00
|
|
|
skiatest::Reporter* reporter,
|
|
|
|
int cacheEntriesPerProxy) {
|
2020-07-23 17:54:35 +00:00
|
|
|
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
|
|
|
|
GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
|
|
|
|
GrResourceCache* cache = dContext->priv().getResourceCache();
|
2017-09-27 17:11:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
|
|
|
|
static GrUniqueKey::Domain d = GrUniqueKey::GenerateDomain();
|
|
|
|
GrUniqueKey key;
|
|
|
|
GrUniqueKey::Builder builder(&key, d, 1, nullptr);
|
|
|
|
builder[0] = 0;
|
|
|
|
builder.finish();
|
|
|
|
|
|
|
|
// Create proxy, assign unique key
|
2020-07-23 17:54:35 +00:00
|
|
|
sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, dContext, proxyProvider,
|
2018-11-16 20:43:41 +00:00
|
|
|
SkBackingFit::kExact);
|
2018-01-17 18:35:46 +00:00
|
|
|
SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
|
2017-09-27 17:11:16 +00:00
|
|
|
|
|
|
|
// Send an invalidation message, which will be sitting in the cache's inbox
|
2021-03-11 19:44:42 +00:00
|
|
|
SkMessageBus<GrUniqueKeyInvalidatedMessage, uint32_t>::Post(
|
2020-07-23 17:54:35 +00:00
|
|
|
GrUniqueKeyInvalidatedMessage(key, dContext->priv().contextID()));
|
2017-09-27 17:11:16 +00:00
|
|
|
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2017-09-27 17:11:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
|
|
|
|
// Instantiate the proxy. This will trigger the message to be processed, so the resulting
|
|
|
|
// texture should *not* have the unique key on it!
|
2018-01-08 18:40:32 +00:00
|
|
|
SkAssertResult(proxy->instantiate(resourceProvider));
|
2017-09-27 17:11:16 +00:00
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2021-03-12 21:29:40 +00:00
|
|
|
REPORTER_ASSERT(reporter, cacheEntriesPerProxy == cache->getResourceCount());
|
2017-09-27 17:11:16 +00:00
|
|
|
|
|
|
|
proxy = nullptr;
|
2021-06-10 00:49:48 +00:00
|
|
|
dContext->priv().getResourceCache()->purgeUnlockedResources();
|
2017-09-27 17:11:16 +00:00
|
|
|
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
|
2017-09-27 17:11:16 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
}
|
|
|
|
|
2017-09-21 12:26:08 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
|
2020-07-16 14:58:58 +00:00
|
|
|
auto direct = ctxInfo.directContext();
|
|
|
|
GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
|
|
|
|
GrResourceCache* cache = direct->priv().getResourceCache();
|
2017-09-21 12:26:08 +00:00
|
|
|
|
2018-01-08 18:40:32 +00:00
|
|
|
REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
|
2017-09-21 12:26:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
|
|
|
|
2021-03-12 21:29:40 +00:00
|
|
|
// As we transition to using attachments instead of GrTextures and GrRenderTargets individual
|
|
|
|
// proxy instansiations may add multiple things to the cache. There would be an entry for the
|
|
|
|
// GrTexture/GrRenderTarget and entries for one or more attachments.
|
|
|
|
int cacheEntriesPerProxy = 1;
|
|
|
|
// We currently only have attachments on the vulkan backend
|
|
|
|
if (direct->backend() == GrBackend::kVulkan) {
|
|
|
|
cacheEntriesPerProxy++;
|
|
|
|
// If we ever have a test with multisamples this would have an additional attachment as
|
|
|
|
// well.
|
|
|
|
}
|
|
|
|
|
2017-09-21 12:26:08 +00:00
|
|
|
for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
|
2017-09-26 16:49:26 +00:00
|
|
|
for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
|
2017-09-21 12:26:08 +00:00
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
2021-03-12 21:29:40 +00:00
|
|
|
basic_test(direct, reporter, create(reporter, direct, proxyProvider, fit),
|
|
|
|
cacheEntriesPerProxy);
|
2017-09-21 12:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
|
2021-06-10 00:49:48 +00:00
|
|
|
cache->purgeUnlockedResources();
|
2017-09-21 12:26:08 +00:00
|
|
|
}
|
|
|
|
|
2021-03-12 21:29:40 +00:00
|
|
|
basic_test(direct, reporter, create_wrapped_backend(direct), cacheEntriesPerProxy);
|
2020-10-13 00:45:06 +00:00
|
|
|
|
2021-03-12 21:29:40 +00:00
|
|
|
invalidation_test(direct, reporter, cacheEntriesPerProxy);
|
|
|
|
invalidation_and_instantiation_test(direct, reporter, cacheEntriesPerProxy);
|
2017-09-21 12:26:08 +00:00
|
|
|
}
|