radeonsi: use r600_resource() typecast helper
[mesa.git] / src / gallium / drivers / radeonsi / si_state.c
index b5fe6726b9a7b6a87a9424351f2f82ad0a374524..41c614ab7e9b77b1ff36ece511a828a0eeea1ff5 100644 (file)
 #include "util/u_resource.h"
 #include "util/u_upload_mgr.h"
 
-/* Initialize an external atom (owned by ../radeon). */
-static void
-si_init_external_atom(struct si_context *sctx, struct r600_atom *atom,
-                     struct r600_atom **list_elem)
-{
-       atom->id = list_elem - sctx->atoms.array;
-       *list_elem = atom;
-}
-
-/* Initialize an atom owned by radeonsi.  */
-void si_init_atom(struct si_context *sctx, struct r600_atom *atom,
-                 struct r600_atom **list_elem,
-                 void (*emit_func)(struct si_context *ctx, struct r600_atom *state))
-{
-       atom->emit = emit_func;
-       atom->id = list_elem - sctx->atoms.array;
-       *list_elem = atom;
-}
-
 static unsigned si_map_swizzle(unsigned swizzle)
 {
        switch (swizzle) {
@@ -83,7 +64,7 @@ static unsigned si_pack_float_12p4(float x)
  * CB_TARGET_MASK is emitted here to avoid a hang with dual source blending
  * if there is not enough PS outputs.
  */
-static void si_emit_cb_render_state(struct si_context *sctx, struct r600_atom *atom)
+static void si_emit_cb_render_state(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
        struct si_state_blend *blend = sctx->queued.named.blend;
@@ -672,7 +653,7 @@ static void si_bind_blend_state(struct pipe_context *ctx, void *state)
            (old_blend->blend_enable_4bit != blend->blend_enable_4bit &&
             sctx->framebuffer.nr_samples >= 2 &&
             sctx->screen->dcc_msaa_allowed))
-               si_mark_atom_dirty(sctx, &sctx->cb_render_state);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.cb_render_state);
 
        if (!old_blend ||
            old_blend->cb_target_mask != blend->cb_target_mask ||
@@ -688,7 +669,7 @@ static void si_bind_blend_state(struct pipe_context *ctx, void *state)
             old_blend->alpha_to_coverage != blend->alpha_to_coverage ||
             old_blend->blend_enable_4bit != blend->blend_enable_4bit ||
             old_blend->cb_target_enabled_4bit != blend->cb_target_enabled_4bit))
-               si_mark_atom_dirty(sctx, &sctx->dpbb_state);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.dpbb_state);
 
        if (sctx->screen->has_out_of_order_rast &&
            (!old_blend ||
@@ -696,7 +677,7 @@ static void si_bind_blend_state(struct pipe_context *ctx, void *state)
              old_blend->cb_target_enabled_4bit != blend->cb_target_enabled_4bit ||
              old_blend->commutative_4bit != blend->commutative_4bit ||
              old_blend->logicop_enable != blend->logicop_enable)))
-               si_mark_atom_dirty(sctx, &sctx->msaa_config);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
 }
 
 static void si_delete_blend_state(struct pipe_context *ctx, void *state)
@@ -713,10 +694,10 @@ static void si_set_blend_color(struct pipe_context *ctx,
 
        sctx->blend_color.state = *state;
        sctx->blend_color.any_nonzeros = memcmp(state, &zeros, sizeof(*state)) != 0;
-       si_mark_atom_dirty(sctx, &sctx->blend_color.atom);
+       si_mark_atom_dirty(sctx, &sctx->atoms.s.blend_color);
 }
 
