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

Alexandros Frantzis alexandros.frantzis at collabora.com
Wed Apr 11 13:39:11 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 edbc9ea..8e4c121 100644
--- a/src/vrend_blitter.c
+++ b/src/vrend_blitter.c
@@ -540,6 +540,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,
@@ -561,6 +576,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);
@@ -615,8 +632,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 32a4961..1ab64d5 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.15.1



More information about the virglrenderer-devel mailing list