Reland "Reland "Clear out atlases if they haven't been used in a while.""

This is a reland of 0bd00f438e

Original change's description:
> Reland "Clear out atlases if they haven't been used in a while."
> 
> This is a reland of 79007c9309
> 
> Original change's description:
> > Clear out atlases if they haven't been used in a while.
> > 
> > This will stage out atlas pages one at a time with an interval of
> > 256 flushes between them. Also removes the last page to help
> > conserve memory if text or other atlas-using systems are not in use.
> > 
> > Bug: 1058905
> > Change-Id: I8717621033068d0e24da944356d91b0f35e5373b
> > Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276764
> > Commit-Queue: Jim Van Verth <jvanverth@google.com>
> > Reviewed-by: Herb Derby <herb@google.com>
> 
> Bug: 1058905
> Change-Id: I25b0037cb1608ae0bda641e0d0588afaf3dd47e5
> Reviewed-on: https://skia-review.googlesource.com/c/skia/+/276960
> Reviewed-by: Jim Van Verth <jvanverth@google.com>
> Commit-Queue: Jim Van Verth <jvanverth@google.com>

Bug: 1058905
Change-Id: I6e6cf7b30ced25c6a5af6ad57311b2a305d7c73a
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/277611
Reviewed-by: Herb Derby <herb@google.com>
Commit-Queue: Jim Van Verth <jvanverth@google.com>
This commit is contained in:
Jim Van Verth 2020-03-18 12:32:34 -04:00 committed by Skia Commit-Bot
parent 2fade72a4e
commit 77eb96d0c2
2 changed files with 21 additions and 9 deletions

View File

@ -221,6 +221,7 @@ GrDrawOpAtlas::GrDrawOpAtlas(
, fGenerationCounter(generationCounter)
, fAtlasGeneration(fGenerationCounter->next())
, fPrevFlushToken(GrDeferredUploadToken::AlreadyFlushedToken())
, fFlushesSinceLastUse(0)
, fMaxPages(AllowMultitexturing::kYes == allowMultitexturing ? kMaxMultitexturePages : 1)
, fNumActivePages(0) {
int numPlotsX = width/plotWidth;
@ -293,7 +294,8 @@ bool GrDrawOpAtlas::uploadToPage(const GrCaps& caps, unsigned int pageIdx, PlotL
// a page with unused plots will get removed reasonably quickly, but allow it
// to hang around for a bit in case it's needed. The assumption is that flushes
// are rare; i.e., we are not continually refreshing the frame.
static constexpr auto kRecentlyUsedCount = 256;
static constexpr auto kPlotRecentlyUsedCount = 256;
static constexpr auto kAtlasRecentlyUsedCount = 1024;
GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceProvider,
PlotLocator* plotLocator,
@ -407,7 +409,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP
}
void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
if (fNumActivePages <= 1) {
if (fNumActivePages < 1) {
fPrevFlushToken = startTokenForNextFlush;
return;
}
@ -428,11 +430,17 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
}
}
// We only try to compact if the atlas was used in the recently completed flush.
if (atlasUsedThisFlush) {
fFlushesSinceLastUse = 0;
} else {
++fFlushesSinceLastUse;
}
// We only try to compact if the atlas was used in the recently completed flush or
// hasn't been used in a long time.
// This is to handle the case where a lot of text or path rendering has occurred but then just
// a blinking cursor is drawn.
// TODO: consider if we should also do this if it's been a long time since the last atlas use
if (atlasUsedThisFlush) {
if (atlasUsedThisFlush || fFlushesSinceLastUse > kAtlasRecentlyUsedCount) {
SkTArray<Plot*> availablePlots;
uint32_t lastPageIndex = fNumActivePages - 1;
@ -461,7 +469,7 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
#endif
// Count plots we can potentially upload to in all pages except the last one
// (the potential compactee).
if (plot->flushesSinceLastUsed() > kRecentlyUsedCount) {
if (plot->flushesSinceLastUsed() > kPlotRecentlyUsedCount) {
availablePlots.push_back() = plot;
}
@ -496,7 +504,7 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
}
#endif
// If this plot was used recently
if (plot->flushesSinceLastUsed() <= kRecentlyUsedCount) {
if (plot->flushesSinceLastUsed() <= kPlotRecentlyUsedCount) {
usedPlots++;
} else if (plot->lastUseToken() != GrDeferredUploadToken::AlreadyFlushedToken()) {
// otherwise if aged out just evict it.
@ -518,7 +526,7 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
plotIter.init(fPages[lastPageIndex].fPlotList, PlotList::Iter::kHead_IterStart);
while (Plot* plot = plotIter.get()) {
// If this plot was used recently
if (plot->flushesSinceLastUsed() <= kRecentlyUsedCount) {
if (plot->flushesSinceLastUsed() <= kPlotRecentlyUsedCount) {
// See if there's room in an earlier page and if so evict.
// We need to be somewhat harsh here so that a handful of plots that are
// consistently in use don't end up locking the page in memory.
@ -540,10 +548,11 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
if (!usedPlots) {
#ifdef DUMP_ATLAS_DATA
if (gDumpAtlasData) {
SkDebugf("delete %d\n", fNumPages-1);
SkDebugf("delete %d\n", fNumActivePages-1);
}
#endif
this->deactivateLastPage();
fFlushesSinceLastUse = 0;
}
}

View File

@ -435,6 +435,9 @@ private:
// nextTokenToFlush() value at the end of the previous flush
GrDeferredUploadToken fPrevFlushToken;
// the number of flushes since this atlas has been last used
int fFlushesSinceLastUse;
std::vector<EvictionCallback*> fEvictionCallbacks;
struct Page {