From 545988c6172e51ea00c87abe966d5ecd03b08e98 Mon Sep 17 00:00:00 2001 From: Qiang Yu Date: Sun, 9 Feb 2020 11:49:52 +0800 Subject: [PATCH] lima: add lima_submit_get Replace all usage of "ctx->submit" in draw code path with lima_submit_get(). This function will create new submit in the following changes. Reviewed-by: Vasily Khoruzhick Signed-off-by: Qiang Yu Part-of: --- src/gallium/drivers/lima/lima_context.c | 3 ++- src/gallium/drivers/lima/lima_draw.c | 24 +++++++++++++++--------- src/gallium/drivers/lima/lima_submit.c | 10 ++++++++++ src/gallium/drivers/lima/lima_submit.h | 2 ++ src/gallium/drivers/lima/lima_texture.c | 7 ++++++- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/src/gallium/drivers/lima/lima_context.c b/src/gallium/drivers/lima/lima_context.c index f30a75c9770..32d75784931 100644 --- a/src/gallium/drivers/lima/lima_context.c +++ b/src/gallium/drivers/lima/lima_context.c @@ -47,11 +47,12 @@ int lima_ctx_num_plb = LIMA_CTX_PLB_DEF_NUM; uint32_t lima_ctx_buff_va(struct lima_context *ctx, enum lima_ctx_buff buff) { + struct lima_submit *submit = lima_submit_get(ctx); struct lima_ctx_buff_state *cbs = ctx->buffer_state + buff; struct lima_resource *res = lima_resource(cbs->res); int pipe = buff < lima_ctx_buff_num_gp ? LIMA_PIPE_GP : LIMA_PIPE_PP; - lima_submit_add_bo(ctx->submit, pipe, res->bo, LIMA_SUBMIT_BO_READ); + lima_submit_add_bo(submit, pipe, res->bo, LIMA_SUBMIT_BO_READ); return res->bo->va + cbs->offset; } diff --git a/src/gallium/drivers/lima/lima_draw.c b/src/gallium/drivers/lima/lima_draw.c index 73ae5b68086..194da4c0856 100644 --- a/src/gallium/drivers/lima/lima_draw.c +++ b/src/gallium/drivers/lima/lima_draw.c @@ -61,20 +61,21 @@ lima_is_scissor_zero(struct lima_context *ctx) static void lima_update_submit_wb(struct lima_context *ctx, unsigned buffers) { + struct lima_submit *submit = lima_submit_get(ctx); struct lima_context_framebuffer *fb = &ctx->framebuffer; /* add to submit when the buffer is dirty and resolve is clear (not added before) */ if (fb->base.nr_cbufs && (buffers & PIPE_CLEAR_COLOR0) && !(ctx->resolve & PIPE_CLEAR_COLOR0)) { struct lima_resource *res = lima_resource(fb->base.cbufs[0]->texture); - lima_submit_add_bo(ctx->submit, LIMA_PIPE_PP, res->bo, LIMA_SUBMIT_BO_WRITE); + lima_submit_add_bo(submit, LIMA_PIPE_PP, res->bo, LIMA_SUBMIT_BO_WRITE); } /* add to submit when the buffer is dirty and resolve is clear (not added before) */ if (fb->base.zsbuf && (buffers & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL)) && !(ctx->resolve & (PIPE_CLEAR_DEPTH | PIPE_CLEAR_STENCIL))) { struct lima_resource *res = lima_resource(fb->base.zsbuf->texture); - lima_submit_add_bo(ctx->submit, LIMA_PIPE_PP, res->bo, LIMA_SUBMIT_BO_WRITE); + lima_submit_add_bo(submit, LIMA_PIPE_PP, res->bo, LIMA_SUBMIT_BO_WRITE); } ctx->resolve |= buffers; @@ -742,6 +743,7 @@ lima_pack_render_state(struct lima_context *ctx, const struct pipe_draw_info *in static void lima_update_gp_attribute_info(struct lima_context *ctx, const struct pipe_draw_info *info) { + struct lima_submit *submit = lima_submit_get(ctx); struct lima_vertex_element_state *ve = ctx->vertex_elements; struct lima_context_vertex_buffer *vb = &ctx->vertex_buffers; @@ -759,7 +761,7 @@ lima_update_gp_attribute_info(struct lima_context *ctx, const struct pipe_draw_i struct pipe_vertex_buffer *pvb = vb->vb + pve->vertex_buffer_index; struct lima_resource *res = lima_resource(pvb->buffer.resource); - lima_submit_add_bo(ctx->submit, LIMA_PIPE_GP, res->bo, LIMA_SUBMIT_BO_READ); + lima_submit_add_bo(submit, LIMA_PIPE_GP, res->bo, LIMA_SUBMIT_BO_READ); unsigned start = info->index_size ? (ctx->min_index + info->index_bias) : info->start; attribute[n++] = res->bo->va + pvb->buffer_offset + pve->src_offset @@ -837,6 +839,7 @@ lima_update_pp_uniform(struct lima_context *ctx) static void lima_update_varying(struct lima_context *ctx, const struct pipe_draw_info *info) { + struct lima_submit *submit = lima_submit_get(ctx); struct lima_screen *screen = lima_screen(ctx->base.screen); struct lima_vs_shader_state *vs = ctx->vs; uint32_t gp_output_size; @@ -888,8 +891,8 @@ lima_update_varying(struct lima_context *ctx, const struct pipe_draw_info *info) */ ctx->gp_output = lima_bo_create(screen, gp_output_size, 0); assert(ctx->gp_output); - lima_submit_add_bo(ctx->submit, LIMA_PIPE_GP, ctx->gp_output, LIMA_SUBMIT_BO_WRITE); - lima_submit_add_bo(ctx->submit, LIMA_PIPE_PP, ctx->gp_output, LIMA_SUBMIT_BO_READ); + lima_submit_add_bo(submit, LIMA_PIPE_GP, ctx->gp_output, LIMA_SUBMIT_BO_WRITE); + lima_submit_add_bo(submit, LIMA_PIPE_PP, ctx->gp_output, LIMA_SUBMIT_BO_READ); for (int i = 0; i < vs->num_outputs; i++) { struct lima_varying_info *v = vs->varying + i; @@ -977,6 +980,7 @@ lima_draw_vbo_indexed(struct pipe_context *pctx, const struct pipe_draw_info *info) { struct lima_context *ctx = lima_context(pctx); + struct lima_submit *submit = lima_submit_get(ctx); struct pipe_resource *indexbuf = NULL; /* Mali Utgard GPU always need min/max index info for index draw, @@ -997,8 +1001,8 @@ lima_draw_vbo_indexed(struct pipe_context *pctx, ctx->index_offset = 0; } - lima_submit_add_bo(ctx->submit, LIMA_PIPE_GP, ctx->index_res->bo, LIMA_SUBMIT_BO_READ); - lima_submit_add_bo(ctx->submit, LIMA_PIPE_PP, ctx->index_res->bo, LIMA_SUBMIT_BO_READ); + lima_submit_add_bo(submit, LIMA_PIPE_GP, ctx->index_res->bo, LIMA_SUBMIT_BO_READ); + lima_submit_add_bo(submit, LIMA_PIPE_PP, ctx->index_res->bo, LIMA_SUBMIT_BO_READ); lima_draw_vbo_update(pctx, info); if (indexbuf) @@ -1052,6 +1056,8 @@ lima_draw_vbo(struct pipe_context *pctx, if (!lima_update_vs_state(ctx) || !lima_update_fs_state(ctx)) return; + struct lima_submit *submit = lima_submit_get(ctx); + lima_dump_command_stream_print( ctx->vs->bo->map, ctx->vs->shader_size, false, "add vs at va %x\n", ctx->vs->bo->va); @@ -1060,8 +1066,8 @@ lima_draw_vbo(struct pipe_context *pctx, ctx->fs->bo->map, ctx->fs->shader_size, false, "add fs at va %x\n", ctx->fs->bo->va); - lima_submit_add_bo(ctx->submit, LIMA_PIPE_GP, ctx->vs->bo, LIMA_SUBMIT_BO_READ); - lima_submit_add_bo(ctx->submit, LIMA_PIPE_PP, ctx->fs->bo, LIMA_SUBMIT_BO_READ); + lima_submit_add_bo(submit, LIMA_PIPE_GP, ctx->vs->bo, LIMA_SUBMIT_BO_READ); + lima_submit_add_bo(submit, LIMA_PIPE_PP, ctx->fs->bo, LIMA_SUBMIT_BO_READ); if (info->index_size) lima_draw_vbo_indexed(pctx, info); diff --git a/src/gallium/drivers/lima/lima_submit.c b/src/gallium/drivers/lima/lima_submit.c index be792e86413..3c1ec3234fe 100644 --- a/src/gallium/drivers/lima/lima_submit.c +++ b/src/gallium/drivers/lima/lima_submit.c @@ -83,6 +83,16 @@ lima_submit_free(struct lima_submit *submit) } +/* + * Note: this function can only be called in draw code path, + * must not exist in flush code path. + */ +struct lima_submit * +lima_submit_get(struct lima_context *ctx) +{ + return ctx->submit; +} + bool lima_submit_add_bo(struct lima_submit *submit, int pipe, struct lima_bo *bo, uint32_t flags) { diff --git a/src/gallium/drivers/lima/lima_submit.h b/src/gallium/drivers/lima/lima_submit.h index 47203107120..b538f4c8be7 100644 --- a/src/gallium/drivers/lima/lima_submit.h +++ b/src/gallium/drivers/lima/lima_submit.h @@ -31,6 +31,8 @@ struct lima_context; struct lima_submit; struct lima_bo; +struct lima_submit *lima_submit_get(struct lima_context *ctx); + bool lima_submit_add_bo(struct lima_submit *submit, int pipe, struct lima_bo *bo, uint32_t flags); bool lima_submit_has_bo(struct lima_submit *submit, struct lima_bo *bo, bool all); diff --git a/src/gallium/drivers/lima/lima_texture.c b/src/gallium/drivers/lima/lima_texture.c index 6a8fa128582..4d925427b52 100644 --- a/src/gallium/drivers/lima/lima_texture.c +++ b/src/gallium/drivers/lima/lima_texture.c @@ -63,6 +63,10 @@ lima_texture_desc_set_va(lima_tex_desc *desc, desc->va[va_idx + 1] |= va >> (32 - va_bit_idx); } +/* + * Note: this function is used by both draw and flush code path, + * make sure no lima_submit_get() is called inside this. + */ void lima_texture_desc_set_res(struct lima_context *ctx, lima_tex_desc *desc, struct pipe_resource *prsc, @@ -253,6 +257,7 @@ lima_calc_tex_desc_size(struct lima_sampler_view *texture) void lima_update_textures(struct lima_context *ctx) { + struct lima_submit *submit = lima_submit_get(ctx); struct lima_texture_stateobj *lima_tex = &ctx->tex_stateobj; assert (lima_tex->num_samplers <= 16); @@ -265,7 +270,7 @@ lima_update_textures(struct lima_context *ctx) for (int i = 0; i < lima_tex->num_samplers; i++) { struct lima_sampler_view *texture = lima_sampler_view(lima_tex->textures[i]); struct lima_resource *rsc = lima_resource(texture->base.texture); - lima_submit_add_bo(ctx->submit, LIMA_PIPE_PP, rsc->bo, LIMA_SUBMIT_BO_READ); + lima_submit_add_bo(submit, LIMA_PIPE_PP, rsc->bo, LIMA_SUBMIT_BO_READ); } /* do not regenerate texture desc if no change */ -- 2.30.2