Merge branch 'gallium-0.2' into gallium-winsys-private
[mesa.git] / src / gallium / drivers / nv40 / nv40_miptree.c
index 6516bff4b815c12f5c18edf24ca7047eb77cfdbd..6ed0d39edff6f6c7c3847452bdf3c69fbdef1532 100644 (file)
@@ -8,7 +8,6 @@ static void
 nv40_miptree_layout(struct nv40_miptree *mt)
 {
        struct pipe_texture *pt = &mt->base;
-       boolean swizzled = FALSE;
        uint width = pt->width[0], height = pt->height[0], depth = pt->depth[0];
        uint offset = 0;
        int nr_faces, l, f, pitch;
@@ -30,7 +29,7 @@ nv40_miptree_layout(struct nv40_miptree *mt)
                pt->nblocksx[l] = pf_get_nblocksx(&pt->block, width);
                pt->nblocksy[l] = pf_get_nblocksy(&pt->block, height);
 
-               if (swizzled)
+               if (!(pt->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR))
                        pitch = pt->nblocksx[l];
                pitch = align(pitch, 64);
 
@@ -58,6 +57,8 @@ nv40_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)
 {
        struct pipe_winsys *ws = pscreen->winsys;
        struct nv40_miptree *mt;
+       unsigned buf_usage = PIPE_BUFFER_USAGE_PIXEL |
+                            NOUVEAU_BUFFER_USAGE_TEXTURE;
 
        mt = MALLOC(sizeof(struct nv40_miptree));
        if (!mt)
@@ -68,8 +69,6 @@ nv40_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)
        mt->shadow_tex = NULL;
        mt->shadow_surface = NULL;
 
-       nv40_miptree_layout(mt);
-
        /* Swizzled textures must be POT */
        if (pt->width[0] & (pt->width[0] - 1) ||
            pt->height[0] & (pt->height[0] - 1))
@@ -78,23 +77,27 @@ nv40_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *pt)
        if (pt->tex_usage & (PIPE_TEXTURE_USAGE_PRIMARY |
                             PIPE_TEXTURE_USAGE_DISPLAY_TARGET))
                mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+       else
+       if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
+               mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
        else {
                switch (pt->format) {
                /* TODO: Figure out which formats can be swizzled */
                case PIPE_FORMAT_A8R8G8B8_UNORM:
                case PIPE_FORMAT_X8R8G8B8_UNORM:
-               /* XXX: Re-enable when SIFM size limits are fixed */
-               /*case PIPE_FORMAT_R16_SNORM:*/
+               case PIPE_FORMAT_R16_SNORM:
                        break;
                default:
                        mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
                }
        }
 
-       mt->buffer = ws->buffer_create(ws, 256,
-                                      PIPE_BUFFER_USAGE_PIXEL |
-                                      NOUVEAU_BUFFER_USAGE_TEXTURE,
-                                      mt->total_size);
+       if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
+               buf_usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE;
+
+       nv40_miptree_layout(mt);
+
+       mt->buffer = ws->_buffer_create(ws, 256, buf_usage, mt->total_size);
        if (!mt->buffer) {
                FREE(mt);
                return NULL;
@@ -152,7 +155,6 @@ nv40_miptree_surface_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
        ps->usage = flags;
        ps->status = PIPE_SURFACE_STATUS_DEFINED;
        ps->refcount = 1;
-       ps->winsys = pscreen->winsys;
        ps->face = face;
        ps->level = level;
        ps->zslice = zslice;