From 660eaa21260a4d67ee16f65b02e9d1a13b7d9759 Mon Sep 17 00:00:00 2001 From: Chia-I Wu Date: Thu, 26 Mar 2020 16:23:20 -0700 Subject: [PATCH] vrend: ctx0 does not need to be a vrend_decode_ctx It can just be a vrend_context. Signed-off-by: Chia-I Wu Reviewed-by: Gurchetan Singh --- src/vrend_decode.c | 21 ++++----------------- src/vrend_renderer.c | 35 +++++++++++++++++++++-------------- src/vrend_renderer.h | 2 +- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/src/vrend_decode.c b/src/vrend_decode.c index 9c20088..39e2954 100644 --- a/src/vrend_decode.c +++ b/src/vrend_decode.c @@ -54,8 +54,6 @@ struct vrend_decode_ctx { struct vrend_context *grctx; }; -static struct vrend_decode_ctx *dec_ctx0; - static inline uint32_t get_buf_entry(struct vrend_decode_ctx *ctx, uint32_t offset) { return ctx->ds->buf[ctx->ds->buf_offset + offset]; @@ -1407,17 +1405,13 @@ struct virgl_context *vrend_renderer_context_create(uint32_t handle, dctx->ds = &dctx->ids; - if (handle == 0) - dec_ctx0 = dctx; - return &dctx->base; } struct vrend_context *vrend_lookup_renderer_ctx(uint32_t ctx_id) { - struct vrend_decode_ctx *dctx = ctx_id ? - (struct vrend_decode_ctx *)virgl_context_lookup(ctx_id) : - dec_ctx0; + struct vrend_decode_ctx *dctx = + (struct vrend_decode_ctx *)virgl_context_lookup(ctx_id); return dctx ? dctx->grctx : NULL; } @@ -1641,14 +1635,7 @@ static void vrend_decode_ctx_init_base(struct vrend_decode_ctx *dctx, ctx->submit_cmd = vrend_decode_ctx_submit_cmd; } -void vrend_decode_reset(bool ctx_0_only) +void vrend_decode_reset(void) { - vrend_hw_switch_context(dec_ctx0->grctx, true); - - if (!ctx_0_only) { - virgl_context_table_reset(); - } else { - vrend_decode_ctx_destroy(&dec_ctx0->base); - dec_ctx0 = NULL; - } + virgl_context_table_reset(); } diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 2de4055..c5ea3ac 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -297,6 +297,8 @@ struct global_renderer_state { struct list_head fence_wait_list; pipe_condvar fence_cond; + struct vrend_context *ctx0; + pipe_thread sync_thread; virgl_gl_context sync_context; @@ -5868,7 +5870,7 @@ int vrend_renderer_init(struct vrend_if_cbs *cbs, uint32_t flags) list_inithead(&vrend_state.waiting_query_list); list_inithead(&vrend_state.active_ctx_list); /* create 0 context */ - vrend_renderer_context_create(0, strlen("HOST"), "HOST"); + vrend_state.ctx0 = vrend_create_context(0, strlen("HOST"), "HOST"); vrend_state.eventfd = -1; if (flags & VREND_USE_THREAD_SYNC) { @@ -5894,9 +5896,11 @@ vrend_renderer_fini(void) } vrend_blitter_fini(); - vrend_decode_reset(false); + + vrend_hw_switch_context(vrend_state.ctx0, true); + vrend_decode_reset(); vrend_object_fini_resource_table(); - vrend_decode_reset(true); + vrend_destroy_context(vrend_state.ctx0); vrend_state.current_ctx = NULL; vrend_state.current_hw_ctx = NULL; @@ -7651,14 +7655,15 @@ int vrend_renderer_transfer_iov(const struct vrend_transfer_info *info, if (!info->box) return EINVAL; - ctx = vrend_lookup_renderer_ctx(info->ctx_id); - if (!ctx) - return EINVAL; - - if (info->ctx_id == 0) + if (info->ctx_id == 0) { + ctx = vrend_state.ctx0; res = vrend_resource_lookup(info->handle, 0); - else + } else { + ctx = vrend_lookup_renderer_ctx(info->ctx_id); + if (!ctx) + return EINVAL; res = vrend_renderer_ctx_res_lookup(ctx, info->handle); + } if (!res) { if (info->ctx_id) @@ -9990,10 +9995,9 @@ void *vrend_renderer_get_cursor_contents(uint32_t res_handle, uint32_t *width, u void vrend_renderer_force_ctx_0(void) { - struct vrend_context *ctx0 = vrend_lookup_renderer_ctx(0); vrend_state.current_ctx = NULL; vrend_state.current_hw_ctx = NULL; - vrend_hw_switch_context(ctx0, true); + vrend_hw_switch_context(vrend_state.ctx0, true); } void vrend_renderer_get_rect(int res_handle, struct iovec *iov, unsigned int num_iovs, @@ -10279,11 +10283,14 @@ void vrend_renderer_reset(void) } vrend_reset_fences(); vrend_blitter_fini(); - vrend_decode_reset(false); + + vrend_hw_switch_context(vrend_state.ctx0, true); + vrend_decode_reset(); vrend_object_fini_resource_table(); - vrend_decode_reset(true); + vrend_destroy_context(vrend_state.ctx0); + vrend_object_init_resource_table(); - vrend_renderer_context_create(0, strlen("HOST"), "HOST"); + vrend_state.ctx0 = vrend_create_context(0, strlen("HOST"), "HOST"); } int vrend_renderer_get_poll_fd(void) diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h index e8a751e..5e2d6fa 100644 --- a/src/vrend_renderer.h +++ b/src/vrend_renderer.h @@ -445,7 +445,7 @@ void vrend_blitter_fini(void); void vrend_renderer_reset(void); int vrend_renderer_get_poll_fd(void); -void vrend_decode_reset(bool ctx_0_only); +void vrend_decode_reset(void); unsigned vrend_context_has_debug_flag(struct vrend_context *ctx, enum virgl_debug_flags flag);