Mesa (master): r300g: turn blend color into a CB

Marek Olšák mareko at kemper.freedesktop.org
Sun Jun 13 17:17:52 UTC 2010


Module: Mesa
Branch: master
Commit: 9dd50993c6540729fe7c7397b4a947b3068db162
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=9dd50993c6540729fe7c7397b4a947b3068db162

Author: Marek Olšák <maraeo at gmail.com>
Date:   Sun Jun 13 03:25:39 2010 +0200

r300g: turn blend color into a CB

---

 src/gallium/drivers/r300/r300_context.c |   15 +++++++++++++++
 src/gallium/drivers/r300/r300_context.h |    6 +-----
 src/gallium/drivers/r300/r300_emit.c    |   12 +-----------
 src/gallium/drivers/r300/r300_state.c   |   30 ++++++++++++++++++------------
 4 files changed, 35 insertions(+), 28 deletions(-)

diff --git a/src/gallium/drivers/r300/r300_context.c b/src/gallium/drivers/r300/r300_context.c
index 43e567c..aac3660 100644
--- a/src/gallium/drivers/r300/r300_context.c
+++ b/src/gallium/drivers/r300/r300_context.c
@@ -164,6 +164,19 @@ static void r300_setup_atoms(struct r300_context* r300)
     r300->texture_cache_inval.allow_null_state = TRUE;
 }
 
+/* Not every state tracker calls every driver function before the first draw
+ * call and we must initialize the command buffers somehow. */
+static void r300_init_states(struct pipe_context *pipe)
+{
+    struct pipe_blend_color bc = {{0}};
+    struct pipe_clip_state cs = {{{0}}};
+    struct pipe_scissor_state ss = {0};
+
+    pipe->set_blend_color(pipe, &bc);
+    pipe->set_clip_state(pipe, &cs);
+    pipe->set_scissor_state(pipe, &ss);
+}
+
 struct pipe_context* r300_create_context(struct pipe_screen* screen,
                                          void *priv)
 {
@@ -231,6 +244,8 @@ struct pipe_context* r300_create_context(struct pipe_screen* screen,
 
     r300->tran.translate_cache = translate_cache_create();
 
+    r300_init_states(&r300->context);
+
     return &r300->context;
 
  no_upload_ib:
diff --git a/src/gallium/drivers/r300/r300_context.h b/src/gallium/drivers/r300/r300_context.h
index a527ba0..6d6185c 100644
--- a/src/gallium/drivers/r300/r300_context.h
+++ b/src/gallium/drivers/r300/r300_context.h
@@ -67,11 +67,7 @@ struct r300_blend_state {
 };
 
 struct r300_blend_color_state {
-    /* RV515 and earlier */
-    uint32_t blend_color;            /* R300_RB3D_BLEND_COLOR: 0x4e10 */
-    /* R520 and newer */
-    uint32_t blend_color_red_alpha;  /* R500_RB3D_CONSTANT_COLOR_AR: 0x4ef8 */
-    uint32_t blend_color_green_blue; /* R500_RB3D_CONSTANT_COLOR_GB: 0x4efc */
+    uint32_t cb[3];
 };
 
 struct r300_dsa_state {
diff --git a/src/gallium/drivers/r300/r300_emit.c b/src/gallium/drivers/r300/r300_emit.c
index 2c1d67e..04a3ab5 100644
--- a/src/gallium/drivers/r300/r300_emit.c
+++ b/src/gallium/drivers/r300/r300_emit.c
@@ -56,17 +56,7 @@ void r300_emit_blend_color_state(struct r300_context* r300,
     struct r300_blend_color_state* bc = (struct r300_blend_color_state*)state;
     CS_LOCALS(r300);
 
-    if (r300->screen->caps.is_r500) {
-        BEGIN_CS(size);
-        OUT_CS_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2);
-        OUT_CS(bc->blend_color_red_alpha);
-        OUT_CS(bc->blend_color_green_blue);
-        END_CS;
-    } else {
-        BEGIN_CS(size);
-        OUT_CS_REG(R300_RB3D_BLEND_COLOR, bc->blend_color);
-        END_CS;
-    }
+    WRITE_CS_TABLE(bc->cb, size);
 }
 
 void r300_emit_clip_state(struct r300_context* r300,
diff --git a/src/gallium/drivers/r300/r300_state.c b/src/gallium/drivers/r300/r300_state.c
index 73d866f..d5ed119 100644
--- a/src/gallium/drivers/r300/r300_state.c
+++ b/src/gallium/drivers/r300/r300_state.c
@@ -394,20 +394,26 @@ static void r300_set_blend_color(struct pipe_context* pipe,
     struct r300_context* r300 = r300_context(pipe);
     struct r300_blend_color_state* state =
         (struct r300_blend_color_state*)r300->blend_color_state.state;
-    union util_color uc;
+    CB_LOCALS;
 
-    util_pack_color(color->color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
-    state->blend_color = uc.ui;
+    if (r300->screen->caps.is_r500) {
+        /* XXX if FP16 blending is enabled, we should use the FP16 format */
+        BEGIN_CB(state->cb, 3);
+        OUT_CB_REG_SEQ(R500_RB3D_CONSTANT_COLOR_AR, 2);
+        OUT_CB(float_to_fixed10(color->color[0]) |
+               (float_to_fixed10(color->color[3]) << 16));
+        OUT_CB(float_to_fixed10(color->color[2]) |
+               (float_to_fixed10(color->color[1]) << 16));
+        END_CB;
+    } else {
+        union util_color uc;
+        util_pack_color(color->color, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
 
-    /* XXX if FP16 blending is enabled, we should use the FP16 format */
-    state->blend_color_red_alpha =
-        float_to_fixed10(color->color[0]) |
-        (float_to_fixed10(color->color[3]) << 16);
-    state->blend_color_green_blue =
-        float_to_fixed10(color->color[2]) |
-        (float_to_fixed10(color->color[1]) << 16);
+        BEGIN_CB(state->cb, 2);
+        OUT_CB_REG(R300_RB3D_BLEND_COLOR, uc.ui);
+        END_CB;
+    }
 
-    r300->blend_color_state.size = r300->screen->caps.is_r500 ? 3 : 2;
     r300->blend_color_state.dirty = TRUE;
 }
 




More information about the mesa-commit mailing list