From 11143f2e005ffaa801bdc64fce22204d0e529ff8 Mon Sep 17 00:00:00 2001 From: Gert Wollny Date: Tue, 19 Oct 2021 11:37:31 +0200 Subject: [PATCH] formats: rework the logic for identifying which formats can be read back On OpenGL all textures can be read back using glGetTexture. On GLES we have to be able to bind the texture to an FBO to use glReadPixels, and only a few formats are supported as destination formats. Signed-off-by: Gert Wollny Reviewed-by: John Bates --- src/vrend_formats.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/src/vrend_formats.c b/src/vrend_formats.c index 47ed34ecc..11b3cc4fb 100644 --- a/src/vrend_formats.c +++ b/src/vrend_formats.c @@ -483,6 +483,7 @@ static void vrend_add_formats(struct vrend_format_table *table, int num_entries) entry = &rg_base_formats[0]; swizzle[0] = swizzle[1] = swizzle[2] = PIPE_SWIZZLE_ZERO; swizzle[3] = PIPE_SWIZZLE_RED; + break; case VIRGL_FORMAT_A16_UNORM: entry = &rg_base_formats[2]; @@ -523,14 +524,19 @@ static void vrend_add_formats(struct vrend_format_table *table, int num_entries) status = glCheckFramebufferStatus(GL_FRAMEBUFFER); binding = VIRGL_BIND_SAMPLER_VIEW; - if (status == GL_FRAMEBUFFER_COMPLETE) { + if (status == GL_FRAMEBUFFER_COMPLETE) binding |= is_depth ? VIRGL_BIND_DEPTH_STENCIL : VIRGL_BIND_RENDER_TARGET; - if (is_desktop_gl || - (is_depth && depth_stencil_formats_can_readback(table[i].format)) || - color_format_can_readback(&table[i], gles_ver)) - flags |= VIRGL_TEXTURE_CAN_READBACK; - } + /* On OpenGL all textures can be read back using glGetTexImage, but on GLES + we have to be able to bind textures to framebuffers, and use glReadPixels + to get the data. And apart from a few formats where support is required + (by the GLES version), we have to query the driver to identify additional + formats that are supported as destination formats by glReadPixels. */ + if (is_desktop_gl || + (status == GL_FRAMEBUFFER_COMPLETE && + ((is_depth && depth_stencil_formats_can_readback(table[i].format)) || + color_format_can_readback(&table[i], gles_ver)))) + flags |= VIRGL_TEXTURE_CAN_READBACK; glDeleteTextures(1, &tex_id); glDeleteFramebuffers(1, &fb_id); -- GitLab