-static void si_emit_blend_color(struct si_context *sctx, struct r600_atom *atom)
+static void si_emit_blend_color(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
 
@@ -740,7 +721,7 @@ static void si_set_clip_state(struct pipe_context *ctx,
 
        sctx->clip_state.state = *state;
        sctx->clip_state.any_nonzeros = memcmp(state, &zeros, sizeof(*state)) != 0;
-       si_mark_atom_dirty(sctx, &sctx->clip_state.atom);
+       si_mark_atom_dirty(sctx, &sctx->atoms.s.clip_state);
 
        cb.buffer = NULL;
        cb.user_buffer = state->ucp;
@@ -750,7 +731,7 @@ static void si_set_clip_state(struct pipe_context *ctx,
        pipe_resource_reference(&cb.buffer, NULL);
 }
 
-static void si_emit_clip_state(struct si_context *sctx, struct r600_atom *atom)
+static void si_emit_clip_state(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
 
@@ -758,7 +739,7 @@ static void si_emit_clip_state(struct si_context *sctx, struct r600_atom *atom)
        radeon_emit_array(cs, (uint32_t*)sctx->clip_state.state.ucp, 6*4);
 }
 
-static void si_emit_clip_regs(struct si_context *sctx, struct r600_atom *atom)
+static void si_emit_clip_regs(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
        struct si_shader *vs = si_get_vs_state(sctx);
@@ -1006,12 +987,12 @@ static void si_bind_rs_state(struct pipe_context *ctx, void *state)
                return;
 
        if (!old_rs || old_rs->multisample_enable != rs->multisample_enable) {
-               si_mark_atom_dirty(sctx, &sctx->db_render_state);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.db_render_state);
 
                /* Update the small primitive filter workaround if necessary. */
                if (sctx->screen->has_msaa_sample_loc_bug &&
                    sctx->framebuffer.nr_samples > 1)
-                       si_mark_atom_dirty(sctx, &sctx->msaa_sample_locs.atom);
+                       si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_sample_locs);
        }
 
        sctx->current_vs_state &= C_VS_STATE_CLAMP_VERTEX_COLOR;
@@ -1025,19 +1006,19 @@ static void si_bind_rs_state(struct pipe_context *ctx, void *state)
             old_rs->line_width != rs->line_width ||
             old_rs->max_point_size != rs->max_point_size)) {
                sctx->scissors.dirty_mask = (1 << SI_MAX_VIEWPORTS) - 1;
-               si_mark_atom_dirty(sctx, &sctx->scissors.atom);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.scissors);
        }
 
        if (!old_rs ||
            old_rs->clip_halfz != rs->clip_halfz) {
                sctx->viewports.depth_range_dirty_mask = (1 << SI_MAX_VIEWPORTS) - 1;
-               si_mark_atom_dirty(sctx, &sctx->viewports.atom);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.viewports);
        }
 
        if (!old_rs ||
            old_rs->clip_plane_enable != rs->clip_plane_enable ||
            old_rs->pa_cl_clip_cntl != rs->pa_cl_clip_cntl)
-               si_mark_atom_dirty(sctx, &sctx->clip_regs);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.clip_regs);
 
        sctx->ia_multi_vgt_param_key.u.line_stipple_enabled =
                rs->line_stipple_enable;
@@ -1072,7 +1053,7 @@ static void si_delete_rs_state(struct pipe_context *ctx, void *state)
 /*
  * infeered state between dsa and stencil ref
  */
-static void si_emit_stencil_ref(struct si_context *sctx, struct r600_atom *atom)
+static void si_emit_stencil_ref(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
        struct pipe_stencil_ref *ref = &sctx->stencil_ref.state;
@@ -1098,7 +1079,7 @@ static void si_set_stencil_ref(struct pipe_context *ctx,
                return;
 
        sctx->stencil_ref.state = *state;
-       si_mark_atom_dirty(sctx, &sctx->stencil_ref.atom);
+       si_mark_atom_dirty(sctx, &sctx->atoms.s.stencil_ref);
 }
 
 
@@ -1286,7 +1267,7 @@ static void si_bind_dsa_state(struct pipe_context *ctx, void *state)
        if (memcmp(&dsa->stencil_ref, &sctx->stencil_ref.dsa_part,
                   sizeof(struct si_dsa_stencil_ref_part)) != 0) {
                sctx->stencil_ref.dsa_part = dsa->stencil_ref;
-               si_mark_atom_dirty(sctx, &sctx->stencil_ref.atom);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.stencil_ref);
        }
 
        if (!old_dsa || old_dsa->alpha_func != dsa->alpha_func)
@@ -1297,13 +1278,13 @@ static void si_bind_dsa_state(struct pipe_context *ctx, void *state)
             (old_dsa->depth_enabled != dsa->depth_enabled ||
              old_dsa->stencil_enabled != dsa->stencil_enabled ||
              old_dsa->db_can_write != dsa->db_can_write)))
