radeonsi: clarify the conditions when FLUSH_AND_INV_DB is needed
authorPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Wed, 18 Mar 2020 20:57:31 +0000 (21:57 +0100)
committerPierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Tue, 24 Mar 2020 07:05:12 +0000 (08:05 +0100)
FLUSH_AND_INV_DB should be done when we're changing surface state
registers of a bound depth target.

When depth_clear_value changes, si_state will modify
S_028038_ZRANGE_PRECISION so we need to flush the DB caches.

Verified with the captures from bugs cited below.

Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/1283
Closes: https://gitlab.freedesktop.org/mesa/mesa/issues/1330
Reviewed-by: Marek Olšák <marek.olsak@amd.com>
Tested-by: Marge Bot <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4263>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4263>

src/gallium/drivers/radeonsi/si_clear.c
src/gallium/drivers/radeonsi/si_debug_options.h
src/util/00-mesa-defaults.conf

index ef48b94a46dbc72246768ea00c13d54306e65ed5..2af778b41ad423ac8ff1937652b00bd21abc6242 100644 (file)
@@ -575,6 +575,7 @@ static void si_clear(struct pipe_context *ctx, unsigned buffers,
        struct pipe_surface *zsbuf = fb->zsbuf;
        struct si_texture *zstex =
                zsbuf ? (struct si_texture*)zsbuf->texture : NULL;
+       bool needs_db_flush = false;
 
        if (buffers & PIPE_CLEAR_COLOR) {
                si_do_fast_color_clear(sctx, &buffers, color);
@@ -610,6 +611,11 @@ static void si_clear(struct pipe_context *ctx, unsigned buffers,
                        }
 
                        if (zstex->depth_clear_value != (float)depth) {
+                               if ((zstex->depth_clear_value != 0) != (depth != 0)) {
+                                       /* ZRANGE_PRECISION register of a bound surface will change so we
+                                        * must flush the DB caches. */
+                                       needs_db_flush = true;
+                               }
                                /* Update DB_DEPTH_CLEAR. */
                                zstex->depth_clear_value = depth;
                                sctx->framebuffer.dirty_zsbuf = true;
@@ -641,19 +647,7 @@ static void si_clear(struct pipe_context *ctx, unsigned buffers,
                        si_mark_atom_dirty(sctx, &sctx->atoms.s.db_render_state);
                }
 
-               /* TODO: Find out what's wrong here. Fast depth clear leads to
-                * corruption in ARK: Survival Evolved, but that may just be
-                * a coincidence and the root cause is elsewhere.
-                *
-                * The corruption can be fixed by putting the DB flush before
-                * or after the depth clear. (surprisingly)
-                *
-                * https://bugs.freedesktop.org/show_bug.cgi?id=102955 (apitrace)
-                *
-                * This hack decreases back-to-back ClearDepth performance.
-                */
-               if ((sctx->db_depth_clear || sctx->db_stencil_clear) &&
-                   sctx->screen->options.clear_db_cache_before_clear)
+               if (needs_db_flush)
                        sctx->flags |= SI_CONTEXT_FLUSH_AND_INV_DB;
        }
 
index 9a0dd0c9f78bb9c522564c972e3bb58c9a4f06ae..b0e8db8646a982299bb6fa8348e4cd2ae76c884b 100644 (file)
@@ -1,4 +1,3 @@
-OPT_BOOL(clear_db_cache_before_clear, false, "Clear DB cache before fast depth clear")
 OPT_BOOL(aux_debug, false, "Generate ddebug_dumps for the auxiliary context")
 OPT_BOOL(sync_compile, false, "Always compile synchronously (will cause stalls)")
 OPT_BOOL(dump_shader_binary, false, "Dump shader binary as part of ddebug_dumps")
index 3b14fe7aec4fa352956923eefa2e2af5029d2dab..72c415abef8bddfd08717f1142b0c9b1f1a0f20c 100644 (file)
@@ -547,9 +547,6 @@ TODO: document the other workarounds.
         </application>
     </device>
     <device driver="radeonsi">
-        <application name="ARK: Survival Evolved (and unintentionally the UE4 demo template)" executable="ShooterGame">
-            <option name="radeonsi_clear_db_cache_before_clear" value="true" />
-        </application>
         <application name="American Truck Simulator" executable="amtrucks">
             <option name="radeonsi_zerovram" value="true" />
         </application>