nv50: fix build-predicate function
[mesa.git] / src / gallium / drivers / nvfx / nv04_surface_2d.c
index ed18c9f24dc911583fa22cace89c279a4b051c53..7acbb505df3387ffda7418a01862170fd395ab8a 100644 (file)
@@ -25,7 +25,7 @@ nv04_surface_format(enum pipe_format format)
        case PIPE_FORMAT_B8G8R8X8_UNORM:
        case PIPE_FORMAT_B8G8R8A8_UNORM:
                return NV04_CONTEXT_SURFACES_2D_FORMAT_A8R8G8B8;
-       case PIPE_FORMAT_S8Z24_UNORM:
+       case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
        case PIPE_FORMAT_X8Z24_UNORM:
                return NV04_CONTEXT_SURFACES_2D_FORMAT_Y32;
        default:
@@ -45,7 +45,7 @@ nv04_rect_format(enum pipe_format format)
                return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A16R5G6B5;
        case PIPE_FORMAT_B8G8R8X8_UNORM:
        case PIPE_FORMAT_B8G8R8A8_UNORM:
-       case PIPE_FORMAT_S8Z24_UNORM:
+       case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
        case PIPE_FORMAT_X8Z24_UNORM:
                return NV04_GDI_RECTANGLE_TEXT_COLOR_FORMAT_A8R8G8B8;
        default:
