From: Dave Airlie <airl...@redhat.com>

I rewrote this to use the sample positions properly.

Signed-off-by: Dave Airlie <airl...@redhat.com>
---
 src/gallium/drivers/r600/evergreen_state.c | 269 +++++++++++++++++------------
 src/gallium/drivers/r600/r600_state.c      |  67 +++++--
 2 files changed, 214 insertions(+), 122 deletions(-)

diff --git a/src/gallium/drivers/r600/evergreen_state.c 
b/src/gallium/drivers/r600/evergreen_state.c
index 7169614..d513ad5 100644
--- a/src/gallium/drivers/r600/evergreen_state.c
+++ b/src/gallium/drivers/r600/evergreen_state.c
@@ -1868,38 +1868,70 @@ static void evergreen_set_framebuffer_state(struct 
pipe_context *ctx,
        (((s2x) & 0xf) << 16) | (((s2y) & 0xf) << 20) |    \
         (((s3x) & 0xf) << 24) | (((s3y) & 0xf) << 28))
 
+/* 2xMSAA
+ * There are two locations (-4, 4), (4, -4). */
+static uint32_t sample_locs_2x[] = {
+        FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
+        FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
+        FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
+        FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
+};
+static unsigned max_dist_2x = 4;
+/* 4xMSAA
+ * There are 4 locations: (-2, -2), (2, 2), (-6, 6), (6, -6). */
+static uint32_t sample_locs_4x[] = {
+        FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
+        FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
+        FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
+        FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
+};
+static unsigned max_dist_4x = 6;
+/* 8xMSAA */
+static uint32_t sample_locs_8x[] = {
+        FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
+        FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
+        FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
+        FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
+        FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
+        FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
+        FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
+        FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
+};
+static unsigned max_dist_8x = 7;
+
+static void evergreen_get_sample_position(struct pipe_context *ctx,
+                                    int max_sample,
+                                    unsigned sample_index,
+                                    float *out_value)
+{
+        int offset, index;
+       switch (max_sample) {
+       case 1:
+       default:
+               out_value[0] = out_value[1] = 0.5;
+               break;
+        case 2:
+                offset = 4 * (sample_index * 2);
+                out_value[0] = (float)(((sample_locs_2x[0] >> offset) & 0xf) + 
8) / 16.0;
+                out_value[1] = (float)(((sample_locs_2x[0] >> (offset + 4)) & 
0xf) + 8) / 16.0;
+                break;               
+        case 4: {
+                offset = 4 * (sample_index * 2);
+                out_value[0] = (float)(((sample_locs_4x[0] >> offset) & 0xf) + 
8) / 16.0;
+                out_value[1] = (float)(((sample_locs_4x[0] >> (offset + 4)) & 
0xf) + 8) / 16.0;
+        }
+                break;
+        case 8:
+                offset = 4 * ((sample_index % 4) * 2);
+                index = sample_index / 4;
+                out_value[0] = (float)(((sample_locs_8x[index] >> offset) & 
0xf) + 8) / 16.0;
+                out_value[1] = (float)(((sample_locs_8x[index] >> (offset + 
4)) & 0xf) + 8) / 16.0;
+                break;
+        }
+}
+
 static void evergreen_emit_msaa_state(struct r600_context *rctx, int 
nr_samples)
 {
-       /* 2xMSAA
-        * There are two locations (-4, 4), (4, -4). */
-       static uint32_t sample_locs_2x[] = {
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-       };
-       static unsigned max_dist_2x = 4;
-       /* 4xMSAA
-        * There are 4 locations: (-2, -2), (2, 2), (-6, 6), (6, -6). */
-       static uint32_t sample_locs_4x[] = {
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-       };
-       static unsigned max_dist_4x = 6;
-       /* 8xMSAA */
-       static uint32_t sample_locs_8x[] = {
-               FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
-               FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
-               FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
-               FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
-               FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
-               FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
-               FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
-               FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
-       };
-       static unsigned max_dist_8x = 7;
 
        struct radeon_winsys_cs *cs = rctx->rings.gfx.cs;
        unsigned max_dist = 0;
@@ -1938,58 +1970,78 @@ static void evergreen_emit_msaa_state(struct 
r600_context *rctx, int nr_samples)
        }
 }
 
