84constexpr ProxyParams::Kind kDeferred = ProxyParams::Kind::kDeferred;
85constexpr ProxyParams::Kind kBackend = ProxyParams::Kind::kBackend;
86constexpr ProxyParams::Kind kInstantiated = ProxyParams::Kind::kInstantiated;
87constexpr ProxyParams::Kind kLazy = ProxyParams::Kind::kLazy;
88constexpr ProxyParams::Kind kFullyLazy = ProxyParams::Kind::kFullyLazy;
92 const ProxyParams& p) {
98 skgpu::Mipmapped::kNo,
102 "ResourceAllocatorTest_Deffered");
111 auto mbet = sk_gpu_test::ManagedBackendTexture::MakeWithoutData(
112 dContext, p.fSize, p.fSize, skColorType, skgpu::Mipmapped::kNo, GrRenderable::kNo);
122 mbet->refCountedCallback());
126 const ProxyParams& p) {
137 "ResourceAllocatorTest_FullLazy");
141 GrProtected::kNo, *caps,
146 const ProxyParams& p) {
157 "ResourceAllocatorTest_Lazy");
163 skgpu::Mipmapped::kNo,
178 case ProxyParams::kDeferred:
181 case ProxyParams::kBackend:
184 case ProxyParams::kFullyLazy:
187 case ProxyParams::kLazy:
188 proxy =
make_lazy(proxyProvider, caps, p);
190 case ProxyParams::kInstantiated:
194 proxy->priv().assign(std::move(surf));
198 if (proxy && p.fUniqueKey.isValid()) {
209 bool expectedResult) {
225 bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID();
233 bool expectedResult) {
254 bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID();
262 auto dContext = ctxInfo.directContext();
263 const GrCaps* caps = dContext->priv().caps();
271 constexpr bool kShare =
true;
272 constexpr bool kDontShare =
false;
277 static const TestCase overlappingTests[] = {
280 {{64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
281 {64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
284 {{64, kNotRT,
kRGBA,
kA, 1, kNotB, kDeferred},
285 {64, kNotRT,
kRGBA,
kA, 1, kNotB, kDeferred},
289 for (
size_t i = 0; i < std::size(overlappingTests); i++) {
304 const TestCase nonOverlappingTests[] = {
307 {{64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
308 {64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
310 {{64, kNotRT,
kRGBA,
kA, 1, kNotB, kDeferred},
311 {64, kNotRT,
kRGBA,
kA, 1, kNotB, kDeferred},
312 kConditionallyShare},
314 {{64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
315 {50, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
317 {{64, kNotRT,
kRGBA,
kA, 1, kNotB, kDeferred},
318 {50, kNotRT,
kRGBA,
kA, 1, kNotB, kDeferred},
319 kConditionallyShare},
321 {{64, kRT,
kRGBA, kE, 1, kNotB, kDeferred},
322 {64, kRT,
kRGBA, kE, 1, kNotB, kDeferred},
324 {{64, kNotRT,
kRGBA, kE, 1, kNotB, kDeferred},
325 {64, kNotRT,
kRGBA, kE, 1, kNotB, kDeferred},
326 kConditionallyShare},
328 {{56, kRT,
kRGBA, kE, 1, kNotB, kDeferred},
329 {54, kRT,
kRGBA, kE, 1, kNotB, kDeferred},
332 {{255, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
333 {127, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
336 {{64, kRT,
kRGBA,
kA, k2, kNotB, kDeferred},
337 {64, kRT,
kRGBA,
kA, k4, kNotB, kDeferred},
340 {{64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
341 {64, kRT,
kAlpha,
kA, 1, kNotB, kDeferred},
344 {{64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
345 {64, kNotRT,
kRGBA,
kA, 1, kNotB, kDeferred},
347 {{64, kNotRT,
kRGBA,
kA, 1, kNotB, kDeferred},
348 {64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
351 {{64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
352 {64, kRT,
kRGBA,
kA, 1, kNotB, kDeferred},
355 {{64, kNotRT,
kRGBA, kE, 1, kNotB, kBackend},
356 {64, kNotRT,
kRGBA, kE, 1, kNotB, kDeferred},
360 for (
size_t i = 0; i < std::size(nonOverlappingTests); i++) {
391 auto context = ctxInfo.directContext();
393 size_t maxBytes = context->getResourceCacheLimit();
395 context->setResourceCacheLimit(0);
401 context->flushAndSubmit();
403 context->setResourceCacheLimit(maxBytes);
428 cache->setLimit(
test.fBudget);
431 size_t expectedPurgeableBytes = 0;
433 for (
auto&
params :
test.fPurgeableResourcesInCache) {
437 expectedPurgeableBytes += proxy->gpuMemorySize();
440 purgeableSurfaces.
clear();
442 "%zu", cache->getPurgeableBytes());
445 size_t expectedUnpurgeableBytes = 0;
447 for (
auto&
params :
test.fUnpurgeableResourcesInCache) {
451 expectedUnpurgeableBytes += proxy->gpuMemorySize();
455 auto unpurgeableBytes = cache->getBudgetedResourceBytes() - cache->getPurgeableBytes();
457 "%zu", unpurgeableBytes);
461 for (
auto& interval :
test.fIntervals) {
462 for (
int i = interval.fStart; i <= interval.fEnd; i++) {
465 alloc.
addInterval(interval.fProxy.get(), interval.fStart, interval.fEnd,
477 auto dContext = ctxInfo.directContext();
479 constexpr bool kUnder =
true;
480 constexpr bool kOver =
false;
481 constexpr size_t kRGBA64Bytes = 4 * 64 * 64;
482 const ProxyParams kProxy64 = {64, kRT,
kRGBA, kE, 1,
kB, kDeferred};
483 const ProxyParams kProxy64NotBudgeted = {64, kRT,
kRGBA, kE, 1, kNotB, kDeferred};
484 const ProxyParams kProxy64Lazy = {64, kRT,
kRGBA, kE, 1,
kB, kLazy};
485 const ProxyParams kProxy64FullyLazy = {64, kRT,
kRGBA, kE, 1,
kB, kFullyLazy};
486 const ProxyParams kProxy32Instantiated = {32, kRT,
kRGBA, kE, 1,
kB, kInstantiated};
487 const ProxyParams kProxy64Instantiated = {64, kRT,
kRGBA, kE, 1,
kB, kInstantiated};
490 {
"empty DAG", kUnder, 0, {}, {}, {}},
491 {
"unbudgeted", kUnder, 0, {}, {}, {{kProxy64NotBudgeted, 0, 2}}},
492 {
"basic", kUnder, kRGBA64Bytes, {}, {}, {{kProxy64, 0, 2}}},
493 {
"basic, over",
kOver, kRGBA64Bytes - 1, {}, {}, {{kProxy64, 0, 2}}},
494 {
"shared", kUnder, kRGBA64Bytes, {}, {},
499 {
"retrieved from cache", kUnder, kRGBA64Bytes,
500 {kProxy64Instantiated},
505 {
"purge 4", kUnder, kRGBA64Bytes,
507 kProxy32Instantiated,
508 kProxy32Instantiated,
509 kProxy32Instantiated,
516 {
"dont purge what we've reserved",
kOver, kRGBA64Bytes,
517 {kProxy64Instantiated},
523 {
"unpurgeable",
kOver, kRGBA64Bytes,
525 {kProxy64Instantiated},
529 {
"lazy", kUnder, kRGBA64Bytes,
535 {
"lazy, over",
kOver, kRGBA64Bytes - 1,
541 {
"fully-lazy", kUnder, kRGBA64Bytes,
545 {kProxy64FullyLazy, 0, 2}
547 {
"fully-lazy, over",
kOver, kRGBA64Bytes - 1,
551 {kProxy64FullyLazy, 0, 2}
555 for (
size_t i = 0; i < std::size(
tests); i++) {
560 interval.fProxy =
make_proxy(dContext, interval.fParams);
static bool match(const char *needle, const char *haystack)
@ kBorrow_GrWrapOwnership
static constexpr SkColorType GrColorTypeToSkColorType(GrColorType ct)
@ kTopLeft_GrSurfaceOrigin
static const uint64_t kAlpha
static sk_sp< GrSurfaceProxy > make_proxy(GrDirectContext *dContext, const ProxyParams &p)
static void overlap_test(skiatest::Reporter *reporter, GrDirectContext *dContext, const sk_sp< GrSurfaceProxy > &p1, const sk_sp< GrSurfaceProxy > &p2, bool expectedResult)
static sk_sp< GrSurfaceProxy > make_backend(GrDirectContext *dContext, const ProxyParams &p)
static void memory_budget_test(skiatest::Reporter *reporter, GrDirectContext *dContext, const TestCase &test)
static void non_overlap_test(skiatest::Reporter *reporter, GrDirectContext *dContext, const sk_sp< GrSurfaceProxy > &p1, const sk_sp< GrSurfaceProxy > &p2, bool expectedResult)
static sk_sp< GrSurfaceProxy > make_deferred(GrProxyProvider *proxyProvider, const GrCaps *caps, const ProxyParams &p)
static sk_sp< GrSurfaceProxy > make_lazy(GrProxyProvider *proxyProvider, const GrCaps *caps, const ProxyParams &p)
static void draw(GrRecordingContext *rContext)
static sk_sp< GrSurfaceProxy > make_fully_lazy(GrProxyProvider *proxyProvider, const GrCaps *caps, const ProxyParams &p)
@ kPremul_SkAlphaType
pixel components are premultiplied by alpha
@ kRGBA_8888_SkColorType
pixel with 8 bits for red, green, blue, alpha; in 32-bit word
@ kUnknown_SkColorType
uninitialized
constexpr SkColor SK_ColorBLACK
sk_sp< T > sk_ref_sp(T *obj)
SK_API SkString static SkString SkStringPrintf()
constexpr int SkToInt(S x)
#define REPORTER_ASSERT(r, cond,...)
#define DEF_GANESH_TEST_FOR_RENDERING_CONTEXTS(name, reporter, context_info, ctsEnforcement)
const GrCaps * caps() const
GrBackendFormat getDefaultBackendFormat(GrColorType, GrRenderable) const
virtual int getRenderTargetSampleCount(int requestedCount, const GrBackendFormat &) const =0
bool reuseScratchTextures() const
GrResourceProvider * resourceProvider()
GrResourceCache * getResourceCache()
GrDirectContextPriv priv()
sk_sp< GrTextureProxy > createLazyProxy(LazyInstantiateCallback &&, const GrBackendFormat &, SkISize dimensions, skgpu::Mipmapped, GrMipmapStatus, GrInternalSurfaceFlags, SkBackingFit, skgpu::Budgeted, GrProtected, UseAllocator, std::string_view label)
sk_sp< GrTextureProxy > wrapBackendTexture(const GrBackendTexture &, GrWrapOwnership, GrWrapCacheable, GrIOType, sk_sp< skgpu::RefCntedCallback >=nullptr)
sk_sp< GrTextureProxy > createProxy(const GrBackendFormat &, SkISize dimensions, GrRenderable, int renderTargetSampleCnt, skgpu::Mipmapped, SkBackingFit, skgpu::Budgeted, GrProtected, std::string_view label, GrInternalSurfaceFlags=GrInternalSurfaceFlags::kNone, UseAllocator useAllocator=UseAllocator::kYes)
bool assignUniqueKeyToProxy(const skgpu::UniqueKey &, GrTextureProxy *)
static sk_sp< GrTextureProxy > MakeFullyLazyProxy(LazyInstantiateCallback &&, const GrBackendFormat &, GrRenderable, int renderTargetSampleCnt, GrProtected, const GrCaps &, UseAllocator)
GrProxyProvider * proxyProvider()
void addInterval(GrSurfaceProxy *, unsigned int start, unsigned int end, ActualUse actualUse, AllowRecycling SkDEBUGCODE(, bool isDirectDstRead=false))
bool makeBudgetHeadroom()
sk_sp< GrTexture > createTexture(SkISize dimensions, const GrBackendFormat &format, GrTextureType textureType, skgpu::Renderable renderable, int renderTargetSampleCnt, skgpu::Mipmapped mipmapped, skgpu::Budgeted budgeted, skgpu::Protected isProtected, std::string_view label)
void clear(SkColor color)
const EmbeddedViewParams * params
uint32_t uint32_t * format
SK_API sk_sp< SkSurface > RenderTarget(GrRecordingContext *context, skgpu::Budgeted budgeted, const SkImageInfo &imageInfo, int sampleCount, GrSurfaceOrigin surfaceOrigin, const SkSurfaceProps *surfaceProps, bool shouldCreateWithMips=false, bool isProtected=false)
sk_sp< GrSurfaceProxy > fProxy
static SkImageInfo Make(int width, int height, SkColorType ct, SkAlphaType at)
TArray< ProxyParams > fUnpurgeableResourcesInCache
TArray< Interval > fIntervals
TArray< ProxyParams > fPurgeableResourcesInCache