Reland "Reland "Clear out atlases if they haven't been used in a while.""
This is a reland of0bd00f438e
Original change's description: > Reland "Clear out atlases if they haven't been used in a while." > > This is a reland of79007c9309
> > 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:
parent
2fade72a4e
commit
77eb96d0c2
@ -221,6 +221,7 @@ GrDrawOpAtlas::GrDrawOpAtlas(
|
|||||||
, fGenerationCounter(generationCounter)
|
, fGenerationCounter(generationCounter)
|
||||||
, fAtlasGeneration(fGenerationCounter->next())
|
, fAtlasGeneration(fGenerationCounter->next())
|
||||||
, fPrevFlushToken(GrDeferredUploadToken::AlreadyFlushedToken())
|
, fPrevFlushToken(GrDeferredUploadToken::AlreadyFlushedToken())
|
||||||
|
, fFlushesSinceLastUse(0)
|
||||||
, fMaxPages(AllowMultitexturing::kYes == allowMultitexturing ? kMaxMultitexturePages : 1)
|
, fMaxPages(AllowMultitexturing::kYes == allowMultitexturing ? kMaxMultitexturePages : 1)
|
||||||
, fNumActivePages(0) {
|
, fNumActivePages(0) {
|
||||||
int numPlotsX = width/plotWidth;
|
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
|
// 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
|
// 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.
|
// 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,
|
GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceProvider,
|
||||||
PlotLocator* plotLocator,
|
PlotLocator* plotLocator,
|
||||||
@ -407,7 +409,7 @@ GrDrawOpAtlas::ErrorCode GrDrawOpAtlas::addToAtlas(GrResourceProvider* resourceP
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
|
void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
|
||||||
if (fNumActivePages <= 1) {
|
if (fNumActivePages < 1) {
|
||||||
fPrevFlushToken = startTokenForNextFlush;
|
fPrevFlushToken = startTokenForNextFlush;
|
||||||
return;
|
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
|
// This is to handle the case where a lot of text or path rendering has occurred but then just
|
||||||
// a blinking cursor is drawn.
|
// 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 || fFlushesSinceLastUse > kAtlasRecentlyUsedCount) {
|
||||||
if (atlasUsedThisFlush) {
|
|
||||||
SkTArray<Plot*> availablePlots;
|
SkTArray<Plot*> availablePlots;
|
||||||
uint32_t lastPageIndex = fNumActivePages - 1;
|
uint32_t lastPageIndex = fNumActivePages - 1;
|
||||||
|
|
||||||
@ -461,7 +469,7 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
|
|||||||
#endif
|
#endif
|
||||||
// Count plots we can potentially upload to in all pages except the last one
|
// Count plots we can potentially upload to in all pages except the last one
|
||||||
// (the potential compactee).
|
// (the potential compactee).
|
||||||
if (plot->flushesSinceLastUsed() > kRecentlyUsedCount) {
|
if (plot->flushesSinceLastUsed() > kPlotRecentlyUsedCount) {
|
||||||
availablePlots.push_back() = plot;
|
availablePlots.push_back() = plot;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -496,7 +504,7 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// If this plot was used recently
|
// If this plot was used recently
|
||||||
if (plot->flushesSinceLastUsed() <= kRecentlyUsedCount) {
|
if (plot->flushesSinceLastUsed() <= kPlotRecentlyUsedCount) {
|
||||||
usedPlots++;
|
usedPlots++;
|
||||||
} else if (plot->lastUseToken() != GrDeferredUploadToken::AlreadyFlushedToken()) {
|
} else if (plot->lastUseToken() != GrDeferredUploadToken::AlreadyFlushedToken()) {
|
||||||
// otherwise if aged out just evict it.
|
// 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);
|
plotIter.init(fPages[lastPageIndex].fPlotList, PlotList::Iter::kHead_IterStart);
|
||||||
while (Plot* plot = plotIter.get()) {
|
while (Plot* plot = plotIter.get()) {
|
||||||
// If this plot was used recently
|
// 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.
|
// 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
|
// 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.
|
// consistently in use don't end up locking the page in memory.
|
||||||
@ -540,10 +548,11 @@ void GrDrawOpAtlas::compact(GrDeferredUploadToken startTokenForNextFlush) {
|
|||||||
if (!usedPlots) {
|
if (!usedPlots) {
|
||||||
#ifdef DUMP_ATLAS_DATA
|
#ifdef DUMP_ATLAS_DATA
|
||||||
if (gDumpAtlasData) {
|
if (gDumpAtlasData) {
|
||||||
SkDebugf("delete %d\n", fNumPages-1);
|
SkDebugf("delete %d\n", fNumActivePages-1);
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
this->deactivateLastPage();
|
this->deactivateLastPage();
|
||||||
|
fFlushesSinceLastUse = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -435,6 +435,9 @@ private:
|
|||||||
// nextTokenToFlush() value at the end of the previous flush
|
// nextTokenToFlush() value at the end of the previous flush
|
||||||
GrDeferredUploadToken fPrevFlushToken;
|
GrDeferredUploadToken fPrevFlushToken;
|
||||||
|
|
||||||
|
// the number of flushes since this atlas has been last used
|
||||||
|
int fFlushesSinceLastUse;
|
||||||
|
|
||||||
std::vector<EvictionCallback*> fEvictionCallbacks;
|
std::vector<EvictionCallback*> fEvictionCallbacks;
|
||||||
|
|
||||||
struct Page {
|
struct Page {
|
||||||
|
Loading…
Reference in New Issue
Block a user