Check budget for task reordering and report stats

In this CL we don't actually bail and use the record-time-ordered
DAG in this case, but we at least will see which perf bots with
reordering turned on are going over budget.

Bug: skia:10877
Change-Id: I38666166f15a7c168eadf262f7e975822c4308db
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/394158
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 e1ce658..abf9c94 100644
--- a/src/gpu/GrDrawingManager.cpp
+++ b/src/gpu/GrDrawingManager.cpp
@@ -211,8 +211,15 @@
             task->gatherProxyIntervals(&alloc);
         }
 
-        // TODO: Call makeBudgetHeadroom before proceeding with reordered DAG.
-        flushed = alloc.planAssignment() && alloc.assign() && this->executeRenderTasks(&flushState);
+        if (alloc.planAssignment()) {
+            if (fReduceOpsTaskSplitting) {
+                if (!alloc.makeBudgetHeadroom()) {
+                    // TODO: Switch to the original DAG in this case.
+                    gpu->stats()->incNumReorderedDAGsOverBudget();
+                }
+            }
+            flushed = alloc.assign() && this->executeRenderTasks(&flushState);
+        }
     }
     this->removeRenderTasks();
 
diff --git a/src/gpu/GrGpu.cpp b/src/gpu/GrGpu.cpp
index 15e2637..523a007 100644
--- a/src/gpu/GrGpu.cpp
+++ b/src/gpu/GrGpu.cpp
@@ -726,6 +726,7 @@
     out->appendf("Number of Scratch MSAA Attachments reused %d\n",
                  fNumScratchMSAAAttachmentsReused);
     out->appendf("Number of Render Passes: %d\n", fRenderPasses);
+    out->appendf("Reordered DAGs Over Budget: %d\n", fNumReorderedDAGsOverBudget);
 
     // enable this block to output CSV-style stats for program pre-compilation
 #if 0
@@ -746,6 +747,8 @@
 void GrGpu::Stats::dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values) {
     keys->push_back(SkString("render_passes"));
     values->push_back(fRenderPasses);
+    keys->push_back(SkString("reordered_dags_over_budget"));
+    values->push_back(fNumReorderedDAGsOverBudget);
 }
 
 #endif // GR_GPU_STATS
diff --git a/src/gpu/GrGpu.h b/src/gpu/GrGpu.h
index c5d2a44..17d2a93 100644
--- a/src/gpu/GrGpu.h
+++ b/src/gpu/GrGpu.h
@@ -450,6 +450,9 @@
         int renderPasses() const { return fRenderPasses; }
         void incRenderPasses() { fRenderPasses++; }
 
+        int numReorderedDAGsOverBudget() const { return fNumReorderedDAGsOverBudget; }
+        void incNumReorderedDAGsOverBudget() { fNumReorderedDAGsOverBudget++; }
+
 #if GR_TEST_UTILS
         void dump(SkString*);
         void dumpKeyValuePairs(SkTArray<SkString>* keys, SkTArray<double>* values);
@@ -467,6 +470,7 @@
         int fNumScratchTexturesReused = 0;
         int fNumScratchMSAAAttachmentsReused = 0;
         int fRenderPasses = 0;
+        int fNumReorderedDAGsOverBudget = 0;
 
 #else  // !GR_GPU_STATS
 
@@ -486,6 +490,7 @@
         void incNumScratchTexturesReused() {}
         void incNumScratchMSAAAttachmentsReused() {}
         void incRenderPasses() {}
+        void incNumReorderedDAGsOverBudget() {}
 #endif
     };