-               si_mark_atom_dirty(sctx, &sctx->dpbb_state);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.dpbb_state);
 
        if (sctx->screen->has_out_of_order_rast &&
            (!old_dsa ||
             memcmp(old_dsa->order_invariance, dsa->order_invariance,
                    sizeof(old_dsa->order_invariance))))
-               si_mark_atom_dirty(sctx, &sctx->msaa_config);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
 }
 
 static void si_delete_dsa_state(struct pipe_context *ctx, void *state)
@@ -1337,19 +1318,19 @@ static void si_set_active_query_state(struct pipe_context *ctx, boolean enable)
        /* Occlusion queries. */
        if (sctx->occlusion_queries_disabled != !enable) {
                sctx->occlusion_queries_disabled = !enable;
-               si_mark_atom_dirty(sctx, &sctx->db_render_state);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.db_render_state);
        }
 }
 
 void si_set_occlusion_query_state(struct si_context *sctx,
                                  bool old_perfect_enable)
 {
-       si_mark_atom_dirty(sctx, &sctx->db_render_state);
+       si_mark_atom_dirty(sctx, &sctx->atoms.s.db_render_state);
 
        bool perfect_enable = sctx->num_perfect_occlusion_queries != 0;
 
        if (perfect_enable != old_perfect_enable)
-               si_mark_atom_dirty(sctx, &sctx->msaa_config);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
 }
 
 void si_save_qbo_state(struct si_context *sctx, struct si_qbo_state *st)
@@ -1360,7 +1341,7 @@ void si_save_qbo_state(struct si_context *sctx, struct si_qbo_state *st)
        si_get_shader_buffers(sctx, PIPE_SHADER_COMPUTE, 0, 3, st->saved_ssbo);
 }
 
-static void si_emit_db_render_state(struct si_context *sctx, struct r600_atom *state)
+static void si_emit_db_render_state(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
        struct si_state_rasterizer *rs = sctx->queued.named.rasterizer;
@@ -2895,24 +2876,24 @@ static void si_set_framebuffer_state(struct pipe_context *ctx,
 
        si_update_ps_colorbuf0_slot(sctx);
        si_update_poly_offset_state(sctx);
-       si_mark_atom_dirty(sctx, &sctx->cb_render_state);
-       si_mark_atom_dirty(sctx, &sctx->framebuffer.atom);
+       si_mark_atom_dirty(sctx, &sctx->atoms.s.cb_render_state);
+       si_mark_atom_dirty(sctx, &sctx->atoms.s.framebuffer);
 
        if (sctx->screen->dpbb_allowed)
-               si_mark_atom_dirty(sctx, &sctx->dpbb_state);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.dpbb_state);
 
        if (sctx->framebuffer.any_dst_linear != old_any_dst_linear)
-               si_mark_atom_dirty(sctx, &sctx->msaa_config);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
 
        if (sctx->screen->has_out_of_order_rast &&
            (sctx->framebuffer.colorbuf_enabled_4bit != old_colorbuf_enabled_4bit ||
             !!sctx->framebuffer.state.zsbuf != old_has_zsbuf ||
             (zstex && zstex->surface.has_stencil != old_has_stencil)))
-               si_mark_atom_dirty(sctx, &sctx->msaa_config);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
 
        if (sctx->framebuffer.nr_samples != old_nr_samples) {
-               si_mark_atom_dirty(sctx, &sctx->msaa_config);
-               si_mark_atom_dirty(sctx, &sctx->db_render_state);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.db_render_state);
 
                /* Set sample locations as fragment shader constants. */
                switch (sctx->framebuffer.nr_samples) {
@@ -2939,7 +2920,7 @@ static void si_set_framebuffer_state(struct pipe_context *ctx,
                constbuf.buffer_size = sctx->framebuffer.nr_samples * 2 * 4;
                si_set_rw_buffer(sctx, SI_PS_CONST_SAMPLE_POSITIONS, &constbuf);
 
-               si_mark_atom_dirty(sctx, &sctx->msaa_sample_locs.atom);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_sample_locs);
        }
 
        sctx->do_update_shaders = true;
@@ -2952,7 +2933,7 @@ static void si_set_framebuffer_state(struct pipe_context *ctx,
        }
 }
 
