nouveau: add pipe_buffer/fence code to pipe drivers, move nv50 over
authorBen Skeggs <bskeggs@redhat.com>
Thu, 4 Jun 2009 00:19:04 +0000 (10:19 +1000)
committerBen Skeggs <bskeggs@redhat.com>
Fri, 5 Jun 2009 04:37:01 +0000 (14:37 +1000)
configure.ac
src/gallium/drivers/nouveau/nouveau_screen.c [new file with mode: 0644]
src/gallium/drivers/nouveau/nouveau_screen.h [new file with mode: 0644]
src/gallium/drivers/nv50/nv50_context.h
src/gallium/drivers/nv50/nv50_query.c
src/gallium/drivers/nv50/nv50_screen.c
src/gallium/drivers/nv50/nv50_screen.h
src/gallium/drivers/nv50/nv50_surface.c
src/gallium/drivers/nv50/nv50_transfer.c
src/gallium/winsys/drm/nouveau/dri/Makefile

index 6f0f1f681d5d4ada73c0b85041e3c112558c67b6..eb2733c0dc862e8e7020fdec454ab3573007108d 100644 (file)
@@ -1181,7 +1181,7 @@ AC_ARG_ENABLE([gallium-nouveau],
     [enable_gallium_nouveau=no])
 if test "x$enable_gallium_nouveau" = xyes; then
     GALLIUM_WINSYS_DRM_DIRS="$GALLIUM_WINSYS_DRM_DIRS nouveau"
-    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nv04 nv10 nv20 nv30 nv40 nv50"
+    GALLIUM_DRIVERS_DIRS="$GALLIUM_DRIVERS_DIRS nouveau nv04 nv10 nv20 nv30 nv40 nv50"
 fi
 
 
diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c
new file mode 100644 (file)
index 0000000..3cab83e
--- /dev/null
@@ -0,0 +1,242 @@
+#include <pipe/p_defines.h>
+#include <pipe/p_screen.h>
+#include <pipe/p_state.h>
+
+#include <util/u_memory.h>
+
+#include "nouveau/nouveau_bo.h"
+#include "nouveau_winsys.h"
+#include "nouveau_screen.h"
+
+static const char *
+nouveau_screen_get_name(struct pipe_screen *pscreen)
+{
+       struct nouveau_device *dev = nouveau_screen(pscreen)->device;
+       static char buffer[128];
+
+       snprintf(buffer, sizeof(buffer), "NV%02X", dev->chipset);
+       return buffer;
+}
+
+static const char *
+nouveau_screen_get_vendor(struct pipe_screen *pscreen)
+{
+       return "nouveau";
+}
+
+static struct pipe_buffer *
+nouveau_screen_bo_skel(struct pipe_screen *pscreen, struct nouveau_bo *bo,
+                      unsigned alignment, unsigned usage, unsigned size)
+{
+       struct pipe_buffer *pb;
+       
+       pb = CALLOC(1, sizeof(struct pipe_buffer)+sizeof(struct nouveau_bo *));
+       if (!pb) {
+               nouveau_bo_ref(NULL, &bo);
+               return NULL;
+       }
+
+       pipe_reference_init(&pb->reference, 1);
+       pb->screen = pscreen;
+       pb->alignment = alignment;
+       pb->usage = usage;
+       pb->size = size;
+       *(struct nouveau_bo **)(pb + 1) = bo;
+       return pb;
+}
+
+static struct pipe_buffer *
+nouveau_screen_bo_new(struct pipe_screen *pscreen, unsigned alignment,
+                     unsigned usage, unsigned size)
+{
+       struct nouveau_device *dev = nouveau_screen(pscreen)->device;
+       struct nouveau_bo *bo = NULL;
+       uint32_t flags = NOUVEAU_BO_MAP;
+       int ret;
+
+       if (usage & NOUVEAU_BUFFER_USAGE_TRANSFER)
+               flags |= NOUVEAU_BO_GART;
+       else
+       if (usage & PIPE_BUFFER_USAGE_VERTEX) {
+               if (pscreen->get_param(pscreen, NOUVEAU_CAP_HW_VTXBUF))
+                       flags |= NOUVEAU_BO_GART;
+       } else
+       if (usage & PIPE_BUFFER_USAGE_INDEX) {
+               if (pscreen->get_param(pscreen, NOUVEAU_CAP_HW_IDXBUF))
+                       flags |= NOUVEAU_BO_GART;
+       }
+
+       if (usage & PIPE_BUFFER_USAGE_PIXEL) {
+               if (usage & NOUVEAU_BUFFER_USAGE_TEXTURE)
+                       flags |= NOUVEAU_BO_GART;
+               if (!(usage & PIPE_BUFFER_USAGE_CPU_READ_WRITE))
+                       flags |= NOUVEAU_BO_VRAM;
+
+               if (dev->chipset == 0x50 || dev->chipset >= 0x80) {
+                       flags |= NOUVEAU_BO_TILED;
+                       if (usage & NOUVEAU_BUFFER_USAGE_ZETA)
+                               flags |= NOUVEAU_BO_ZTILE;
+               }
+       }
+
+       ret = nouveau_bo_new(dev, flags, alignment, size, &bo);
+       if (ret)
+               return NULL;
+
+       return nouveau_screen_bo_skel(pscreen, bo, alignment, usage, size);
+}
+
+static struct pipe_buffer *
+nouveau_screen_bo_user(struct pipe_screen *pscreen, void *ptr, unsigned bytes)
+{
+       struct nouveau_device *dev = nouveau_screen(pscreen)->device;
+       struct nouveau_bo *bo = NULL;
+       int ret;
+
+       ret = nouveau_bo_user(dev, ptr, bytes, &bo);
+       if (ret)
+               return NULL;
+
+       return nouveau_screen_bo_skel(pscreen, bo, 0, 0, bytes);
+}
+
+static inline uint32_t
+nouveau_screen_map_flags(unsigned pipe)
+{
+       uint32_t flags = 0;
+
+       if (pipe & PIPE_BUFFER_USAGE_CPU_READ)
+               flags |= NOUVEAU_BO_RD;
+       if (pipe & PIPE_BUFFER_USAGE_CPU_WRITE)
+               flags |= NOUVEAU_BO_WR;
+#ifdef NOUVEAU_BO_NOWAIT
+       if (pipe & PIPE_BUFFER_USAGE_DISCARD)
+               flags |= NOUVEAU_BO_INVAL;
+
+       if (pipe & PIPE_BUFFER_USAGE_DONTBLOCK)
+               flags |= NOUVEAU_BO_NOWAIT;
+       else
+       if (pipe & 0 /*PIPE_BUFFER_USAGE_UNSYNCHRONIZED*/)
+               flags |= NOUVEAU_BO_NOSYNC;
+#endif
+
+       return flags;
+}
+
+static void *
+nouveau_screen_bo_map(struct pipe_screen *pscreen, struct pipe_buffer *pb,
+                     unsigned usage)
+{
+       struct nouveau_bo *bo = nouveau_bo(pb);
+       int ret;
+
+       ret = nouveau_bo_map(bo, nouveau_screen_map_flags(usage));
+       if (ret) {
+               debug_printf("map failed: %d\n", ret);
+               return NULL;
+       }
+
+       return bo->map;
+}
+
+#ifdef NOUVEAU_BO_NOWAIT
+static void *
+nouveau_screen_bo_map_range(struct pipe_screen *pscreen, struct pipe_buffer *pb,
+                           unsigned offset, unsigned length, unsigned usage)
+{
+       struct nouveau_bo *bo = nouveau_bo(pb);
+       int ret;
+
+       ret = nouveau_bo_map_range(bo, offset, length,
+                                  nouveau_screen_map_flags(usage));
+       if (ret) {
+               debug_printf("map_range failed: %d\n", ret);
+               return NULL;
+       }
+
+       return bo->map;
+}
+
+static void
+nouveau_screen_bo_map_flush(struct pipe_screen *pscreen, struct pipe_buffer *pb,
+                           unsigned offset, unsigned length)
+{
+       struct nouveau_bo *bo = nouveau_bo(pb);
+
+       nouveau_bo_map_flush(bo, offset, length);
+}
+#endif
+
+static void
+nouveau_screen_bo_unmap(struct pipe_screen *pscreen, struct pipe_buffer *pb)
+{
+       struct nouveau_bo *bo = nouveau_bo(pb);
+
+       nouveau_bo_unmap(bo);
+}
+
+static void
+nouveau_screen_bo_del(struct pipe_buffer *pb)
+{
+       struct nouveau_bo *bo = nouveau_bo(pb);
+
+       nouveau_bo_ref(NULL, &bo);
+       FREE(pb);
+}
+
+static void
+nouveau_screen_fence_ref(struct pipe_screen *pscreen,
+                        struct pipe_fence_handle **ptr,
+                        struct pipe_fence_handle *pfence)
+{
+       *ptr = pfence;
+}
+
+static int
+nouveau_screen_fence_signalled(struct pipe_screen *screen,
+                              struct pipe_fence_handle *pfence,
+                              unsigned flags)
+{
+       return 0;
+}
+
+static int
+nouveau_screen_fence_finish(struct pipe_screen *screen,
+                           struct pipe_fence_handle *pfence,
+                           unsigned flags)
+{
+       return 0;
+}
+
+int
+nouveau_screen_init(struct nouveau_screen *screen, struct nouveau_device *dev)
+{
+       struct pipe_screen *pscreen = &screen->base;
+
+       screen->device = dev;
+
+       pscreen->get_name = nouveau_screen_get_name;
+       pscreen->get_vendor = nouveau_screen_get_vendor;
+
+       pscreen->buffer_create = nouveau_screen_bo_new;
+       pscreen->user_buffer_create = nouveau_screen_bo_user;
+       pscreen->buffer_map = nouveau_screen_bo_map;
+#ifdef NOUVEAU_BO_NOWAIT
+       pscreen->buffer_map_range = nouveau_screen_bo_map_range;
+       pscreen->buffer_flush_mapped_range = nouveau_screen_bo_map_flush;
+#endif
+       pscreen->buffer_unmap = nouveau_screen_bo_unmap;
+       pscreen->buffer_destroy = nouveau_screen_bo_del;
+
+       pscreen->fence_reference = nouveau_screen_fence_ref;
+       pscreen->fence_signalled = nouveau_screen_fence_signalled;
+       pscreen->fence_finish = nouveau_screen_fence_finish;
+
+       return 0;
+}
+
+void
+nouveau_screen_fini(struct nouveau_screen *screen)
+{
+}
+
diff --git a/src/gallium/drivers/nouveau/nouveau_screen.h b/src/gallium/drivers/nouveau/nouveau_screen.h
new file mode 100644 (file)
index 0000000..cffba11
--- /dev/null
@@ -0,0 +1,24 @@
+#ifndef __NOUVEAU_SCREEN_H__
+#define __NOUVEAU_SCREEN_H__
+
+struct nouveau_screen {
+       struct pipe_screen base;
+       struct nouveau_device *device;
+};
+
+static inline struct nouveau_screen *
+nouveau_screen(struct pipe_screen *pscreen)
+{
+       return (struct nouveau_screen *)pscreen;
+}
+
+static inline struct nouveau_bo *
+nouveau_bo(struct pipe_buffer *pb)
+{
+       return pb ? *(struct nouveau_bo **)(pb + 1) : NULL;
+}
+
+int nouveau_screen_init(struct nouveau_screen *, struct nouveau_device *);
+void nouveau_screen_fini(struct nouveau_screen *);
+
+#endif
index d960657066c0cfd78ea352a4cac7793ad00c8626..7b67a7543978e643bc39e4fa7c39e960e45ced6f 100644 (file)
@@ -23,8 +23,6 @@
 #define NOUVEAU_MSG(fmt, args...) \
        fprintf(stderr, "nouveau: "fmt, ##args);
 
-#define nouveau_bo(pb) nv50->screen->nvws->get_bo(pb)
-
 /* Constant buffer assignment */
 #define NV50_CB_PMISC          0
 #define NV50_CB_PVP            1
index 35cebdbdc32c1481eb3a621846fff552708d826b..4d05eeac2c849e47e03b0c39d9e41f1b8b6cebb7 100644 (file)
@@ -90,7 +90,7 @@ nv50_query_end(struct pipe_context *pipe, struct pipe_query *pq)
        struct nouveau_channel *chan = nv50->screen->nvws->channel;
        struct nouveau_grobj *tesla = nv50->screen->tesla;
        struct nv50_query *q = nv50_query(pq);
-       struct nouveau_bo *bo = nv50->screen->nvws->get_bo(q->buffer);
+       struct nouveau_bo *bo = nouveau_bo(q->buffer);
 
        WAIT_RING (chan, 5);
        BEGIN_RING(chan, tesla, 0x1b00, 4);
index b7e9df77dbdb1c7c0e4d95ab20511a4ebf390f84..3b830847ca151ab3af226b77c91c29e4194f60f8 100644 (file)
@@ -22,8 +22,6 @@
 
 #include "pipe/p_screen.h"
 
-#include "util/u_simple_screen.h"
-
 #include "nv50_context.h"
 #include "nv50_screen.h"
 
@@ -68,23 +66,6 @@ nv50_screen_is_format_supported(struct pipe_screen *pscreen,
        return FALSE;
 }
 
-static const char *
-nv50_screen_get_name(struct pipe_screen *pscreen)
-{
-       struct nv50_screen *screen = nv50_screen(pscreen);
-       struct nouveau_device *dev = screen->nvws->channel->device;
-       static char buffer[128];
-
-       snprintf(buffer, sizeof(buffer), "NV%02X", dev->chipset);
-       return buffer;
-}
-
-static const char *
-nv50_screen_get_vendor(struct pipe_screen *pscreen)
-{
-       return "nouveau";
-}
-
 static int
 nv50_screen_get_param(struct pipe_screen *pscreen, int param)
 {
@@ -153,7 +134,10 @@ nv50_screen_get_paramf(struct pipe_screen *pscreen, int param)
 static void
 nv50_screen_destroy(struct pipe_screen *pscreen)
 {
-       FREE(pscreen);
+       struct nv50_screen *screen = nv50_screen(pscreen);
+
+       nouveau_screen_fini(&screen->base);
+       FREE(screen);
 }
 
 struct pipe_screen *
@@ -161,6 +145,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
 {
        struct nv50_screen *screen = CALLOC_STRUCT(nv50_screen);
        struct nouveau_device *dev = nvws->channel->device;
+       struct pipe_screen *pscreen;
        struct nouveau_stateobj *so;
        unsigned chipset = dev->chipset;
        unsigned tesla_class = 0;
@@ -168,13 +153,31 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
 
        if (!screen)
                return NULL;
+       pscreen = &screen->base.base;
+
+       ret = nouveau_screen_init(&screen->base, nvws->channel->device);
+       if (ret) {
+               nv50_screen_destroy(pscreen);
+               return NULL;
+       }
+
+        /* Setup the pipe */
        screen->nvws = nvws;
 
+       pscreen->winsys = ws;
+       pscreen->destroy = nv50_screen_destroy;
+       pscreen->get_param = nv50_screen_get_param;
+       pscreen->get_paramf = nv50_screen_get_paramf;
+       pscreen->is_format_supported = nv50_screen_is_format_supported;
+
+       nv50_screen_init_miptree_functions(pscreen);
+       nv50_transfer_init_screen_functions(pscreen);
+
        /* DMA engine object */
        ret = nvws->grobj_alloc(nvws, 0x5039, &screen->m2mf);
        if (ret) {
                NOUVEAU_ERR("Error creating M2MF object: %d\n", ret);
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
@@ -182,7 +185,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
        ret = nvws->grobj_alloc(nvws, NV50_2D, &screen->eng2d);
        if (ret) {
                NOUVEAU_ERR("Error creating 2D object: %d\n", ret);
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
@@ -200,20 +203,20 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
                break;
        default:
                NOUVEAU_ERR("Not a known NV50 chipset: NV%02x\n", chipset);
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
        if (tesla_class == 0) {
                NOUVEAU_ERR("Unknown G8x chipset: NV%02x\n", chipset);
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
        ret = nvws->grobj_alloc(nvws, tesla_class, &screen->tesla);
        if (ret) {
                NOUVEAU_ERR("Error creating 3D object: %d\n", ret);
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
@@ -221,26 +224,10 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
        ret = nvws->notifier_alloc(nvws, 1, &screen->sync);
        if (ret) {
                NOUVEAU_ERR("Error creating notifier object: %d\n", ret);
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
-        /* Setup the pipe */
-       screen->pipe.winsys = ws;
-
-       screen->pipe.destroy = nv50_screen_destroy;
-
-       screen->pipe.get_name = nv50_screen_get_name;
-       screen->pipe.get_vendor = nv50_screen_get_vendor;
-       screen->pipe.get_param = nv50_screen_get_param;
-       screen->pipe.get_paramf = nv50_screen_get_paramf;
-
-       screen->pipe.is_format_supported = nv50_screen_is_format_supported;
-
-       nv50_screen_init_miptree_functions(&screen->pipe);
-       nv50_transfer_init_screen_functions(&screen->pipe);
-       u_simple_screen_init(&screen->pipe);
-
        /* Static M2MF init */
        so = so_new(32, 0);
        so_method(so, screen->m2mf, 0x0180, 3);
@@ -295,7 +282,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
        ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 128*4*4,
                             &screen->constbuf_misc[0]);
        if (ret) {
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
@@ -303,7 +290,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
                ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 128*4*4,
                                     &screen->constbuf_parm[i]);
                if (ret) {
-                       nv50_screen_destroy(&screen->pipe);
+                       nv50_screen_destroy(pscreen);
                        return NULL;
                }
        }
@@ -313,7 +300,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
                nvws->res_init(&screen->parm_heap[1], 0, 128))
        {
                NOUVEAU_ERR("Error initialising constant buffers.\n");
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
@@ -362,7 +349,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
         */
        ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 32*8*4, &screen->tic);
        if (ret) {
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
@@ -381,7 +368,7 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
 
        ret = nouveau_bo_new(dev, NOUVEAU_BO_VRAM, 0, 32*8*4, &screen->tsc);
        if (ret) {
-               nv50_screen_destroy(&screen->pipe);
+               nv50_screen_destroy(pscreen);
                return NULL;
        }
 
@@ -420,6 +407,6 @@ nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
        so_ref (NULL, &so);
        nouveau_pushbuf_flush(nvws->channel, 0);
 
-       return &screen->pipe;
+       return pscreen;
 }
 
index fa7d8d0f0d6fe2bd9d41068573fb26e8c4b7aba2..61e24a5b571746e3b5b9c2af0fb76ff4398b2a2e 100644 (file)
@@ -1,10 +1,10 @@
 #ifndef __NV50_SCREEN_H__
 #define __NV50_SCREEN_H__
 
-#include "pipe/p_screen.h"
+#include "nouveau/nouveau_screen.h"
 
 struct nv50_screen {
-       struct pipe_screen pipe;
+       struct nouveau_screen base;
 
        struct nouveau_winsys *nvws;
 
index c0f0efe158bdb51fe513aec28640d5013c4bb70a..121eddfc83414a2c496745b1bfd77ae5c6b767d8 100644 (file)
@@ -54,14 +54,10 @@ nv50_surface_set(struct nv50_screen *screen, struct pipe_surface *ps, int dst)
        struct nv50_miptree *mt = nv50_miptree(ps->texture);
        struct nouveau_channel *chan = screen->nvws->channel;
        struct nouveau_grobj *eng2d = screen->eng2d;
-       struct nouveau_bo *bo;
+       struct nouveau_bo *bo = nouveau_bo(nv50_miptree(ps->texture)->buffer);
        int format, mthd = dst ? NV50_2D_DST_FORMAT : NV50_2D_SRC_FORMAT;
        int flags = NOUVEAU_BO_VRAM | (dst ? NOUVEAU_BO_WR : NOUVEAU_BO_RD);
 
-       bo = screen->nvws->get_bo(nv50_miptree(ps->texture)->buffer);
-       if (!bo)
-               return 1;
-
        format = nv50_format(ps->format);
        if (format < 0)
                return 1;
index 28e7edd144a2ab2e5201f16c545af94a37783c95..5f1e430ad1f56daf495cea7c061678b55e1cc91c 100644 (file)
@@ -27,8 +27,8 @@ nv50_transfer_rect_m2mf(struct pipe_screen *pscreen, struct pipe_buffer *src,
        struct nouveau_winsys *nvws = screen->nvws;
        struct nouveau_channel *chan = nvws->channel;
        struct nouveau_grobj *m2mf = screen->m2mf;
-       struct nouveau_bo *src_bo = nvws->get_bo(src);
-       struct nouveau_bo *dst_bo = nvws->get_bo(dst);
+       struct nouveau_bo *src_bo = nouveau_bo(src);
+       struct nouveau_bo *dst_bo = nouveau_bo(dst);
 
        src_reloc |= NOUVEAU_BO_RD;
        dst_reloc |= NOUVEAU_BO_WR;
index 024ab150cbd1878150bad1ff1ee87d9ba12394db..0937f68c34bbeaf646f3b8f621f8e5c8daf5f1ef 100644 (file)
@@ -11,7 +11,8 @@ PIPE_DRIVERS = \
        $(TOP)/src/gallium/drivers/nv20/libnv20.a \
        $(TOP)/src/gallium/drivers/nv30/libnv30.a \
        $(TOP)/src/gallium/drivers/nv40/libnv40.a \
-       $(TOP)/src/gallium/drivers/nv50/libnv50.a
+       $(TOP)/src/gallium/drivers/nv50/libnv50.a \
+       $(TOP)/src/gallium/drivers/nouveau/libnouveau.a
 
 DRIVER_SOURCES =