radeon/llvm: Eliminate CFGStructurizer dependency on AMDIL instructions
[mesa.git] / src / gallium / drivers / nvc0 / nvc0_miptree.c
index a9d2c85624be2b4845b5353ca5fadacc21357f51..591ac4402db92f0c9de4922afc52bf95ee70fa5b 100644 (file)
@@ -65,80 +65,82 @@ nvc0_mt_choose_storage_type(struct nv50_miptree *mt, boolean compressed)
 
    compressed = FALSE; /* not yet supported */
 
-   if (mt->base.base.bind & PIPE_BIND_CURSOR)
-      return NOUVEAU_BO_TILE_SCANOUT;
+   if (unlikely(mt->base.base.bind & PIPE_BIND_CURSOR))
+      return 0;
+   if (unlikely(mt->base.base.flags & NOUVEAU_RESOURCE_FLAG_LINEAR))
+      return 0;
 
    switch (mt->base.base.format) {
    case PIPE_FORMAT_Z16_UNORM:
       if (compressed)
-         tile_flags = 0x0200 + (ms << 8);
+         tile_flags = 0x02 + ms;
       else
-         tile_flags = 0x0100;
+         tile_flags = 0x01;
       break;
    case PIPE_FORMAT_S8_UINT_Z24_UNORM:
       if (compressed)
-         tile_flags = 0x5100 + (ms << 8);
+         tile_flags = 0x51 + ms;
       else
-         tile_flags = 0x4600;
+         tile_flags = 0x46;
       break;
    case PIPE_FORMAT_Z24X8_UNORM:
    case PIPE_FORMAT_Z24_UNORM_S8_UINT:
       if (compressed)
-         tile_flags = 0x1700 + (ms << 8);
+         tile_flags = 0x17 + ms;
       else
-         tile_flags = 0x1100;
+         tile_flags = 0x11;
       break;
    case PIPE_FORMAT_Z32_FLOAT:
       if (compressed)
-         tile_flags = 0x8600 + (ms << 8);
+         tile_flags = 0x86 + ms;
       else
-         tile_flags = 0x7b00;
+         tile_flags = 0x7b;
       break;
    case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
       if (compressed)
-         tile_flags = 0xce00 + (ms << 8);
+         tile_flags = 0xce + ms;
       else
-         tile_flags = 0xc300;
+         tile_flags = 0xc3;
       break;
    default:
       switch (util_format_get_blocksizebits(mt->base.base.format)) {
       case 128:
          if (compressed)
-            tile_flags = 0xf400 + (ms << 9);
+            tile_flags = 0xf4 + ms;
          else
-            tile_flags = 0xfe00;
+            tile_flags = 0xfe;
          break;
       case 64:
          if (compressed) {
             switch (ms) {
-            case 0: tile_flags = 0xe600; break;
-            case 1: tile_flags = 0xeb00; break;
-            case 2: tile_flags = 0xed00; break;
-            case 3: tile_flags = 0xf200; break;
+            case 0: tile_flags = 0xe6; break;
+            case 1: tile_flags = 0xeb; break;
+            case 2: tile_flags = 0xed; break;
+            case 3: tile_flags = 0xf2; break;
             default:
                return 0;
             }
          } else {
-            tile_flags = 0xfe00;
+            tile_flags = 0xfe;
          }
          break;
       case 32:
          if (compressed) {
             switch (ms) {
-            case 0: tile_flags = 0xdb00; break;
-            case 1: tile_flags = 0xdd00; break;
-            case 2: tile_flags = 0xdf00; break;
-            case 3: tile_flags = 0xe400; break;
+            case 0: tile_flags = 0xdb; break;
+            case 1: tile_flags = 0xdd; break;
+            case 2: tile_flags = 0xdf; break;
+            case 3: tile_flags = 0xe4; break;
             default:
                return 0;
             }
          } else {
-            tile_flags = 0xfe00;
+            tile_flags = 0xfe;
          }
          break;
       case 16:
       case 8:
-         tile_flags = 0xfe00;
+         tile_flags = 0xfe;
          break;
       default:
          return 0;
@@ -146,12 +148,6 @@ nvc0_mt_choose_storage_type(struct nv50_miptree *mt, boolean compressed)
       break;
    }
 
-   if (mt->base.base.bind & PIPE_BIND_SCANOUT)
-      tile_flags |= NOUVEAU_BO_TILE_SCANOUT;
-
-   if (unlikely(mt->base.base.flags & NOUVEAU_RESOURCE_FLAG_LINEAR))
-      tile_flags &= ~0xff00;
-
    return tile_flags;
 }
 
