radeonsi: don't set number of IB dwords for states
[mesa.git] / src / gallium / drivers / radeonsi / si_dma.c
index c02b01eca6d86a1a55f78f77d3e62990781e8323..309ae04424a652638676e1cf0eafa3ace45a6027 100644 (file)
 
 #include "util/u_format.h"
 
-static unsigned si_array_mode(unsigned mode)
-{
-       switch (mode) {
-       case RADEON_SURF_MODE_LINEAR_ALIGNED:
-               return V_009910_ARRAY_LINEAR_ALIGNED;
-       case RADEON_SURF_MODE_1D:
-               return V_009910_ARRAY_1D_TILED_THIN1;
-       case RADEON_SURF_MODE_2D:
-               return V_009910_ARRAY_2D_TILED_THIN1;
-       default:
-       case RADEON_SURF_MODE_LINEAR:
-               return V_009910_ARRAY_LINEAR_GENERAL;
-       }
-}
-
 static uint32_t si_micro_tile_mode(struct si_screen *sscreen, unsigned tile_mode)
 {
        if (sscreen->b.info.si_tile_mode_array_valid) {
@@ -93,16 +78,16 @@ static void si_dma_copy_buffer(struct si_context *ctx,
 
        r600_need_dma_space(&ctx->b, ncopy * 5);
 
-       r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rsrc, RADEON_USAGE_READ,
+       radeon_add_to_buffer_list(&ctx->b, &ctx->b.rings.dma, rsrc, RADEON_USAGE_READ,
                              RADEON_PRIO_MIN);
-       r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, rdst, RADEON_USAGE_WRITE,
+       radeon_add_to_buffer_list(&ctx->b, &ctx->b.rings.dma, rdst, RADEON_USAGE_WRITE,
                              RADEON_PRIO_MIN);
 
        for (i = 0; i < ncopy; i++) {
                csize = size < max_csize ? size : max_csize;
                cs->buf[cs->cdw++] = SI_DMA_PACKET(SI_DMA_PACKET_COPY, sub_cmd, csize);
-               cs->buf[cs->cdw++] = dst_offset & 0xffffffff;
-               cs->buf[cs->cdw++] = src_offset & 0xffffffff;
+               cs->buf[cs->cdw++] = dst_offset;
+               cs->buf[cs->cdw++] = src_offset;
                cs->buf[cs->cdw++] = (dst_offset >> 32UL) & 0xff;
                cs->buf[cs->cdw++] = (src_offset >> 32UL) & 0xff;
                dst_offset += csize << shift;
@@ -162,6 +147,8 @@ static void si_dma_copy_tile(struct si_context *ctx,
        tiled_y = detile ? src_y : dst_y;
        tiled_z = detile ? src_z : dst_z;
 
+       assert(!util_format_is_depth_and_stencil(rtiled->resource.b.b.format));
+
        array_mode = si_array_mode(rtiled->surface.level[tiled_lvl].mode);
        slice_tile_max = (rtiled->surface.level[tiled_lvl].nblk_x *
                          rtiled->surface.level[tiled_lvl].nblk_y) / (8*8) - 1;
@@ -170,7 +157,7 @@ static void si_dma_copy_tile(struct si_context *ctx,
         * dma packet will be using the copy_height which is always smaller or equal
         * to the linear height
         */
-       height = rtiled->surface.level[tiled_lvl].npix_y;
+       height = rtiled->surface.level[tiled_lvl].nblk_y;
        base = rtiled->surface.level[tiled_lvl].offset;
        addr = rlinear->surface.level[linear_lvl].offset;
        addr += rlinear->surface.level[linear_lvl].slice_size * linear_z;
@@ -179,8 +166,7 @@ static void si_dma_copy_tile(struct si_context *ctx,
        bank_w = cik_bank_wh(rtiled->surface.bankw);
        mt_aspect = cik_macro_tile_aspect(rtiled->surface.mtilea);
        tile_split = cik_tile_split(rtiled->surface.tile_split);
-       tile_mode_index = si_tile_mode_index(rtiled, tiled_lvl,
-                                            util_format_has_stencil(util_format_description(rtiled->resource.b.b.format)));
+       tile_mode_index = si_tile_mode_index(rtiled, tiled_lvl, false);
        nbanks = si_num_banks(sscreen, rtiled);
        base += rtiled->resource.gpu_address;
        addr += rlinear->resource.gpu_address;
@@ -191,9 +177,9 @@ static void si_dma_copy_tile(struct si_context *ctx,
        ncopy = (size / SI_DMA_COPY_MAX_SIZE_DW) + !!(size % SI_DMA_COPY_MAX_SIZE_DW);
        r600_need_dma_space(&ctx->b, ncopy * 9);
 
-       r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, &rsrc->resource,
+       radeon_add_to_buffer_list(&ctx->b, &ctx->b.rings.dma, &rsrc->resource,
                              RADEON_USAGE_READ, RADEON_PRIO_MIN);
-       r600_context_bo_reloc(&ctx->b, &ctx->b.rings.dma, &rdst->resource,
+       radeon_add_to_buffer_list(&ctx->b, &ctx->b.rings.dma, &rdst->resource,
                              RADEON_USAGE_WRITE, RADEON_PRIO_MIN);
 
        for (i = 0; i < ncopy; i++) {
@@ -230,7 +216,7 @@ void si_dma_copy(struct pipe_context *ctx,
        struct si_context *sctx = (struct si_context *)ctx;
        struct r600_texture *rsrc = (struct r600_texture*)src;
        struct r600_texture *rdst = (struct r600_texture*)dst;
-       unsigned dst_pitch, src_pitch, bpp, dst_mode, src_mode, copy_height;
+       unsigned dst_pitch, src_pitch, bpp, dst_mode, src_mode;
        unsigned src_w, dst_w;
        unsigned src_x, src_y;
        unsigned dst_x = dstx, dst_y = dsty, dst_z = dstz;
@@ -239,18 +225,30 @@ void si_dma_copy(struct pipe_context *ctx,
                goto fallback;
        }
 
-       /* TODO: Implement DMA copy for CIK */
-       if (sctx->b.chip_class >= CIK) {
-               goto fallback;
-       }
-
        if (dst->target == PIPE_BUFFER && src->target == PIPE_BUFFER) {
                si_dma_copy_buffer(sctx, dst, src, dst_x, src_box->x, src_box->width);
                return;
        }
 
+       /* XXX: Using the asynchronous DMA engine for multi-dimensional
+        * operations seems to cause random GPU lockups for various people.
+        * While the root cause for this might need to be fixed in the kernel,
+        * let's disable it for now.
+        *
+        * Before re-enabling this, please make sure you can hit all newly
+        * enabled paths in your testing, preferably with both piglit and real
+        * world apps, and get in touch with people on the bug reports below
+        * for stability testing.
+        *
+        * https://bugs.freedesktop.org/show_bug.cgi?id=85647
+        * https://bugs.freedesktop.org/show_bug.cgi?id=83500
+        */
+       goto fallback;
+
        if (src->format != dst->format || src_box->depth > 1 ||
-           rdst->dirty_level_mask != 0) {
+           rdst->dirty_level_mask != 0 ||
+           rdst->cmask.size || rdst->fmask.size ||
+           rsrc->cmask.size || rsrc->fmask.size) {
                goto fallback;
        }
 
@@ -268,7 +266,6 @@ void si_dma_copy(struct pipe_context *ctx,
        src_pitch = rsrc->surface.level[src_level].pitch_bytes;
        src_w = rsrc->surface.level[src_level].npix_x;
        dst_w = rdst->surface.level[dst_level].npix_x;
-       copy_height = src_box->height / rsrc->surface.blk_h;
 
        dst_mode = rdst->surface.level[dst_level].mode;
        src_mode = rsrc->surface.level[src_level].mode;
@@ -276,14 +273,20 @@ void si_dma_copy(struct pipe_context *ctx,
        src_mode = src_mode == RADEON_SURF_MODE_LINEAR_ALIGNED ? RADEON_SURF_MODE_LINEAR : src_mode;
        dst_mode = dst_mode == RADEON_SURF_MODE_LINEAR_ALIGNED ? RADEON_SURF_MODE_LINEAR : dst_mode;
 
-       if (src_pitch != dst_pitch || src_box->x || dst_x || src_w != dst_w) {
+       if (src_pitch != dst_pitch || src_box->x || dst_x || src_w != dst_w ||
+           src_box->width != src_w ||
+           src_box->height != rsrc->surface.level[src_level].npix_y ||
+           src_box->height != rdst->surface.level[dst_level].npix_y ||
+           rsrc->surface.level[src_level].nblk_y !=
+           rdst->surface.level[dst_level].nblk_y) {
                /* FIXME si can do partial blit */
                goto fallback;
        }
        /* the x test here are currently useless (because we don't support partial blit)
         * but keep them around so we don't forget about those
         */
-       if ((src_pitch % 8) || (src_box->x % 8) || (dst_x % 8) || (src_box->y % 8) || (dst_y % 8)) {
+       if ((src_pitch % 8) || (src_box->x % 8) || (dst_x % 8) ||
+           (src_box->y % 8) || (dst_y % 8) || (src_box->height % 8)) {
                goto fallback;
        }
 
@@ -301,15 +304,16 @@ void si_dma_copy(struct pipe_context *ctx,
                dst_offset += rdst->surface.level[dst_level].slice_size * dst_z;
                dst_offset += dst_y * dst_pitch + dst_x * bpp;
                si_dma_copy_buffer(sctx, dst, src, dst_offset, src_offset,
-                           src_box->height * src_pitch);
+                                  rsrc->surface.level[src_level].slice_size);
        } else {
                si_dma_copy_tile(sctx, dst, dst_level, dst_x, dst_y, dst_z,
                                 src, src_level, src_x, src_y, src_box->z,
-                                copy_height, dst_pitch, bpp);
+                                src_box->height / rsrc->surface.blk_h,
+                                dst_pitch, bpp);
        }
        return;
 
 fallback:
-       ctx->resource_copy_region(ctx, dst, dst_level, dstx, dsty, dstz,
-                                 src, src_level, src_box);
+       si_resource_copy_region(ctx, dst, dst_level, dstx, dsty, dstz,
+                               src, src_level, src_box);
 }