radeonsi: Assorted depth/stencil changes ported from r600g.

[ Squashed port of the following r600g commits: - Michel Dänzer ]

commit c1e8c845ea
Author: Marek Olšák <maraeo@gmail.com>
Date:   Sat Jul 7 19:10:00 2012 +0200

    r600g: inline r600_hw_copy_region

commit 4891c5dc64
Author: Marek Olšák <maraeo@gmail.com>
Date:   Mon Jun 25 22:53:21 2012 +0200

    r600g: inline r600_blit_push_depth and use resource_copy_region

    We are going to have a separate resource for depth texturing and transfers
    and this is just a transfer thing.

commit da98bb6fc1
Author: Marek Olšák <maraeo@gmail.com>
Date:   Mon Jun 25 12:45:32 2012 +0200

    r600g: split flushed depth texture creation and flushing

Signed-off-by: Michel Dänzer <michel.daenzer@amd.com>
This commit is contained in:
Marek Olšák 2013-01-15 19:04:13 +01:00 committed by Michel Dänzer
parent f0ffbbc9ff
commit bfb405ceee
5 changed files with 48 additions and 56 deletions

View File

@ -234,25 +234,6 @@ static void r600_clear_depth_stencil(struct pipe_context *ctx,
r600_blitter_end(ctx);
}
/* Copy a block of pixels from one surface to another using HW. */
static void r600_hw_copy_region(struct pipe_context *ctx,
struct pipe_resource *dst,
unsigned dst_level,
unsigned dstx, unsigned dsty, unsigned dstz,
struct pipe_resource *src,
unsigned src_level,
const struct pipe_box *src_box)
{
struct r600_context *rctx = (struct r600_context *)ctx;
r600_blitter_begin(ctx, R600_COPY);
util_blitter_copy_texture(rctx->blitter, dst, dst_level, dstx, dsty, dstz,
src, src_level, src_box, PIPE_MASK_RGBAZS, TRUE);
r600_blitter_end(ctx);
}
struct texture_orig_info {
unsigned format;
unsigned width0;
@ -320,6 +301,7 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
unsigned src_level,
const struct pipe_box *src_box)
{
struct r600_context *rctx = (struct r600_context *)ctx;
struct r600_resource_texture *rsrc = (struct r600_resource_texture*)src;
struct texture_orig_info orig_info[2];
struct pipe_box sbox;
@ -336,7 +318,7 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
}
if (rsrc->depth && !rsrc->is_flushing_texture)
r600_texture_depth_flush(ctx, src, FALSE);
r600_texture_depth_flush(ctx, src);
restore_orig[0] = restore_orig[1] = FALSE;
@ -361,8 +343,10 @@ static void r600_resource_copy_region(struct pipe_context *ctx,
dsty = util_format_get_nblocksy(orig_info[1].format, dsty);
}
r600_hw_copy_region(ctx, dst, dst_level, dstx, dsty, dstz,
src, src_level, psbox);
r600_blitter_begin(ctx, R600_COPY);
util_blitter_copy_texture(rctx->blitter, dst, dst_level, dstx, dsty, dstz,
src, src_level, psbox, PIPE_MASK_RGBAZS, TRUE);
r600_blitter_end(ctx);
if (restore_orig[0])
r600_reset_blittable_to_compressed(src, src_level, &orig_info[0]);
@ -388,7 +372,7 @@ static void si_blit(struct pipe_context *ctx,
}
if (rsrc->depth && !rsrc->is_flushing_texture)
r600_texture_depth_flush(ctx, info->src.resource, FALSE);
r600_texture_depth_flush(ctx, info->src.resource);
r600_blitter_begin(ctx, R600_BLIT);
util_blitter_blit(rctx->blitter, info);
@ -403,19 +387,3 @@ void si_init_blit_functions(struct r600_context *rctx)
rctx->context.resource_copy_region = r600_resource_copy_region;
rctx->context.blit = si_blit;
}
void r600_blit_push_depth(struct pipe_context *ctx, struct r600_resource_texture *texture)
{
struct pipe_box sbox;
sbox.x = sbox.y = sbox.z = 0;
sbox.width = texture->resource.b.b.width0;
sbox.height = texture->resource.b.b.height0;
/* XXX that might be wrong */
sbox.depth = 1;
r600_hw_copy_region(ctx, (struct pipe_resource *)texture, 0,
0, 0, 0,
(struct pipe_resource *)texture->flushed_depth_texture, 0,
&sbox);
}

View File

@ -68,7 +68,10 @@ struct pipe_resource *si_texture_from_handle(struct pipe_screen *screen,
const struct pipe_resource *base,
struct winsys_handle *whandle);
int r600_texture_depth_flush(struct pipe_context *ctx, struct pipe_resource *texture, boolean just_create);
void r600_init_flushed_depth_texture(struct pipe_context *ctx,
struct pipe_resource *texture);
void r600_texture_depth_flush(struct pipe_context *ctx,
struct pipe_resource *texture);
struct r600_context;

