nv20: copy miptree flags from nv40
authorPekka Paalanen <pq@iki.fi>
Thu, 5 Feb 2009 18:12:04 +0000 (20:12 +0200)
committerPekka Paalanen <pq@iki.fi>
Thu, 5 Feb 2009 18:35:24 +0000 (20:35 +0200)
nv20_miptree_create() should set various flags.
Copy stuff over from nv40.

trivial/tri does not abort on nv04 swizzled copy anymore.
I still miss my triangle.

Signed-off-by: Pekka Paalanen <pq@iki.fi>
src/gallium/drivers/nv20/nv20_miptree.c

index 89a4058700c63a06629ca7572f4cd73ed2dba1e9..c1155682dc62b8e81c4e6be0b6d17d82b4b975d4 100644 (file)
@@ -79,6 +79,8 @@ nv20_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt)
 {
        struct pipe_winsys *ws = screen->winsys;
        struct nv20_miptree *mt;
+       unsigned buf_usage = PIPE_BUFFER_USAGE_PIXEL |
+                            NOUVEAU_BUFFER_USAGE_TEXTURE;
 
        mt = MALLOC(sizeof(struct nv20_miptree));
        if (!mt)
@@ -87,10 +89,35 @@ nv20_miptree_create(struct pipe_screen *screen, const struct pipe_texture *pt)
        mt->base.refcount = 1;
        mt->base.screen = screen;
 
+       /* Swizzled textures must be POT */
+       if (pt->width[0] & (pt->width[0] - 1) ||
+           pt->height[0] & (pt->height[0] - 1))
+               mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+       else
+       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:
+               case PIPE_FORMAT_R16_SNORM:
+                       break;
+               default:
+                       mt->base.tex_usage |= NOUVEAU_TEXTURE_USAGE_LINEAR;
+               }
+       }
+
+       if (pt->tex_usage & PIPE_TEXTURE_USAGE_DYNAMIC)
+               buf_usage |= PIPE_BUFFER_USAGE_CPU_READ_WRITE;
+
        nv20_miptree_layout(mt);
 
-       mt->buffer = ws->buffer_create(ws, 256, PIPE_BUFFER_USAGE_PIXEL,
-                                          mt->total_size);
+       mt->buffer = ws->buffer_create(ws, 256, buf_usage, mt->total_size);
        if (!mt->buffer) {
                FREE(mt);
                return NULL;