Optimize GrOpsTask::onIsUsed
Before this CL, the render task clustering algorithm was taking
a ton more CPU time than needed by visiting proxies every
time it needed to check for surface usage.
Note also, the fSampledProxies does indeed usually contain many
duplicates in our SKPs. Sometimes 3 or 4x. I may experiment with
using a hash set as suggested by a comment.
Bug: skia:10877
Change-Id: Iae01ed16d7b4c7cda343d37ab8fd6147ae6c65e7
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/409416
Reviewed-by: Robert Phillips <robertphillips@google.com>
Auto-Submit: Adlai Holler <adlai@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
diff --git a/src/gpu/GrOpsTask.cpp b/src/gpu/GrOpsTask.cpp
index 1cb5ff5..a387269 100644
--- a/src/gpu/GrOpsTask.cpp
+++ b/src/gpu/GrOpsTask.cpp
@@ -886,15 +886,22 @@
bool GrOpsTask::onIsUsed(GrSurfaceProxy* proxyToCheck) const {
bool used = false;
-
- auto visit = [ proxyToCheck, &used ] (GrSurfaceProxy* p, GrMipmapped) {
- if (p == proxyToCheck) {
+ for (GrSurfaceProxy* proxy : fSampledProxies) {
+ if (proxy == proxyToCheck) {
used = true;
+ break;
+ }
+ }
+#ifdef SK_DEBUG
+ bool usedSlow = false;
+ auto visit = [ proxyToCheck, &usedSlow ] (GrSurfaceProxy* p, GrMipmapped) {
+ if (p == proxyToCheck) {
+ usedSlow = true;
}
};
- for (const OpChain& recordedOp : fOpChains) {
- recordedOp.visitProxies(visit);
- }
+ this->visitProxies_debugOnly(visit);
+ SkASSERT(used == usedSlow);
+#endif
return used;
}
@@ -939,6 +946,7 @@
GrResourceAllocator::ActualUse::kYes
SkDEBUGCODE(, this->target(0) == p));
};
+ // TODO: visitProxies is expensive. Can we do this with fSampledProxies instead?
for (const OpChain& recordedOp : fOpChains) {
recordedOp.visitProxies(gather);