skia2/tests/TextureProxyTest.cpp

352 lines
15 KiB
C++
Raw Normal View History

/*
* 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.
#include "tests/Test.h"
#include "include/core/SkBitmap.h"
#include "include/core/SkImage.h"
#include "include/gpu/GrBackendSurface.h"
#include "include/gpu/GrDirectContext.h"
#include "src/gpu/ganesh/GrDirectContextPriv.h"
#include "src/gpu/ganesh/GrProxyProvider.h"
#include "src/gpu/ganesh/GrRecordingContextPriv.h"
#include "src/gpu/ganesh/GrResourceCache.h"
#include "src/gpu/ganesh/GrResourceProvider.h"
#include "src/gpu/ganesh/GrTexture.h"
#include "src/gpu/ganesh/GrTextureProxy.h"
#include "src/gpu/ganesh/SkGr.h"
#include "tools/gpu/ManagedBackendTexture.h"
#ifdef SK_DAWN
#include "src/gpu/ganesh/dawn/GrDawnGpu.h"
#endif
int GrProxyProvider::numUniqueKeyProxies_TestOnly() const {
return fUniquelyKeyedProxies.count();
}
static constexpr auto kColorType = GrColorType::kRGBA_8888;
static constexpr auto kSize = SkISize::Make(64, 64);
///////////////////////////////////////////////////////////////////////////////////////////////////
// Basic test
static sk_sp<GrTextureProxy> deferred_tex(skiatest::Reporter* reporter,
GrRecordingContext* rContext,
GrProxyProvider* proxyProvider,
SkBackingFit fit) {
const GrCaps* caps = rContext->priv().caps();
GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kNo);
sk_sp<GrTextureProxy> proxy =
proxyProvider->createProxy(format, kSize, GrRenderable::kNo, 1, GrMipmapped::kNo, fit,
Revert "Reland "Create updateResourceLabel method."" This reverts commit 35ef74b7a4c5ac23fecea00fa71076bc1be4d8ac. Reason for revert: causing chrome roll failure? Original change's description: > Reland "Create updateResourceLabel method." > > This is a reland of commit 605f92c7d7f97d6edf152f6e9d0fc88f8cd8c700 > > Original change's description: > > Create updateResourceLabel method. > > > > In this CL, the GrSurfaceProxy's and GrDrawOpAtlas's label strings > > are plumbed so that it can be stored in the label string of > > GrGpuResource. updateResourceLabel method, which is called from > > setLabel method, will add labels to Skia OpenGL backend using ANGLE's > > labeling API. > > > > Bug: chromium:1164111 > > Change-Id: I370715d186357e920d260d624d77586cdddd11e8 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541230 > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Bug: chromium:1164111 > Change-Id: Ia20a81d22e320813cbc4ad1d41e06e47dc3827bb > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544058 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> Bug: chromium:1164111 Change-Id: Icacb3a0f2f2ee03afc09e03c2ee59b03d5bdd811 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544241 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Auto-Submit: Tyler Denniston <tdenniston@google.com>
2022-05-26 15:24:19 +00:00
SkBudgeted::kYes, GrProtected::kNo);
// Only budgeted & wrapped external proxies get to carry uniqueKeys
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
return proxy;
}
static sk_sp<GrTextureProxy> deferred_texRT(skiatest::Reporter* reporter,
GrRecordingContext* rContext,
GrProxyProvider* proxyProvider,
SkBackingFit fit) {
const GrCaps* caps = rContext->priv().caps();
GrBackendFormat format = caps->getDefaultBackendFormat(kColorType, GrRenderable::kYes);
sk_sp<GrTextureProxy> proxy =
proxyProvider->createProxy(format, kSize, GrRenderable::kYes, 1, GrMipmapped::kNo, fit,
Revert "Reland "Create updateResourceLabel method."" This reverts commit 35ef74b7a4c5ac23fecea00fa71076bc1be4d8ac. Reason for revert: causing chrome roll failure? Original change's description: > Reland "Create updateResourceLabel method." > > This is a reland of commit 605f92c7d7f97d6edf152f6e9d0fc88f8cd8c700 > > Original change's description: > > Create updateResourceLabel method. > > > > In this CL, the GrSurfaceProxy's and GrDrawOpAtlas's label strings > > are plumbed so that it can be stored in the label string of > > GrGpuResource. updateResourceLabel method, which is called from > > setLabel method, will add labels to Skia OpenGL backend using ANGLE's > > labeling API. > > > > Bug: chromium:1164111 > > Change-Id: I370715d186357e920d260d624d77586cdddd11e8 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/541230 > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Bug: chromium:1164111 > Change-Id: Ia20a81d22e320813cbc4ad1d41e06e47dc3827bb > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544058 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> Bug: chromium:1164111 Change-Id: Icacb3a0f2f2ee03afc09e03c2ee59b03d5bdd811 No-Presubmit: true No-Tree-Checks: true No-Try: true Reviewed-on: https://skia-review.googlesource.com/c/skia/+/544241 Bot-Commit: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Commit-Queue: Rubber Stamper <rubber-stamper@appspot.gserviceaccount.com> Auto-Submit: Tyler Denniston <tdenniston@google.com>
2022-05-26 15:24:19 +00:00
SkBudgeted::kYes, GrProtected::kNo);
// Only budgeted & wrapped external proxies get to carry uniqueKeys
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
return proxy;
}
static sk_sp<GrTextureProxy> wrapped(skiatest::Reporter* reporter, GrRecordingContext*,
GrProxyProvider* proxyProvider, SkBackingFit fit) {
sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
// Only budgeted & wrapped external proxies get to carry uniqueKeys
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
return proxy;
}
static sk_sp<GrTextureProxy> wrapped_with_key(skiatest::Reporter* reporter, GrRecordingContext*,
GrProxyProvider* proxyProvider, SkBackingFit fit) {
static skgpu::UniqueKey::Domain d = skgpu::UniqueKey::GenerateDomain();
static int kUniqueKeyData = 0;
skgpu::UniqueKey key;
skgpu::UniqueKey::Builder builder(&key, d, 1, nullptr);
builder[0] = kUniqueKeyData++;
builder.finish();
// Only budgeted & wrapped external proxies get to carry uniqueKeys
sk_sp<GrTextureProxy> proxy = proxyProvider->testingOnly_createInstantiatedProxy(
kSize, kColorType, GrRenderable::kNo, 1, fit, SkBudgeted::kYes, GrProtected::kNo);
SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
REPORTER_ASSERT(reporter, proxy->getUniqueKey().isValid());
return proxy;
}
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) {
return nullptr;
}
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
return proxyProvider->wrapBackendTexture(mbet->texture(),
kBorrow_GrWrapOwnership,
GrWrapCacheable::kYes,
kRead_GrIOType,
mbet->refCountedCallback());
}
// This tests the basic capabilities of the uniquely keyed texture proxies. Does assigning
// and looking them up work, etc.
static void basic_test(GrDirectContext* dContext,
skiatest::Reporter* reporter,
sk_sp<GrTextureProxy> proxy,
int cacheEntriesPerProxy) {
static int id = 1;
GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
GrResourceCache* cache = dContext->priv().getResourceCache();
int startCacheCount = cache->getResourceCount();
skgpu::UniqueKey key;
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
REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
}
REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
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
REPORTER_ASSERT(reporter, proxyProvider->findOrCreateProxyByUniqueKey(key));
REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
Reland "Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage." This reverts commit 9ef3f2e3da9f82565ba236284ab4e9c9a97e4647. Reason for revert: relanding with fix Original change's description: > Revert "Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage." > > This reverts commit 3dc6c190dabbe424345f3a8220be87bb92cdaf05. > > Reason for revert: hitting assert about RT having input attachment on mali bots > > Original change's description: > > Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage. > > > > This change moves the color and resolve attachments used in a > > GrVkRenderTarget to be a GrVkAttachment. These along with the msaa > > attachment now mean that GrVkRenderTarget no longer needs to derive from > > a GrVkImage. > > > > There are a couple ugly things in this CL since GrVkTexture still is a > > GrVkImage since we can't share attachments between GrVkRT and GrVkTex. > > But when that gets updated in the follow on CL things will look much nicer. > > > > Bug: skia:10727 > > Change-Id: I2f12674d7517c6d6dea389e2d1fb7296028bcc85 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/379576 > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com > > Change-Id: Ic46f3947ed9f7b2ca26e8418d643e7f89b6108d2 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10727 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380459 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> # Not skipping CQ checks because this is a reland. Bug: skia:10727 Change-Id: I7a995ee9ad35bdac34cfcfd6b0d963c3e0bb90b8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380460 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2021-03-05 22:50:08 +00:00
int expectedCacheCount = startCacheCount + (proxy->isInstantiated() ? 0 : cacheEntriesPerProxy);
// Once instantiated, the backing resource should have the same key
SkAssertResult(proxy->instantiate(resourceProvider));
const skgpu::UniqueKey texKey = proxy->peekSurface()->getUniqueKey();
REPORTER_ASSERT(reporter, texKey.isValid());
REPORTER_ASSERT(reporter, key == texKey);
// 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;
// deleting the proxy should delete it from the hash but not the cache
proxy = nullptr;
if (expectDeletingProxyToDeleteResource) {
Reland "Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage." This reverts commit 9ef3f2e3da9f82565ba236284ab4e9c9a97e4647. Reason for revert: relanding with fix Original change's description: > Revert "Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage." > > This reverts commit 3dc6c190dabbe424345f3a8220be87bb92cdaf05. > > Reason for revert: hitting assert about RT having input attachment on mali bots > > Original change's description: > > Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage. > > > > This change moves the color and resolve attachments used in a > > GrVkRenderTarget to be a GrVkAttachment. These along with the msaa > > attachment now mean that GrVkRenderTarget no longer needs to derive from > > a GrVkImage. > > > > There are a couple ugly things in this CL since GrVkTexture still is a > > GrVkImage since we can't share attachments between GrVkRT and GrVkTex. > > But when that gets updated in the follow on CL things will look much nicer. > > > > Bug: skia:10727 > > Change-Id: I2f12674d7517c6d6dea389e2d1fb7296028bcc85 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/379576 > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com > > Change-Id: Ic46f3947ed9f7b2ca26e8418d643e7f89b6108d2 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10727 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380459 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> # Not skipping CQ checks because this is a reland. Bug: skia:10727 Change-Id: I7a995ee9ad35bdac34cfcfd6b0d963c3e0bb90b8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380460 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2021-03-05 22:50:08 +00:00
expectedCacheCount -= cacheEntriesPerProxy;
}
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
// If the proxy was cached refinding it should bring it back to life
proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
REPORTER_ASSERT(reporter, proxy);
REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
// Mega-purging it should remove it from both the hash and the cache
proxy = nullptr;
cache->purgeUnlockedResources();
if (!expectResourceToOutliveProxy) {
Reland "Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage." This reverts commit 9ef3f2e3da9f82565ba236284ab4e9c9a97e4647. Reason for revert: relanding with fix Original change's description: > Revert "Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage." > > This reverts commit 3dc6c190dabbe424345f3a8220be87bb92cdaf05. > > Reason for revert: hitting assert about RT having input attachment on mali bots > > Original change's description: > > Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage. > > > > This change moves the color and resolve attachments used in a > > GrVkRenderTarget to be a GrVkAttachment. These along with the msaa > > attachment now mean that GrVkRenderTarget no longer needs to derive from > > a GrVkImage. > > > > There are a couple ugly things in this CL since GrVkTexture still is a > > GrVkImage since we can't share attachments between GrVkRT and GrVkTex. > > But when that gets updated in the follow on CL things will look much nicer. > > > > Bug: skia:10727 > > Change-Id: I2f12674d7517c6d6dea389e2d1fb7296028bcc85 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/379576 > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com > > Change-Id: Ic46f3947ed9f7b2ca26e8418d643e7f89b6108d2 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10727 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380459 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> # Not skipping CQ checks because this is a reland. Bug: skia:10727 Change-Id: I7a995ee9ad35bdac34cfcfd6b0d963c3e0bb90b8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380460 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2021-03-05 22:50:08 +00:00
expectedCacheCount -= cacheEntriesPerProxy;
}
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
// If the texture was deleted then the proxy should no longer be findable. Otherwise, it should
// be.
proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
REPORTER_ASSERT(reporter, expectResourceToOutliveProxy ? (bool)proxy : !proxy);
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
if (expectResourceToOutliveProxy) {
proxy.reset();
skgpu::UniqueKeyInvalidatedMessage msg(texKey, dContext->priv().contextID());
SkMessageBus<skgpu::UniqueKeyInvalidatedMessage, uint32_t>::Post(msg);
cache->purgeAsNeeded();
Reland "Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage." This reverts commit 9ef3f2e3da9f82565ba236284ab4e9c9a97e4647. Reason for revert: relanding with fix Original change's description: > Revert "Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage." > > This reverts commit 3dc6c190dabbe424345f3a8220be87bb92cdaf05. > > Reason for revert: hitting assert about RT having input attachment on mali bots > > Original change's description: > > Have GrVkRenderTarget only use GrVkAttachments and not derive from GrVkImage. > > > > This change moves the color and resolve attachments used in a > > GrVkRenderTarget to be a GrVkAttachment. These along with the msaa > > attachment now mean that GrVkRenderTarget no longer needs to derive from > > a GrVkImage. > > > > There are a couple ugly things in this CL since GrVkTexture still is a > > GrVkImage since we can't share attachments between GrVkRT and GrVkTex. > > But when that gets updated in the follow on CL things will look much nicer. > > > > Bug: skia:10727 > > Change-Id: I2f12674d7517c6d6dea389e2d1fb7296028bcc85 > > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/379576 > > Reviewed-by: Brian Salomon <bsalomon@google.com> > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,jvanverth@google.com,bsalomon@google.com > > Change-Id: Ic46f3947ed9f7b2ca26e8418d643e7f89b6108d2 > No-Presubmit: true > No-Tree-Checks: true > No-Try: true > Bug: skia:10727 > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380459 > Reviewed-by: Greg Daniel <egdaniel@google.com> > Commit-Queue: Greg Daniel <egdaniel@google.com> # Not skipping CQ checks because this is a reland. Bug: skia:10727 Change-Id: I7a995ee9ad35bdac34cfcfd6b0d963c3e0bb90b8 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/380460 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2021-03-05 22:50:08 +00:00
expectedCacheCount -= cacheEntriesPerProxy;
proxy = proxyProvider->findOrCreateProxyByUniqueKey(key);
REPORTER_ASSERT(reporter, !proxy);
REPORTER_ASSERT(reporter, expectedCacheCount == cache->getResourceCount());
}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
// Invalidation test
// Test if invalidating unique ids operates as expected for texture proxies.
static void invalidation_test(GrDirectContext* dContext,
skiatest::Reporter* reporter,
int cacheEntriesPerProxy) {
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
GrResourceCache* cache = dContext->priv().getResourceCache();
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);
rasterImg = bm.asImage();
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
}
// 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;
if (dContext->backend() == GrBackendApi::kDawn ||
dContext->backend() == GrBackendApi::kVulkan ||
dContext->backend() == GrBackendApi::kDirect3D ||
dContext->backend() == GrBackendApi::kMetal) {
bufferResources = 1;
}
sk_sp<SkImage> textureImg = rasterImg->makeTextureImage(dContext);
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, cacheEntriesPerProxy + bufferResources == cache->getResourceCount());
rasterImg = nullptr; // this invalidates the uniqueKey
// this forces the cache to respond to the inval msg
size_t maxBytes = dContext->getResourceCacheLimit();
dContext->setResourceCacheLimit(maxBytes-1);
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, cacheEntriesPerProxy + bufferResources == cache->getResourceCount());
textureImg = nullptr;
// For backends that use buffers to upload lets make sure that work has been submit and done
// before we try to purge all resources.
dContext->submit(true);
dContext->priv().getResourceCache()->purgeUnlockedResources();
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
}
// Test if invalidating unique ids prior to instantiating operates as expected
static void invalidation_and_instantiation_test(GrDirectContext* dContext,
skiatest::Reporter* reporter,
int cacheEntriesPerProxy) {
GrProxyProvider* proxyProvider = dContext->priv().proxyProvider();
GrResourceProvider* resourceProvider = dContext->priv().resourceProvider();
GrResourceCache* cache = dContext->priv().getResourceCache();
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
static skgpu::UniqueKey::Domain d = skgpu::UniqueKey::GenerateDomain();
skgpu::UniqueKey key;
skgpu::UniqueKey::Builder builder(&key, d, 1, nullptr);
builder[0] = 0;
builder.finish();
// Create proxy, assign unique key
sk_sp<GrTextureProxy> proxy = deferred_tex(reporter, dContext, proxyProvider,
Reland "Reland "Have a GrBackendFormat be stored on gpu proxies."" This is a reland of 2f9a5ea639925f38785f4d3a0af237822007cfd6 Original change's description: > Reland "Have a GrBackendFormat be stored on gpu proxies." > > This reverts commit 919c9e77c3492af766ff5982acda76ee49da3168. > > Reason for revert: Flutter change has landed and fixed memory issue. > > Original change's description: > > Revert "Have a GrBackendFormat be stored on gpu proxies." > > > > This reverts commit 51b1c12bbc2fa3f8d4faa29ad19c6f3cb34837ce. > > > > Reason for revert: reverting till flutter gets to 1.1 to fix build issues. > > > > Original change's description: > > > Have a GrBackendFormat be stored on gpu proxies. > > > > > > Bug: skia: > > > Change-Id: Iaf1fb24ab29a61d44e5fa59a5e0867ed02dcda90 > > > Reviewed-on: https://skia-review.googlesource.com/c/168021 > > > Reviewed-by: Brian Osman <brianosman@google.com> > > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > > > Change-Id: I574fdc084ef5994596c51fb0d60423b5dc01b885 > > No-Presubmit: true > > No-Tree-Checks: true > > No-Try: true > > Bug: chromium:903701 chromium:903756 > > Reviewed-on: https://skia-review.googlesource.com/c/169835 > > Commit-Queue: Greg Daniel <egdaniel@google.com> > > Reviewed-by: Greg Daniel <egdaniel@google.com> > > TBR=egdaniel@google.com,bsalomon@google.com,brianosman@google.com > > Change-Id: Ifd9b6b8e194af9fb9258fa626644e76e6ecf090d > Bug: chromium:903701 chromium:903756 > Reviewed-on: https://skia-review.googlesource.com/c/170104 > Commit-Queue: Greg Daniel <egdaniel@google.com> > Reviewed-by: Greg Daniel <egdaniel@google.com> > Reviewed-by: Brian Osman <brianosman@google.com> Bug: chromium:903701 chromium:903756 Change-Id: Id1360067d8e928b0a4e1848dae8bc1e7f1994403 Reviewed-on: https://skia-review.googlesource.com/c/171660 Reviewed-by: Greg Daniel <egdaniel@google.com> Commit-Queue: Greg Daniel <egdaniel@google.com>
2018-11-16 20:43:41 +00:00
SkBackingFit::kExact);
SkAssertResult(proxyProvider->assignUniqueKeyToProxy(key, proxy.get()));
// Send an invalidation message, which will be sitting in the cache's inbox
SkMessageBus<skgpu::UniqueKeyInvalidatedMessage, uint32_t>::Post(
skgpu::UniqueKeyInvalidatedMessage(key, dContext->priv().contextID()));
REPORTER_ASSERT(reporter, 1 == proxyProvider->numUniqueKeyProxies_TestOnly());
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!
SkAssertResult(proxy->instantiate(resourceProvider));
REPORTER_ASSERT(reporter, !proxy->getUniqueKey().isValid());
REPORTER_ASSERT(reporter, !proxy->peekTexture()->getUniqueKey().isValid());
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, cacheEntriesPerProxy == cache->getResourceCount());
proxy = nullptr;
dContext->priv().getResourceCache()->purgeUnlockedResources();
REPORTER_ASSERT(reporter, 0 == proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
}
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(TextureProxyTest, reporter, ctxInfo) {
auto direct = ctxInfo.directContext();
GrProxyProvider* proxyProvider = direct->priv().proxyProvider();
GrResourceCache* cache = direct->priv().getResourceCache();
REPORTER_ASSERT(reporter, !proxyProvider->numUniqueKeyProxies_TestOnly());
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
// 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 and metal backends
if (direct->backend() == GrBackend::kVulkan || direct->backend() == GrBackend::kMetal) {
cacheEntriesPerProxy++;
// If we ever have a test with multisamples this would have an additional attachment as
// well.
}
for (auto fit : { SkBackingFit::kExact, SkBackingFit::kApprox }) {
for (auto create : { deferred_tex, deferred_texRT, wrapped, wrapped_with_key }) {
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
basic_test(direct, reporter, create(reporter, direct, proxyProvider, fit),
cacheEntriesPerProxy);
}
REPORTER_ASSERT(reporter, 0 == cache->getResourceCount());
cache->purgeUnlockedResources();
}
basic_test(direct, reporter, create_wrapped_backend(direct), cacheEntriesPerProxy);
invalidation_test(direct, reporter, cacheEntriesPerProxy);
invalidation_and_instantiation_test(direct, reporter, cacheEntriesPerProxy);
}