etnaviv: fix blend color for RB swapped rendertargets
authorLucas Stach <dev@lynxeye.de>
Mon, 5 Jun 2017 19:11:02 +0000 (21:11 +0200)
committerChristian Gmeiner <christian.gmeiner@gmail.com>
Wed, 21 Jun 2017 05:45:15 +0000 (07:45 +0200)
Same as with the colormasks, the blend color needs to be swizzled according
to the rendertarget format.

Signed-off-by: Lucas Stach <dev@lynxeye.de>
Reviewed-by: Wladimir J. van der Laan <laanwj@gmail.com>
Reviewed-by: Christian Gmeiner <christian.gmeiner@gmail.com>
src/gallium/drivers/etnaviv/etnaviv_blend.c
src/gallium/drivers/etnaviv/etnaviv_blend.h
src/gallium/drivers/etnaviv/etnaviv_internal.h
src/gallium/drivers/etnaviv/etnaviv_state.c

index 8ea09a37ae7fe5a5fdd125d56a33ab4be3479119..6ed0e0f3fc7b29466c8bb89eda3eb7556056d62e 100644 (file)
@@ -129,3 +129,38 @@ etna_update_blend(struct etna_context *ctx)
 
    return true;
 }
+
+void
+etna_set_blend_color(struct pipe_context *pctx, const struct pipe_blend_color *bc)
+{
+   struct etna_context *ctx = etna_context(pctx);
+   struct compiled_blend_color *cs = &ctx->blend_color;
+
+   memcpy(cs->color, bc->color, sizeof(float) * 4);
+
+   ctx->dirty |= ETNA_DIRTY_BLEND_COLOR;
+}
+
+bool
+etna_update_blend_color(struct etna_context *ctx)
+{
+   struct pipe_framebuffer_state *pfb = &ctx->framebuffer_s;
+   struct compiled_blend_color *cs = &ctx->blend_color;
+
+   if (pfb->cbufs[0] &&
+       translate_rs_format_rb_swap(pfb->cbufs[0]->texture->format)) {
+      cs->PE_ALPHA_BLEND_COLOR =
+         VIVS_PE_ALPHA_BLEND_COLOR_R(etna_cfloat_to_uint8(cs->color[2])) |
+         VIVS_PE_ALPHA_BLEND_COLOR_G(etna_cfloat_to_uint8(cs->color[1])) |
+         VIVS_PE_ALPHA_BLEND_COLOR_B(etna_cfloat_to_uint8(cs->color[0])) |
+         VIVS_PE_ALPHA_BLEND_COLOR_A(etna_cfloat_to_uint8(cs->color[3]));
+   } else {
+      cs->PE_ALPHA_BLEND_COLOR =
+         VIVS_PE_ALPHA_BLEND_COLOR_R(etna_cfloat_to_uint8(cs->color[0])) |
+         VIVS_PE_ALPHA_BLEND_COLOR_G(etna_cfloat_to_uint8(cs->color[1])) |
+         VIVS_PE_ALPHA_BLEND_COLOR_B(etna_cfloat_to_uint8(cs->color[2])) |
+         VIVS_PE_ALPHA_BLEND_COLOR_A(etna_cfloat_to_uint8(cs->color[3]));
+       }
+
+       return true;
+}
index e26864d409f280fbd1d5cb4922160facbedb49a5..c21939603d1e135455e9afd8aefaf87633f2880b 100644 (file)
@@ -56,4 +56,10 @@ etna_blend_state_create(struct pipe_context *pctx,
 bool
 etna_update_blend(struct etna_context *ctx);
 
+void
+etna_set_blend_color(struct pipe_context *pctx, const struct pipe_blend_color *bc);
+
+bool
+etna_update_blend_color(struct etna_context *ctx);
+
 #endif
index 2f8dacbce5f625bd8d130c9af7e8242168b4c6df..1212fdfa3102eed86ffce44870879d032c8ebaeb 100644 (file)
@@ -126,6 +126,7 @@ struct etna_specs {
 
 /* Compiled pipe_blend_color */
 struct compiled_blend_color {
+   float color[4];
    uint32_t PE_ALPHA_BLEND_COLOR;
 };
 
index fb7bb0f4c50d88bed181309dab7fdcd91d2a836e..fc3d9f108faca88297a9c4aeb8a028115ad1d113 100644 (file)
 #include "util/u_math.h"
 #include "util/u_memory.h"
 
-static void
-etna_set_blend_color(struct pipe_context *pctx, const struct pipe_blend_color *bc)
-{
-   struct etna_context *ctx = etna_context(pctx);
-   struct compiled_blend_color *cs = &ctx->blend_color;
-
-   cs->PE_ALPHA_BLEND_COLOR =
-      VIVS_PE_ALPHA_BLEND_COLOR_R(etna_cfloat_to_uint8(bc->color[0])) |
-      VIVS_PE_ALPHA_BLEND_COLOR_G(etna_cfloat_to_uint8(bc->color[1])) |
-      VIVS_PE_ALPHA_BLEND_COLOR_B(etna_cfloat_to_uint8(bc->color[2])) |
-      VIVS_PE_ALPHA_BLEND_COLOR_A(etna_cfloat_to_uint8(bc->color[3]));
-   ctx->dirty |= ETNA_DIRTY_BLEND_COLOR;
-}
-
 static void
 etna_set_stencil_ref(struct pipe_context *pctx, const struct pipe_stencil_ref *sr)
 {
@@ -600,6 +586,9 @@ static const struct etna_state_updater etna_state_updates[] = {
    },
    {
       etna_update_blend, ETNA_DIRTY_BLEND | ETNA_DIRTY_FRAMEBUFFER
+   },
+   {
+      etna_update_blend_color, ETNA_DIRTY_BLEND_COLOR | ETNA_DIRTY_FRAMEBUFFER,
    }
 };