[virglrenderer-devel] [PATCH 3/4] formats: simplify red-alpha swizzle formats

marcandre.lureau at redhat.com marcandre.lureau at redhat.com
Fri Jun 10 17:25:02 UTC 2016


From: Marc-André Lureau <marcandre.lureau at redhat.com>

Allowing arbitrary texture swizzle seems unnecessary for now, so
simplify to only red-alpha case.

Signed-off-by: Marc-André Lureau <marcandre.lureau at redhat.com>
---
 src/vrend_formats.c  | 11 +++--------
 src/vrend_renderer.c | 23 ++++++++---------------
 src/vrend_renderer.h |  9 ++++-----
 3 files changed, 15 insertions(+), 28 deletions(-)

diff --git a/src/vrend_formats.c b/src/vrend_formats.c
index 976f063..c9200f4 100644
--- a/src/vrend_formats.c
+++ b/src/vrend_formats.c
@@ -260,26 +260,21 @@ static void vrend_add_formats(struct vrend_format_table *table, int num_entries)
     status = glGetError();
     if (status == GL_INVALID_VALUE) {
       struct vrend_format_table *entry = NULL;
-      uint8_t swizzle[4];
-      binding = VREND_BIND_SAMPLER | VREND_BIND_RENDER | VREND_BIND_NEED_SWIZZLE;
+      binding = VREND_BIND_SAMPLER | VREND_BIND_RENDER | VREND_BIND_RED_ALPHA;
 
       switch (table[i].format) {
       case PIPE_FORMAT_A8_UNORM:
         entry = &rg_base_formats[0];
-        swizzle[0] = swizzle[1] = swizzle[2] = PIPE_SWIZZLE_ZERO;
-        swizzle[3] = PIPE_SWIZZLE_RED;
         break;
       case PIPE_FORMAT_A16_UNORM:
         entry = &rg_base_formats[2];
-        swizzle[0] = swizzle[1] = swizzle[2] = PIPE_SWIZZLE_ZERO;
-        swizzle[3] = PIPE_SWIZZLE_RED;
         break;
       default:
         break;
       }
 
       if (entry) {
-        vrend_insert_format_swizzle(table[i].format, entry, binding, swizzle);
+         vrend_insert_format(table[i].format, entry, binding);
       }
       glDeleteTextures(1, &tex_id);
       glDeleteFramebuffers(1, &fb_id);
@@ -310,7 +305,7 @@ static void vrend_add_formats(struct vrend_format_table *table, int num_entries)
 
     glDeleteTextures(1, &tex_id);
     glDeleteFramebuffers(1, &fb_id);
-    vrend_insert_format(&table[i], binding);
+    vrend_insert_format_entry(&table[i], binding);
   }
 }
 
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index cc0f8b8..c3605b3 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -607,21 +607,16 @@ vrend_shader_state_reference(struct vrend_shader_selector **ptr, struct vrend_sh
 }
 
 void
-vrend_insert_format(struct vrend_format_table *entry, uint32_t bindings)
+vrend_insert_format(int format, struct vrend_format_table *entry, uint32_t bindings)
 {
-   tex_conv_table[entry->format] = *entry;
-   tex_conv_table[entry->format].bindings = bindings;
+   tex_conv_table[format] = *entry;
+   tex_conv_table[format].bindings = bindings;
 }
 
 void
-vrend_insert_format_swizzle(int override_format, struct vrend_format_table *entry, uint32_t bindings, uint8_t swizzle[4])
+vrend_insert_format_entry(struct vrend_format_table *entry, uint32_t bindings)
 {
-   int i;
-   tex_conv_table[override_format] = *entry;
-   tex_conv_table[override_format].bindings = bindings;
-   tex_conv_table[override_format].flags = VREND_BIND_NEED_SWIZZLE;
-   for (i = 0; i < 4; i++)
-      tex_conv_table[override_format].swizzle[i] = swizzle[i];
+   vrend_insert_format(entry->format, entry, bindings);
 }
 
 static bool vrend_is_timer_query(GLenum gltype)
@@ -1317,12 +1312,10 @@ int vrend_create_sampler_view(struct vrend_context *ctx,
            view->gl_swizzle_b = GL_ONE;
    }
 
-   if (tex_conv_table[format].flags & VREND_BIND_NEED_SWIZZLE) {
-      view->gl_swizzle_r = to_gl_swizzle(tex_conv_table[format].swizzle[0]);
-      view->gl_swizzle_g = to_gl_swizzle(tex_conv_table[format].swizzle[1]);
-      view->gl_swizzle_b = to_gl_swizzle(tex_conv_table[format].swizzle[2]);
-      view->gl_swizzle_a = to_gl_swizzle(tex_conv_table[format].swizzle[3]);
+   if (tex_conv_table[format].bindings & VREND_BIND_RED_ALPHA) {
+      view->gl_swizzle_a = GL_RED;
    }
+
    ret_handle = vrend_renderer_object_insert(ctx, view, sizeof(*view), handle, VIRGL_OBJECT_SAMPLER_VIEW);
    if (ret_handle == 0) {
       FREE(view);
diff --git a/src/vrend_renderer.h b/src/vrend_renderer.h
index f769695..bc96497 100644
--- a/src/vrend_renderer.h
+++ b/src/vrend_renderer.h
@@ -67,7 +67,7 @@ struct vrend_resource {
 #define VREND_BIND_RENDER (1 << 1)
 #define VREND_BIND_DEPTHSTENCIL (1 << 2)
 
-#define VREND_BIND_NEED_SWIZZLE (1 << 28)
+#define VREND_BIND_RED_ALPHA (1 << 28)
 
 struct vrend_format_table {
    enum virgl_formats format;
@@ -75,8 +75,6 @@ struct vrend_format_table {
    GLenum glformat;
    GLenum gltype;
    uint32_t bindings;
-   int flags;
-   uint8_t swizzle[4];
 };
 
 struct vrend_transfer_info {
@@ -103,8 +101,9 @@ struct vrend_if_cbs {
 
 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]);
+void vrend_insert_format(int format, struct vrend_format_table *entry, uint32_t bindings);
+void vrend_insert_format_entry(struct vrend_format_table *entry, uint32_t bindings);
+
 int vrend_create_shader(struct vrend_context *ctx,
                         uint32_t handle,
                         const struct pipe_stream_output_info *stream_output,
-- 
2.7.4



More information about the virglrenderer-devel mailing list