Add a driver workaround for Adreno 620, 640 GL reordering

This will be followed up by a CL that actually flips the flag
back for these GPUs under Vulkan. For reasons that are
entirely wacky, flipping the flag AND landing this change in
one CL causes the segfault in the Pixel5 perf job. Makes no
sense.

So we separate this flag into its own CL to see what happens.

Bug: skia:10877
Change-Id: Ia7c91b52f1d9c7e0817454a1af2de69706ed8c34
Cq-Include-Trybots: luci.skia.skia.primary:Perf-Android-Clang-Pixel5-GPU-Adreno620-arm64-Release-All-Android
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/403576
Reviewed-by: Robert Phillips <robertphillips@google.com>
Commit-Queue: Adlai Holler <adlai@google.com>
diff --git a/src/gpu/GrCaps.cpp b/src/gpu/GrCaps.cpp
index 291a2d4..3b3e56d 100644
--- a/src/gpu/GrCaps.cpp
+++ b/src/gpu/GrCaps.cpp
@@ -81,6 +81,7 @@
     fAvoidWritePixelsFastPath = false;
     fRequiresManualFBBarrierAfterTessellatedStencilDraw = false;
     fNativeDrawIndexedIndirectIsBroken = false;
+    fAvoidReorderingRenderTasks = false;
 
     fPreferVRAMUseOverFlushes = true;
 
@@ -239,6 +240,7 @@
                        fRequiresManualFBBarrierAfterTessellatedStencilDraw);
     writer->appendBool("Native draw indexed indirect is broken [workaround]",
                        fNativeDrawIndexedIndirectIsBroken);
+    writer->appendBool("Avoid DAG reordering [workaround]", fAvoidReorderingRenderTasks);
 
     if (this->advancedBlendEquationSupport()) {
         writer->appendHexU32("Advanced Blend Equation Disable Flags", fAdvBlendEqDisableFlags);
diff --git a/src/gpu/GrCaps.h b/src/gpu/GrCaps.h
index d5d1c5d..33bbdf2 100644
--- a/src/gpu/GrCaps.h
+++ b/src/gpu/GrCaps.h
@@ -475,6 +475,11 @@
 
     bool supportsDynamicMSAA(const GrRenderTargetProxy*) const;
 
+    // skbug.com/11935. Task reordering is disabled for some GPUs on GL due to driver bugs.
+    bool avoidReorderingRenderTasks() const {
+        return fAvoidReorderingRenderTasks;
+    }
+
 #if GR_TEST_UTILS
     struct TestFormatColorTypeCombination {
         GrColorType fColorType;
@@ -536,6 +541,7 @@
     bool fAvoidWritePixelsFastPath                   : 1;
     bool fRequiresManualFBBarrierAfterTessellatedStencilDraw : 1;
     bool fNativeDrawIndexedIndirectIsBroken          : 1;
+    bool fAvoidReorderingRenderTasks                 : 1;
 
     // ANGLE performance workaround
     bool fPreferVRAMUseOverFlushes                   : 1;
diff --git a/src/gpu/GrRecordingContext.cpp b/src/gpu/GrRecordingContext.cpp
index 052df2b..501f01e 100644
--- a/src/gpu/GrRecordingContext.cpp
+++ b/src/gpu/GrRecordingContext.cpp
@@ -72,7 +72,9 @@
     }
 
     bool reduceOpsTaskSplitting = false;
-    if (GrContextOptions::Enable::kYes == this->options().fReduceOpsTaskSplitting) {
+    if (this->caps()->avoidReorderingRenderTasks()) {
+        reduceOpsTaskSplitting = false;
+    } else if (GrContextOptions::Enable::kYes == this->options().fReduceOpsTaskSplitting) {
         reduceOpsTaskSplitting = true;
     } else if (GrContextOptions::Enable::kNo == this->options().fReduceOpsTaskSplitting) {
         reduceOpsTaskSplitting = false;
diff --git a/src/gpu/gl/GrGLCaps.cpp b/src/gpu/gl/GrGLCaps.cpp
index 8975240..eab35c6 100644
--- a/src/gpu/gl/GrGLCaps.cpp
+++ b/src/gpu/gl/GrGLCaps.cpp
@@ -3462,7 +3462,7 @@
                                                  const GrGLInterface* glInterface,
                                                  GrShaderCaps* shaderCaps,
                                                  FormatWorkarounds* formatWorkarounds) {
-    // A driver but on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
+    // A driver bug on the nexus 6 causes incorrect dst copies when invalidate is called beforehand.
     // Thus we are disabling this extension for now on Adreno4xx devices.
     if (kAdreno430_GrGLRenderer == ctxInfo.renderer() ||
         kAdreno4xx_other_GrGLRenderer == ctxInfo.renderer() ||
@@ -4100,6 +4100,12 @@
     if (fDisallowTexSubImageForUnormConfigTexturesEverBoundToFBO) {
         fReuseScratchTextures = false;
     }
+
+    // skbug.com/11935. Don't reorder on these GPUs in GL.
+    if (kAdreno620_GrGLRenderer == ctxInfo.renderer() ||
+        kAdreno640_GrGLRenderer == ctxInfo.renderer()) {
+        fAvoidReorderingRenderTasks = true;
+    }
 }
 
 void GrGLCaps::onApplyOptionsOverrides(const GrContextOptions& options) {
diff --git a/src/gpu/gl/GrGLUtil.cpp b/src/gpu/gl/GrGLUtil.cpp
index 65f4779..3edb4d4 100644
--- a/src/gpu/gl/GrGLUtil.cpp
+++ b/src/gpu/gl/GrGLUtil.cpp
@@ -361,6 +361,9 @@
                 if (adrenoNumber == 615) {
                     return kAdreno615_GrGLRenderer;
                 }
+                if (adrenoNumber == 620) {
+                    return kAdreno620_GrGLRenderer;
+                }
                 if (adrenoNumber == 630) {
                     return kAdreno630_GrGLRenderer;
                 }
diff --git a/src/gpu/gl/GrGLUtil.h b/src/gpu/gl/GrGLUtil.h
index 032ef29..fac6336 100644
--- a/src/gpu/gl/GrGLUtil.h
+++ b/src/gpu/gl/GrGLUtil.h
@@ -97,6 +97,7 @@
     kAdreno530_GrGLRenderer,
     kAdreno5xx_other_GrGLRenderer,
     kAdreno615_GrGLRenderer,  // Pixel3a
+    kAdreno620_GrGLRenderer,  // Pixel5
     kAdreno630_GrGLRenderer,  // Pixel3
     kAdreno640_GrGLRenderer,  // Pixel4
     kGoogleSwiftShader_GrGLRenderer,