From 6a9e3b94c6117b023955642268d9d6c5182c8d37 Mon Sep 17 00:00:00 2001 From: Akihiko Odaki Date: Fri, 19 Feb 2021 13:43:42 +0900 Subject: [PATCH] Replace virgl_renderer_resource_get_info virgl_renderer_resource_get_info is used to get texture information for scanout. However, it is also crucial to configure the texture correctly for scanout. Replace it with virgl_renderer_borrow_texture_for_scanout, which "borrows" the texture and modifies its configuration. Signed-off-by: Akihiko Odaki --- src/virglrenderer.c | 8 ++++---- src/virglrenderer.h | 8 ++++---- src/vrend_renderer.c | 46 +++++++++++++++++++++++++++++++++----------- src/vrend_renderer.h | 6 +++--- 4 files changed, 46 insertions(+), 22 deletions(-) diff --git a/src/virglrenderer.c b/src/virglrenderer.c index 29674b3..f3e5af4 100644 --- a/src/virglrenderer.c +++ b/src/virglrenderer.c @@ -453,8 +453,8 @@ void virgl_renderer_ctx_detach_resource(int ctx_id, int res_handle) ctx->detach_resource(ctx, res); } -int virgl_renderer_resource_get_info(int res_handle, - struct virgl_renderer_resource_info *info) +int virgl_renderer_borrow_texture_for_scanout(int res_handle, + struct virgl_renderer_texture_info *info) { TRACE_FUNC(); struct virgl_resource *res = virgl_resource_lookup(res_handle); @@ -464,8 +464,8 @@ int virgl_renderer_resource_get_info(int res_handle, if (!info) return EINVAL; - vrend_renderer_resource_get_info(res->pipe_resource, - (struct vrend_renderer_resource_info *)info); + vrend_renderer_borrow_texture_for_scanout(res->pipe_resource, + (struct vrend_renderer_texture_info *)info); info->handle = res_handle; if (state.winsys_initialized) { diff --git a/src/virglrenderer.h b/src/virglrenderer.h index cd3523a..3b52510 100644 --- a/src/virglrenderer.h +++ b/src/virglrenderer.h @@ -275,9 +275,9 @@ VIRGL_EXPORT void virgl_renderer_ctx_detach_resource(int ctx_id, int res_handle) VIRGL_EXPORT virgl_debug_callback_type virgl_set_debug_callback(virgl_debug_callback_type cb); -/* return information about a resource */ +/* borrow a texture for scanout */ -struct virgl_renderer_resource_info { +struct virgl_renderer_texture_info { uint32_t handle; uint32_t virgl_format; uint32_t width; @@ -289,8 +289,8 @@ struct virgl_renderer_resource_info { int drm_fourcc; }; -VIRGL_EXPORT int virgl_renderer_resource_get_info(int res_handle, - struct virgl_renderer_resource_info *info); +VIRGL_EXPORT int virgl_renderer_borrow_texture_for_scanout(int res_handle, + struct virgl_renderer_texture_info *info); VIRGL_EXPORT void virgl_renderer_cleanup(void *cookie); diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c index 6e4ba85..9eb69ef 100644 --- a/src/vrend_renderer.c +++ b/src/vrend_renderer.c @@ -11236,21 +11236,45 @@ void vrend_context_set_debug_flags(struct vrend_context *ctx, const char *flagst } } -void vrend_renderer_resource_get_info(struct pipe_resource *pres, - struct vrend_renderer_resource_info *info) +void vrend_renderer_borrow_texture_for_scanout(struct pipe_resource *pres, + struct vrend_renderer_texture_info *info) { - struct vrend_resource *res = (struct vrend_resource *)pres; + struct vrend_texture *tex = (struct vrend_texture *)pres; + struct vrend_format_table *tex_conv = &tex_conv_table[tex->base.base.format]; int elsize; - elsize = util_format_get_blocksize(res->base.format); + assert(tex->base.target == GL_TEXTURE_2D); + assert(!util_format_is_depth_or_stencil(tex->base.base.format)); + + elsize = util_format_get_blocksize(tex->base.base.format); + + glBindTexture(GL_TEXTURE_2D, tex->base.id); + + if (tex_conv->flags & VIRGL_TEXTURE_NEED_SWIZZLE) { + for (unsigned i = 0; i < ARRAY_SIZE(tex->cur_swizzle); ++i) { + GLint next_swizzle = to_gl_swizzle(tex_conv->swizzle[i]); + if (tex->cur_swizzle[i] != next_swizzle) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SWIZZLE_R + i, next_swizzle); + tex->cur_swizzle[i] = next_swizzle; + } + } + } + + if (tex->cur_srgb_decode != GL_DECODE_EXT && util_format_is_srgb(tex->base.base.format)) { + if (has_feature(feat_texture_srgb_decode)) { + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_SRGB_DECODE_EXT, + GL_DECODE_EXT); + tex->cur_srgb_decode = GL_DECODE_EXT; + } + } - info->tex_id = res->id; - info->width = res->base.width0; - info->height = res->base.height0; - info->depth = res->base.depth0; - info->format = res->base.format; - info->flags = res->y_0_top ? VIRGL_RESOURCE_Y_0_TOP : 0; - info->stride = util_format_get_nblocksx(res->base.format, u_minify(res->base.width0, 0)) * elsize; + info->tex_id = tex->base.id; + info->width = tex->base.base.width0; + info->height = tex->base.base.height0; + info->depth = tex->base.base.depth0; + info->format = tex->base.base.format; + info->flags = tex->base.y_0_top ? VIRGL_RESOURCE_Y_0_TOP : 0; + info->stride = util_format_get_nblocksx(tex->base.base.format, u_minify(tex->base.base.width0, 0)) * elsize; } void vrend_renderer_get_cap_set(uint32_t cap_set, uint32_t *max_ver, diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h index e561dac..3a1ba91 100644 --- a/src/vrend_renderer.h +++ b/src/vrend_renderer.h @@ -447,7 +447,7 @@ void vrend_renderer_detach_res_ctx(struct vrend_context *ctx, struct vrend_context_tweaks *vrend_get_context_tweaks(struct vrend_context *ctx); -struct vrend_renderer_resource_info { +struct vrend_renderer_texture_info { uint32_t handle; uint32_t format; uint32_t width; @@ -471,8 +471,8 @@ struct vrend_blit_info { bool has_srgb_write_control; }; -void vrend_renderer_resource_get_info(struct pipe_resource *pres, - struct vrend_renderer_resource_info *info); +void vrend_renderer_borrow_texture_for_scanout(struct pipe_resource *pres, + struct vrend_renderer_texture_info *info); void vrend_renderer_get_cap_set(uint32_t cap_set, uint32_t *max_ver, uint32_t *max_size);