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@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11965>
This commit is contained in:
Mike Blumenkrantz 2021-05-11 18:13:02 -04:00 committed by Marge Bot
parent 9823b970fb
commit 49ee703e11
3 changed files with 15 additions and 24 deletions

View File

@ -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)
{

View File

@ -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);

View File

@ -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>