nv50: account for pesky prefetch in size calculation of linear textures
[mesa.git] / src / gallium / drivers / nv50 / nv50_miptree.c
index 7883edbe75e52f2a998dfe3937875b46788121c3..ed0f8c2b2f1f4ad396f22c553223f43bf5c7ed3b 100644 (file)
@@ -147,6 +147,10 @@ nv50_miptree_destroy(struct pipe_screen *pscreen, struct pipe_resource *pt)
    nouveau_fence_ref(NULL, &mt->base.fence);
    nouveau_fence_ref(NULL, &mt->base.fence_wr);
 
+   NOUVEAU_DRV_STAT(nouveau_screen(pscreen), tex_obj_current_count, -1);
+   NOUVEAU_DRV_STAT(nouveau_screen(pscreen), tex_obj_current_bytes,
+                    -(uint64_t)mt->total_size);
+
    FREE(mt);
 }
 
@@ -213,6 +217,7 @@ nv50_miptree_init_layout_linear(struct nv50_miptree *mt)
 {
    struct pipe_resource *pt = &mt->base.base;
    const unsigned blocksize = util_format_get_blocksize(pt->format);
+   unsigned h = pt->height0;
 
    if (util_format_is_depth_or_stencil(pt->format))
       return FALSE;
@@ -224,7 +229,11 @@ nv50_miptree_init_layout_linear(struct nv50_miptree *mt)
 
    mt->level[0].pitch = align(pt->width0 * blocksize, 64);
 
-   mt->total_size = mt->level[0].pitch * pt->height0;
+   /* Account for very generous prefetch (allocate size as if tiled). */
+   h = MAX2(h, 8);
+   h = util_next_power_of_two(h);
+
+   mt->total_size = mt->level[0].pitch * h;
 
    return TRUE;
 }
@@ -406,6 +415,7 @@ nv50_surface_from_miptree(struct nv50_miptree *mt,
    pipe_resource_reference(&ps->texture, &mt->base.base);
 
    ps->format = templ->format;
+   ps->writable = templ->writable;
    ps->u.tex.level = templ->u.tex.level;
    ps->u.tex.first_layer = templ->u.tex.first_layer;
    ps->u.tex.last_layer = templ->u.tex.last_layer;