2017-07-18 18:49:38 +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.
|
|
|
|
*/
|
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkTypes.h"
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "tests/Test.h"
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/gpu/GrTexture.h"
|
|
|
|
#include "src/gpu/GrContextPriv.h"
|
|
|
|
#include "src/gpu/GrGpu.h"
|
|
|
|
#include "src/gpu/GrProxyProvider.h"
|
|
|
|
#include "src/gpu/GrResourceAllocator.h"
|
|
|
|
#include "src/gpu/GrResourceProvider.h"
|
|
|
|
#include "src/gpu/GrSurfaceProxyPriv.h"
|
2019-06-18 13:58:02 +00:00
|
|
|
#include "src/gpu/GrTextureProxy.h"
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2019-04-23 17:05:21 +00:00
|
|
|
#include "include/core/SkSurface.h"
|
2018-08-21 17:52:09 +00:00
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
struct ProxyParams {
|
|
|
|
int fSize;
|
2019-07-17 13:59:59 +00:00
|
|
|
GrRenderable fRenderable;
|
2019-07-23 14:27:09 +00:00
|
|
|
GrColorType fColorType;
|
2017-07-21 15:38:13 +00:00
|
|
|
SkBackingFit fFit;
|
|
|
|
int fSampleCnt;
|
|
|
|
GrSurfaceOrigin fOrigin;
|
2019-03-26 18:50:08 +00:00
|
|
|
SkBudgeted fBudgeted;
|
2017-07-21 15:38:13 +00:00
|
|
|
// TODO: do we care about mipmapping
|
|
|
|
};
|
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_deferred(GrProxyProvider* proxyProvider, const GrCaps* caps,
|
|
|
|
const ProxyParams& p) {
|
2019-07-23 14:27:09 +00:00
|
|
|
GrPixelConfig config = GrColorTypeToPixelConfig(p.fColorType);
|
2018-09-25 13:31:10 +00:00
|
|
|
|
2017-07-18 18:49:38 +00:00
|
|
|
GrSurfaceDesc desc;
|
2017-07-21 15:38:13 +00:00
|
|
|
desc.fWidth = p.fSize;
|
|
|
|
desc.fHeight = p.fSize;
|
2018-09-25 13:31:10 +00:00
|
|
|
desc.fConfig = config;
|
2017-07-21 15:38:13 +00:00
|
|
|
|
2019-07-30 16:49:10 +00:00
|
|
|
const GrBackendFormat format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable);
|
2020-01-21 19:29:57 +00:00
|
|
|
GrSwizzle swizzle = caps->getReadSwizzle(format, p.fColorType);
|
2018-11-16 20:43:41 +00:00
|
|
|
|
2020-01-21 19:29:57 +00:00
|
|
|
return proxyProvider->createProxy(format, desc, swizzle, p.fRenderable, p.fSampleCnt, p.fOrigin,
|
2019-08-30 20:19:42 +00:00
|
|
|
GrMipMapped::kNo, p.fFit, p.fBudgeted, GrProtected::kNo);
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
static sk_sp<GrSurfaceProxy> make_backend(GrContext* context, const ProxyParams& p,
|
|
|
|
GrBackendTexture* backendTex) {
|
2019-02-04 18:26:26 +00:00
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
2018-01-16 13:06:32 +00:00
|
|
|
|
2019-07-23 14:27:09 +00:00
|
|
|
SkColorType skColorType = GrColorTypeToSkColorType(p.fColorType);
|
|
|
|
SkASSERT(SkColorType::kUnknown_SkColorType != skColorType);
|
|
|
|
|
|
|
|
*backendTex = context->createBackendTexture(p.fSize, p.fSize, skColorType,
|
2019-06-04 15:03:06 +00:00
|
|
|
SkColors::kTransparent,
|
2019-07-01 19:04:06 +00:00
|
|
|
GrMipMapped::kNo, GrRenderable::kNo,
|
|
|
|
GrProtected::kNo);
|
2018-09-25 13:31:10 +00:00
|
|
|
if (!backendTex->isValid()) {
|
|
|
|
return nullptr;
|
|
|
|
}
|
2017-12-12 18:01:25 +00:00
|
|
|
|
2019-07-23 14:27:09 +00:00
|
|
|
return proxyProvider->wrapBackendTexture(*backendTex, p.fColorType, p.fOrigin,
|
|
|
|
kBorrow_GrWrapOwnership, GrWrapCacheable::kNo,
|
|
|
|
kRead_GrIOType);
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
static void cleanup_backend(GrContext* context, const GrBackendTexture& backendTex) {
|
2019-05-20 12:38:07 +00:00
|
|
|
context->deleteBackendTexture(backendTex);
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
// Basic test that two proxies with overlapping intervals and compatible descriptors are
|
|
|
|
// assigned different GrSurfaces.
|
|
|
|
static void overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider,
|
2019-06-11 12:08:08 +00:00
|
|
|
sk_sp<GrSurfaceProxy> p1, sk_sp<GrSurfaceProxy> p2,
|
2019-04-02 15:52:03 +00:00
|
|
|
bool expectedResult) {
|
2019-08-30 20:19:42 +00:00
|
|
|
GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, 1));
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
alloc.addInterval(p1.get(), 0, 4, GrResourceAllocator::ActualUse::kYes);
|
2019-03-26 18:50:08 +00:00
|
|
|
alloc.incOps();
|
2019-06-11 12:08:08 +00:00
|
|
|
alloc.addInterval(p2.get(), 1, 2, GrResourceAllocator::ActualUse::kYes);
|
2019-03-26 18:50:08 +00:00
|
|
|
alloc.incOps();
|
2019-08-22 20:19:24 +00:00
|
|
|
alloc.markEndOfOpsTask(0);
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2019-04-24 12:49:48 +00:00
|
|
|
alloc.determineRecyclability();
|
|
|
|
|
2017-11-16 12:52:08 +00:00
|
|
|
int startIndex, stopIndex;
|
2018-01-29 15:34:25 +00:00
|
|
|
GrResourceAllocator::AssignError error;
|
2018-11-30 18:32:23 +00:00
|
|
|
alloc.assign(&startIndex, &stopIndex, &error);
|
2018-01-29 15:34:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error);
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, p1->peekSurface());
|
|
|
|
REPORTER_ASSERT(reporter, p2->peekSurface());
|
2017-07-21 15:38:13 +00:00
|
|
|
bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID();
|
|
|
|
REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test various cases when two proxies do not have overlapping intervals.
|
|
|
|
// This mainly acts as a test of the ResourceAllocator's free pool.
|
|
|
|
static void non_overlap_test(skiatest::Reporter* reporter, GrResourceProvider* resourceProvider,
|
2019-06-11 12:08:08 +00:00
|
|
|
sk_sp<GrSurfaceProxy> p1, sk_sp<GrSurfaceProxy> p2,
|
2017-07-21 15:38:13 +00:00
|
|
|
bool expectedResult) {
|
2019-08-30 20:19:42 +00:00
|
|
|
GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, 1));
|
2019-03-26 18:50:08 +00:00
|
|
|
|
|
|
|
alloc.incOps();
|
|
|
|
alloc.incOps();
|
|
|
|
alloc.incOps();
|
|
|
|
alloc.incOps();
|
|
|
|
alloc.incOps();
|
|
|
|
alloc.incOps();
|
2017-07-21 15:38:13 +00:00
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
alloc.addInterval(p1.get(), 0, 2, GrResourceAllocator::ActualUse::kYes);
|
|
|
|
alloc.addInterval(p2.get(), 3, 5, GrResourceAllocator::ActualUse::kYes);
|
2019-08-22 20:19:24 +00:00
|
|
|
alloc.markEndOfOpsTask(0);
|
2017-07-21 15:38:13 +00:00
|
|
|
|
2019-04-24 12:49:48 +00:00
|
|
|
alloc.determineRecyclability();
|
|
|
|
|
2017-11-16 12:52:08 +00:00
|
|
|
int startIndex, stopIndex;
|
2018-01-29 15:34:25 +00:00
|
|
|
GrResourceAllocator::AssignError error;
|
2018-11-30 18:32:23 +00:00
|
|
|
alloc.assign(&startIndex, &stopIndex, &error);
|
2018-01-29 15:34:25 +00:00
|
|
|
REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error);
|
2017-07-21 15:38:13 +00:00
|
|
|
|
2018-07-31 21:25:29 +00:00
|
|
|
REPORTER_ASSERT(reporter, p1->peekSurface());
|
|
|
|
REPORTER_ASSERT(reporter, p2->peekSurface());
|
2017-07-21 15:38:13 +00:00
|
|
|
bool doTheBackingStoresMatch = p1->underlyingUniqueID() == p2->underlyingUniqueID();
|
|
|
|
REPORTER_ASSERT(reporter, expectedResult == doTheBackingStoresMatch);
|
2017-07-18 18:49:38 +00:00
|
|
|
}
|
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorTest, reporter, ctxInfo) {
|
2019-02-04 18:26:26 +00:00
|
|
|
const GrCaps* caps = ctxInfo.grContext()->priv().caps();
|
|
|
|
GrProxyProvider* proxyProvider = ctxInfo.grContext()->priv().proxyProvider();
|
|
|
|
GrResourceProvider* resourceProvider = ctxInfo.grContext()->priv().resourceProvider();
|
2017-07-18 18:49:38 +00:00
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
struct TestCase {
|
|
|
|
ProxyParams fP1;
|
|
|
|
ProxyParams fP2;
|
|
|
|
bool fExpectation;
|
|
|
|
};
|
|
|
|
|
2019-07-17 13:59:59 +00:00
|
|
|
constexpr GrRenderable kRT = GrRenderable::kYes;
|
|
|
|
constexpr GrRenderable kNotRT = GrRenderable::kNo;
|
2017-07-21 15:38:13 +00:00
|
|
|
|
|
|
|
constexpr bool kShare = true;
|
|
|
|
constexpr bool kDontShare = false;
|
|
|
|
// Non-RT GrSurfaces are never recycled on some platforms.
|
|
|
|
bool kConditionallyShare = resourceProvider->caps()->reuseScratchTextures();
|
|
|
|
|
2019-07-23 14:27:09 +00:00
|
|
|
const GrColorType kRGBA = GrColorType::kRGBA_8888;
|
|
|
|
const GrColorType kBGRA = GrColorType::kBGRA_8888;
|
2017-07-21 15:38:13 +00:00
|
|
|
|
|
|
|
const SkBackingFit kE = SkBackingFit::kExact;
|
|
|
|
const SkBackingFit kA = SkBackingFit::kApprox;
|
|
|
|
|
|
|
|
const GrSurfaceOrigin kTL = kTopLeft_GrSurfaceOrigin;
|
|
|
|
const GrSurfaceOrigin kBL = kBottomLeft_GrSurfaceOrigin;
|
|
|
|
|
2019-03-26 18:50:08 +00:00
|
|
|
const SkBudgeted kNotB = SkBudgeted::kNo;
|
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
//--------------------------------------------------------------------------------------------
|
|
|
|
TestCase gOverlappingTests[] = {
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
// Two proxies with overlapping intervals and compatible descriptors should never share
|
|
|
|
// RT version
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, kDontShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
// non-RT version
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 64, kNotRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kNotRT, kRGBA, kA, 1, kTL, kNotB }, kDontShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto test : gOverlappingTests) {
|
2019-06-11 12:08:08 +00:00
|
|
|
sk_sp<GrSurfaceProxy> p1 = make_deferred(proxyProvider, caps, test.fP1);
|
|
|
|
sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, test.fP2);
|
2019-06-18 21:15:04 +00:00
|
|
|
overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2), test.fExpectation);
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
|
|
|
|
2019-08-07 19:52:37 +00:00
|
|
|
auto beFormat = caps->getDefaultBackendFormat(GrColorType::kRGBA_8888, GrRenderable::kYes);
|
|
|
|
int k2 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(2, beFormat);
|
|
|
|
int k4 = ctxInfo.grContext()->priv().caps()->getRenderTargetSampleCount(4, beFormat);
|
2017-07-21 15:38:13 +00:00
|
|
|
|
|
|
|
//--------------------------------------------------------------------------------------------
|
|
|
|
TestCase gNonOverlappingTests[] = {
|
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
// Two non-overlapping intervals w/ compatible proxies should share
|
|
|
|
// both same size & approx
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, kShare },
|
|
|
|
{ { 64, kNotRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kNotRT, kRGBA, kA, 1, kTL, kNotB }, kConditionallyShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
// diffs sizes but still approx
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, { 50, kRT, kRGBA, kA, 1, kTL, kNotB }, kShare },
|
|
|
|
{ { 64, kNotRT, kRGBA, kA, 1, kTL, kNotB }, { 50, kNotRT, kRGBA, kA, 1, kTL, kNotB }, kConditionallyShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
// sames sizes but exact
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 64, kRT, kRGBA, kE, 1, kTL, kNotB }, { 64, kRT, kRGBA, kE, 1, kTL, kNotB }, kShare },
|
|
|
|
{ { 64, kNotRT, kRGBA, kE, 1, kTL, kNotB }, { 64, kNotRT, kRGBA, kE, 1, kTL, kNotB }, kConditionallyShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
//----------------------------------------------------------------------------------------
|
|
|
|
// Two non-overlapping intervals w/ different exact sizes should not share
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 56, kRT, kRGBA, kE, 1, kTL, kNotB }, { 54, kRT, kRGBA, kE, 1, kTL, kNotB }, kDontShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
// Two non-overlapping intervals w/ _very different_ approx sizes should not share
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 255, kRT, kRGBA, kA, 1, kTL, kNotB }, { 127, kRT, kRGBA, kA, 1, kTL, kNotB }, kDontShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
// Two non-overlapping intervals w/ different MSAA sample counts should not share
|
2019-03-26 18:50:08 +00:00
|
|
|
{ { 64, kRT, kRGBA, kA, k2, kTL, kNotB },{ 64, kRT, kRGBA, kA, k4,kTL, kNotB}, k2 == k4 },
|
2017-07-21 15:38:13 +00:00
|
|
|
// Two non-overlapping intervals w/ different configs should not share
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kRT, kBGRA, kA, 1, kTL, kNotB }, kDontShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
// Two non-overlapping intervals w/ different RT classifications should never share
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kNotRT, kRGBA, kA, 1, kTL, kNotB }, kDontShare },
|
|
|
|
{ { 64, kNotRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, kDontShare },
|
2017-08-29 12:26:54 +00:00
|
|
|
// Two non-overlapping intervals w/ different origins should share
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 64, kRT, kRGBA, kA, 1, kTL, kNotB }, { 64, kRT, kRGBA, kA, 1, kBL, kNotB }, kShare },
|
2017-07-21 15:38:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
for (auto test : gNonOverlappingTests) {
|
2019-06-11 12:08:08 +00:00
|
|
|
sk_sp<GrSurfaceProxy> p1 = make_deferred(proxyProvider, caps, test.fP1);
|
|
|
|
sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, test.fP2);
|
2018-07-18 17:56:48 +00:00
|
|
|
|
2017-07-21 15:38:13 +00:00
|
|
|
if (!p1 || !p2) {
|
|
|
|
continue; // creation can fail (i.e., for msaa4 on iOS)
|
|
|
|
}
|
2018-07-18 17:56:48 +00:00
|
|
|
|
2019-06-18 21:15:04 +00:00
|
|
|
non_overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2),
|
|
|
|
test.fExpectation);
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// Wrapped backend textures should never be reused
|
|
|
|
TestCase t[1] = {
|
2019-07-22 18:23:45 +00:00
|
|
|
{ { 64, kNotRT, kRGBA, kE, 1, kTL, kNotB }, { 64, kNotRT, kRGBA, kE, 1, kTL, kNotB }, kDontShare }
|
2017-07-21 15:38:13 +00:00
|
|
|
};
|
|
|
|
|
2017-12-12 18:01:25 +00:00
|
|
|
GrBackendTexture backEndTex;
|
2019-06-11 12:08:08 +00:00
|
|
|
sk_sp<GrSurfaceProxy> p1 = make_backend(ctxInfo.grContext(), t[0].fP1, &backEndTex);
|
|
|
|
sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, t[0].fP2);
|
2018-07-18 17:56:48 +00:00
|
|
|
|
2019-06-18 21:15:04 +00:00
|
|
|
non_overlap_test(reporter, resourceProvider, std::move(p1), std::move(p2),
|
|
|
|
t[0].fExpectation);
|
2018-07-18 17:56:48 +00:00
|
|
|
|
2018-03-09 14:33:19 +00:00
|
|
|
cleanup_backend(ctxInfo.grContext(), backEndTex);
|
2017-07-21 15:38:13 +00:00
|
|
|
}
|
2017-07-18 18:49:38 +00:00
|
|
|
}
|
2018-08-21 17:52:09 +00:00
|
|
|
|
|
|
|
static void draw(GrContext* context) {
|
|
|
|
SkImageInfo ii = SkImageInfo::Make(1024, 1024, kRGBA_8888_SkColorType, kPremul_SkAlphaType);
|
|
|
|
|
|
|
|
sk_sp<SkSurface> s = SkSurface::MakeRenderTarget(context, SkBudgeted::kYes,
|
|
|
|
ii, 1, kTopLeft_GrSurfaceOrigin, nullptr);
|
|
|
|
|
|
|
|
SkCanvas* c = s->getCanvas();
|
|
|
|
|
|
|
|
c->clear(SK_ColorBLACK);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorStressTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
size_t maxBytes = context->getResourceCacheLimit();
|
2018-08-21 17:52:09 +00:00
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(0); // We'll always be overbudget
|
2018-08-21 17:52:09 +00:00
|
|
|
|
|
|
|
draw(context);
|
|
|
|
draw(context);
|
|
|
|
draw(context);
|
|
|
|
draw(context);
|
|
|
|
context->flush();
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(maxBytes);
|
2018-08-21 17:52:09 +00:00
|
|
|
}
|
2018-11-30 18:32:23 +00:00
|
|
|
|
|
|
|
sk_sp<GrSurfaceProxy> make_lazy(GrProxyProvider* proxyProvider, const GrCaps* caps,
|
2019-08-30 20:19:42 +00:00
|
|
|
const ProxyParams& p) {
|
2019-07-23 14:27:09 +00:00
|
|
|
GrPixelConfig config = GrColorTypeToPixelConfig(p.fColorType);
|
2019-08-05 16:58:39 +00:00
|
|
|
const auto format = caps->getDefaultBackendFormat(p.fColorType, p.fRenderable);
|
2018-11-30 18:32:23 +00:00
|
|
|
|
|
|
|
GrSurfaceDesc desc;
|
|
|
|
desc.fWidth = p.fSize;
|
|
|
|
desc.fHeight = p.fSize;
|
|
|
|
desc.fConfig = config;
|
|
|
|
|
|
|
|
SkBackingFit fit = p.fFit;
|
2019-08-05 16:58:39 +00:00
|
|
|
auto callback = [fit, desc, format, p](GrResourceProvider* resourceProvider) {
|
2019-04-01 16:29:34 +00:00
|
|
|
sk_sp<GrTexture> texture;
|
2018-11-30 18:32:23 +00:00
|
|
|
if (fit == SkBackingFit::kApprox) {
|
2019-04-09 22:41:27 +00:00
|
|
|
texture = resourceProvider->createApproxTexture(
|
2019-09-06 15:48:27 +00:00
|
|
|
desc, format, p.fRenderable, p.fSampleCnt, GrProtected::kNo);
|
2018-11-30 18:32:23 +00:00
|
|
|
} else {
|
2019-08-05 16:58:39 +00:00
|
|
|
texture = resourceProvider->createTexture(desc, format, p.fRenderable, p.fSampleCnt,
|
2019-09-17 13:01:56 +00:00
|
|
|
GrMipMapped::kNo, SkBudgeted::kNo,
|
|
|
|
GrProtected::kNo);
|
2018-11-30 18:32:23 +00:00
|
|
|
}
|
2019-08-30 20:19:42 +00:00
|
|
|
return GrSurfaceProxy::LazyCallbackResult(std::move(texture));
|
2018-11-30 18:32:23 +00:00
|
|
|
};
|
|
|
|
GrInternalSurfaceFlags flags = GrInternalSurfaceFlags::kNone;
|
2019-07-30 17:17:59 +00:00
|
|
|
return proxyProvider->createLazyProxy(
|
|
|
|
callback, format, desc, p.fRenderable, p.fSampleCnt, p.fOrigin, GrMipMapped::kNo,
|
2019-08-30 20:19:42 +00:00
|
|
|
GrMipMapsStatus::kNotAllocated, flags, p.fFit, p.fBudgeted, GrProtected::kNo,
|
|
|
|
GrSurfaceProxy::UseAllocator::kYes);
|
2018-11-30 18:32:23 +00:00
|
|
|
}
|
2019-03-26 18:50:08 +00:00
|
|
|
|
2019-08-22 20:19:24 +00:00
|
|
|
// Set up so there are two opsTasks that need to be flushed but the resource allocator thinks
|
|
|
|
// it is over budget. The two opsTasks should be flushed separately and the opsTask indices
|
2019-03-26 18:50:08 +00:00
|
|
|
// returned from assign should be correct.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorOverBudgetTest, reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
size_t origMaxBytes = context->getResourceCacheLimit();
|
2019-03-26 18:50:08 +00:00
|
|
|
|
|
|
|
// Force the resource allocator to always believe it is over budget
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(0);
|
2019-03-26 18:50:08 +00:00
|
|
|
|
2019-07-23 14:27:09 +00:00
|
|
|
const ProxyParams params = { 64, GrRenderable::kNo, GrColorType::kRGBA_8888,
|
2019-07-22 18:23:45 +00:00
|
|
|
SkBackingFit::kExact, 1, kTopLeft_GrSurfaceOrigin,
|
2019-03-26 18:50:08 +00:00
|
|
|
SkBudgeted::kYes };
|
|
|
|
|
|
|
|
{
|
2019-06-11 12:08:08 +00:00
|
|
|
sk_sp<GrSurfaceProxy> p1 = make_deferred(proxyProvider, caps, params);
|
|
|
|
sk_sp<GrSurfaceProxy> p2 = make_deferred(proxyProvider, caps, params);
|
|
|
|
sk_sp<GrSurfaceProxy> p3 = make_deferred(proxyProvider, caps, params);
|
|
|
|
sk_sp<GrSurfaceProxy> p4 = make_deferred(proxyProvider, caps, params);
|
2019-03-26 18:50:08 +00:00
|
|
|
|
2019-08-30 20:19:42 +00:00
|
|
|
GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, 2));
|
2019-03-26 18:50:08 +00:00
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
alloc.addInterval(p1.get(), 0, 0, GrResourceAllocator::ActualUse::kYes);
|
2019-03-26 18:50:08 +00:00
|
|
|
alloc.incOps();
|
2019-06-11 12:08:08 +00:00
|
|
|
alloc.addInterval(p2.get(), 1, 1, GrResourceAllocator::ActualUse::kYes);
|
2019-03-26 18:50:08 +00:00
|
|
|
alloc.incOps();
|
2019-08-22 20:19:24 +00:00
|
|
|
alloc.markEndOfOpsTask(0);
|
2019-03-26 18:50:08 +00:00
|
|
|
|
2019-06-11 12:08:08 +00:00
|
|
|
alloc.addInterval(p3.get(), 2, 2, GrResourceAllocator::ActualUse::kYes);
|
2019-03-26 18:50:08 +00:00
|
|
|
alloc.incOps();
|
2019-06-11 12:08:08 +00:00
|
|
|
alloc.addInterval(p4.get(), 3, 3, GrResourceAllocator::ActualUse::kYes);
|
2019-03-26 18:50:08 +00:00
|
|
|
alloc.incOps();
|
2019-08-22 20:19:24 +00:00
|
|
|
alloc.markEndOfOpsTask(1);
|
2019-03-26 18:50:08 +00:00
|
|
|
|
|
|
|
int startIndex, stopIndex;
|
|
|
|
GrResourceAllocator::AssignError error;
|
|
|
|
|
2019-04-24 12:49:48 +00:00
|
|
|
alloc.determineRecyclability();
|
|
|
|
|
2019-03-26 18:50:08 +00:00
|
|
|
alloc.assign(&startIndex, &stopIndex, &error);
|
|
|
|
REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error);
|
|
|
|
REPORTER_ASSERT(reporter, 0 == startIndex && 1 == stopIndex);
|
|
|
|
|
|
|
|
alloc.assign(&startIndex, &stopIndex, &error);
|
|
|
|
REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error);
|
|
|
|
REPORTER_ASSERT(reporter, 1 == startIndex && 2 == stopIndex);
|
|
|
|
}
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(origMaxBytes);
|
2019-03-26 18:50:08 +00:00
|
|
|
}
|
2019-08-29 18:37:46 +00:00
|
|
|
|
|
|
|
// This test is used to make sure we are tracking the current task index during the assign call in
|
|
|
|
// the GrResourceAllocator. Specifically we can fall behind if we have intervals that don't
|
|
|
|
// use the allocator. In this case we need to possibly increment the fCurOpsTaskIndex multiple times
|
|
|
|
// to get in back in sync. We had a bug where we'd only every increment the index by one,
|
|
|
|
// http://crbug.com/996610.
|
|
|
|
DEF_GPUTEST_FOR_RENDERING_CONTEXTS(ResourceAllocatorCurOpsTaskIndexTest,
|
|
|
|
reporter, ctxInfo) {
|
|
|
|
GrContext* context = ctxInfo.grContext();
|
|
|
|
const GrCaps* caps = context->priv().caps();
|
|
|
|
GrProxyProvider* proxyProvider = context->priv().proxyProvider();
|
|
|
|
GrResourceProvider* resourceProvider = context->priv().resourceProvider();
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
size_t origMaxBytes = context->getResourceCacheLimit();
|
2019-08-29 18:37:46 +00:00
|
|
|
|
|
|
|
// Force the resource allocator to always believe it is over budget
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(0);
|
2019-08-29 18:37:46 +00:00
|
|
|
|
|
|
|
ProxyParams params;
|
|
|
|
params.fFit = SkBackingFit::kExact;
|
|
|
|
params.fOrigin = kTopLeft_GrSurfaceOrigin;
|
|
|
|
params.fColorType = GrColorType::kRGBA_8888;
|
|
|
|
params.fRenderable = GrRenderable::kYes;
|
|
|
|
params.fSampleCnt = 1;
|
|
|
|
params.fSize = 100;
|
|
|
|
params.fBudgeted = SkBudgeted::kYes;
|
|
|
|
|
|
|
|
sk_sp<GrSurfaceProxy> proxy1 = make_deferred(proxyProvider, caps, params);
|
|
|
|
if (!proxy1) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
sk_sp<GrSurfaceProxy> proxy2 = make_deferred(proxyProvider, caps, params);
|
|
|
|
if (!proxy2) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Wrapped proxy that will be ignored by the resourceAllocator. We use this to try and get the
|
|
|
|
// resource allocator fCurOpsTaskIndex to fall behind what it really should be.
|
|
|
|
GrBackendTexture backEndTex;
|
|
|
|
sk_sp<GrSurfaceProxy> proxyWrapped = make_backend(ctxInfo.grContext(), params,
|
|
|
|
&backEndTex);
|
|
|
|
if (!proxyWrapped) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Same as above, but we actually need to have at least two intervals that don't go through the
|
|
|
|
// resource allocator to expose the index bug.
|
|
|
|
GrBackendTexture backEndTex2;
|
|
|
|
sk_sp<GrSurfaceProxy> proxyWrapped2 = make_backend(ctxInfo.grContext(), params,
|
|
|
|
&backEndTex2);
|
|
|
|
if (!proxyWrapped2) {
|
|
|
|
cleanup_backend(ctxInfo.grContext(), backEndTex);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-08-30 20:19:42 +00:00
|
|
|
GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, 4));
|
2019-08-29 18:37:46 +00:00
|
|
|
|
|
|
|
alloc.addInterval(proxyWrapped.get(), 0, 0, GrResourceAllocator::ActualUse::kYes);
|
|
|
|
alloc.incOps();
|
|
|
|
alloc.markEndOfOpsTask(0);
|
|
|
|
|
|
|
|
alloc.addInterval(proxyWrapped2.get(), 1, 1, GrResourceAllocator::ActualUse::kYes);
|
|
|
|
alloc.incOps();
|
|
|
|
alloc.markEndOfOpsTask(1);
|
|
|
|
|
|
|
|
alloc.addInterval(proxy1.get(), 2, 2, GrResourceAllocator::ActualUse::kYes);
|
|
|
|
alloc.incOps();
|
|
|
|
alloc.markEndOfOpsTask(2);
|
|
|
|
|
|
|
|
// We want to force the resource allocator to do a intermediateFlush for the previous interval.
|
|
|
|
// But if it is the resource allocator is at the of its list of intervals it skips the
|
|
|
|
// intermediate flush call, so we add another interval here so it is not skipped.
|
|
|
|
alloc.addInterval(proxy2.get(), 3, 3, GrResourceAllocator::ActualUse::kYes);
|
|
|
|
alloc.incOps();
|
|
|
|
alloc.markEndOfOpsTask(3);
|
|
|
|
|
|
|
|
int startIndex, stopIndex;
|
|
|
|
GrResourceAllocator::AssignError error;
|
|
|
|
|
|
|
|
alloc.determineRecyclability();
|
|
|
|
|
|
|
|
alloc.assign(&startIndex, &stopIndex, &error);
|
|
|
|
REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error);
|
|
|
|
// The original bug in the allocator here would return a stopIndex of 2 since it would have only
|
|
|
|
// incremented its fCurOpsTaskIndex once instead of the needed two times to skip the first two
|
|
|
|
// unused intervals.
|
|
|
|
REPORTER_ASSERT(reporter, 0 == startIndex && 3 == stopIndex);
|
|
|
|
|
|
|
|
alloc.assign(&startIndex, &stopIndex, &error);
|
|
|
|
REPORTER_ASSERT(reporter, GrResourceAllocator::AssignError::kNoError == error);
|
|
|
|
REPORTER_ASSERT(reporter, 3 == startIndex && 4 == stopIndex);
|
|
|
|
|
|
|
|
cleanup_backend(ctxInfo.grContext(), backEndTex);
|
|
|
|
cleanup_backend(ctxInfo.grContext(), backEndTex2);
|
|
|
|
|
2019-09-03 14:29:20 +00:00
|
|
|
context->setResourceCacheLimit(origMaxBytes);
|
2019-08-29 18:37:46 +00:00
|
|
|
}
|
|
|
|
|