View File

@ -281,7 +281,6 @@ static void *si_texture_transfer_map(struct pipe_context *ctx,
struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
struct pipe_resource resource;
struct r600_transfer *trans;
int r;
boolean use_staging_texture = FALSE;
struct radeon_winsys_cs_handle *buf;
enum pipe_format format = texture->format;
@ -329,8 +328,8 @@ static void *si_texture_transfer_map(struct pipe_context *ctx,
*/
/* XXX: when discard is true, no need to read back from depth texture
*/
r = r600_texture_depth_flush(ctx, texture, FALSE);
if (r < 0) {
r600_texture_depth_flush(ctx, texture);
if (!rtex->flushed_depth_texture) {
R600_ERR("failed to create temporary texture to hold untiled copy\n");
pipe_resource_reference(&trans->transfer.resource, NULL);
FREE(trans);
@ -438,8 +437,19 @@ static void si_texture_transfer_unmap(struct pipe_context *ctx,
}
if (rtex->depth && !rtex->is_flushing_texture) {
if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtex->flushed_depth_texture)
r600_blit_push_depth(ctx, rtex);
if ((transfer->usage & PIPE_TRANSFER_WRITE) && rtex->flushed_depth_texture) {
struct pipe_box sbox;
sbox.x = sbox.y = sbox.z = 0;
sbox.width = texture->width0;
sbox.height = texture->height0;
/* XXX that might be wrong */
sbox.depth = 1;
ctx->resource_copy_region(ctx, texture, 0, 0, 0, 0,
&rtex->flushed_depth_texture->resource.b.b, 0,
&sbox);
}
}
pipe_resource_reference(&transfer->resource, NULL);
@ -617,14 +627,14 @@ struct pipe_resource *si_texture_from_handle(struct pipe_screen *screen,
stride, 0, buf, FALSE, &surface);
}
int r600_texture_depth_flush(struct pipe_context *ctx,
struct pipe_resource *texture, boolean just_create)
void r600_init_flushed_depth_texture(struct pipe_context *ctx,
struct pipe_resource *texture)
{
struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
struct pipe_resource resource;
if (rtex->flushed_depth_texture)
goto out;
return; /* it's ready */
resource.target = texture->target;
resource.format = texture->format;
@ -641,18 +651,25 @@ int r600_texture_depth_flush(struct pipe_context *ctx,
rtex->flushed_depth_texture = (struct r600_resource_texture *)ctx->screen->resource_create(ctx->screen, &resource);
if (rtex->flushed_depth_texture == NULL) {
R600_ERR("failed to create temporary texture to hold untiled copy\n");
return -ENOMEM;
return;
}
((struct r600_resource_texture *)rtex->flushed_depth_texture)->is_flushing_texture = TRUE;
out:
if (just_create)
return 0;
}
void r600_texture_depth_flush(struct pipe_context *ctx,
struct pipe_resource *texture)
{
struct r600_resource_texture *rtex = (struct r600_resource_texture*)texture;
r600_init_flushed_depth_texture(ctx, texture);
if (!rtex->flushed_depth_texture)
return; /* error */
/* XXX: only do this if the depth texture has actually changed:
*/
si_blit_uncompress_depth(ctx, rtex);
return 0;
}
void si_init_surface_functions(struct r600_context *r600)

View File

@ -186,7 +186,6 @@ struct r600_context {
/* r600_blit.c */
void si_init_blit_functions(struct r600_context *rctx);
void si_blit_uncompress_depth(struct pipe_context *ctx, struct r600_resource_texture *texture);
void r600_blit_push_depth(struct pipe_context *ctx, struct r600_resource_texture *texture);
void si_flush_depth_textures(struct r600_context *rctx);
/* r600_buffer.c */

View File

@ -1585,8 +1585,9 @@ static void si_cb(struct r600_context *rctx, struct si_pm4_state *pm4,
rctx->have_depth_fb = TRUE;
if (rtex->depth && !rtex->is_flushing_texture) {
r600_texture_depth_flush(&rctx->context, state->cbufs[cb]->texture, TRUE);
r600_init_flushed_depth_texture(&rctx->context, state->cbufs[cb]->texture);
rtex = rtex->flushed_depth_texture;
assert(rtex);
}
offset = rtex->surface.level[level].offset;
@ -2083,8 +2084,12 @@ static struct pipe_sampler_view *si_create_sampler_view(struct pipe_context *ctx
}
if (tmp->depth && !tmp->is_flushing_texture) {
r600_texture_depth_flush(ctx, texture, TRUE);
r600_init_flushed_depth_texture(ctx, texture);
tmp = tmp->flushed_depth_texture;
if (!tmp) {
FREE(view);
return NULL;
}
texture = &tmp->resource.b.b;
}