[virglrenderer-devel] [PATCH v2 2/7] vrend: Use source swizzle when blitting with GL

Alexandros Frantzis alexandros.frantzis at collabora.com
Mon Apr 23 15:45:57 UTC 2018


Use the source format swizzle information to set the
GL_TEXTURE_SWIZZLE_* parameters for the GL blit operation. This also
removes the need for the emulated alpha special case, since when using
emulated alpha the source format already has proper swizzle information.

Signed-off-by: Alexandros Frantzis <alexandros.frantzis at collabora.com>
---
 src/vrend_blitter.c  | 30 ++++++++++++++++++++++++++++--
 src/vrend_renderer.c |  6 ++++++
 src/vrend_renderer.h |  1 +
 3 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/src/vrend_blitter.c b/src/vrend_blitter.c
index 2acad14..a70da14 100644
--- a/src/vrend_blitter.c
+++ b/src/vrend_blitter.c
@@ -614,6 +614,21 @@ static void set_dsa_write_depth_keep_stencil(void)
    glDepthMask(GL_TRUE);
 }
 
+static inline GLenum to_gl_swizzle(int swizzle)
+{
+   switch (swizzle) {
+   case PIPE_SWIZZLE_RED: return GL_RED;
+   case PIPE_SWIZZLE_GREEN: return GL_GREEN;
+   case PIPE_SWIZZLE_BLUE: return GL_BLUE;
+   case PIPE_SWIZZLE_ALPHA: return GL_ALPHA;
+   case PIPE_SWIZZLE_ZERO: return GL_ZERO;
+   case PIPE_SWIZZLE_ONE: return GL_ONE;
+   default:
+      assert(0);
+      return 0;
+   }
+}
+
 /* implement blitting using OpenGL. */
 void vrend_renderer_blit_gl(struct vrend_context *ctx,
                             struct vrend_resource *src_res,
@@ -635,6 +650,8 @@ void vrend_renderer_blit_gl(struct vrend_context *ctx,
       util_format_description(src_res->base.format);
    const struct util_format_description *dst_desc =
       util_format_description(dst_res->base.format);
+   const struct vrend_format_table *src_entry =
+      vrend_get_format_table_entry(info->src.format);
 
    has_depth = util_format_has_depth(src_desc) &&
       util_format_has_depth(dst_desc);
@@ -691,8 +708,17 @@ void vrend_renderer_blit_gl(struct vrend_context *ctx,
 
    glBindTexture(src_res->target, src_res->id);
 
-   if (vrend_format_is_emulated_alpha(info->src.format))
-      glTexParameteri(src_res->target, GL_TEXTURE_SWIZZLE_A, GL_RED);
+   if (src_entry->flags & VREND_BIND_NEED_SWIZZLE) {
+      glTexParameteri(src_res->target, GL_TEXTURE_SWIZZLE_R,
+                      to_gl_swizzle(src_entry->swizzle[0]));
+      glTexParameteri(src_res->target, GL_TEXTURE_SWIZZLE_G,
+                      to_gl_swizzle(src_entry->swizzle[1]));
+      glTexParameteri(src_res->target, GL_TEXTURE_SWIZZLE_B,
+                      to_gl_swizzle(src_entry->swizzle[2]));
+      glTexParameteri(src_res->target, GL_TEXTURE_SWIZZLE_A,
+                      to_gl_swizzle(src_entry->swizzle[3]));
+   }
+
 
    glTexParameteri(src_res->target, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
    glTexParameteri(src_res->target, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 2fa0f2a..5c16afe 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -673,6 +673,12 @@ vrend_insert_format_swizzle(int override_format, struct vrend_format_table *entr
       tex_conv_table[override_format].swizzle[i] = swizzle[i];
 }
 
+const struct vrend_format_table *
+vrend_get_format_table_entry(enum virgl_formats format)
+{
+   return &tex_conv_table[format];
+}
+
 static bool vrend_is_timer_query(GLenum gltype)
 {
    return gltype == GL_TIMESTAMP ||
diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h
index 7e83c20..0a139c7 100644
--- a/src/vrend_renderer.h
+++ b/src/vrend_renderer.h
@@ -105,6 +105,7 @@ int vrend_renderer_init(struct vrend_if_cbs *cbs, uint32_t flags);
 
 void vrend_insert_format(struct vrend_format_table *entry, uint32_t bindings);
 void vrend_insert_format_swizzle(int override_format, struct vrend_format_table *entry, uint32_t bindings, uint8_t swizzle[4]);
+const struct vrend_format_table *vrend_get_format_table_entry(enum virgl_formats format);
 int vrend_create_shader(struct vrend_context *ctx,
                         uint32_t handle,
                         const struct pipe_stream_output_info *stream_output,
-- 
2.17.0



More information about the virglrenderer-devel mailing list