- struct nouveau_device *dev = nouveau_screen(pscreen)->device;
- struct nv50_miptree *mt = CALLOC_STRUCT(nv50_miptree);
- struct pipe_resource *pt = &mt->base.base;
- unsigned width = tmp->width0, height = tmp->height0;
- unsigned depth = tmp->depth0, image_alignment;
- uint32_t tile_flags;
- int ret, i, l;
-
- if (!mt)
- return NULL;
-
- *pt = *tmp;
- mt->base.vtbl = &nv50_miptree_vtbl;
- pipe_reference_init(&pt->reference, 1);
- pt->screen = pscreen;
-
- switch (pt->format) {
- case PIPE_FORMAT_Z32_FLOAT:
- tile_flags = 0x4800;
- break;
- case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
- tile_flags = 0x1800;
- break;
- case PIPE_FORMAT_Z16_UNORM:
- tile_flags = 0x6c00;
- break;
- case PIPE_FORMAT_Z24X8_UNORM:
- case PIPE_FORMAT_Z24_UNORM_S8_USCALED:
- tile_flags = 0x2800;
- break;
- case PIPE_FORMAT_Z32_FLOAT_S8X24_USCALED:
- tile_flags = 0xe000;
- break;
- case PIPE_FORMAT_R32G32B32A32_FLOAT:
- case PIPE_FORMAT_R32G32B32_FLOAT:
- tile_flags = 0x7400;
- break;
- default:
- if ((pt->bind & PIPE_BIND_SCANOUT) &&
- util_format_get_blocksizebits(pt->format) == 32)
- tile_flags = 0x7a00;
- else
- tile_flags = 0x7000;
- break;
- }
-
- /* XXX: texture arrays */
- mt->image_nr = (pt->target == PIPE_TEXTURE_CUBE) ? 6 : 1;
-
- for (l = 0; l <= pt->last_level; l++) {
- struct nv50_miptree_level *lvl = &mt->level[l];
- unsigned nblocksy = util_format_get_nblocksy(pt->format, height);
-
- lvl->image_offset = CALLOC(mt->image_nr, sizeof(int));
- lvl->pitch = align(util_format_get_stride(pt->format, width), 64);
- lvl->tile_mode = get_tile_mode(nblocksy, depth);
-
- width = u_minify(width, 1);
- height = u_minify(height, 1);
- depth = u_minify(depth, 1);
- }
-
- image_alignment = get_tile_height(mt->level[0].tile_mode) * 64;
- image_alignment *= get_tile_depth(mt->level[0].tile_mode);
-
- /* NOTE the distinction between arrays of mip-mapped 2D textures and
- * mip-mapped 3D textures. We can't use image_nr == depth for 3D mip.
- */
- for (i = 0; i < mt->image_nr; i++) {
- for (l = 0; l <= pt->last_level; l++) {
- struct nv50_miptree_level *lvl = &mt->level[l];
- int size;
- unsigned tile_h = get_tile_height(lvl->tile_mode);
- unsigned tile_d = get_tile_depth(lvl->tile_mode);
-
- size = lvl->pitch;
- size *= align(util_format_get_nblocksy(pt->format, u_minify(pt->height0, l)), tile_h);
- size *= align(u_minify(pt->depth0, l), tile_d);
-
- lvl->image_offset[i] = mt->total_size;
-
- mt->total_size += size;
- }
- mt->total_size = align(mt->total_size, image_alignment);
- }
-
- ret = nouveau_bo_new_tile(dev, NOUVEAU_BO_VRAM, 256, mt->total_size,
- mt->level[0].tile_mode, tile_flags,
- &mt->base.bo);
- if (ret) {
- for (l = 0; l <= pt->last_level; ++l)
- FREE(mt->level[l].image_offset);
- FREE(mt);
- return NULL;
- }
-
- return pt;
+ struct nouveau_device *dev = nouveau_screen(pscreen)->device;
+ struct nv50_miptree *mt = CALLOC_STRUCT(nv50_miptree);
+ struct pipe_resource *pt = &mt->base.base;
+ int ret;
+ uint32_t tile_flags;
+
+ if (!mt)
+ return NULL;
+
+ mt->base.vtbl = &nv50_miptree_vtbl;
+ *pt = *templ;
+ pipe_reference_init(&pt->reference, 1);
+ pt->screen = pscreen;
+
+ tile_flags = nv50_mt_choose_storage_type(mt, TRUE);
+
+ if (!nv50_miptree_init_ms_mode(mt)) {
+ FREE(mt);
+ return NULL;
+ }
+
+ if (tile_flags & NOUVEAU_BO_TILE_LAYOUT_MASK) {
+ nv50_miptree_init_layout_tiled(mt);
+ } else
+ if (!nv50_miptree_init_layout_linear(mt)) {
+ FREE(mt);
+ return NULL;
+ }
+
+ ret = nouveau_bo_new_tile(dev, NOUVEAU_BO_VRAM, 4096,
+ mt->total_size,
+ mt->level[0].tile_mode, tile_flags,
+ &mt->base.bo);
+ if (ret) {
+ FREE(mt);
+ return NULL;
+ }
+ mt->base.domain = NOUVEAU_BO_VRAM;
+
+ return pt;