@@ -125,8 +125,8 @@ nv04_surface_copy_swizzle(struct nv04_surface_2d *ctx,
        struct nouveau_channel *chan = ctx->swzsurf->channel;
        struct nouveau_grobj *swzsurf = ctx->swzsurf;
        struct nouveau_grobj *sifm = ctx->sifm;
-       struct nouveau_bo *src_bo = nouveau_bo(ctx->buf(src));
-       struct nouveau_bo *dst_bo = nouveau_bo(ctx->buf(dst));
+       struct nouveau_bo *src_bo = ctx->buf(src);
+       struct nouveau_bo *dst_bo = ctx->buf(dst);
        const unsigned src_pitch = ((struct nv04_surface *)src)->pitch;
         /* Max width & height may not be the same on all HW, but must be POT */
        const unsigned max_w = 1024;
@@ -148,7 +148,7 @@ nv04_surface_copy_swizzle(struct nv04_surface_2d *ctx,
 
        BEGIN_RING(chan, swzsurf, NV04_SWIZZLED_SURFACE_DMA_IMAGE, 1);
        OUT_RELOCo(chan, dst_bo,
-                        NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
+                        NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
 
        BEGIN_RING(chan, swzsurf, NV04_SWIZZLED_SURFACE_FORMAT, 1);
        OUT_RING  (chan, nv04_surface_format(dst->format) |
@@ -171,7 +171,7 @@ nv04_surface_copy_swizzle(struct nv04_surface_2d *ctx,
 
            BEGIN_RING(chan, swzsurf, NV04_SWIZZLED_SURFACE_OFFSET, 1);
            OUT_RELOCl(chan, dst_bo, dst->offset,
-                             NOUVEAU_BO_GART | NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
+                             NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
 
            BEGIN_RING(chan, sifm, NV05_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION, 9);
            OUT_RING  (chan, NV05_SCALED_IMAGE_FROM_MEMORY_COLOR_CONVERSION_TRUNCATE);
@@ -205,8 +205,8 @@ nv04_surface_copy_m2mf(struct nv04_surface_2d *ctx,
 {
        struct nouveau_channel *chan = ctx->m2mf->channel;
        struct nouveau_grobj *m2mf = ctx->m2mf;
-       struct nouveau_bo *src_bo = nouveau_bo(ctx->buf(src));
-       struct nouveau_bo *dst_bo = nouveau_bo(ctx->buf(dst));
+       struct nouveau_bo *src_bo = ctx->buf(src);
+       struct nouveau_bo *dst_bo = ctx->buf(dst);
        unsigned src_pitch = ((struct nv04_surface *)src)->pitch;
        unsigned dst_pitch = ((struct nv04_surface *)dst)->pitch;
        unsigned dst_offset = dst->offset + dy * dst_pitch +
@@ -252,8 +252,8 @@ nv04_surface_copy_blit(struct nv04_surface_2d *ctx, struct pipe_surface *dst,
        struct nouveau_channel *chan = ctx->surf2d->channel;
        struct nouveau_grobj *surf2d = ctx->surf2d;
        struct nouveau_grobj *blit = ctx->blit;
-       struct nouveau_bo *src_bo = nouveau_bo(ctx->buf(src));
-       struct nouveau_bo *dst_bo = nouveau_bo(ctx->buf(dst));
+       struct nouveau_bo *src_bo = ctx->buf(src);
+       struct nouveau_bo *dst_bo = ctx->buf(dst);
        unsigned src_pitch = ((struct nv04_surface *)src)->pitch;
        unsigned dst_pitch = ((struct nv04_surface *)dst)->pitch;
        int format;
@@ -285,10 +285,8 @@ nv04_surface_copy(struct nv04_surface_2d *ctx, struct pipe_surface *dst,
                  int dx, int dy, struct pipe_surface *src, int sx, int sy,
                  int w, int h)
 {
-       unsigned src_pitch = ((struct nv04_surface *)src)->pitch;
-       unsigned dst_pitch = ((struct nv04_surface *)dst)->pitch;
-       int src_linear = src->texture->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR;
-       int dst_linear = dst->texture->tex_usage & NOUVEAU_TEXTURE_USAGE_LINEAR;
+       int src_linear = src->texture->flags & NVFX_RESOURCE_FLAG_LINEAR;
+       int dst_linear = dst->texture->flags & NVFX_RESOURCE_FLAG_LINEAR;
 
        assert(src->format == dst->format);
 
@@ -298,16 +296,11 @@ nv04_surface_copy(struct nv04_surface_2d *ctx, struct pipe_surface *dst,
            return;
         }
 
-       /* NV_CONTEXT_SURFACES_2D has buffer alignment restrictions, fallback
-        * to NV_MEMORY_TO_MEMORY_FORMAT in this case.
-        */
-       if ((src->offset & 63) || (dst->offset & 63) ||
-           (src_pitch & 63) || (dst_pitch & 63)) {
-               nv04_surface_copy_m2mf(ctx, dst, dx, dy, src, sx, sy, w, h);
-               return;
-       }
-
-       nv04_surface_copy_blit(ctx, dst, dx, dy, src, sx, sy, w, h);
+        /* Use M2MF instead of the blitter since it always works
+         * Any possible performance drop is likely to be not very significant
+         * and dwarfed anyway by the current buffer management problems
+         */
+        nv04_surface_copy_m2mf(ctx, dst, dx, dy, src, sx, sy, w, h);
 }
 
 static void
@@ -317,7 +310,7 @@ nv04_surface_fill(struct nv04_surface_2d *ctx, struct pipe_surface *dst,
        struct nouveau_channel *chan = ctx->surf2d->channel;
        struct nouveau_grobj *surf2d = ctx->surf2d;
        struct nouveau_grobj *rect = ctx->rect;
-       struct nouveau_bo *dst_bo = nouveau_bo(ctx->buf(dst));
+       struct nouveau_bo *dst_bo = ctx->buf(dst);
        unsigned dst_pitch = ((struct nv04_surface *)dst)->pitch;
        int cs2d_format, gdirect_format;
 
@@ -501,26 +494,18 @@ nv04_surface_2d_init(struct nouveau_screen *screen)
 }
 
 struct nv04_surface*
-nv04_surface_wrap_for_render(struct pipe_screen *pscreen, struct nv04_surface_2d* eng2d, struct nv04_surface* ns)
+nv04_surface_wrap_for_render(struct pipe_screen *pscreen,
+                            struct nv04_surface_2d* eng2d, struct nv04_surface* ns)
 {
+       struct pipe_resource templ;
+       struct pipe_resource* temp_tex;
+       struct nv04_surface* temp_ns;
        int temp_flags;
 
-       // printf("creating temp, flags is %i!\n", flags);
-
-       if(ns->base.usage & PIPE_BUFFER_USAGE_DISCARD)
-       {
-               temp_flags = ns->base.usage | PIPE_BUFFER_USAGE_GPU_READ;
-               ns->base.usage = PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER | PIPE_BUFFER_USAGE_DISCARD;
-       }
-       else
-       {
-               temp_flags = ns->base.usage | PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE;
-               ns->base.usage = PIPE_BUFFER_USAGE_GPU_WRITE | NOUVEAU_BUFFER_USAGE_NO_RENDER | PIPE_BUFFER_USAGE_GPU_READ;
-       }
+       temp_flags = ns->base.usage;
 
-       ns->base.usage = PIPE_BUFFER_USAGE_GPU_READ | PIPE_BUFFER_USAGE_GPU_WRITE;
+       ns->base.usage = 0;
 
-       struct pipe_texture templ;
        memset(&templ, 0, sizeof(templ));
        templ.format = ns->base.texture->format;
        templ.target = PIPE_TEXTURE_2D;
@@ -532,14 +517,16 @@ nv04_surface_wrap_for_render(struct pipe_screen *pscreen, struct nv04_surface_2d
        // TODO: this is probably wrong and we should specifically handle multisampling somehow once it is implemented
        templ.nr_samples = ns->base.texture->nr_samples;
 
-       templ.tex_usage = ns->base.texture->tex_usage | PIPE_TEXTURE_USAGE_RENDER_TARGET;
+       templ.bind = ns->base.texture->bind | PIPE_BIND_RENDER_TARGET;
 
-       struct pipe_texture* temp_tex = pscreen->texture_create(pscreen, &templ);
-       struct nv04_surface* temp_ns = (struct nv04_surface*)pscreen->get_tex_surface(pscreen, temp_tex, 0, 0, 0, temp_flags);
+       temp_tex = pscreen->resource_create(pscreen, &templ);
+       temp_ns = (struct nv04_surface*)pscreen->get_tex_surface(pscreen, temp_tex, 0, 0, 0, temp_flags);
        temp_ns->backing = ns;
 
-       if(ns->base.usage & PIPE_BUFFER_USAGE_GPU_READ)
-               eng2d->copy(eng2d, &temp_ns->backing->base, 0, 0, &ns->base, 0, 0, ns->base.width, ns->base.height);
+       if(1) /* hmm */
+               eng2d->copy(eng2d, &temp_ns->backing->base,
+                           0, 0, &ns->base,
+                           0, 0, ns->base.width, ns->base.height);
 
        return temp_ns;
 }