+/* Cayman 8xMSAA */
+static uint32_t cm_sample_locs_8x[] = {
+        FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
+        FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
+        FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
+        FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
+        FILL_SREG( 6,  0, 0,  0, -5, 3,  4,  4),
+        FILL_SREG( 6,  0, 0,  0, -5, 3,  4,  4),
+        FILL_SREG( 6,  0, 0,  0, -5, 3,  4,  4),
+        FILL_SREG( 6,  0, 0,  0, -5, 3,  4,  4),
+};
+static unsigned cm_max_dist_8x = 8;
+/* Cayman 16xMSAA */
+static uint32_t cm_sample_locs_16x[] = {
+        FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
+        FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
+        FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
+        FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
+        FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
+        FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
+        FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
+        FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
+        FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
+        FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
+        FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
+        FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
+        FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
+        FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
+        FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
+        FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
+};
+static unsigned cm_max_dist_16x = 8;
+static void cayman_get_sample_position(struct pipe_context *ctx,
+                                    int max_sample,
+                                    unsigned sample_index,
+                                    float *out_value)
+{
+        int offset, index;
+       switch (max_sample) {
+       case 1:
+       default:
+               out_value[0] = out_value[1] = 0.5;
+               break;
+        case 2:
+                offset = 4 * (sample_index * 2);
+                out_value[0] = (float)(((sample_locs_2x[0] >> offset) & 0xf) + 
8) / 16.0;
+                out_value[1] = (float)(((sample_locs_2x[0] >> (offset + 4)) & 
0xf) + 8) / 16.0;
+                break;               
+        case 4: {
+                offset = 4 * (sample_index * 2);
+                out_value[0] = (float)(((sample_locs_4x[0] >> offset) & 0xf) + 
8) / 16.0;
+                out_value[1] = (float)(((sample_locs_4x[0] >> (offset + 4)) & 
0xf) + 8) / 16.0;
+        }
+                break;
+        case 8:
+                offset = 4 * (sample_index % 4 * 2);
+                index = (sample_index / 4) * 4;
+                out_value[0] = (float)(((cm_sample_locs_8x[index] >> offset) & 
0xf) + 8) / 16.0;
+                out_value[1] = (float)(((cm_sample_locs_8x[index] >> (offset + 
4)) & 0xf) + 8) / 16.0;
+                break;
+        case 16:
+                offset = 4 * (sample_index % 4 * 2);
+                index = (sample_index / 4) * 4;
+                out_value[0] = (float)(((cm_sample_locs_16x[index] >> offset) 
& 0xf) + 8) / 16.0;
+                out_value[1] = (float)(((cm_sample_locs_16x[index] >> (offset 
+ 4)) & 0xf) + 8) / 16.0;
+                break;
+        }
+}
+
 static void cayman_emit_msaa_state(struct r600_context *rctx, int nr_samples)
 {
-       /* 2xMSAA
-        * There are two locations (-4, 4), (4, -4). */
-       static uint32_t sample_locs_2x[] = {
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-       };
-       static unsigned max_dist_2x = 4;
-       /* 4xMSAA
-        * There are 4 locations: (-2, -2), (2, 2), (-6, 6), (6, -6). */
-       static uint32_t sample_locs_4x[] = {
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-       };
-       static unsigned max_dist_4x = 6;
-       /* 8xMSAA */
-       static uint32_t sample_locs_8x[] = {
-               FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
-               FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
-               FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
-               FILL_SREG(-2, -5, 3, -4, -1, 5, -6, -2),
-               FILL_SREG( 6,  0, 0,  0, -5, 3,  4,  4),
-               FILL_SREG( 6,  0, 0,  0, -5, 3,  4,  4),
-               FILL_SREG( 6,  0, 0,  0, -5, 3,  4,  4),
-               FILL_SREG( 6,  0, 0,  0, -5, 3,  4,  4),
-       };
-       static unsigned max_dist_8x = 8;
-       /* 16xMSAA */
-       static uint32_t sample_locs_16x[] = {
-               FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
-               FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
-               FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
-               FILL_SREG(-7, -3, 7, 3, 1, -5, -5, 5),
-               FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
-               FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
-               FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
-               FILL_SREG(-3, -7, 3, 7, 5, -1, -1, 1),
-               FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
-               FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
-               FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
-               FILL_SREG(-8, -6, 4, 2, 2, -8, -2, 6),
-               FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
-               FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
-               FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
-               FILL_SREG(-4, -2, 0, 4, 6, -4, -6, 0),
-       };
-       static unsigned max_dist_16x = 8;
+
 
        struct radeon_winsys_cs *cs = rctx->rings.gfx.cs;
        unsigned max_dist = 0;
@@ -2014,41 +2066,41 @@ static void cayman_emit_msaa_state(struct r600_context 
*rctx, int nr_samples)
                break;
        case 8:
                r600_write_context_reg_seq(cs, 
CM_R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, 14);
-               r600_write_value(cs, sample_locs_8x[0]);
-               r600_write_value(cs, sample_locs_8x[4]);
+               r600_write_value(cs, cm_sample_locs_8x[0]);
+               r600_write_value(cs, cm_sample_locs_8x[4]);
                r600_write_value(cs, 0);
                r600_write_value(cs, 0);
-               r600_write_value(cs, sample_locs_8x[1]);
-               r600_write_value(cs, sample_locs_8x[5]);
+               r600_write_value(cs, cm_sample_locs_8x[1]);
+               r600_write_value(cs, cm_sample_locs_8x[5]);
                r600_write_value(cs, 0);
                r600_write_value(cs, 0);
-               r600_write_value(cs, sample_locs_8x[2]);
-               r600_write_value(cs, sample_locs_8x[6]);
+               r600_write_value(cs, cm_sample_locs_8x[2]);
+               r600_write_value(cs, cm_sample_locs_8x[6]);
                r600_write_value(cs, 0);
                r600_write_value(cs, 0);
-               r600_write_value(cs, sample_locs_8x[3]);
-               r600_write_value(cs, sample_locs_8x[7]);
-               max_dist = max_dist_8x;
+               r600_write_value(cs, cm_sample_locs_8x[3]);
+               r600_write_value(cs, cm_sample_locs_8x[7]);
+               max_dist = cm_max_dist_8x;
                break;
        case 16:
                r600_write_context_reg_seq(cs, 
CM_R_028BF8_PA_SC_AA_SAMPLE_LOCS_PIXEL_X0Y0_0, 16);
-               r600_write_value(cs, sample_locs_16x[0]);
-               r600_write_value(cs, sample_locs_16x[4]);
-               r600_write_value(cs, sample_locs_16x[8]);
-               r600_write_value(cs, sample_locs_16x[12]);
-               r600_write_value(cs, sample_locs_16x[1]);
-               r600_write_value(cs, sample_locs_16x[5]);
-               r600_write_value(cs, sample_locs_16x[9]);
-               r600_write_value(cs, sample_locs_16x[13]);
-               r600_write_value(cs, sample_locs_16x[2]);
-               r600_write_value(cs, sample_locs_16x[6]);
-               r600_write_value(cs, sample_locs_16x[10]);
-               r600_write_value(cs, sample_locs_16x[14]);
-               r600_write_value(cs, sample_locs_16x[3]);
-               r600_write_value(cs, sample_locs_16x[7]);
-               r600_write_value(cs, sample_locs_16x[11]);
-               r600_write_value(cs, sample_locs_16x[15]);
-               max_dist = max_dist_16x;
+               r600_write_value(cs, cm_sample_locs_16x[0]);
+               r600_write_value(cs, cm_sample_locs_16x[4]);
+               r600_write_value(cs, cm_sample_locs_16x[8]);
+               r600_write_value(cs, cm_sample_locs_16x[12]);
+               r600_write_value(cs, cm_sample_locs_16x[1]);
+               r600_write_value(cs, cm_sample_locs_16x[5]);
+               r600_write_value(cs, cm_sample_locs_16x[9]);
+               r600_write_value(cs, cm_sample_locs_16x[13]);
+               r600_write_value(cs, cm_sample_locs_16x[2]);
+               r600_write_value(cs, cm_sample_locs_16x[6]);
+               r600_write_value(cs, cm_sample_locs_16x[10]);
+               r600_write_value(cs, cm_sample_locs_16x[14]);
+               r600_write_value(cs, cm_sample_locs_16x[3]);
+               r600_write_value(cs, cm_sample_locs_16x[7]);
+               r600_write_value(cs, cm_sample_locs_16x[11]);
+               r600_write_value(cs, cm_sample_locs_16x[15]);
+               max_dist = cm_max_dist_16x;
                break;
        }
 
