From 4b7961da770f7a90ab7bbe4ca7dfd0cb1c6a5b43 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Nicolai=20H=C3=A4hnle?= Date: Thu, 30 Jun 2016 16:25:39 +0200 Subject: [PATCH] radeonsi: extract DB->CB copy logic into its own function MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Also clean up some of the looping. Reviewed-by: Marek Olšák --- src/gallium/drivers/radeonsi/si_blit.c | 97 ++++++++++++++++---------- 1 file changed, 61 insertions(+), 36 deletions(-) diff --git a/src/gallium/drivers/radeonsi/si_blit.c b/src/gallium/drivers/radeonsi/si_blit.c index 26ce8200a95..85c8ca3e87a 100644 --- a/src/gallium/drivers/radeonsi/si_blit.c +++ b/src/gallium/drivers/radeonsi/si_blit.c @@ -101,61 +101,61 @@ static unsigned u_max_sample(struct pipe_resource *r) return r->nr_samples ? r->nr_samples - 1 : 0; } -static void si_blit_decompress_depth(struct pipe_context *ctx, - struct r600_texture *texture, - struct r600_texture *staging, - unsigned first_level, unsigned last_level, - unsigned first_layer, unsigned last_layer, - unsigned first_sample, unsigned last_sample) +static void +si_blit_dbcb_copy(struct si_context *sctx, + struct r600_texture *src, + struct r600_texture *dst, + unsigned planes, unsigned level_mask, + unsigned first_layer, unsigned last_layer, + unsigned first_sample, unsigned last_sample) { - struct si_context *sctx = (struct si_context *)ctx; - unsigned layer, level, sample, checked_last_layer, max_layer; - float depth = 1.0f; - const struct util_format_description *desc; - - assert(staging != NULL && "use si_blit_decompress_zs_in_place instead"); - - desc = util_format_description(staging->resource.b.b.format); + struct pipe_surface surf_tmpl = {{0}}; + unsigned layer, sample, checked_last_layer, max_layer; - if (util_format_has_depth(desc)) + if (planes & PIPE_MASK_Z) sctx->dbcb_depth_copy_enabled = true; - if (util_format_has_stencil(desc)) + if (planes & PIPE_MASK_S) sctx->dbcb_stencil_copy_enabled = true; + si_mark_atom_dirty(sctx, &sctx->db_render_state); assert(sctx->dbcb_depth_copy_enabled || sctx->dbcb_stencil_copy_enabled); - for (level = first_level; level <= last_level; level++) { + while (level_mask) { + unsigned level = u_bit_scan(&level_mask); + /* The smaller the mipmap level, the less layers there are * as far as 3D textures are concerned. */ - max_layer = util_max_layer(&texture->resource.b.b, level); + max_layer = util_max_layer(&src->resource.b.b, level); checked_last_layer = MIN2(last_layer, max_layer); + surf_tmpl.u.tex.level = level; + for (layer = first_layer; layer <= checked_last_layer; layer++) { - for (sample = first_sample; sample <= last_sample; sample++) { - struct pipe_surface *zsurf, *cbsurf, surf_tmpl; + struct pipe_surface *zsurf, *cbsurf; - sctx->dbcb_copy_sample = sample; - si_mark_atom_dirty(sctx, &sctx->db_render_state); + surf_tmpl.format = src->resource.b.b.format; + surf_tmpl.u.tex.first_layer = layer; + surf_tmpl.u.tex.last_layer = layer; - surf_tmpl.format = texture->resource.b.b.format; - surf_tmpl.u.tex.level = level; - surf_tmpl.u.tex.first_layer = layer; - surf_tmpl.u.tex.last_layer = layer; + zsurf = sctx->b.b.create_surface(&sctx->b.b, &src->resource.b.b, &surf_tmpl); - zsurf = ctx->create_surface(ctx, &texture->resource.b.b, &surf_tmpl); + surf_tmpl.format = dst->resource.b.b.format; + cbsurf = sctx->b.b.create_surface(&sctx->b.b, &dst->resource.b.b, &surf_tmpl); - surf_tmpl.format = staging->resource.b.b.format; - cbsurf = ctx->create_surface(ctx, - (struct pipe_resource*)staging, &surf_tmpl); + for (sample = first_sample; sample <= last_sample; sample++) { + if (sample != sctx->dbcb_copy_sample) { + sctx->dbcb_copy_sample = sample; + si_mark_atom_dirty(sctx, &sctx->db_render_state); + } - si_blitter_begin(ctx, SI_DECOMPRESS); + si_blitter_begin(&sctx->b.b, SI_DECOMPRESS); util_blitter_custom_depth_stencil(sctx->blitter, zsurf, cbsurf, 1 << sample, - sctx->custom_dsa_flush, depth); - si_blitter_end(ctx); - - pipe_surface_reference(&zsurf, NULL); - pipe_surface_reference(&cbsurf, NULL); + sctx->custom_dsa_flush, 1.0f); + si_blitter_end(&sctx->b.b); } + + pipe_surface_reference(&zsurf, NULL); + pipe_surface_reference(&cbsurf, NULL); } } @@ -164,6 +164,31 @@ static void si_blit_decompress_depth(struct pipe_context *ctx, si_mark_atom_dirty(sctx, &sctx->db_render_state); } +static void si_blit_decompress_depth(struct pipe_context *ctx, + struct r600_texture *texture, + struct r600_texture *staging, + unsigned first_level, unsigned last_level, + unsigned first_layer, unsigned last_layer, + unsigned first_sample, unsigned last_sample) +{ + const struct util_format_description *desc; + unsigned planes = 0; + + assert(staging != NULL && "use si_blit_decompress_zs_in_place instead"); + + desc = util_format_description(staging->resource.b.b.format); + + if (util_format_has_depth(desc)) + planes |= PIPE_MASK_Z; + if (util_format_has_stencil(desc)) + planes |= PIPE_MASK_S; + + si_blit_dbcb_copy( + (struct si_context *)ctx, texture, staging, planes, + u_bit_consecutive(first_level, last_level - first_level + 1), + first_layer, last_layer, first_sample, last_sample); +} + /* Helper function for si_blit_decompress_zs_in_place. */ static void -- 2.30.2