Mesa (main): zink: split and move maybe_flush_or_stall mechanic
GitLab Mirror
gitlab-mirror at kemper.freedesktop.org
Thu Jul 22 00:31:33 UTC 2021
Module: Mesa
Branch: main
Commit: 49ee703e112aa4579a01f3783ab34a124740a796
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=49ee703e112aa4579a01f3783ab34a124740a796
Author: Mike Blumenkrantz <michael.blumenkrantz at gmail.com>
Date: Tue May 11 18:13:02 2021 -0400
zink: split and move maybe_flush_or_stall mechanic
the batch state counting belongs in the flush call, and draws/computes
should each just check their counts and flush directly
Reviewed-by: Dave Airlie <airlied at redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11965>
---
src/gallium/drivers/zink/zink_context.c | 24 +++++++-----------------
src/gallium/drivers/zink/zink_context.h | 3 ---
src/gallium/drivers/zink/zink_draw.cpp | 12 ++++++++----
3 files changed, 15 insertions(+), 24 deletions(-)
diff --git a/src/gallium/drivers/zink/zink_context.c b/src/gallium/drivers/zink/zink_context.c
index 4bc8c9c23a3..d89f3feb7ea 100644
--- a/src/gallium/drivers/zink/zink_context.c
+++ b/src/gallium/drivers/zink/zink_context.c
@@ -1906,6 +1906,13 @@ flush_batch(struct zink_context *ctx, bool sync)
ctx->pipeline_changed[0] = ctx->pipeline_changed[1] = true;
zink_select_draw_vbo(ctx);
zink_select_launch_grid(ctx);
+
+ if (ctx->resource_size >= zink_screen(ctx->base.screen)->total_video_mem / 2 ||
+ _mesa_hash_table_num_entries(&ctx->batch_states) > 100) {
+ sync_flush(ctx, zink_batch_state(ctx->last_fence));
+ zink_vkfence_wait(zink_screen(ctx->base.screen), ctx->last_fence, PIPE_TIMEOUT_INFINITE);
+ zink_batch_reset_all(ctx);
+ }
}
}
@@ -2590,23 +2597,6 @@ zink_flush(struct pipe_context *pctx,
}
}
-void
-zink_maybe_flush_or_stall(struct zink_context *ctx)
-{
- struct zink_screen *screen = zink_screen(ctx->base.screen);
- /* flush anytime our total batch memory usage is potentially >= 50% of total video memory */
- if (ctx->batch.state->resource_size >= screen->total_video_mem / 2 ||
- /* or if there's >100k draws+computes */
- ctx->batch.state->draw_count + ctx->batch.state->compute_count >= 100000)
- flush_batch(ctx, true);
-
- if (ctx->resource_size >= screen->total_video_mem / 2 || _mesa_hash_table_num_entries(&ctx->batch_states) > 100) {
- sync_flush(ctx, zink_batch_state(ctx->last_fence));
- zink_vkfence_wait(screen, ctx->last_fence, PIPE_TIMEOUT_INFINITE);
- zink_batch_reset_all(ctx);
- }
-}
-
void
zink_fence_wait(struct pipe_context *pctx)
{
diff --git a/src/gallium/drivers/zink/zink_context.h b/src/gallium/drivers/zink/zink_context.h
index 2714899beab..f11c0266613 100644
--- a/src/gallium/drivers/zink/zink_context.h
+++ b/src/gallium/drivers/zink/zink_context.h
@@ -339,9 +339,6 @@ zink_check_batch_completion(struct zink_context *ctx, uint32_t batch_id);
void
zink_flush_queue(struct zink_context *ctx);
-void
-zink_maybe_flush_or_stall(struct zink_context *ctx);
-
bool
zink_resource_access_is_write(VkAccessFlags flags);
diff --git a/src/gallium/drivers/zink/zink_draw.cpp b/src/gallium/drivers/zink/zink_draw.cpp
index 7ae8fee0e6f..3fc58ab9701 100644
--- a/src/gallium/drivers/zink/zink_draw.cpp
+++ b/src/gallium/drivers/zink/zink_draw.cpp
@@ -750,8 +750,10 @@ zink_draw_vbo(struct pipe_context *pctx,
screen->vk.CmdEndTransformFeedbackEXT(batch->state->cmdbuf, 0, ctx->num_so_targets, counter_buffers, counter_buffer_offsets);
}
batch->has_work = true;
- /* check memory usage and flush/stall as needed to avoid oom */
- zink_maybe_flush_or_stall(ctx);
+ /* flush if there's >100k draws */
+ if (unlikely(ctx->batch.state->resource_size >= zink_screen(ctx->base.screen)->total_video_mem / 2 ||
+ ctx->batch.state->draw_count >= 100000))
+ pctx->flush(pctx, NULL, PIPE_FLUSH_ASYNC);
}
template <bool BATCH_CHANGED>
@@ -802,8 +804,10 @@ zink_launch_grid(struct pipe_context *pctx, const struct pipe_grid_info *info)
} else
vkCmdDispatch(batch->state->cmdbuf, info->grid[0], info->grid[1], info->grid[2]);
batch->has_work = true;
- /* check memory usage and flush/stall as needed to avoid oom */
- zink_maybe_flush_or_stall(ctx);
+ /* flush if there's >100k computes */
+ if (unlikely(ctx->batch.state->resource_size >= zink_screen(ctx->base.screen)->total_video_mem / 2 ||
+ ctx->batch.state->compute_count >= 100000))
+ pctx->flush(pctx, NULL, PIPE_FLUSH_ASYNC);
}
template <zink_multidraw HAS_MULTIDRAW, zink_dynamic_state HAS_DYNAMIC_STATE, bool BATCH_CHANGED>
More information about the mesa-commit
mailing list