radeonsi: fix memory exhaustion issue with DCC statistics gathering with DRI2
authorMarek Olšák <marek.olsak@amd.com>
Mon, 18 Jun 2018 19:53:47 +0000 (15:53 -0400)
committerMarek Olšák <marek.olsak@amd.com>
Fri, 29 Jun 2018 02:27:25 +0000 (22:27 -0400)
Cc: 18.1 <mesa-stable@lists.freedesktop.org>
src/gallium/drivers/radeonsi/si_blit.c

index 72adc21..0fd69f3 100644 (file)
@@ -1332,9 +1332,33 @@ static void si_flush_resource(struct pipe_context *ctx,
        }
 
        /* Always do the analysis even if DCC is disabled at the moment. */
-       if (tex->dcc_gather_statistics && tex->separate_dcc_dirty) {
-               tex->separate_dcc_dirty = false;
-               vi_separate_dcc_process_and_reset_stats(ctx, tex);
+       if (tex->dcc_gather_statistics) {
+               bool separate_dcc_dirty = tex->separate_dcc_dirty;
+
+               /* If the color buffer hasn't been unbound and fast clear hasn't
+                * been used, separate_dcc_dirty is false, but there may have been
+                * new rendering. Check if the color buffer is bound and assume
+                * it's dirty.
+                *
+                * Note that DRI2 never unbinds window colorbuffers, which means
+                * the DCC pipeline statistics query would never be re-set and would
+                * keep adding new results until all free memory is exhausted if we
+                * didn't do this.
+                */
+               if (!separate_dcc_dirty) {
+                       for (unsigned i = 0; i < sctx->framebuffer.state.nr_cbufs; i++) {
+                               if (sctx->framebuffer.state.cbufs[i] &&
+                                   sctx->framebuffer.state.cbufs[i]->texture == res) {
+                                       separate_dcc_dirty = true;
+                                       break;
+                               }
+                       }
+               }
+
+               if (separate_dcc_dirty) {
+                       tex->separate_dcc_dirty = false;
+                       vi_separate_dcc_process_and_reset_stats(ctx, tex);
+               }
        }
 }