turnip: Skip rather than invalidate LRZ on gl_FragDepth writes.
authorEmma Anholt <emma@anholt.net>
Tue, 13 Sep 2022 23:16:30 +0000 (16:16 -0700)
committerMarge Bot <emma+marge@anholt.net>
Thu, 15 Sep 2022 21:45:05 +0000 (21:45 +0000)
As long as the direction is still compatible, if we skip the LRZ use and
updates for this draw, then we can keep using LRZ later in the scene, as
whatever gl_FragDepth will get written by the shader later will still have
to move the depth in the right direction.

Similarly, the no_earlyz flag that contributes to DISABLE_LRZ just wants
to make sure we don't kill fragments before dispatch, not change what Z
eventually lands.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/18606>

src/freedreno/vulkan/tu_lrz.c

index be487a4..514c428 100644 (file)
@@ -702,12 +702,18 @@ tu6_calculate_lrz_state(struct tu_cmd_buffer *cmd,
    bool disable_lrz = false;
    bool temporary_disable_lrz = false;
 
-   /* What happens in FS could affect LRZ, e.g.: writes to gl_FragDepth
-    * or early fragment tests.
+   /* What happens in FS could affect LRZ, e.g.: writes to gl_FragDepth or early
+    * fragment tests.  We have to skip LRZ testing and updating, but as long as
+    * the depth direction stayed the same we can continue with LRZ testing later.
     */
    if (pipeline->lrz.force_disable_mask & TU_LRZ_FORCE_DISABLE_LRZ) {
-      perf_debug(cmd->device, "Invalidating LRZ due to FS");
-      disable_lrz = true;
+      if (cmd->state.lrz.prev_direction != TU_LRZ_UNKNOWN || !cmd->state.lrz.gpu_dir_tracking) {
+         perf_debug(cmd->device, "Skipping LRZ due to FS");
+         temporary_disable_lrz = true;
+      } else {
+         perf_debug(cmd->device, "Disabling LRZ due to FS (TODO: fix for gpu-direction-tracking case");
+         disable_lrz = true;
+      }
    }
 
    /* If Z is not written - it doesn't affect LRZ buffer state.