r300g: move AA registers into the new AA state
authorMarek Olšák <maraeo@gmail.com>
Thu, 24 Jun 2010 03:54:18 +0000 (05:54 +0200)
committerMarek Olšák <maraeo@gmail.com>
Thu, 24 Jun 2010 04:10:47 +0000 (06:10 +0200)
src/gallium/drivers/r300/r300_context.c
src/gallium/drivers/r300/r300_context.h
src/gallium/drivers/r300/r300_emit.c
src/gallium/drivers/r300/r300_emit.h
src/gallium/drivers/r300/r300_render.c
src/gallium/drivers/r300/r300_state.c
src/gallium/drivers/r300/r300_state_invariant.c

index 85190eac2b887c632f39974bb02d042e02476515..46d1ed9dbff1d9bac8e403dbd8632af872ff449a 100644 (file)
@@ -73,6 +73,7 @@ static void r300_destroy_context(struct pipe_context* context)
 
     translate_cache_destroy(r300->tran.translate_cache);
 
+    FREE(r300->aa_state.state);
     FREE(r300->blend_color_state.state);
     FREE(r300->clip_state.state);
     FREE(r300->fb_state.state);
@@ -118,16 +119,17 @@ static void r300_setup_atoms(struct r300_context* r300)
      * Some atoms never change size, others change every emit - those have
      * the size of 0 here. */
     make_empty_list(&r300->atom_list);
-    /* XXX unsorted. */
-    R300_INIT_ATOM(invariant_state, 71);
     /* RB3D (unpipelined), ZB (unpipelined), US, SC. */
     R300_INIT_ATOM(gpu_flush, 9);
+    R300_INIT_ATOM(aa_state, 4);
     R300_INIT_ATOM(fb_state, 0);
     R300_INIT_ATOM(ztop_state, 2);
     R300_INIT_ATOM(dsa_state, is_r500 ? 8 : 6);
     R300_INIT_ATOM(blend_state, 8);
     R300_INIT_ATOM(blend_color_state, is_r500 ? 3 : 2);
     R300_INIT_ATOM(scissor_state, 3);
+    /* All sorts of things. */
+    R300_INIT_ATOM(invariant_state, 22);
     /* VAP. */
     R300_INIT_ATOM(viewport_state, 9);
     R300_INIT_ATOM(pvs_flush, 2);
@@ -156,6 +158,7 @@ static void r300_setup_atoms(struct r300_context* r300)
     }
 
     /* Some non-CSO atoms need explicit space to store the state locally. */
+    r300->aa_state.state = CALLOC_STRUCT(r300_aa_state);
     r300->blend_color_state.state = CALLOC_STRUCT(r300_blend_color_state);
     r300->clip_state.state = CALLOC_STRUCT(r300_clip_state);
     r300->fb_state.state = CALLOC_STRUCT(pipe_framebuffer_state);
index c5c662afd0fb044fd23ba3f04f8d27fb73d6b9fe..976ef20510cd999b3f1b5e4381ba3ce1ce13c738 100644 (file)
@@ -61,6 +61,13 @@ struct r300_atom {
     boolean allow_null_state;
 };
 