-static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom *atom)
+static void si_emit_framebuffer_state(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
        struct pipe_framebuffer_state *state = &sctx->framebuffer.state;
@@ -2963,7 +2944,7 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
 
        /* Colorbuffers. */
        for (i = 0; i < nr_cbufs; i++) {
-               uint64_t cb_color_base, cb_color_fmask, cb_dcc_base;
+               uint64_t cb_color_base, cb_color_fmask, cb_color_cmask, cb_dcc_base;
                unsigned cb_color_attrib;
 
                if (!(sctx->framebuffer.dirty_cbufs & (1 << i)))
@@ -2998,10 +2979,14 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
                /* Compute mutable surface parameters. */
                cb_color_base = tex->resource.gpu_address >> 8;
                cb_color_fmask = 0;
+               cb_color_cmask = tex->cmask.base_address_reg;
                cb_dcc_base = 0;
                cb_color_info = cb->cb_color_info | tex->cb_color_info;
                cb_color_attrib = cb->cb_color_attrib;
 
+               if (cb->base.u.tex.level > 0)
+                       cb_color_info &= C_028C70_FAST_CLEAR;
+
                if (tex->fmask.size) {
                        cb_color_fmask = (tex->resource.gpu_address + tex->fmask.offset) >> 8;
                        cb_color_fmask |= tex->fmask.tile_swizzle;
@@ -3035,6 +3020,8 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
                        cb_color_base |= tex->surface.tile_swizzle;
                        if (!tex->fmask.size)
                                cb_color_fmask = cb_color_base;
+                       if (cb->base.u.tex.level > 0)
+                               cb_color_cmask = cb_color_base;
                        cb_color_attrib |= S_028C74_COLOR_SW_MODE(tex->surface.u.gfx9.surf.swizzle_mode) |
                                           S_028C74_FMASK_SW_MODE(tex->surface.u.gfx9.fmask.swizzle_mode) |
                                           S_028C74_RB_ALIGNED(meta.rb_aligned) |
@@ -3048,8 +3035,8 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
                        radeon_emit(cs, cb_color_info);         /* CB_COLOR0_INFO */
                        radeon_emit(cs, cb_color_attrib);       /* CB_COLOR0_ATTRIB */
                        radeon_emit(cs, cb->cb_dcc_control);    /* CB_COLOR0_DCC_CONTROL */
-                       radeon_emit(cs, tex->cmask.base_address_reg); /* CB_COLOR0_CMASK */
-                       radeon_emit(cs, S_028C80_BASE_256B(tex->cmask.base_address_reg >> 32)); /* CB_COLOR0_CMASK_BASE_EXT */
+                       radeon_emit(cs, cb_color_cmask);        /* CB_COLOR0_CMASK */
+                       radeon_emit(cs, S_028C80_BASE_256B(cb_color_cmask >> 32)); /* CB_COLOR0_CMASK_BASE_EXT */
                        radeon_emit(cs, cb_color_fmask);        /* CB_COLOR0_FMASK */
                        radeon_emit(cs, S_028C88_BASE_256B(cb_color_fmask >> 32)); /* CB_COLOR0_FMASK_BASE_EXT */
                        radeon_emit(cs, tex->color_clear_value[0]); /* CB_COLOR0_CLEAR_WORD0 */
@@ -3073,6 +3060,8 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
 
                        if (!tex->fmask.size)
                                cb_color_fmask = cb_color_base;
+                       if (cb->base.u.tex.level > 0)
+                               cb_color_cmask = cb_color_base;
                        if (cb_dcc_base)
                                cb_dcc_base += level_info->dcc_offset >> 8;
 
@@ -3107,7 +3096,7 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
                        radeon_emit(cs, cb_color_info);         /* CB_COLOR0_INFO */
                        radeon_emit(cs, cb_color_attrib);       /* CB_COLOR0_ATTRIB */
                        radeon_emit(cs, cb->cb_dcc_control);    /* CB_COLOR0_DCC_CONTROL */
-                       radeon_emit(cs, tex->cmask.base_address_reg);   /* CB_COLOR0_CMASK */
+                       radeon_emit(cs, cb_color_cmask);        /* CB_COLOR0_CMASK */
                        radeon_emit(cs, tex->cmask.slice_tile_max);     /* CB_COLOR0_CMASK_SLICE */
                        radeon_emit(cs, cb_color_fmask);                /* CB_COLOR0_FMASK */
                        radeon_emit(cs, cb_color_fmask_slice);          /* CB_COLOR0_FMASK_SLICE */
@@ -3201,8 +3190,7 @@ static void si_emit_framebuffer_state(struct si_context *sctx, struct r600_atom
        sctx->framebuffer.dirty_zsbuf = false;
 }
 
-static void si_emit_msaa_sample_locs(struct si_context *sctx,
-                                    struct r600_atom *atom)
+static void si_emit_msaa_sample_locs(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
        unsigned nr_samples = sctx->framebuffer.nr_samples;
@@ -3220,8 +3208,8 @@ static void si_emit_msaa_sample_locs(struct si_context *sctx,
        if (has_msaa_sample_loc_bug)
                nr_samples = MAX2(nr_samples, 1);
 
-       if (nr_samples != sctx->msaa_sample_locs.nr_samples) {
-               sctx->msaa_sample_locs.nr_samples = nr_samples;
+       if (nr_samples != sctx->sample_locs_num_samples) {
+               sctx->sample_locs_num_samples = nr_samples;
                si_emit_sample_locations(cs, nr_samples);
        }
 
@@ -3313,7 +3301,7 @@ static bool si_out_of_order_rasterization(struct si_context *sctx)
        return true;
 }
 
-static void si_emit_msaa_config(struct si_context *sctx, struct r600_atom *atom)
+static void si_emit_msaa_config(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
        unsigned num_tile_pipes = sctx->screen->info.num_tile_pipes;
@@ -3408,9 +3396,9 @@ static void si_emit_msaa_config(struct si_context *sctx, struct r600_atom *atom)
 void si_update_ps_iter_samples(struct si_context *sctx)
 {
        if (sctx->framebuffer.nr_samples > 1)
-               si_mark_atom_dirty(sctx, &sctx->msaa_config);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.msaa_config);
        if (sctx->screen->dpbb_allowed)
-               si_mark_atom_dirty(sctx, &sctx->dpbb_state);
+               si_mark_atom_dirty(sctx, &sctx->atoms.s.dpbb_state);
 }
 
 static void si_set_min_samples(struct pipe_context *ctx, unsigned min_samples)
@@ -3734,9 +3722,7 @@ si_make_texture_descriptor(struct si_screen *screen,
        }
 
        if (tex->dcc_offset) {
-               unsigned swap = si_translate_colorswap(pipe_format, false);
-
-               state[6] = S_008F28_ALPHA_IS_ON_MSB(swap <= 1);
+               state[6] = S_008F28_ALPHA_IS_ON_MSB(vi_alpha_is_on_msb(pipe_format));
        } else {
                /* The last dword is unused by hw. The shader uses it to clear
                 * bits in the first dword of sampler state.
@@ -3866,7 +3852,7 @@ si_create_sampler_view_custom(struct pipe_context *ctx,
        /* Buffer resource. */
        if (texture->target == PIPE_BUFFER) {
                si_make_buffer_descriptor(sctx->screen,
-                                         (struct r600_resource *)texture,
+                                         r600_resource(texture),
                                          state->format,
                                          state->u.buf.offset,
                                          state->u.buf.size,
@@ -4164,17 +4150,17 @@ static void si_set_sample_mask(struct pipe_context *ctx, unsigned sample_mask)
 {
        struct si_context *sctx = (struct si_context *)ctx;
 
-       if (sctx->sample_mask.sample_mask == (uint16_t)sample_mask)
+       if (sctx->sample_mask == (uint16_t)sample_mask)
                return;
 
-       sctx->sample_mask.sample_mask = sample_mask;
-       si_mark_atom_dirty(sctx, &sctx->sample_mask.atom);
+       sctx->sample_mask = sample_mask;
+       si_mark_atom_dirty(sctx, &sctx->atoms.s.sample_mask);
 }
 
-static void si_emit_sample_mask(struct si_context *sctx, struct r600_atom *atom)
+static void si_emit_sample_mask(struct si_context *sctx)
 {
        struct radeon_winsys_cs *cs = sctx->gfx_cs;
-       unsigned mask = sctx->sample_mask.sample_mask;
+       unsigned mask = sctx->sample_mask;
 
        /* Needed for line and polygon smoothing as well as for the Polaris
         * small primitive filter. We expect the state tracker to take care of
@@ -4524,23 +4510,17 @@ static void si_init_config(struct si_context *sctx);
 
 void si_init_state_functions(struct si_context *sctx)
 {
-       si_init_external_atom(sctx, &sctx->render_cond_atom, &sctx->atoms.s.render_cond);
-       si_init_external_atom(sctx, &sctx->streamout.begin_atom, &sctx->atoms.s.streamout_begin);
-       si_init_external_atom(sctx, &sctx->streamout.enable_atom, &sctx->atoms.s.streamout_enable);
-       si_init_external_atom(sctx, &sctx->scissors.atom, &sctx->atoms.s.scissors);
-       si_init_external_atom(sctx, &sctx->viewports.atom, &sctx->atoms.s.viewports);
-
-       si_init_atom(sctx, &sctx->framebuffer.atom, &sctx->atoms.s.framebuffer, si_emit_framebuffer_state);
-       si_init_atom(sctx, &sctx->msaa_sample_locs.atom, &sctx->atoms.s.msaa_sample_locs, si_emit_msaa_sample_locs);
-       si_init_atom(sctx, &sctx->db_render_state, &sctx->atoms.s.db_render_state, si_emit_db_render_state);
-       si_init_atom(sctx, &sctx->dpbb_state, &sctx->atoms.s.dpbb_state, si_emit_dpbb_state);
-       si_init_atom(sctx, &sctx->msaa_config, &sctx->atoms.s.msaa_config, si_emit_msaa_config);
-       si_init_atom(sctx, &sctx->sample_mask.atom, &sctx->atoms.s.sample_mask, si_emit_sample_mask);
-       si_init_atom(sctx, &sctx->cb_render_state, &sctx->atoms.s.cb_render_state, si_emit_cb_render_state);
-       si_init_atom(sctx, &sctx->blend_color.atom, &sctx->atoms.s.blend_color, si_emit_blend_color);
-       si_init_atom(sctx, &sctx->clip_regs, &sctx->atoms.s.clip_regs, si_emit_clip_regs);
-       si_init_atom(sctx, &sctx->clip_state.atom, &sctx->atoms.s.clip_state, si_emit_clip_state);
-       si_init_atom(sctx, &sctx->stencil_ref.atom, &sctx->atoms.s.stencil_ref, si_emit_stencil_ref);
+       sctx->atoms.s.framebuffer.emit = si_emit_framebuffer_state;
+       sctx->atoms.s.msaa_sample_locs.emit = si_emit_msaa_sample_locs;
+       sctx->atoms.s.db_render_state.emit = si_emit_db_render_state;
+       sctx->atoms.s.dpbb_state.emit = si_emit_dpbb_state;
+       sctx->atoms.s.msaa_config.emit = si_emit_msaa_config;
+       sctx->atoms.s.sample_mask.emit = si_emit_sample_mask;
+       sctx->atoms.s.cb_render_state.emit = si_emit_cb_render_state;
+       sctx->atoms.s.blend_color.emit = si_emit_blend_color;
+       sctx->atoms.s.clip_regs.emit = si_emit_clip_regs;
+       sctx->atoms.s.clip_state.emit = si_emit_clip_state;
+       sctx->atoms.s.stencil_ref.emit = si_emit_stencil_ref;
 
        sctx->b.create_blend_state = si_create_blend_state;
        sctx->b.bind_blend_state = si_bind_blend_state;
@@ -4621,213 +4601,35 @@ si_write_harvested_raster_configs(struct si_context *sctx,
                                  unsigned raster_config,
                                  unsigned raster_config_1)
 {
-       unsigned sh_per_se = MAX2(sctx->screen->info.max_sh_per_se, 1);
        unsigned num_se = MAX2(sctx->screen->info.max_se, 1);
-       unsigned rb_mask = sctx->screen->info.enabled_rb_mask;
-       unsigned num_rb = MIN2(sctx->screen->info.num_render_backends, 16);
-       unsigned rb_per_pkr = MIN2(num_rb / num_se / sh_per_se, 2);
-       unsigned rb_per_se = num_rb / num_se;
-       unsigned se_mask[4];
+       unsigned raster_config_se[4];
        unsigned se;
 
-       se_mask[0] = ((1 << rb_per_se) - 1);
-       se_mask[1] = (se_mask[0] << rb_per_se);
-       se_mask[2] = (se_mask[1] << rb_per_se);
-       se_mask[3] = (se_mask[2] << rb_per_se);
-
-       se_mask[0] &= rb_mask;
-       se_mask[1] &= rb_mask;
-       se_mask[2] &= rb_mask;
-       se_mask[3] &= rb_mask;
-
-       assert(num_se == 1 || num_se == 2 || num_se == 4);
-       assert(sh_per_se == 1 || sh_per_se == 2);
-       assert(rb_per_pkr == 1 || rb_per_pkr == 2);
-
-       /* XXX: I can't figure out what the *_XSEL and *_YSEL
-        * fields are for, so I'm leaving them as their default
-        * values. */
+       ac_get_harvested_configs(&sctx->screen->info,
+                                raster_config,
+                                &raster_config_1,
+                                raster_config_se);
 
        for (se = 0; se < num_se; se++) {
-               unsigned raster_config_se = raster_config;
-               unsigned pkr0_mask = ((1 << rb_per_pkr) - 1) << (se * rb_per_se);
-               unsigned pkr1_mask = pkr0_mask << rb_per_pkr;
-               int idx = (se / 2) * 2;
-
-               if ((num_se > 1) && (!se_mask[idx] || !se_mask[idx + 1])) {
-                       raster_config_se &= C_028350_SE_MAP;
-
-                       if (!se_mask[idx]) {
-                               raster_config_se |=
-                                       S_028350_SE_MAP(V_028350_RASTER_CONFIG_SE_MAP_3);
-                       } else {
-                               raster_config_se |=
-                                       S_028350_SE_MAP(V_028350_RASTER_CONFIG_SE_MAP_0);
-                       }
-               }
-
-               pkr0_mask &= rb_mask;
-               pkr1_mask &= rb_mask;
-               if (rb_per_se > 2 && (!pkr0_mask || !pkr1_mask)) {
-                       raster_config_se &= C_028350_PKR_MAP;
-
-                       if (!pkr0_mask) {
-                               raster_config_se |=
-                                       S_028350_PKR_MAP(V_028350_RASTER_CONFIG_PKR_MAP_3);
-                       } else {
-                               raster_config_se |=
-                                       S_028350_PKR_MAP(V_028350_RASTER_CONFIG_PKR_MAP_0);
-                       }
-               }
-
-               if (rb_per_se >= 2) {
-                       unsigned rb0_mask = 1 << (se * rb_per_se);
-                       unsigned rb1_mask = rb0_mask << 1;
-
-                       rb0_mask &= rb_mask;
-                       rb1_mask &= rb_mask;
-                       if (!rb0_mask || !rb1_mask) {
-                               raster_config_se &= C_028350_RB_MAP_PKR0;
-
-                               if (!rb0_mask) {
-                                       raster_config_se |=
-                                               S_028350_RB_MAP_PKR0(V_028350_RASTER_CONFIG_RB_MAP_3);
-                               } else {
-                                       raster_config_se |=
-                                               S_028350_RB_MAP_PKR0(V_028350_RASTER_CONFIG_RB_MAP_0);
-                               }
-                       }
-
-                       if (rb_per_se > 2) {
-                               rb0_mask = 1 << (se * rb_per_se + rb_per_pkr);
-                               rb1_mask = rb0_mask << 1;
-                               rb0_mask &= rb_mask;
-                               rb1_mask &= rb_mask;
-                               if (!rb0_mask || !rb1_mask) {
-                                       raster_config_se &= C_028350_RB_MAP_PKR1;
-
-                                       if (!rb0_mask) {
-                                               raster_config_se |=
-                                                       S_028350_RB_MAP_PKR1(V_028350_RASTER_CONFIG_RB_MAP_3);
-                                       } else {
-                                               raster_config_se |=
-                                                       S_028350_RB_MAP_PKR1(V_028350_RASTER_CONFIG_RB_MAP_0);
-                                       }
-                               }
-                       }
-               }
-
                si_set_grbm_gfx_index_se(sctx, pm4, se);
-               si_pm4_set_reg(pm4, R_028350_PA_SC_RASTER_CONFIG, raster_config_se);
+               si_pm4_set_reg(pm4, R_028350_PA_SC_RASTER_CONFIG, raster_config_se[se]);
        }
        si_set_grbm_gfx_index(sctx, pm4, ~0);
 
        if (sctx->chip_class >= CIK) {
-               if ((num_se > 2) && ((!se_mask[0] && !se_mask[1]) ||
-                                    (!se_mask[2] && !se_mask[3]))) {
-                       raster_config_1 &= C_028354_SE_PAIR_MAP;
-
-                       if (!se_mask[0] && !se_mask[1]) {
-                               raster_config_1 |=
-                                       S_028354_SE_PAIR_MAP(V_028354_RASTER_CONFIG_SE_PAIR_MAP_3);
-                       } else {
-                               raster_config_1 |=
-                                       S_028354_SE_PAIR_MAP(V_028354_RASTER_CONFIG_SE_PAIR_MAP_0);
-                       }
-               }
-
                si_pm4_set_reg(pm4, R_028354_PA_SC_RASTER_CONFIG_1, raster_config_1);
        }
 }
 
 static void si_set_raster_config(struct si_context *sctx, struct si_pm4_state *pm4)
 {
-       struct si_screen *sscreen = sctx->screen;
        unsigned num_rb = MIN2(sctx->screen->info.num_render_backends, 16);
        unsigned rb_mask = sctx->screen->info.enabled_rb_mask;
        unsigned raster_config, raster_config_1;
 
-       switch (sctx->family) {
-       case CHIP_TAHITI:
-       case CHIP_PITCAIRN:
-               raster_config = 0x2a00126a;
-               raster_config_1 = 0x00000000;
-               break;
-       case CHIP_VERDE:
-               raster_config = 0x0000124a;
-               raster_config_1 = 0x00000000;
-               break;
-       case CHIP_OLAND:
-               raster_config = 0x00000082;
-               raster_config_1 = 0x00000000;
-               break;
-       case CHIP_HAINAN:
-               raster_config = 0x00000000;
-               raster_config_1 = 0x00000000;
-               break;
-       case CHIP_BONAIRE:
-               raster_config = 0x16000012;
-               raster_config_1 = 0x00000000;
-               break;
-       case CHIP_HAWAII:
-               raster_config = 0x3a00161a;
-               raster_config_1 = 0x0000002e;
-               break;
-       case CHIP_FIJI:
-               if (sscreen->info.cik_macrotile_mode_array[0] == 0x000000e8) {
-                       /* old kernels with old tiling config */
-                       raster_config = 0x16000012;
-                       raster_config_1 = 0x0000002a;
-               } else {
-                       raster_config = 0x3a00161a;
-                       raster_config_1 = 0x0000002e;
-               }
-               break;
-       case CHIP_VEGAM:
-               raster_config = 0x3a00161a;
-               raster_config_1 = 0x0000002e;
-               break;
-       case CHIP_POLARIS10:
-               raster_config = 0x16000012;
-               raster_config_1 = 0x0000002a;
-               break;
-       case CHIP_POLARIS11:
-       case CHIP_POLARIS12:
-               raster_config = 0x16000012;
-               raster_config_1 = 0x00000000;
-               break;
-       case CHIP_TONGA:
-               raster_config = 0x16000012;
-               raster_config_1 = 0x0000002a;
-               break;
-       case CHIP_ICELAND:
-               if (num_rb == 1)
-                       raster_config = 0x00000000;
-               else
-                       raster_config = 0x00000002;
-               raster_config_1 = 0x00000000;
-               break;
-       case CHIP_CARRIZO:
-               raster_config = 0x00000002;
-               raster_config_1 = 0x00000000;
-               break;
-       case CHIP_KAVERI:
-               /* KV should be 0x00000002, but that causes problems with radeon */
-               raster_config = 0x00000000; /* 0x00000002 */
-               raster_config_1 = 0x00000000;
-               break;
-       case CHIP_KABINI:
-       case CHIP_MULLINS:
-       case CHIP_STONEY:
-               raster_config = 0x00000000;
-               raster_config_1 = 0x00000000;
-               break;
-       default:
-               fprintf(stderr,
-                       "radeonsi: Unknown GPU, using 0 for raster_config\n");
-               raster_config = 0x00000000;
-               raster_config_1 = 0x00000000;
-       }
+       ac_get_raster_config(&sctx->screen->info,
+                            &raster_config,
+                            &raster_config_1);
 
        if (!rb_mask || util_bitcount(rb_mask) >= num_rb) {
                /* Always use the default config when all backends are enabled