Merge commit 'origin/perrtblend'
[mesa.git] / src / gallium / drivers / r300 / r300_state.c
index 641e95e7fcae90cd49e085b19949a0cb3f4a1be4..3cdcf94274c041c89110fcf7be67a41137e3039f 100644 (file)
@@ -30,7 +30,6 @@
 #include "tgsi/tgsi_parse.h"
 
 #include "pipe/p_config.h"
-#include "pipe/internal/p_winsys_screen.h"
 
 #include "r300_context.h"
 #include "r300_reg.h"
@@ -164,15 +163,15 @@ static void* r300_create_blend_state(struct pipe_context* pipe,
 {
     struct r300_blend_state* blend = CALLOC_STRUCT(r300_blend_state);
 
-    if (state->blend_enable)
+    if (state->rt[0].blend_enable)
     {
-        unsigned eqRGB = state->rgb_func;
-        unsigned srcRGB = state->rgb_src_factor;
-        unsigned dstRGB = state->rgb_dst_factor;
+        unsigned eqRGB = state->rt[0].rgb_func;
+        unsigned srcRGB = state->rt[0].rgb_src_factor;
+        unsigned dstRGB = state->rt[0].rgb_dst_factor;
 
-        unsigned eqA = state->alpha_func;
-        unsigned srcA = state->alpha_src_factor;
-        unsigned dstA = state->alpha_dst_factor;
+        unsigned eqA = state->rt[0].alpha_func;
+        unsigned srcA = state->rt[0].alpha_src_factor;
+        unsigned dstA = state->rt[0].alpha_dst_factor;
 
         /* despite the name, ALPHA_BLEND_ENABLE has nothing to do with alpha,
          * this is just the crappy D3D naming */
@@ -290,16 +289,16 @@ static void* r300_create_blend_state(struct pipe_context* pipe,
     }
 
     /* Color Channel Mask */
-    if (state->colormask & PIPE_MASK_R) {
+    if (state->rt[0].colormask & PIPE_MASK_R) {
         blend->color_channel_mask |= RB3D_COLOR_CHANNEL_MASK_RED_MASK0;
     }
-    if (state->colormask & PIPE_MASK_G) {
+    if (state->rt[0].colormask & PIPE_MASK_G) {
         blend->color_channel_mask |= RB3D_COLOR_CHANNEL_MASK_GREEN_MASK0;
     }
-    if (state->colormask & PIPE_MASK_B) {
+    if (state->rt[0].colormask & PIPE_MASK_B) {
         blend->color_channel_mask |= RB3D_COLOR_CHANNEL_MASK_BLUE_MASK0;
     }
-    if (state->colormask & PIPE_MASK_A) {
+    if (state->rt[0].colormask & PIPE_MASK_A) {
         blend->color_channel_mask |= RB3D_COLOR_CHANNEL_MASK_ALPHA_MASK0;
     }
 
@@ -488,20 +487,30 @@ static void
     struct r300_context* r300 = r300_context(pipe);
     uint32_t zbuffer_bpp = 0;
 
+    r300->fb_state.size = (10 * state->nr_cbufs) +
+        (2 * (4 - state->nr_cbufs)) +
+        (state->zsbuf ? 10 : 0) + 6;
+
+    if (state->nr_cbufs > 4) {
+        debug_printf("r300: Implementation error: Too many MRTs in %s, "
+            "refusing to bind framebuffer state!\n", __FUNCTION__);
+        return;
+    }
+
     if (r300->draw) {
         draw_flush(r300->draw);
     }
 
-    r300->framebuffer_state = *state;
+    r300->fb_state.state = state;
 
     /* Don't rely on the order of states being set for the first time. */
-    r300->dirty_state |= R300_NEW_FRAMEBUFFERS;
-
+    /* XXX wait what */
     r300->blend_state.dirty = TRUE;
     r300->dsa_state.dirty = TRUE;
+    r300->fb_state.dirty = TRUE;
     r300->scissor_state.dirty = TRUE;
 
-    /* Polyfon offset depends on the zbuffer bit depth. */
+    /* Polygon offset depends on the zbuffer bit depth. */
     if (state->zsbuf && r300->polygon_offset_enabled) {
         switch (util_format_get_blocksize(state->zsbuf->texture->format)) {
             case 2:
@@ -552,7 +561,7 @@ static void r300_bind_fs_state(struct pipe_context* pipe, void* shader)
     r300_pick_fragment_shader(r300);
 
     if (r300->vs && r300_vertex_shader_setup_wpos(r300)) {
-        r300->dirty_state |= R300_NEW_VERTEX_FORMAT;
+        r300->vertex_format_state.dirty = TRUE;
     }
 
     r300->dirty_state |= R300_NEW_FRAGMENT_SHADER | R300_NEW_FRAGMENT_SHADER_CONSTANTS;
@@ -720,7 +729,6 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state)
     r300->viewport_state.dirty = TRUE;
 
     /* XXX Clean these up when we move to atom emits */
-    r300->dirty_state |= R300_NEW_RS_BLOCK;
     if (r300->fs && r300->fs->inputs.wpos != ATTR_UNUSED) {
         r300->dirty_state |= R300_NEW_FRAGMENT_SHADER_CONSTANTS;
     }
@@ -921,7 +929,7 @@ static void r300_set_vertex_buffers(struct pipe_context* pipe,
         draw_set_vertex_buffers(r300->draw, count, buffers);
     }
 
-    r300->dirty_state |= R300_NEW_VERTEX_FORMAT;
+    r300->vertex_format_state.dirty = TRUE;
 }
 
 static boolean r300_validate_aos(struct r300_context *r300)
@@ -1001,9 +1009,10 @@ static void r300_bind_vs_state(struct pipe_context* pipe, void* shader)
             r300_vertex_shader_setup_wpos(r300);
         }
 
+        r300->vertex_format_state.dirty = TRUE;
+
         r300->dirty_state |=
-            R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS |
-            R300_NEW_VERTEX_FORMAT;
+            R300_NEW_VERTEX_SHADER | R300_NEW_VERTEX_SHADER_CONSTANTS;
     } else {
         draw_flush(r300->draw);
         draw_bind_vertex_shader(r300->draw,