[virglrenderer-devel] [PATCH 1/3] emulate alpha texures as rgba instead of red

Erik Faye-Lund erik.faye-lund at collabora.com
Tue Jul 3 06:04:48 UTC 2018


This is a lot simpler, and has the nice bonus of actually working:

When we need to swizzle the blend-color due to R<->A conversion, we
end up messing up the blend color for blends to other MRT targets
that does *not* swizzle R<->A.

Signed-off-by: Erik Faye-Lund <erik.faye-lund at collabora.com>
---
 src/vrend_formats.c  |  8 ++++----
 src/vrend_renderer.c | 31 ++++++-------------------------
 src/vrend_shader.c   | 16 ----------------
 src/vrend_shader.h   |  1 -
 4 files changed, 10 insertions(+), 46 deletions(-)

diff --git a/src/vrend_formats.c b/src/vrend_formats.c
index eb9f217..91d898c 100644
--- a/src/vrend_formats.c
+++ b/src/vrend_formats.c
@@ -317,14 +317,14 @@ static void vrend_add_formats(struct vrend_format_table *table, int num_entries)
 
       switch (table[i].format) {
       case PIPE_FORMAT_A8_UNORM:
-        entry = &rg_base_formats[0];
+        entry = &base_rgba_formats[0];
         swizzle[0] = swizzle[1] = swizzle[2] = PIPE_SWIZZLE_ZERO;
-        swizzle[3] = PIPE_SWIZZLE_RED;
+        swizzle[3] = PIPE_SWIZZLE_ALPHA;
         break;
       case PIPE_FORMAT_A16_UNORM:
-        entry = &rg_base_formats[2];
+        entry = &base_rgba_formats[12];
         swizzle[0] = swizzle[1] = swizzle[2] = PIPE_SWIZZLE_ZERO;
-        swizzle[3] = PIPE_SWIZZLE_RED;
+        swizzle[3] = PIPE_SWIZZLE_ALPHA;
         break;
       default:
         break;
diff --git a/src/vrend_renderer.c b/src/vrend_renderer.c
index 33e8478..3b3982b 100644
--- a/src/vrend_renderer.c
+++ b/src/vrend_renderer.c
@@ -2266,12 +2266,9 @@ static inline void vrend_fill_shader_key(struct vrend_context *ctx,
    if (vrend_state.use_core_profile == true) {
       int i;
       bool add_alpha_test = true;
-      key->cbufs_are_a8_bitmask = 0;
       for (i = 0; i < ctx->sub->nr_cbufs; i++) {
          if (!ctx->sub->surf[i])
             continue;
-         if (vrend_format_is_emulated_alpha(ctx->sub->surf[i]->format))
-            key->cbufs_are_a8_bitmask |= (1 << i);
          if (util_format_is_pure_integer(ctx->sub->surf[i]->format))
             add_alpha_test = false;
       }
@@ -2682,11 +2679,7 @@ void vrend_clear(struct vrend_context *ctx,
    vrend_use_program(ctx, 0);
 
    if (buffers & PIPE_CLEAR_COLOR) {
-      if (ctx->sub->nr_cbufs && ctx->sub->surf[0] && vrend_format_is_emulated_alpha(ctx->sub->surf[0]->format)) {
-         glClearColor(color->f[3], 0.0, 0.0, 0.0);
-      } else {
-         glClearColor(color->f[0], color->f[1], color->f[2], color->f[3]);
-      }
+      glClearColor(color->f[0], color->f[1], color->f[2], color->f[3]);
 
       /* This function implements Gallium's full clear callback (st->pipe->clear) on the host. This
          callback requires no color component be masked. We must unmask all components before
@@ -3529,10 +3522,10 @@ static inline bool is_dst_blend(int blend_factor)
 
 static inline int conv_a8_blend(int blend_factor)
 {
-   if (blend_factor == PIPE_BLENDFACTOR_DST_ALPHA)
-      return PIPE_BLENDFACTOR_DST_COLOR;
-   if (blend_factor == PIPE_BLENDFACTOR_INV_DST_ALPHA)
-      return PIPE_BLENDFACTOR_INV_DST_COLOR;
+   if (blend_factor == PIPE_BLENDFACTOR_DST_COLOR)
+      return PIPE_BLENDFACTOR_ZERO;
+   if (blend_factor == PIPE_BLENDFACTOR_INV_DST_COLOR)
+      return PIPE_BLENDFACTOR_ONE;
    return blend_factor;
 }
 
@@ -3639,7 +3632,6 @@ static void vrend_patch_blend_state(struct vrend_context *ctx)
    struct pipe_blend_state new_state = ctx->sub->blend_state;
    struct pipe_blend_state *state = &ctx->sub->blend_state;
    bool dest_alpha_only = false, dest_has_no_alpha = false;
-   struct pipe_blend_color blend_color = ctx->sub->blend_color;
    int i;
 
    if (ctx->sub->nr_cbufs == 0)
@@ -3666,14 +3658,7 @@ static void vrend_patch_blend_state(struct vrend_context *ctx)
             new_state.rt[i].alpha_src_factor = PIPE_BLENDFACTOR_ZERO;
             new_state.rt[i].alpha_dst_factor = PIPE_BLENDFACTOR_ZERO;
          }
-         new_state.rt[i].colormask = 0;
-         if (state->rt[i].colormask & PIPE_MASK_A)
-            new_state.rt[i].colormask |= PIPE_MASK_R;
-      }
-      blend_color.color[0] = blend_color.color[3];
-      blend_color.color[1] = 0.0f;
-      blend_color.color[2] = 0.0f;
-      blend_color.color[3] = 0.0f;
+      }
    } else if (dest_has_no_alpha) {
       for (i = 0; i < (state->independent_blend_enable ? PIPE_MAX_COLOR_BUFS : 1); i++) {
          if (!(is_dst_blend(state->rt[i].rgb_src_factor) ||
@@ -3689,10 +3674,6 @@ static void vrend_patch_blend_state(struct vrend_context *ctx)
    }
 
    vrend_hw_emit_blend(ctx, &new_state);
-   glBlendColor(blend_color.color[0],
-                blend_color.color[1],
-                blend_color.color[2],
-                blend_color.color[3]);
 }
 
 void vrend_object_bind_blend(struct vrend_context *ctx,
diff --git a/src/vrend_shader.c b/src/vrend_shader.c
index f7bf853..04f1f06 100644
--- a/src/vrend_shader.c
+++ b/src/vrend_shader.c
@@ -1220,17 +1220,6 @@ static int emit_cbuf_writes(struct dump_ctx *ctx)
    return 0;
 }
 
-static int emit_a8_swizzle(struct dump_ctx *ctx)
-{
-   char buf[255];
-   char *sret;
-   snprintf(buf, 255, "fsout_c0.x = fsout_c0.w;\n");
-   sret = add_str_to_glsl_main(ctx, buf);
-   if (!sret)
-      return ENOMEM;
-   return 0;
-}
-
 static const char *atests[PIPE_FUNC_ALWAYS + 1] = {
    "false",
    "<",
@@ -1517,11 +1506,6 @@ static int handle_fragment_proc_exit(struct dump_ctx *ctx)
           return FALSE;
     }
 
-    if (ctx->key->cbufs_are_a8_bitmask) {
-       if (emit_a8_swizzle(ctx))
-          return FALSE;
-    }
-
     if (ctx->key->add_alpha_test) {
        if (emit_alpha_test(ctx))
           return FALSE;
diff --git a/src/vrend_shader.h b/src/vrend_shader.h
index a20d1be..78dedce 100644
--- a/src/vrend_shader.h
+++ b/src/vrend_shader.h
@@ -93,7 +93,6 @@ struct vrend_shader_key {
    uint8_t prev_stage_num_clip_out;
    uint8_t prev_stage_num_cull_out;
    float alpha_ref_val;
-   uint32_t cbufs_are_a8_bitmask;
    uint8_t num_indirect_generic_outputs;
    uint8_t num_indirect_patch_outputs;
    uint8_t num_indirect_generic_inputs;
-- 
2.18.0.rc2



More information about the virglrenderer-devel mailing list