diff --git a/src/gallium/drivers/radeonsi/r600_blit.c b/src/gallium/drivers/radeonsi/r600_blit.c index 40967d64ea5..f368292ccb2 100644 --- a/src/gallium/drivers/radeonsi/r600_blit.c +++ b/src/gallium/drivers/radeonsi/r600_blit.c @@ -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); -} diff --git a/src/gallium/drivers/radeonsi/r600_resource.h b/src/gallium/drivers/radeonsi/r600_resource.h index 8b44034bd53..4cacf6274c7 100644 --- a/src/gallium/drivers/radeonsi/r600_resource.h +++ b/src/gallium/drivers/radeonsi/r600_resource.h @@ -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; diff --git a/src/gallium/drivers/radeonsi/r600_texture.c b/src/gallium/drivers/radeonsi/r600_texture.c index 4c6ca6eb3a7..4c107b26bea 100644 --- a/src/gallium/drivers/radeonsi/r600_texture.c +++ b/src/gallium/drivers/radeonsi/r600_texture.c @@ -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) diff --git a/src/gallium/drivers/radeonsi/radeonsi_pipe.h b/src/gallium/drivers/radeonsi/radeonsi_pipe.h index 686ed055039..8df32416c1f 100644 --- a/src/gallium/drivers/radeonsi/radeonsi_pipe.h +++ b/src/gallium/drivers/radeonsi/radeonsi_pipe.h @@ -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 */ diff --git a/src/gallium/drivers/radeonsi/si_state.c b/src/gallium/drivers/radeonsi/si_state.c index ee353edb816..fe3efb6adc9 100644 --- a/src/gallium/drivers/radeonsi/si_state.c +++ b/src/gallium/drivers/radeonsi/si_state.c @@ -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; }