winsys/radeon: fold cs_set_flush_callback into cs_create
[mesa.git] / src / gallium / drivers / radeonsi / si_state.c
index 6cb898490b4be937ea66ac0bf52acd8438a83738..d81354ebe8d21b7dcfb05cc1ebefb948924bcc2f 100644 (file)
@@ -78,7 +78,7 @@ static uint32_t cik_num_banks(struct si_screen *sscreen, unsigned bpe, unsigned
        }
 }
 
-static unsigned cik_tile_split(unsigned tile_split)
+unsigned cik_tile_split(unsigned tile_split)
 {
        switch (tile_split) {
        case 64:
@@ -107,7 +107,7 @@ static unsigned cik_tile_split(unsigned tile_split)
        return tile_split;
 }
 
-static unsigned cik_macro_tile_aspect(unsigned macro_tile_aspect)
+unsigned cik_macro_tile_aspect(unsigned macro_tile_aspect)
 {
        switch (macro_tile_aspect) {
        default:
@@ -127,7 +127,7 @@ static unsigned cik_macro_tile_aspect(unsigned macro_tile_aspect)
        return macro_tile_aspect;
 }
 
-static unsigned cik_bank_wh(unsigned bankwh)
+unsigned cik_bank_wh(unsigned bankwh)
 {
        switch (bankwh) {
        default:
@@ -147,7 +147,7 @@ static unsigned cik_bank_wh(unsigned bankwh)
        return bankwh;
 }
 
-static unsigned cik_db_pipe_config(struct si_screen *sscreen, unsigned tile_mode)
+unsigned cik_db_pipe_config(struct si_screen *sscreen, unsigned tile_mode)
 {
        if (sscreen->b.info.si_tile_mode_array_valid) {
                uint32_t gb_tile_mode = sscreen->b.info.si_tile_mode_array[tile_mode];
@@ -1514,7 +1514,7 @@ boolean si_is_format_supported(struct pipe_screen *screen,
        return retval == usage;
 }
 
-static unsigned si_tile_mode_index(struct r600_texture *rtex, unsigned level, bool stencil)
+unsigned si_tile_mode_index(struct r600_texture *rtex, unsigned level, bool stencil)
 {
        unsigned tile_mode_index = 0;
 
@@ -1655,10 +1655,6 @@ static void si_initialize_color_surface(struct si_context *sctx,
                }
        }
 
-       if (rtex->cmask.size) {
-               color_info |= S_028C70_FAST_CLEAR(1);
-       }
-
        offset += r600_resource_va(sctx->b.b.screen, surf->base.texture);
 
        surf->cb_color_base = offset >> 8;
@@ -1668,13 +1664,23 @@ static void si_initialize_color_surface(struct si_context *sctx,
        surf->cb_color_info = color_info;
        surf->cb_color_attrib = color_attrib;
 
-       if (rtex->cmask.size) {
-               surf->cb_color_cmask = (offset + rtex->cmask.offset) >> 8;
-               surf->cb_color_cmask_slice = S_028C80_TILE_MAX(rtex->cmask.slice_tile_max);
-       }
        if (rtex->fmask.size) {
                surf->cb_color_fmask = (offset + rtex->fmask.offset) >> 8;
                surf->cb_color_fmask_slice = S_028C88_TILE_MAX(rtex->fmask.slice_tile_max);
+       } else {
+               /* This must be set for fast clear to work without FMASK. */
+               surf->cb_color_fmask = surf->cb_color_base;
+               surf->cb_color_fmask_slice = surf->cb_color_slice;
+               surf->cb_color_attrib |= S_028C74_FMASK_TILE_MODE_INDEX(tile_mode_index);
+
+               if (sctx->b.chip_class == SI) {
+                       unsigned bankh = util_logbase2(rtex->surface.bankh);
+                       surf->cb_color_attrib |= S_028C74_FMASK_BANK_HEIGHT(bankh);
+               }
+
+               if (sctx->b.chip_class >= CIK) {
+                       surf->cb_color_pitch |= S_028C64_FMASK_TILE_MAX(pitch);
+               }
        }
 
        /* Determine pixel shader export format */
@@ -1699,7 +1705,7 @@ static void si_init_depth_surface(struct si_context *sctx,
        unsigned macro_aspect, tile_split, stile_split, bankh, bankw, nbanks, pipe_config;
        uint32_t z_info, s_info, db_depth_info;
        uint64_t z_offs, s_offs;
-       uint32_t db_htile_data_base, db_htile_surface, pa_su_poly_offset_db_fmt_cntl;
+       uint32_t db_htile_data_base, db_htile_surface, pa_su_poly_offset_db_fmt_cntl = 0;
 
        switch (sctx->framebuffer.state.zsbuf->texture->format) {
        case PIPE_FORMAT_S8_UINT_Z24_UNORM:
@@ -1874,7 +1880,7 @@ static void si_set_framebuffer_state(struct pipe_context *ctx,
                        sctx->framebuffer.export_16bpc |= 1 << i;
                }
 
-               if (rtex->fmask.size || rtex->cmask.size) {
+               if (rtex->fmask.size && rtex->cmask.size) {
                        sctx->framebuffer.compressed_cb_mask |= 1 << i;
                }
        }
@@ -1908,12 +1914,12 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
        struct radeon_winsys_cs *cs = sctx->b.rings.gfx.cs;
        struct pipe_framebuffer_state *state = &sctx->framebuffer.state;
        unsigned i, nr_cbufs = state->nr_cbufs;
+       struct r600_texture *tex = NULL;
+       struct r600_surface *cb = NULL;
 
        /* Colorbuffers. */
        for (i = 0; i < nr_cbufs; i++) {
-               struct r600_surface *cb = (struct r600_surface*)state->cbufs[i];
-               struct r600_texture *tex;
-
+               cb = (struct r600_surface*)state->cbufs[i];
                if (!cb) {
                        r600_write_context_reg(cs, R_028C70_CB_COLOR0_INFO + i * 0x3C,
                                               S_028C70_FORMAT(V_028C70_COLOR_INVALID));
@@ -1938,11 +1944,11 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
                radeon_emit(cs, cb->cb_color_pitch);    /* R_028C64_CB_COLOR0_PITCH */
                radeon_emit(cs, cb->cb_color_slice);    /* R_028C68_CB_COLOR0_SLICE */
                radeon_emit(cs, cb->cb_color_view);     /* R_028C6C_CB_COLOR0_VIEW */
-               radeon_emit(cs, cb->cb_color_info);     /* R_028C70_CB_COLOR0_INFO */
+               radeon_emit(cs, cb->cb_color_info | tex->cb_color_info); /* R_028C70_CB_COLOR0_INFO */
                radeon_emit(cs, cb->cb_color_attrib);   /* R_028C74_CB_COLOR0_ATTRIB */
                radeon_emit(cs, 0);                     /* R_028C78 unused */
-               radeon_emit(cs, cb->cb_color_cmask);    /* R_028C7C_CB_COLOR0_CMASK */
-               radeon_emit(cs, cb->cb_color_cmask_slice);      /* R_028C80_CB_COLOR0_CMASK_SLICE */
+               radeon_emit(cs, tex->cmask.base_address_reg);   /* R_028C7C_CB_COLOR0_CMASK */
+               radeon_emit(cs, tex->cmask.slice_tile_max);     /* R_028C80_CB_COLOR0_CMASK_SLICE */
                radeon_emit(cs, cb->cb_color_fmask);            /* R_028C84_CB_COLOR0_FMASK */
                radeon_emit(cs, cb->cb_color_fmask_slice);      /* R_028C88_CB_COLOR0_FMASK_SLICE */
                radeon_emit(cs, tex->color_clear_value[0]);     /* R_028C8C_CB_COLOR0_CLEAR_WORD0 */
@@ -1951,7 +1957,7 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
        /* set CB_COLOR1_INFO for possible dual-src blending */
        if (i == 1 && state->cbufs[0]) {
                r600_write_context_reg(cs, R_028C70_CB_COLOR0_INFO + 1 * 0x3C,
-                                      ((struct r600_surface*)state->cbufs[0])->cb_color_info);
+                                      cb->cb_color_info | tex->cb_color_info);
                i++;
        }
        for (; i < 8 ; i++) {
@@ -2920,18 +2926,6 @@ static void *si_create_blend_custom(struct si_context *sctx, unsigned mode)
        return si_create_blend_state_mode(&sctx->b.b, &blend, mode);
 }
 
-static boolean si_dma_copy(struct pipe_context *ctx,
-                          struct pipe_resource *dst,
-                          unsigned dst_level,
-                          unsigned dst_x, unsigned dst_y, unsigned dst_z,
-                          struct pipe_resource *src,
-                          unsigned src_level,
-                          const struct pipe_box *src_box)
-{
-       /* XXX implement this or share evergreen_dma_blit with r600g */
-       return FALSE;
-}
-
 static void si_set_occlusion_query_state(struct pipe_context *ctx, bool enable)
 {
        /* XXX Turn this into a proper state. Right now the queries are
@@ -2972,6 +2966,7 @@ void si_init_state_functions(struct si_context *sctx)
        sctx->custom_dsa_flush_inplace = si_create_db_flush_dsa(sctx, false, false, 0);
        sctx->custom_blend_resolve = si_create_blend_custom(sctx, V_028808_CB_RESOLVE);
        sctx->custom_blend_decompress = si_create_blend_custom(sctx, V_028808_CB_FMASK_DECOMPRESS);
+       sctx->custom_blend_fastclear = si_create_blend_custom(sctx, V_028808_CB_ELIMINATE_FAST_CLEAR);
 
        sctx->b.b.set_clip_state = si_set_clip_state;
        sctx->b.b.set_scissor_states = si_set_scissor_states;
@@ -3057,7 +3052,6 @@ void si_init_config(struct si_context *sctx)
        si_pm4_set_reg(pm4, R_028B68_VGT_GS_VERT_ITEMSIZE_3, 0);
        si_pm4_set_reg(pm4, R_028B90_VGT_GS_INSTANCE_CNT, 0);
 
-       si_pm4_set_reg(pm4, R_028B94_VGT_STRMOUT_CONFIG, 0x0);
        si_pm4_set_reg(pm4, R_028B98_VGT_STRMOUT_BUFFER_CONFIG, 0x0);
        if (sctx->b.chip_class == SI) {
                si_pm4_set_reg(pm4, R_028AA8_IA_MULTI_VGT_PARAM,