+struct r300_aa_state {
+    struct r300_surface *dest;
+
+    uint32_t aa_config;
+    uint32_t aaresolve_ctl;
+};
+
 struct r300_blend_state {
     uint32_t cb[8];
     uint32_t cb_no_readwrite[8];
@@ -111,7 +118,6 @@ struct r300_rs_state {
     uint32_t vap_control_status;    /* R300_VAP_CNTL_STATUS: 0x2140 */
     uint32_t multisample_position_0;/* R300_GB_MSPOS0: 0x4010 */
     uint32_t multisample_position_1;/* R300_GB_MSPOS1: 0x4014 */
-    uint32_t antialiasing_config;   /* R300_GB_AA_CONFIG: 0x4020 */
     uint32_t point_size;            /* R300_GA_POINT_SIZE: 0x421c */
     uint32_t point_minmax;          /* R300_GA_POINT_MINMAX: 0x4230 */
     uint32_t line_control;          /* R300_GA_LINE_CNTL: 0x4234 */
@@ -425,6 +431,8 @@ struct r300_context {
     /* Various CSO state objects. */
     /* Beginning of atom list. */
     struct r300_atom atom_list;
+    /* Anti-aliasing (MSAA) state. */
+    struct r300_atom aa_state;
     /* Blend state. */
     struct r300_atom blend_state;
     /* Blend color state. */
index dd6cc4d4f84f10547214f616093bf1875573bfee..2a03e5a70f1c7f4f71cf2ba4d57f31a879f95b1c 100644 (file)
@@ -295,6 +295,26 @@ void r300_emit_gpu_flush(struct r300_context *r300, unsigned size, void *state)
     END_CS;
 }
 
+void r300_emit_aa_state(struct r300_context *r300, unsigned size, void *state)
+{
+    struct r300_aa_state *aa = (struct r300_aa_state*)state;
+    CS_LOCALS(r300);
+
+    BEGIN_CS(size);
+    OUT_CS_REG(R300_GB_AA_CONFIG, aa->aa_config);
+
+    if (aa->dest) {
+        OUT_CS_REG_SEQ(R300_RB3D_AARESOLVE_OFFSET, 1);
+        OUT_CS_RELOC(aa->dest->buffer, aa->dest->offset, 0, aa->dest->domain, 0);
+
+        OUT_CS_REG_SEQ(R300_RB3D_AARESOLVE_PITCH, 1);
+        OUT_CS_RELOC(aa->dest->buffer, aa->dest->pitch, 0, aa->dest->domain, 0);
+    }
+
+    OUT_CS_REG(R300_RB3D_AARESOLVE_CTL, aa->aaresolve_ctl);
+    END_CS;
+}
+
 void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state)
 {
     struct pipe_framebuffer_state* fb = (struct pipe_framebuffer_state*)state;
@@ -511,7 +531,7 @@ void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state)
     struct r300_rs_state* rs = state;
     struct pipe_framebuffer_state* fb = r300->fb_state.state;
     float scale, offset;
-    unsigned mspos0, mspos1, aa_config;
+    unsigned mspos0, mspos1;
     CS_LOCALS(r300);
 
     BEGIN_CS(size);
@@ -520,26 +540,21 @@ void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state)
     /* Multisampling. Depends on framebuffer sample count. */
     if (r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0)) {
         if (fb->nr_cbufs && fb->cbufs[0]->texture->nr_samples > 1) {
-            aa_config = R300_GB_AA_CONFIG_AA_ENABLE;
             /* Subsample placement. These may not be optimal. */
             switch (fb->cbufs[0]->texture->nr_samples) {
                 case 2:
-                    aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_2;
                     mspos0 = 0x33996633;
                     mspos1 = 0x6666663;
                     break;
                 case 3:
-                    aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_3;
                     mspos0 = 0x33936933;
                     mspos1 = 0x6666663;
                     break;
                 case 4:
-                    aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_4;
                     mspos0 = 0x33939933;
                     mspos1 = 0x3966663;
                     break;
                 case 6:
-                    aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_6;
                     mspos0 = 0x22a2aa22;
                     mspos1 = 0x2a65672;
                     break;
@@ -553,14 +568,10 @@ void r300_emit_rs_state(struct r300_context* r300, unsigned size, void* state)
             OUT_CS_REG_SEQ(R300_GB_MSPOS0, 2);
             OUT_CS(mspos0);
             OUT_CS(mspos1);
-
-            OUT_CS_REG(R300_GB_AA_CONFIG, aa_config);
         } else {
             OUT_CS_REG_SEQ(R300_GB_MSPOS0, 2);
             OUT_CS(rs->multisample_position_0);
             OUT_CS(rs->multisample_position_1);
-
-            OUT_CS_REG(R300_GB_AA_CONFIG, rs->antialiasing_config);
         }
     }
 
index 16a2b5e9f17641329c4a2d95bf12906656b7a696..0d4e1f7a23bdbd1e1673c76d2544bb2c2d1909d5 100644 (file)
@@ -61,6 +61,8 @@ void r300_emit_fb_state(struct r300_context* r300, unsigned size, void* state);
 
 void r300_emit_gpu_flush(struct r300_context *r300, unsigned size, void *state);
 
+void r300_emit_aa_state(struct r300_context *r300, unsigned size, void *state);
+
 void r300_emit_query_start(struct r300_context *r300, unsigned size, void *state);
 
 void r300_emit_query_end(struct r300_context* r300);
index 0fd05b51ac15357dd6de2e60948c88f92cc5bdab..99ad162504c6f19d76cda87485290d33945d9729 100644 (file)
@@ -1028,33 +1028,35 @@ static void r300_resource_resolve(struct pipe_context* pipe,
                                   struct pipe_subresource subsrc)
 {
     struct r300_context* r300 = r300_context(pipe);
-    struct r300_surface* destsurf = r300_surface(
-        dest->screen->get_tex_surface(dest->screen,
-            dest, subdest.face, subdest.level, 0, 0));
+    struct r300_aa_state *aa = (struct r300_aa_state*)r300->aa_state.state;
     struct pipe_surface* srcsurf = src->screen->get_tex_surface(src->screen,
             src, subsrc.face, subsrc.level, 0, 0);
     float color[] = {0, 0, 0, 0};
-    CS_LOCALS(r300);
 
     DBG(r300, DBG_DRAW, "r300: Resolving resource...\n");
 
-    OUT_CS_REG_SEQ(R300_RB3D_AARESOLVE_OFFSET, 1);
-    OUT_CS_RELOC(destsurf->buffer, destsurf->offset, 0, destsurf->domain, 0);
-
-    OUT_CS_REG_SEQ(R300_RB3D_AARESOLVE_PITCH, 1);
-    OUT_CS_RELOC(destsurf->buffer, destsurf->pitch, 0, destsurf->domain, 0);
+    /* Enable AA resolve. */
+    aa->dest = r300_surface(
+            dest->screen->get_tex_surface(dest->screen, dest, subdest.face,
+                                          subdest.level, 0, 0));
 
-    OUT_CS_REG(R300_RB3D_AARESOLVE_CTL,
+    aa->aaresolve_ctl =
         R300_RB3D_AARESOLVE_CTL_AARESOLVE_MODE_RESOLVE |
-        R300_RB3D_AARESOLVE_CTL_AARESOLVE_ALPHA_AVERAGE);
+        R300_RB3D_AARESOLVE_CTL_AARESOLVE_ALPHA_AVERAGE;
+    r300->aa_state.size = 12;
+    r300->aa_state.dirty = TRUE;
 
+    /* Resolve the surface. */
     r300->context.clear_render_target(pipe,
         srcsurf, color, 0, 0, src->width0, src->height0);
 
-    OUT_CS_REG(R300_RB3D_AARESOLVE_CTL, 0x0);
+    /* Disable AA resolve. */
+    aa->aaresolve_ctl = 0;
+    r300->aa_state.size = 4;
+    r300->aa_state.dirty = TRUE;
 
     pipe_surface_reference((struct pipe_surface**)&srcsurf, NULL);
-    pipe_surface_reference((struct pipe_surface**)&destsurf, NULL);
+    pipe_surface_reference((struct pipe_surface**)&aa->dest, NULL);
 }
 
 void r300_init_render_functions(struct r300_context *r300)
index f2534e473da13efda240815283dc42363add4080..9c0f877e8149375944f57e6681d7c57c78e4cbc2 100644 (file)
@@ -664,6 +664,7 @@ static void
                                const struct pipe_framebuffer_state* state)
 {
     struct r300_context* r300 = r300_context(pipe);
+    struct r300_aa_state *aa = (struct r300_aa_state*)r300->aa_state.state;
     struct pipe_framebuffer_state *old_state = r300->fb_state.state;
     unsigned max_width, max_height, i;
     uint32_t zbuffer_bpp = 0;
@@ -687,6 +688,7 @@ static void
     }
 
     r300->gpu_flush.dirty = TRUE;
