zink: force batch flush if batches are using more than 1/10 total system memory
authorMike Blumenkrantz <michael.blumenkrantz@gmail.com>
Mon, 28 Sep 2020 14:51:57 +0000 (10:51 -0400)
committerMarge Bot <eric+marge@anholt.net>
Mon, 1 Mar 2021 19:36:26 +0000 (19:36 +0000)
this is only tracking memory used by resources referenced in the batch, but it
can be adjusted a bit if we see that we're flushing too often

fixes spec@!opengl 1.1@streaming-texture-leak hogging all system memory and ooming

Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/9274>

src/gallium/drivers/zink/zink_draw.c

index 534314f..497e26d 100644 (file)
@@ -670,6 +670,11 @@ zink_draw_vbo(struct pipe_context *pctx,
    VkDeviceSize counter_buffer_offsets[PIPE_MAX_SO_OUTPUTS] = {};
    bool need_index_buffer_unref = false;
 
+   /* flush anytime our total batch memory usage is potentially >= 1/10 of total gpu memory
+    * this should also eventually trigger a stall if the app is going nuts with gpu memory
+    */
+   if (zink_curr_batch(ctx)->resource_size >= screen->total_mem / 10 / ZINK_NUM_BATCHES)
+      ctx->base.flush(&ctx->base, NULL, 0);
 
    if (dinfo->primitive_restart && !restart_supported(dinfo->mode)) {
        util_draw_vbo_without_prim_restart(pctx, dinfo, dindirect, &draws[0]);
@@ -964,6 +969,13 @@ zink_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info)
    struct zink_context *ctx = zink_context(pctx);
    struct zink_screen *screen = zink_screen(pctx->screen);
    struct zink_batch *batch = &ctx->compute_batch;
+
+   /* flush anytime our total batch memory usage is potentially >= 1/10 of total gpu memory
+    * this should also eventually trigger a stall if the app is going nuts with gpu memory
+    */
+   if (batch->resource_size >= screen->total_mem / 10 / ZINK_NUM_BATCHES)
+      zink_flush_compute(ctx);
+
    struct zink_compute_program *comp_program = get_compute_program(ctx);
    if (!comp_program)
       return;