r600g/sb: fix debug dump code in scheduler
[mesa.git] / src / gallium / drivers / r600 / r600_texture.c
index 60d8c3610d6059119b6fd8b0f6188676927f155b..36cca17eb110ae0be0f6d4fbfcfa951f9f0a9165 100644 (file)
@@ -116,11 +116,15 @@ static void r600_copy_from_staging_texture(struct pipe_context *ctx, struct r600
        }
 }
 
-unsigned r600_texture_get_offset(struct r600_texture *rtex,
-                                       unsigned level, unsigned layer)
+static unsigned r600_texture_get_offset(struct r600_texture *rtex, unsigned level,
+                                       const struct pipe_box *box)
 {
+       enum pipe_format format = rtex->resource.b.b.format;
+
        return rtex->surface.level[level].offset +
-              layer * rtex->surface.level[level].slice_size;
+              box->z * rtex->surface.level[level].slice_size +
+              box->y / util_format_get_blockheight(format) * rtex->surface.level[level].pitch_bytes +
+              box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
 }
 
 static int r600_init_surface(struct r600_screen *rscreen,
@@ -805,7 +809,6 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
        struct r600_texture *rtex = (struct r600_texture*)texture;
        struct r600_transfer *trans;
        boolean use_staging_texture = FALSE;
-       enum pipe_format format = texture->format;
        struct r600_resource *buf;
        unsigned offset = 0;
        char *map;
@@ -849,8 +852,6 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
        trans->transfer.box = *box;
 
        if (rtex->is_depth) {
-               /* XXX: only readback the rectangle which is being mapped? */
-               /* XXX: when discard is true, no need to read back from depth texture */
                struct r600_texture *staging_depth;
 
                if (rtex->resource.b.b.nr_samples > 1) {
@@ -861,28 +862,31 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
                         *
                         * First downsample the depth buffer to a temporary texture,
                         * then decompress the temporary one to staging.
+                        *
+                        * Only the region being mapped is transfered.
                         */
-                       struct pipe_resource *temp;
                        struct pipe_resource resource;
 
                        r600_init_temp_resource_from_box(&resource, texture, box, level, 0);
-                       temp = ctx->screen->resource_create(ctx->screen, &resource);
-
-                       r600_copy_region_with_blit(ctx, temp, 0, 0, 0, 0, texture, level, box);
 
-                       if (!r600_init_flushed_depth_texture(ctx, temp, &staging_depth)) {
+                       if (!r600_init_flushed_depth_texture(ctx, &resource, &staging_depth)) {
                                R600_ERR("failed to create temporary texture to hold untiled copy\n");
                                FREE(trans);
                                return NULL;
                        }
 
-                       r600_blit_decompress_depth(ctx, (struct r600_texture*)temp, staging_depth,
-                                                  0, 0, 0, box->depth, 0, 0);
+                       if (usage & PIPE_TRANSFER_READ) {
+                               struct pipe_resource *temp = ctx->screen->resource_create(ctx->screen, &resource);
 
-                       pipe_resource_reference((struct pipe_resource**)&temp, NULL);
-                       trans->offset = 0;
+                               r600_copy_region_with_blit(ctx, temp, 0, 0, 0, 0, texture, level, box);
+                               r600_blit_decompress_depth(ctx, (struct r600_texture*)temp, staging_depth,
+                                                          0, 0, 0, box->depth, 0, 0);
+                               pipe_resource_reference((struct pipe_resource**)&temp, NULL);
+                       }
                }
                else {
+                       /* XXX: only readback the rectangle which is being mapped? */
+                       /* XXX: when discard is true, no need to read back from depth texture */
                        if (!r600_init_flushed_depth_texture(ctx, texture, &staging_depth)) {
                                R600_ERR("failed to create temporary texture to hold untiled copy\n");
                                FREE(trans);
@@ -894,7 +898,7 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
                                                   box->z, box->z + box->depth - 1,
                                                   0, 0);
 
-                       trans->offset = r600_texture_get_offset(staging_depth, level, box->z);
+                       offset = r600_texture_get_offset(staging_depth, level, box);
                }
 
                trans->transfer.stride = staging_depth->surface.level[level].pitch_bytes;
@@ -919,16 +923,12 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
                trans->transfer.layer_stride = staging->surface.level[0].slice_size;
                if (usage & PIPE_TRANSFER_READ) {
                        r600_copy_to_staging_texture(ctx, trans);
-                       /* flush gfx & dma ring, order does not matter as only one can be live */
-                       if (rctx->rings.dma.cs) {
-                               rctx->rings.dma.flush(rctx, 0);
-                       }
-                       rctx->rings.gfx.flush(rctx, 0);
                }
        } else {
+               /* the resource is mapped directly */
                trans->transfer.stride = rtex->surface.level[level].pitch_bytes;
                trans->transfer.layer_stride = rtex->surface.level[level].slice_size;
-               trans->offset = r600_texture_get_offset(rtex, level, box->z);
+               offset = r600_texture_get_offset(rtex, level, box);
        }
 
        if (trans->staging) {
@@ -937,11 +937,6 @@ static void *r600_texture_transfer_map(struct pipe_context *ctx,
                buf = &rtex->resource;
        }
 
-       if (rtex->is_depth || !trans->staging)
-               offset = trans->offset +
-                       box->y / util_format_get_blockheight(format) * trans->transfer.stride +
-                       box->x / util_format_get_blockwidth(format) * util_format_get_blocksize(format);
-
        if (!(map = r600_buffer_mmap_sync_with_rings(rctx, buf, usage))) {
                pipe_resource_reference((struct pipe_resource**)&trans->staging, NULL);
                FREE(trans);