+    r300->aa_state.dirty = TRUE;
     r300->fb_state.dirty = TRUE;
 
     /* If nr_cbufs is changed from zero to non-zero or vice versa... */
@@ -725,6 +727,30 @@ static void
         }
     }
 
+    /* Set up AA config. */
+    if (r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0)) {
+        if (state->nr_cbufs && state->cbufs[0]->texture->nr_samples > 1) {
+            aa->aa_config = R300_GB_AA_CONFIG_AA_ENABLE;
+
+            switch (state->cbufs[0]->texture->nr_samples) {
+                case 2:
+                    aa->aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_2;
+                    break;
+                case 3:
+                    aa->aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_3;
+                    break;
+                case 4:
+                    aa->aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_4;
+                    break;
+                case 6:
+                    aa->aa_config |= R300_GB_AA_CONFIG_NUM_AA_SUBSAMPLES_6;
+                    break;
+            }
+        } else {
+            aa->aa_config = 0;
+        }
+    }
+
     if (DBG_ON(r300, DBG_FB)) {
         fprintf(stderr, "r300: set_framebuffer_state:\n");
         for (i = 0; i < state->nr_cbufs; i++) {
@@ -984,7 +1010,7 @@ static void r300_bind_rs_state(struct pipe_context* pipe, void* state)
 
     UPDATE_STATE(state, r300->rs_state);
     r300->rs_state.size = 25 + (r300->polygon_offset_enabled ? 5 : 0) +
-        (r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0) ? 5 : 0);
+        (r300->rws->get_value(r300->rws, R300_VID_DRM_2_3_0) ? 3 : 0);
 
     if (last_sprite_coord_enable != r300->sprite_coord_enable ||
         last_two_sided_color != r300->two_sided_color) {
index bec6ea1565e291f5979cd214ac46d19390863dcd..acd20974a0011184dbd1cc66d61b37b9fcf8b783 100644 (file)
@@ -38,9 +38,8 @@ void r300_emit_invariant_state(struct r300_context* r300,
 {
     CS_LOCALS(r300);
 
-    BEGIN_CS(20 + (r300->screen->caps.is_rv350 ? 4 : 0));
+    BEGIN_CS(18 + (r300->screen->caps.is_rv350 ? 4 : 0));
 
-    OUT_CS_REG(R300_RB3D_AARESOLVE_CTL, 0);
     OUT_CS_REG(R300_GB_SELECT, 0);
     OUT_CS_REG(R300_FG_FOG_BLEND, 0);
     OUT_CS_REG(R300_GA_ROUND_MODE, 1);