@@ -187,6 +183,31 @@ nvc0_miptree_init_ms_mode(struct nv50_miptree *mt)
 boolean
 nv50_miptree_init_layout_linear(struct nv50_miptree *);
 
+static void
+nvc0_miptree_init_layout_video(struct nv50_miptree *mt)
+{
+   const struct pipe_resource *pt = &mt->base.base;
+   const unsigned blocksize = util_format_get_blocksize(pt->format);
+
+   unsigned nbx = util_format_get_nblocksx(pt->format, pt->width0);
+   unsigned nby = util_format_get_nblocksy(pt->format, pt->height0);
+
+   assert(pt->last_level == 0);
+   assert(mt->ms_x == 0 &&
+          mt->ms_y == 0);
+   assert(!util_format_is_compressed(pt->format));
+
+   assert(nby > 8);
+   mt->level[0].tile_mode = 0x10;
+   mt->level[0].pitch = align(nbx * blocksize, 64);
+   mt->total_size = align(nby, 16) * mt->level[0].pitch;
+
+   if (pt->array_size > 1) {
+      mt->layer_stride = align(mt->total_size, NVC0_TILE_SIZE(0x10));
+      mt->total_size = mt->layer_stride * pt->array_size;
+   }
+}
+
 static void
 nvc0_miptree_init_layout_tiled(struct nv50_miptree *mt)
 {
@@ -254,7 +275,8 @@ nvc0_miptree_create(struct pipe_screen *pscreen,
    struct nv50_miptree *mt = CALLOC_STRUCT(nv50_miptree);
    struct pipe_resource *pt = &mt->base.base;
    int ret;
-   uint32_t tile_flags;
+   union nouveau_bo_config bo_config;
+   uint32_t bo_flags;
 
    if (!mt)
       return NULL;
@@ -264,30 +286,39 @@ nvc0_miptree_create(struct pipe_screen *pscreen,
    pipe_reference_init(&pt->reference, 1);
    pt->screen = pscreen;
 
-   tile_flags = nvc0_mt_choose_storage_type(mt, TRUE);
+   bo_config.nvc0.memtype = nvc0_mt_choose_storage_type(mt, TRUE);
 
    if (!nvc0_miptree_init_ms_mode(mt)) {
       FREE(mt);
       return NULL;
    }
 
-   if (tile_flags & NOUVEAU_BO_TILE_LAYOUT_MASK) {
+   if (unlikely(pt->flags & NVC0_RESOURCE_FLAG_VIDEO)) {
+      nvc0_miptree_init_layout_video(mt);
+   } else
+   if (likely(bo_config.nvc0.memtype)) {
       nvc0_miptree_init_layout_tiled(mt);
    } else
    if (!nv50_miptree_init_layout_linear(mt)) {
       FREE(mt);
       return NULL;
    }
+   bo_config.nvc0.tile_mode = mt->level[0].tile_mode;
+
+   mt->base.domain = NOUVEAU_BO_VRAM;
 
-   ret = nouveau_bo_new_tile(dev, NOUVEAU_BO_VRAM, 4096,
-                             mt->total_size,
-                             mt->level[0].tile_mode, tile_flags,
-                             &mt->base.bo);
+   bo_flags = mt->base.domain | NOUVEAU_BO_NOSNOOP;
+
+   if (mt->base.base.bind & (PIPE_BIND_CURSOR | PIPE_BIND_DISPLAY_TARGET))
+      bo_flags |= NOUVEAU_BO_CONTIG;
+
+   ret = nouveau_bo_new(dev, bo_flags, 4096, mt->total_size, &bo_config,
+                        &mt->base.bo);
    if (ret) {
       FREE(mt);
       return NULL;
    }
-   mt->base.domain = NOUVEAU_BO_VRAM;
+   mt->base.address = mt->base.bo->offset;
 
    return pt;
 }