Remove the partial-flush machinery from GrResourceAllocator
Since review.skia.org/366716 this is unused and it makes our life
a whole lot simpler. And a little faster.
Bug: skia:10877
Change-Id: Ib7205bae57ce282f0e4f33c7c780a4c3e5159ea5
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/369436
Commit-Queue: Adlai Holler <adlai@google.com>
Reviewed-by: Robert Phillips <robertphillips@google.com>
diff --git a/src/gpu/GrDrawingManager.cpp b/src/gpu/GrDrawingManager.cpp
index 0648771..bd3ae75 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -60,7 +60,7 @@
GrDrawingManager::~GrDrawingManager() {
this->closeAllTasks();
- this->removeRenderTasks(0, fDAG.count());
+ this->removeRenderTasks();
}
bool GrDrawingManager::wasAbandoned() const {
@@ -202,58 +202,38 @@
}
#endif
- int startIndex, stopIndex;
bool flushed = false;
{
GrResourceAllocator alloc(resourceProvider SkDEBUGCODE(, fDAG.count()));
- for (int i = 0; i < fDAG.count(); ++i) {
- if (fDAG[i]) {
- fDAG[i]->gatherProxyIntervals(&alloc);
- }
- alloc.markEndOfOpsTask(i);
+ for (const auto& task : fDAG) {
+ SkASSERT(task);
+ task->gatherProxyIntervals(&alloc);
}
- alloc.determineRecyclability();
GrResourceAllocator::AssignError error = GrResourceAllocator::AssignError::kNoError;
- int numRenderTasksExecuted = 0;
- if (alloc.assign(&startIndex, &stopIndex, &error)) {
- // TODO: If this always-execute-everything approach works out, remove the startIndex &
- // stopIndex from the GrResourceProvider API and simplify.
- SkASSERT(startIndex == 0 && stopIndex == fDAG.count());
- if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) {
- for (int i = startIndex; i < stopIndex; ++i) {
- GrRenderTask* renderTask = fDAG[i].get();
- if (!renderTask) {
- continue;
- }
- if (!renderTask->isInstantiated()) {
- // No need to call the renderTask's handleInternalAllocationFailure
- // since we will already skip executing the renderTask since it is not
- // instantiated.
- continue;
- }
- renderTask->handleInternalAllocationFailure();
+ alloc.assign(&error);
+ if (GrResourceAllocator::AssignError::kFailedProxyInstantiation == error) {
+ for (const auto& renderTask : fDAG) {
+ SkASSERT(renderTask);
+ if (!renderTask->isInstantiated()) {
+ // No need to call the renderTask's handleInternalAllocationFailure
+ // since we will already skip executing the renderTask since it is not
+ // instantiated.
+ continue;
}
- this->removeRenderTasks(startIndex, stopIndex);
+ // TODO: If we're going to remove all the render tasks do we really need this call?
+ renderTask->handleInternalAllocationFailure();
}
+ this->removeRenderTasks();
+ }
- if (this->executeRenderTasks(
- startIndex, stopIndex, &flushState, &numRenderTasksExecuted)) {
- flushed = true;
- }
+ if (this->executeRenderTasks(&flushState)) {
+ flushed = true;
}
}
-#ifdef SK_DEBUG
- for (const auto& task : fDAG) {
- // All render tasks should have been cleared out by now – we only reset the array below to
- // reclaim storage.
- SkASSERT(!task);
- }
-#endif
- fLastRenderTasks.reset();
- fDAG.reset();
+ SkASSERT(fDAG.empty());
#ifdef SK_DEBUG
// In non-DDL mode this checks that all the flushed ops have been freed from the memory pool.
@@ -297,14 +277,10 @@
return gpu->submitToGpu(syncToCpu);
}
-bool GrDrawingManager::executeRenderTasks(int startIndex, int stopIndex, GrOpFlushState* flushState,
- int* numRenderTasksExecuted) {
- SkASSERT(startIndex <= stopIndex && stopIndex <= fDAG.count());
-
+bool GrDrawingManager::executeRenderTasks(GrOpFlushState* flushState) {
#if GR_FLUSH_TIME_OP_SPEW
- SkDebugf("Flushing opsTask: %d to %d out of [%d, %d]\n",
- startIndex, stopIndex, 0, fDAG.count());
- for (int i = startIndex; i < stopIndex; ++i) {
+ SkDebugf("Flushing %d opsTasks\n", fDAG.count());
+ for (int i = 0; i < fDAG.count(); ++i) {
if (fDAG[i]) {
SkString label;
label.printf("task %d/%d", i, fDAG.count());
@@ -315,8 +291,7 @@
bool anyRenderTasksExecuted = false;
- for (int i = startIndex; i < stopIndex; ++i) {
- GrRenderTask* renderTask = fDAG[i].get();
+ for (const auto& renderTask : fDAG) {
if (!renderTask || !renderTask->isInstantiated()) {
continue;
}
@@ -335,6 +310,7 @@
// put a cap on the number of oplists we will execute before flushing to the GPU to relieve some
// memory pressure.
static constexpr int kMaxRenderTasksBeforeFlush = 100;
+ int numRenderTasksExecuted = 0;
// Execute the onFlush renderTasks first, if any.
for (sk_sp<GrRenderTask>& onFlushRenderTask : fOnFlushRenderTasks) {
@@ -344,28 +320,26 @@
SkASSERT(onFlushRenderTask->unique());
onFlushRenderTask->disown(this);
onFlushRenderTask = nullptr;
- (*numRenderTasksExecuted)++;
- if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
+ if (++numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
flushState->gpu()->submitToGpu(false);
- *numRenderTasksExecuted = 0;
+ numRenderTasksExecuted = 0;
}
}
fOnFlushRenderTasks.reset();
// Execute the normal op lists.
- for (int i = startIndex; i < stopIndex; ++i) {
- GrRenderTask* renderTask = fDAG[i].get();
- if (!renderTask || !renderTask->isInstantiated()) {
+ for (const auto& renderTask : fDAG) {
+ SkASSERT(renderTask);
+ if (!renderTask->isInstantiated()) {
continue;
}
if (renderTask->execute(flushState)) {
anyRenderTasksExecuted = true;
}
- (*numRenderTasksExecuted)++;
- if (*numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
+ if (++numRenderTasksExecuted >= kMaxRenderTasksBeforeFlush) {
flushState->gpu()->submitToGpu(false);
- *numRenderTasksExecuted = 0;
+ numRenderTasksExecuted = 0;
}
}
@@ -377,17 +351,14 @@
// resources are the last to be purged by the resource cache.
flushState->reset();
- this->removeRenderTasks(startIndex, stopIndex);
+ this->removeRenderTasks();
return anyRenderTasksExecuted;
}
-void GrDrawingManager::removeRenderTasks(int startIndex, int stopIndex) {
- for (int i = startIndex; i < stopIndex; ++i) {
- GrRenderTask* task = fDAG[i].get();
- if (!task) {
- continue;
- }
+void GrDrawingManager::removeRenderTasks() {
+ for (const auto& task : fDAG) {
+ SkASSERT(task);
if (!task->unique() || task->requiresExplicitCleanup()) {
// TODO: Eventually uniqueness should be guaranteed: http://skbug.com/7111.
// DDLs, however, will always require an explicit notification for when they
@@ -395,12 +366,9 @@
task->endFlush(this);
}
task->disown(this);
-
- // This doesn't cleanup any referring pointers (e.g. dependency pointers in the DAG).
- // It works right now bc this is only called after the topological sort is complete
- // (so the dangling pointers aren't used).
- fDAG[i] = nullptr;
}
+ fDAG.reset();
+ fLastRenderTasks.reset();
}
void GrDrawingManager::sortTasks() {