Skip to content

Commit

Permalink
Replace virgl_renderer_resource_get_info
Browse files Browse the repository at this point in the history
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 <akihiko.odaki@gmail.com>
  • Loading branch information
akihikodaki committed Apr 3, 2021
1 parent 74cbf23 commit 01fcbb7
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 22 deletions.
8 changes: 4 additions & 4 deletions src/virglrenderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,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);
Expand All @@ -435,8 +435,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) {
Expand Down
8 changes: 4 additions & 4 deletions src/virglrenderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -232,9 +232,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;
Expand All @@ -246,8 +246,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);

Expand Down
47 changes: 36 additions & 11 deletions src/vrend_renderer.c
Original file line number Diff line number Diff line change
Expand Up @@ -10639,21 +10639,46 @@ 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;
const struct vrend_format_table *tex_conv =
vrend_get_format_table_entry_with_emulation(tex->base.base.bind, 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,
Expand Down
6 changes: 3 additions & 3 deletions src/vrend_renderer.h
Original file line number Diff line number Diff line change
Expand Up @@ -430,7 +430,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;
Expand All @@ -441,8 +441,8 @@ struct vrend_renderer_resource_info {
uint32_t stride;
};

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);
Expand Down

0 comments on commit 01fcbb7

Please sign in to comment.