ilo: move internal shader interface to a new header
[mesa.git] / src / gallium / drivers / r600 / evergreen_state.c
index 6b6d93e3f83b1266b6d72b09b9bf1f513801d53d..3ebb157b530fdd4c75d7805a0702697494b6ce18 100644 (file)
@@ -970,11 +970,11 @@ static void *evergreen_create_rs_state(struct pipe_context *ctx,
 
        if (rctx->chip_class == CAYMAN) {
                r600_store_context_reg(&rs->buffer, CM_R_028BE4_PA_SU_VTX_CNTL,
-                                      S_028C08_PIX_CENTER_HALF(state->gl_rasterization_rules) |
+                                      S_028C08_PIX_CENTER_HALF(state->half_pixel_center) |
                                       S_028C08_QUANT_MODE(V_028C08_X_1_256TH));
        } else {
                r600_store_context_reg(&rs->buffer, R_028C08_PA_SU_VTX_CNTL,
-                                      S_028C08_PIX_CENTER_HALF(state->gl_rasterization_rules) |
+                                      S_028C08_PIX_CENTER_HALF(state->half_pixel_center) |
                                       S_028C08_QUANT_MODE(V_028C08_X_1_256TH));
        }
 
@@ -1047,6 +1047,8 @@ texture_buffer_sampler_view(struct r600_pipe_sampler_view *view,
        unsigned swizzle_res;
        unsigned char swizzle[4];
        const struct util_format_description *desc;
+       unsigned offset = view->base.u.buf.first_element * stride;
+       unsigned size = (view->base.u.buf.last_element - view->base.u.buf.first_element + 1) * stride;
 
        swizzle[0] = view->base.swizzle_r;
        swizzle[1] = view->base.swizzle_g;
@@ -1061,12 +1063,12 @@ texture_buffer_sampler_view(struct r600_pipe_sampler_view *view,
 
        swizzle_res = r600_get_swizzle_combined(desc->swizzle, swizzle, TRUE);
 
-       va = r600_resource_va(ctx->screen, view->base.texture);
+       va = r600_resource_va(ctx->screen, view->base.texture) + offset;
        view->tex_resource = &tmp->resource;
 
        view->skip_mip_address_reloc = true;
        view->tex_resource_words[0] = va;
-       view->tex_resource_words[1] = width0 - 1;
+       view->tex_resource_words[1] = size - 1;
        view->tex_resource_words[2] = S_030008_BASE_ADDRESS_HI(va >> 32UL) |
                S_030008_STRIDE(stride) |
                S_030008_DATA_FORMAT(format) |
@@ -1099,7 +1101,7 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx,
        uint32_t word4 = 0, yuv_format = 0, pitch = 0;
        unsigned char swizzle[4], array_mode = 0, non_disp_tiling = 0;
        unsigned height, depth, width;
-       unsigned macro_aspect, tile_split, bankh, bankw, nbanks;
+       unsigned macro_aspect, tile_split, bankh, bankw, nbanks, fmask_bankh;
        enum pipe_format pipe_format = state->format;
        struct radeon_surface_level *surflevel;
 
@@ -1186,6 +1188,7 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx,
        macro_aspect = eg_macro_tile_aspect(macro_aspect);
        bankw = eg_bank_wh(bankw);
        bankh = eg_bank_wh(bankh);
+       fmask_bankh = eg_bank_wh(tmp->fmask_bank_height);
 
        /* 128 bit formats require tile type = 1 */
        if (rscreen->chip_class == CAYMAN) {
@@ -1216,9 +1219,8 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx,
        view->tex_resource_words[2] = (surflevel[0].offset + r600_resource_va(ctx->screen, texture)) >> 8;
 
        /* TEX_RESOURCE_WORD3.MIP_ADDRESS */
-       if (texture->nr_samples > 1 && rscreen->msaa_texture_support == MSAA_TEXTURE_COMPRESSED) {
-               /* XXX the 2x and 4x cases are broken. */
-               if (tmp->is_depth || tmp->resource.b.b.nr_samples != 8) {
+       if (texture->nr_samples > 1 && rscreen->has_compressed_msaa_texturing) {
+               if (tmp->is_depth) {
                        /* disable FMASK (0 = disabled) */
                        view->tex_resource_words[3] = 0;
                        view->skip_mip_address_reloc = true;
@@ -1237,6 +1239,8 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx,
                                       S_030010_ENDIAN_SWAP(endian));
        view->tex_resource_words[5] = S_030014_BASE_ARRAY(state->u.tex.first_layer) |
                                      S_030014_LAST_ARRAY(state->u.tex.last_layer);
+       view->tex_resource_words[6] = S_030018_TILE_SPLIT(tile_split);
+
        if (texture->nr_samples > 1) {
                unsigned log_samples = util_logbase2(texture->nr_samples);
                if (rscreen->chip_class == CAYMAN) {
@@ -1244,13 +1248,14 @@ evergreen_create_sampler_view_custom(struct pipe_context *ctx,
                }
                /* LAST_LEVEL holds log2(nr_samples) for multisample textures */
                view->tex_resource_words[5] |= S_030014_LAST_LEVEL(log_samples);
+               view->tex_resource_words[6] |= S_030018_FMASK_BANK_HEIGHT(fmask_bankh);
        } else {
                view->tex_resource_words[4] |= S_030010_BASE_LEVEL(state->u.tex.first_level);
                view->tex_resource_words[5] |= S_030014_LAST_LEVEL(state->u.tex.last_level);
+               /* aniso max 16 samples */
+               view->tex_resource_words[6] |= S_030018_MAX_ANISO(4);
        }
-       /* aniso max 16 samples */
-       view->tex_resource_words[6] = (S_030018_MAX_ANISO(4)) |
-                                     (S_030018_TILE_SPLIT(tile_split));
+
        view->tex_resource_words[7] = S_03001C_DATA_FORMAT(format) |
                                      S_03001C_TYPE(V_03001C_SQ_TEX_VTX_VALID_TEXTURE) |
                                      S_03001C_BANK_WIDTH(bankw) |
@@ -1304,7 +1309,9 @@ static void evergreen_get_scissor_rect(struct r600_context *rctx,
        *br = S_028244_BR_X(br_x) | S_028244_BR_Y(br_y);
 }
 
-static void evergreen_set_scissor_state(struct pipe_context *ctx,
+static void evergreen_set_scissor_states(struct pipe_context *ctx,
+                                         unsigned start_slot,
+                                         unsigned num_scissors,
                                        const struct pipe_scissor_state *state)
 {
        struct r600_context *rctx = (struct r600_context *)ctx;
@@ -1574,7 +1581,7 @@ void evergreen_init_color_surface(struct r600_context *rctx,
                surf->cb_color_fmask = surf->cb_color_base;
                surf->cb_color_cmask = surf->cb_color_base;
        }
-       surf->cb_color_fmask_slice = S_028C88_TILE_MAX(slice);
+       surf->cb_color_fmask_slice = S_028C88_TILE_MAX(rtex->fmask_slice_tile_max);
        surf->cb_color_cmask_slice = S_028C80_TILE_MAX(rtex->cmask_slice_tile_max);
 
        surf->color_initialized = true;
@@ -1689,6 +1696,7 @@ static void evergreen_init_depth_surface(struct r600_context *rctx,
                surf->db_htile_data_base = va >> 8;
                surf->db_htile_surface = S_028ABC_HTILE_WIDTH(1) |
                                        S_028ABC_HTILE_HEIGHT(1) |
+                                       S_028ABC_FULL_CACHE(1) |
                                        S_028ABC_LINEAR(1);
                surf->db_depth_info |= S_028040_TILE_SURFACE_ENABLE(1);
                surf->db_preload_control = 0;
@@ -1868,38 +1876,78 @@ 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,
+                                    unsigned sample_count,
+                                    unsigned sample_index,
+                                    float *out_value)
+{
+       int offset, index;
+       struct {
+               int idx:4;
+       } val;
+       switch (sample_count) {
+       case 1:
+       default:
+               out_value[0] = out_value[1] = 0.5;
+               break;
+       case 2:
+               offset = 4 * (sample_index * 2);
+               val.idx = (sample_locs_2x[0] >> offset) & 0xf;
+               out_value[0] = (float)(val.idx + 8) / 16.0f;
+               val.idx = (sample_locs_2x[0] >> (offset + 4)) & 0xf;
+               out_value[1] = (float)(val.idx + 8) / 16.0f;
+               break;
+       case 4:
+               offset = 4 * (sample_index * 2);
+               val.idx = (sample_locs_4x[0] >> offset) & 0xf;
+               out_value[0] = (float)(val.idx + 8) / 16.0f;
+               val.idx = (sample_locs_4x[0] >> (offset + 4)) & 0xf;
+               out_value[1] = (float)(val.idx + 8) / 16.0f;
+               break;
+       case 8:
+               offset = 4 * (sample_index % 4 * 2);
+               index = (sample_index / 4);
+               val.idx = (sample_locs_8x[index] >> offset) & 0xf;
+               out_value[0] = (float)(val.idx + 8) / 16.0f;
+               val.idx = (sample_locs_8x[index] >> (offset + 4)) & 0xf;
+               out_value[1] = (float)(val.idx + 8) / 16.0f;
+               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 +1986,88 @@ 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,
+                                      unsigned sample_count,
+                                      unsigned sample_index,
+                                      float *out_value)
+{
+       int offset, index;
+       struct {
+               int idx:4;
+       } val;
+       switch (sample_count) {
+       case 1:
+       default:
+               out_value[0] = out_value[1] = 0.5;
+               break;
+       case 2:
+               offset = 4 * (sample_index * 2);
+               val.idx = (sample_locs_2x[0] >> offset) & 0xf;
+               out_value[0] = (float)(val.idx + 8) / 16.0f;
+               val.idx = (sample_locs_2x[0] >> (offset + 4)) & 0xf;
+               out_value[1] = (float)(val.idx + 8) / 16.0f;
+               break;
+       case 4:
+               offset = 4 * (sample_index * 2);
+               val.idx = (sample_locs_4x[0] >> offset) & 0xf;
+               out_value[0] = (float)(val.idx + 8) / 16.0f;
+               val.idx = (sample_locs_4x[0] >> (offset + 4)) & 0xf;
+               out_value[1] = (float)(val.idx + 8) / 16.0f;
+               break;
+       case 8:
+               offset = 4 * (sample_index % 4 * 2);
+               index = (sample_index / 4) * 4;
+               val.idx = (cm_sample_locs_8x[index] >> offset) & 0xf;
+               out_value[0] = (float)(val.idx + 8) / 16.0f;
+               val.idx = (cm_sample_locs_8x[index] >> (offset + 4)) & 0xf;
+               out_value[1] = (float)(val.idx + 8) / 16.0f;
+               break;
+       case 16:
+               offset = 4 * (sample_index % 4 * 2);
+               index = (sample_index / 4) * 4;
+               val.idx = (cm_sample_locs_16x[index] >> offset) & 0xf;
+               out_value[0] = (float)(val.idx + 8) / 16.0f;
+               val.idx = (cm_sample_locs_16x[index] >> (offset + 4)) & 0xf;
+               out_value[1] = (float)(val.idx + 8) / 16.0f;
+               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 +2092,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;
        }
 
@@ -2401,7 +2479,8 @@ static void evergreen_emit_constant_buffers(struct r600_context *rctx,
                                            struct r600_constbuf_state *state,
                                            unsigned buffer_id_base,
                                            unsigned reg_alu_constbuf_size,
-                                           unsigned reg_alu_const_cache)
+                                           unsigned reg_alu_const_cache,
+                                           unsigned pkt_flags)
 {
        struct radeon_winsys_cs *cs = rctx->rings.gfx.cs;
        uint32_t dirty_mask = state->dirty_mask;
@@ -2419,14 +2498,15 @@ static void evergreen_emit_constant_buffers(struct r600_context *rctx,
                va = r600_resource_va(&rctx->screen->screen, &rbuffer->b.b);
                va += cb->buffer_offset;
 
-               r600_write_context_reg(cs, reg_alu_constbuf_size + buffer_index * 4,
-                                      ALIGN_DIVUP(cb->buffer_size >> 4, 16));
-               r600_write_context_reg(cs, reg_alu_const_cache + buffer_index * 4, va >> 8);
+               r600_write_context_reg_flag(cs, reg_alu_constbuf_size + buffer_index * 4,
+                                      ALIGN_DIVUP(cb->buffer_size >> 4, 16), pkt_flags);
+               r600_write_context_reg_flag(cs, reg_alu_const_cache + buffer_index * 4, va >> 8,
+                                               pkt_flags);
 
-               r600_write_value(cs, PKT3(PKT3_NOP, 0, 0));
+               r600_write_value(cs, PKT3(PKT3_NOP, 0, 0) | pkt_flags);
                r600_write_value(cs, r600_context_bo_reloc(rctx, &rctx->rings.gfx, rbuffer, RADEON_USAGE_READ));
 
-               r600_write_value(cs, PKT3(PKT3_SET_RESOURCE, 8, 0));
+               r600_write_value(cs, PKT3(PKT3_SET_RESOURCE, 8, 0) | pkt_flags);
                r600_write_value(cs, (buffer_id_base + buffer_index) * 8);
                r600_write_value(cs, va); /* RESOURCEi_WORD0 */
                r600_write_value(cs, rbuffer->buf->size - cb->buffer_offset - 1); /* RESOURCEi_WORD1 */
@@ -2444,7 +2524,7 @@ static void evergreen_emit_constant_buffers(struct r600_context *rctx,
                r600_write_value(cs, 0); /* RESOURCEi_WORD6 */
                r600_write_value(cs, 0xc0000000); /* RESOURCEi_WORD7 */
 
-               r600_write_value(cs, PKT3(PKT3_NOP, 0, 0));
+               r600_write_value(cs, PKT3(PKT3_NOP, 0, 0) | pkt_flags);
                r600_write_value(cs, r600_context_bo_reloc(rctx, &rctx->rings.gfx, rbuffer, RADEON_USAGE_READ));
 
                dirty_mask &= ~(1 << buffer_index);
@@ -2456,21 +2536,32 @@ static void evergreen_emit_vs_constant_buffers(struct r600_context *rctx, struct
 {
        evergreen_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX], 176,
                                        R_028180_ALU_CONST_BUFFER_SIZE_VS_0,
-                                       R_028980_ALU_CONST_CACHE_VS_0);
+                                       R_028980_ALU_CONST_CACHE_VS_0,
+                                       0 /* PKT3 flags */);
 }
 
 static void evergreen_emit_gs_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
 {
        evergreen_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_GEOMETRY], 336,
                                        R_0281C0_ALU_CONST_BUFFER_SIZE_GS_0,
-                                       R_0289C0_ALU_CONST_CACHE_GS_0);
+                                       R_0289C0_ALU_CONST_CACHE_GS_0,
+                                       0 /* PKT3 flags */);
 }
 
 static void evergreen_emit_ps_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
 {
        evergreen_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT], 0,
                                       R_028140_ALU_CONST_BUFFER_SIZE_PS_0,
-                                      R_028940_ALU_CONST_CACHE_PS_0);
+                                      R_028940_ALU_CONST_CACHE_PS_0,
+                                      0 /* PKT3 flags */);
+}
+
+static void evergreen_emit_cs_constant_buffers(struct r600_context *rctx, struct r600_atom *atom)
+{
+       evergreen_emit_constant_buffers(rctx, &rctx->constbuf_state[PIPE_SHADER_COMPUTE], 816,
+                                       R_028FC0_ALU_CONST_BUFFER_SIZE_LS_0,
+                                       R_028F40_ALU_CONST_CACHE_LS_0,
+                                       RADEON_CP_PACKET3_COMPUTE_MODE);
 }
 
 static void evergreen_emit_sampler_views(struct r600_context *rctx,
@@ -2782,7 +2873,6 @@ static void cayman_init_atom_start_cs(struct r600_context *rctx)
        r600_store_value(cb, 0); /* R_0286E4_SPI_PS_IN_CONTROL_2 */
        r600_store_value(cb, 0); /* R_0286E8_SPI_COMPUTE_INPUT_CNTL */
        r600_store_context_reg(cb, R_028B54_VGT_SHADER_STAGES_EN, 0);
-       r600_store_context_reg(cb, R_028838_SQ_DYN_GPR_RESOURCE_LIMIT_1, 0);
 
        eg_store_loop_const(cb, R_03A200_SQ_LOOP_CONST_0, 0x01000FFF);
        eg_store_loop_const(cb, R_03A200_SQ_LOOP_CONST_0 + (32 * 4), 0x01000FFF);
@@ -3449,21 +3539,13 @@ void *evergreen_create_resolve_blend(struct r600_context *rctx)
 void *evergreen_create_decompress_blend(struct r600_context *rctx)
 {
        struct pipe_blend_state blend;
+       unsigned mode = rctx->screen->has_compressed_msaa_texturing ?
+                       V_028808_CB_FMASK_DECOMPRESS : V_028808_CB_DECOMPRESS;
 
        memset(&blend, 0, sizeof(blend));
        blend.independent_blend_enable = true;
        blend.rt[0].colormask = 0xf;
-       return evergreen_create_blend_state_mode(&rctx->context, &blend, V_028808_CB_DECOMPRESS);
-}
-
-void *evergreen_create_fmask_decompress_blend(struct r600_context *rctx)
-{
-       struct pipe_blend_state blend;
-
-       memset(&blend, 0, sizeof(blend));
-       blend.independent_blend_enable = true;
-       blend.rt[0].colormask = 0xf;
-       return evergreen_create_blend_state_mode(&rctx->context, &blend, V_028808_CB_FMASK_DECOMPRESS);
+       return evergreen_create_blend_state_mode(&rctx->context, &blend, mode);
 }
 
 void *evergreen_create_db_flush_dsa(struct r600_context *rctx)
@@ -3528,7 +3610,7 @@ static void evergreen_dma_copy_tile(struct r600_context *rctx,
        struct r600_texture *rdst = (struct r600_texture*)dst;
        unsigned array_mode, lbpp, pitch_tile_max, slice_tile_max, size;
        unsigned ncopy, height, cheight, detile, i, x, y, z, src_mode, dst_mode;
-       unsigned sub_cmd, bank_h, bank_w, mt_aspect, nbanks, tile_split;
+       unsigned sub_cmd, bank_h, bank_w, mt_aspect, nbanks, tile_split, non_disp_tiling = 0;
        uint64_t base, addr;
 
        /* make sure that the dma ring is only one active */
@@ -3541,6 +3623,10 @@ static void evergreen_dma_copy_tile(struct r600_context *rctx,
        dst_mode = dst_mode == RADEON_SURF_MODE_LINEAR_ALIGNED ? RADEON_SURF_MODE_LINEAR : dst_mode;
        assert(dst_mode != src_mode);
 
+       /* non_disp_tiling bit needs to be set for depth, stencil, and fmask surfaces */
+       if (util_format_has_depth(util_format_description(src->format)))
+               non_disp_tiling = 1;
+
        y = 0;
        sub_cmd = 0x8;
        lbpp = util_logbase2(bpp);
@@ -3620,7 +3706,7 @@ static void evergreen_dma_copy_tile(struct r600_context *rctx,
                cs->buf[cs->cdw++] = (pitch_tile_max << 0) | ((height - 1) << 16);
                cs->buf[cs->cdw++] = (slice_tile_max << 0);
                cs->buf[cs->cdw++] = (x << 0) | (z << 18);
-               cs->buf[cs->cdw++] = (y << 0) | (tile_split << 21) | (nbanks << 25);
+               cs->buf[cs->cdw++] = (y << 0) | (tile_split << 21) | (nbanks << 25) | (non_disp_tiling << 28);
                cs->buf[cs->cdw++] = addr & 0xfffffffc;
                cs->buf[cs->cdw++] = (addr >> 32UL) & 0xff;
                copy_height -= cheight;
@@ -3727,6 +3813,7 @@ void evergreen_init_state_functions(struct r600_context *rctx)
        r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_VERTEX].atom, id++, evergreen_emit_vs_constant_buffers, 0);
        r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_GEOMETRY].atom, id++, evergreen_emit_gs_constant_buffers, 0);
        r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_FRAGMENT].atom, id++, evergreen_emit_ps_constant_buffers, 0);
+       r600_init_atom(rctx, &rctx->constbuf_state[PIPE_SHADER_COMPUTE].atom, id++, evergreen_emit_cs_constant_buffers, 0);
        /* shader program */
        r600_init_atom(rctx, &rctx->cs_shader_state.atom, id++, evergreen_emit_cs_shader, 0);
        /* sampler */
@@ -3775,6 +3862,11 @@ void evergreen_init_state_functions(struct r600_context *rctx)
        rctx->context.create_sampler_view = evergreen_create_sampler_view;
        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;
+       rctx->context.set_scissor_states = evergreen_set_scissor_states;
+
+       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);
 }