@@ -3779,5 +3831,10 @@ void evergreen_init_state_functions(struct r600_context 
*rctx)
        rctx->context.set_framebuffer_state = evergreen_set_framebuffer_state;
        rctx->context.set_polygon_stipple = evergreen_set_polygon_stipple;
        rctx->context.set_scissor_state = evergreen_set_scissor_state;
+
+       if (rctx->chip_class == EVERGREEN)
+                rctx->context.get_sample_position = 
evergreen_get_sample_position;
+        else
+                rctx->context.get_sample_position = cayman_get_sample_position;
        evergreen_init_compute_state_functions(rctx);
 }
diff --git a/src/gallium/drivers/r600/r600_state.c 
b/src/gallium/drivers/r600/r600_state.c
index c6d98bb..5b7951b 100644
--- a/src/gallium/drivers/r600/r600_state.c
+++ b/src/gallium/drivers/r600/r600_state.c
@@ -1684,24 +1684,57 @@ static void r600_set_framebuffer_state(struct 
pipe_context *ctx,
        (((s2x) & 0xf) << 16) | (((s2y) & 0xf) << 20) |    \
         (((s3x) & 0xf) << 24) | (((s3y) & 0xf) << 28))
 
+
+static uint32_t sample_locs_2x[] = {
+        FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
+        FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
+};
+static unsigned max_dist_2x = 4;
+
+static uint32_t sample_locs_4x[] = {
+        FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
+        FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
+};
+static unsigned max_dist_4x = 6;
+static uint32_t sample_locs_8x[] = {
+        FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
+        FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
+};
+static unsigned max_dist_8x = 7;
+
+static void r600_get_sample_position(struct pipe_context *ctx,
+                                    int max_sample,
+                                    unsigned sample_index,
+                                    float *out_value)
+{
+        int offset, index;
+       switch (max_sample) {
+       case 1:
+       default:
+               out_value[0] = out_value[1] = 0.5;
+               break;
+        case 2:
+                offset = 4 * (sample_index * 2);
+                out_value[0] = (float)(((sample_locs_2x[0] >> offset) & 0xf) + 
8) / 16.0;
+                out_value[1] = (float)(((sample_locs_2x[0] >> (offset + 4)) & 
0xf) + 8) / 16.0;
+                break;               
+        case 4: {
+                offset = 4 * (sample_index * 2);
+                out_value[0] = (float)(((sample_locs_4x[0] >> offset) & 0xf) + 
8) / 16.0;
+                out_value[1] = (float)(((sample_locs_4x[0] >> (offset + 4)) & 
0xf) + 8) / 16.0;
+        }
+                break;
+        case 8:
+                offset = 4 * (sample_index % 4 * 2);
+                index = sample_index / 4;
+                out_value[0] = (float)(((sample_locs_4x[index] >> offset) & 
0xf) + 8) / 16.0;
+                out_value[1] = (float)(((sample_locs_4x[index] >> (offset + 
4)) & 0xf) + 8) / 16.0;
+                break;
+        }
+}
+
 static void r600_emit_msaa_state(struct r600_context *rctx, int nr_samples)
 {
-       static uint32_t sample_locs_2x[] = {
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-               FILL_SREG(-4, 4, 4, -4, -4, 4, 4, -4),
-       };
-       static unsigned max_dist_2x = 4;
-       static uint32_t sample_locs_4x[] = {
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-               FILL_SREG(-2, -2, 2, 2, -6, 6, 6, -6),
-       };
-       static unsigned max_dist_4x = 6;
-       static uint32_t sample_locs_8x[] = {
-               FILL_SREG(-1,  1,  1,  5,  3, -5,  5,  3),
-               FILL_SREG(-7, -1, -3, -7,  7, -3, -5,  7),
-       };
-       static unsigned max_dist_8x = 7;
-
        struct radeon_winsys_cs *cs = rctx->rings.gfx.cs;
        unsigned max_dist = 0;
 
@@ -3209,5 +3242,7 @@ void r600_init_state_functions(struct r600_context *rctx)
        rctx->context.set_framebuffer_state = r600_set_framebuffer_state;
        rctx->context.set_polygon_stipple = r600_set_polygon_stipple;
        rctx->context.set_scissor_state = r600_set_scissor_state;
+
+       rctx->context.get_sample_position = r600_get_sample_position;
 }
 /* this function must be last */
-- 
1.8.1.2

_______________________________________________
mesa-dev mailing list
mesa-dev@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/mesa-dev

Reply via email to