From cca3132795eb7c7a27fe7929d7fd71785b083414 Mon Sep 17 00:00:00 2001 From: Lepton Wu Date: Fri, 12 Jun 2020 17:12:55 -0700 Subject: [PATCH] vrend: Try to use original context for transfer I don't see the point why we want to use context0 to do transfer. If we always use original context to do transfer, then we can avoid sync between contexts for mobile GPU. Signed-off-by: Lepton Wu Reviewed-by: Gert Wollny --- src/virglrenderer.c | 2 -- src/vrend_decode.c | 1 - src/vrend_iov.h | 1 - src/vrend_renderer.c | 37 +++++++++++-------------------------- 4 files changed, 11 insertions(+), 30 deletions(-) diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 1785a02..dbbf981 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -187,7 +187,6 @@ int virgl_renderer_transfer_write_iov(uint32_t handle, transfer_info.offset = offset; transfer_info.iovec = iovec; transfer_info.iovec_cnt = iovec_cnt; - transfer_info.context0 = true; transfer_info.synchronized = false; if (ctx_id) { @@ -226,7 +225,6 @@ int virgl_renderer_transfer_read_iov(uint32_t handle, uint32_t ctx_id, transfer_info.offset = offset; transfer_info.iovec = iovec; transfer_info.iovec_cnt = iovec_cnt; - transfer_info.context0 = true; transfer_info.synchronized = false; if (ctx_id) { diff --git a/src/vrend_decode.c b/src/vrend_decode.c index 406ffb9..031d5cd 100644 --- a/src/vrend_decode.c +++ b/src/vrend_decode.c @@ -1384,7 +1384,6 @@ static int vrend_decode_transfer3d(struct vrend_decode_ctx *ctx, int length) vrend_decode_transfer_common(ctx, &dst_handle, &info); info.offset = get_buf_entry(ctx, VIRGL_TRANSFER3D_DATA_OFFSET); int transfer_mode = get_buf_entry(ctx, VIRGL_TRANSFER3D_DIRECTION); - info.context0 = false; if (transfer_mode != VIRGL_TRANSFER_TO_HOST && transfer_mode != VIRGL_TRANSFER_FROM_HOST) diff --git a/src/vrend_iov.h b/src/vrend_iov.h index 461785d..c3627f3 100644 --- a/src/vrend_iov.h +++ b/src/vrend_iov.h @@ -44,7 +44,6 @@ struct vrend_transfer_info { unsigned int iovec_cnt; const struct iovec *iovec; uint64_t offset; - bool context0; struct pipe_box *box; bool synchronized; }; diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 5bf2b3b..c113eef 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -7406,7 +7406,8 @@ static void do_readpixels(GLint x, GLint y, glReadPixels(x, y, width, height, format, type, data); } -static int vrend_transfer_send_readpixels(struct vrend_resource *res, +static int vrend_transfer_send_readpixels(struct vrend_context *ctx, + struct vrend_resource *res, const struct iovec *iov, int num_iovs, const struct vrend_transfer_info *info) { @@ -7424,7 +7425,10 @@ static int vrend_transfer_send_readpixels(struct vrend_resource *res, int row_stride = info->stride / elsize; GLint old_fbo; - glUseProgram(0); + if (ctx) + vrend_use_program(ctx, 0); + else + glUseProgram(0); enum virgl_formats fmt = vrend_format_replace_emulated(res->base.bind, res->base.format); format = tex_conv_table[fmt].glformat; @@ -7602,7 +7606,8 @@ static int vrend_transfer_send_readonly(struct vrend_resource *res, return -1; } -static int vrend_renderer_transfer_send_iov(struct vrend_resource *res, +static int vrend_renderer_transfer_send_iov(struct vrend_context *ctx, + struct vrend_resource *res, const struct iovec *iov, int num_iovs, const struct vrend_transfer_info *info) { @@ -7639,7 +7644,7 @@ static int vrend_renderer_transfer_send_iov(struct vrend_resource *res, can_readpixels = vrend_format_can_render(res->base.format) || vrend_format_is_ds(res->base.format); if (can_readpixels) - ret = vrend_transfer_send_readpixels(res, iov, num_iovs, info); + ret = vrend_transfer_send_readpixels(ctx, res, iov, num_iovs, info); /* Can hit this on a non-error path as well. */ if (ret) { @@ -7665,16 +7670,7 @@ static int vrend_renderer_transfer_internal(struct vrend_context *ctx, if (!info->box) return EINVAL; - void* fence = NULL; -#ifdef HAVE_EPOXY_EGL_H - // Some platforms require extra synchronization before transferring. - if (transfer_mode == VIRGL_TRANSFER_FROM_HOST) { - if (virgl_egl_need_fence_and_wait_external(egl)) { - vrend_hw_switch_context(ctx, true); - fence = virgl_egl_fence(egl); - } - } -#endif + vrend_hw_switch_context(ctx, true); iov = info->iovec; num_iovs = info->iovec_cnt; @@ -7708,20 +7704,11 @@ static int vrend_renderer_transfer_internal(struct vrend_context *ctx, return EINVAL; } - if (info->context0) { - vrend_renderer_force_ctx_0(); - ctx = NULL; - } - -#ifdef HAVE_EPOXY_EGL_H - virgl_egl_wait_fence(egl, fence); -#endif - switch (transfer_mode) { case VIRGL_TRANSFER_TO_HOST: return vrend_renderer_transfer_write_iov(ctx, res, iov, num_iovs, info); case VIRGL_TRANSFER_FROM_HOST: - return vrend_renderer_transfer_send_iov(res, iov, num_iovs, info); + return vrend_renderer_transfer_send_iov(ctx, res, iov, num_iovs, info); default: assert(0); @@ -8244,7 +8231,6 @@ GLenum translate_gles_emulation_texture_target(GLenum target) } } - static inline void vrend_copy_sub_image(struct vrend_resource* src_res, struct vrend_resource * dst_res, uint32_t src_level, const struct pipe_box *src_box, @@ -10094,7 +10080,6 @@ void vrend_renderer_get_rect(struct pipe_resource *pres, transfer_info.offset = offset; transfer_info.iovec = iov; transfer_info.iovec_cnt = num_iovs; - transfer_info.context0 = true; vrend_renderer_transfer_pipe(pres, &transfer_info, VIRGL_TRANSFER_FROM_HOST);