diff options
Diffstat (limited to 'src/gallium/winsys/drm/nouveau')
-rw-r--r-- | src/gallium/winsys/drm/nouveau/Makefile | 65 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/Makefile | 32 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/Makefile.template | 59 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_bo.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_bo.c) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_channel.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_channel.c) | 16 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_context.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_context.c) | 130 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_context.h (renamed from src/gallium/winsys/drm/nouveau/nouveau_context.h) | 47 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_device.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_device.c) | 6 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_dma.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_dma.c) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_dma.h (renamed from src/gallium/winsys/drm/nouveau/nouveau_dma.h) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_dri.h (renamed from src/gallium/winsys/drm/nouveau/nouveau_dri.h) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_drmif.h (renamed from src/gallium/winsys/drm/nouveau/nouveau_drmif.h) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_fence.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_fence.c) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_grobj.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_grobj.c) | 8 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_local.h (renamed from src/gallium/winsys/drm/nouveau/nouveau_local.h) | 2 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_lock.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_lock.c) | 50 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_notifier.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_notifier.c) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_pushbuf.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_pushbuf.c) | 7 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_resource.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_resource.c) | 12 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_screen.c | 31 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_screen.h | 27 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_winsys.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_winsys.c) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_winsys_pipe.c) | 100 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.h (renamed from src/gallium/winsys/drm/nouveau/nouveau_winsys_pipe.h) | 5 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nouveau_winsys_softpipe.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_winsys_softpipe.c) | 35 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nv04_surface.c (renamed from src/gallium/winsys/drm/nouveau/nv04_surface.c) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/common/nv50_surface.c (renamed from src/gallium/winsys/drm/nouveau/nv50_surface.c) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/dri/Makefile | 31 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/dri/nouveau_context_dri.c | 124 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/dri/nouveau_context_dri.h | 49 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/dri/nouveau_screen_dri.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_screen.c) | 52 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/dri/nouveau_screen_dri.h | 13 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/dri/nouveau_swapbuffers.c (renamed from src/gallium/winsys/drm/nouveau/nouveau_swapbuffers.c) | 58 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/dri/nouveau_swapbuffers.h (renamed from src/gallium/winsys/drm/nouveau/nouveau_swapbuffers.h) | 0 | ||||
-rw-r--r-- | src/gallium/winsys/drm/nouveau/nouveau_screen.h | 20 |
35 files changed, 614 insertions, 365 deletions
diff --git a/src/gallium/winsys/drm/nouveau/Makefile b/src/gallium/winsys/drm/nouveau/Makefile index 81562ca78d..b5735329ec 100644 --- a/src/gallium/winsys/drm/nouveau/Makefile +++ b/src/gallium/winsys/drm/nouveau/Makefile @@ -1,46 +1,25 @@ - TOP = ../../../../.. include $(TOP)/configs/current -LIBNAME = nouveau_dri.so - -MINIGLX_SOURCES = - -PIPE_DRIVERS = \ - $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ - $(TOP)/src/gallium/drivers/nv04/libnv04.a \ - $(TOP)/src/gallium/drivers/nv10/libnv10.a \ - $(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 - -DRIVER_SOURCES = \ - nouveau_bo.c \ - nouveau_channel.c \ - nouveau_context.c \ - nouveau_device.c \ - nouveau_dma.c \ - nouveau_fence.c \ - nouveau_grobj.c \ - nouveau_lock.c \ - nouveau_notifier.c \ - nouveau_pushbuf.c \ - nouveau_resource.c \ - nouveau_screen.c \ - nouveau_swapbuffers.c \ - nouveau_winsys.c \ - nouveau_winsys_pipe.c \ - nouveau_winsys_softpipe.c \ - nv04_surface.c \ - nv50_surface.c - -C_SOURCES = \ - $(COMMON_GALLIUM_SOURCES) \ - $(DRIVER_SOURCES) - -ASM_SOURCES = - -include ../Makefile.template - -symlinks: + +SUBDIRS = common dri + + +default: subdirs + + +subdirs: + @for dir in $(SUBDIRS) ; do \ + if [ -d $$dir ] ; then \ + (cd $$dir && $(MAKE)) || exit 1 ; \ + fi \ + done + + +clean: + rm -f `find . -name \*.[oa]` + rm -f `find . -name depend` + + +# Dummy install target +install: diff --git a/src/gallium/winsys/drm/nouveau/common/Makefile b/src/gallium/winsys/drm/nouveau/common/Makefile new file mode 100644 index 0000000000..06f558959d --- /dev/null +++ b/src/gallium/winsys/drm/nouveau/common/Makefile @@ -0,0 +1,32 @@ +TOP = ../../../../../.. +include $(TOP)/configs/current + +LIBNAME = nouveaudrm + +C_SOURCES = \ + nouveau_bo.c \ + nouveau_channel.c \ + nouveau_context.c \ + nouveau_device.c \ + nouveau_dma.c \ + nouveau_fence.c \ + nouveau_grobj.c \ + nouveau_lock.c \ + nouveau_notifier.c \ + nouveau_pushbuf.c \ + nouveau_resource.c \ + nouveau_screen.c \ + nouveau_winsys.c \ + nouveau_winsys_pipe.c \ + nouveau_winsys_softpipe.c \ + nv04_surface.c \ + nv50_surface.c + + +include ./Makefile.template + +DRIVER_DEFINES = $(shell pkg-config libdrm --cflags \ + && pkg-config libdrm --atleast-version=2.3.1 \ + && echo "-DDRM_VBLANK_FLIP=DRM_VBLANK_FLIP") +symlinks: + diff --git a/src/gallium/winsys/drm/nouveau/common/Makefile.template b/src/gallium/winsys/drm/nouveau/common/Makefile.template new file mode 100644 index 0000000000..e40836e0a8 --- /dev/null +++ b/src/gallium/winsys/drm/nouveau/common/Makefile.template @@ -0,0 +1,59 @@ +# -*-makefile-*- + +COMMON_SOURCES = + +OBJECTS = $(C_SOURCES:.c=.o) \ + $(CPP_SOURCES:.cpp=.o) \ + $(ASM_SOURCES:.S=.o) + + +### Include directories +INCLUDES = \ + -I. \ + -I$(TOP)/src/gallium/include \ + -I$(TOP)/src/gallium/auxiliary \ + -I$(TOP)/src/gallium/drivers \ + -I$(TOP)/include \ + $(DRIVER_INCLUDES) + + +##### RULES ##### + +.c.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + +.cpp.o: + $(CXX) -c $(INCLUDES) $(CXXFLAGS) $(DRIVER_DEFINES) $< -o $@ + +.S.o: + $(CC) -c $(INCLUDES) $(CFLAGS) $(DRIVER_DEFINES) $< -o $@ + + +##### TARGETS ##### + +default: depend symlinks $(LIBNAME) + + +$(LIBNAME): $(OBJECTS) Makefile Makefile.template + $(TOP)/bin/mklib -o $@ -static $(OBJECTS) $(DRIVER_LIBS) + + +depend: $(C_SOURCES) $(CPP_SOURCES) $(ASM_SOURCES) $(SYMLINKS) + rm -f depend + touch depend + $(MKDEP) $(MKDEP_OPTIONS) $(DRIVER_DEFINES) $(INCLUDES) $(C_SOURCES) $(CPP_SOURCES) \ + $(ASM_SOURCES) 2> /dev/null + + +# Emacs tags +tags: + etags `find . -name \*.[ch]` `find ../include` + + +# Remove .o and backup files +clean:: + -rm -f *.o */*.o *~ *.so *~ server/*.o $(SYMLINKS) + -rm -f depend depend.bak + + +include depend diff --git a/src/gallium/winsys/drm/nouveau/nouveau_bo.c b/src/gallium/winsys/drm/nouveau/common/nouveau_bo.c index 76b98bed67..76b98bed67 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_bo.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_bo.c diff --git a/src/gallium/winsys/drm/nouveau/nouveau_channel.c b/src/gallium/winsys/drm/nouveau/common/nouveau_channel.c index b7127f8860..b7298131c1 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_channel.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_channel.c @@ -23,7 +23,7 @@ #include <stdlib.h> #include <string.h> #include <errno.h> - +#include <util/u_memory.h> #include "nouveau_drmif.h" #include "nouveau_dma.h" @@ -38,7 +38,7 @@ nouveau_channel_alloc(struct nouveau_device *dev, uint32_t fb_ctxdma, if (!nvdev || !chan || *chan) return -EINVAL; - nvchan = calloc(1, sizeof(struct nouveau_channel_priv)); + nvchan = CALLOC_STRUCT(nouveau_channel_priv); if (!nvchan) return -ENOMEM; nvchan->base.device = dev; @@ -48,7 +48,7 @@ nouveau_channel_alloc(struct nouveau_device *dev, uint32_t fb_ctxdma, ret = drmCommandWriteRead(nvdev->fd, DRM_NOUVEAU_CHANNEL_ALLOC, &nvchan->drm, sizeof(nvchan->drm)); if (ret) { - free(nvchan); + FREE(nvchan); return ret; } @@ -111,18 +111,16 @@ nouveau_channel_free(struct nouveau_channel **chan) nvchan = nouveau_channel(*chan); *chan = NULL; nvdev = nouveau_device(nvchan->base.device); - + FIRE_RING_CH(&nvchan->base); nouveau_grobj_free(&nvchan->base.vram); nouveau_grobj_free(&nvchan->base.gart); nouveau_grobj_free(&nvchan->base.nullobj); - free(nvchan->pb.buffers); - free(nvchan->pb.relocs); + FREE(nvchan->pb.buffers); + FREE(nvchan->pb.relocs); cf.channel = nvchan->drm.channel; drmCommandWrite(nvdev->fd, DRM_NOUVEAU_CHANNEL_FREE, &cf, sizeof(cf)); - free(nvchan); + FREE(nvchan); } - - diff --git a/src/gallium/winsys/drm/nouveau/nouveau_context.c b/src/gallium/winsys/drm/nouveau/common/nouveau_context.c index 74413c408f..2f245046d4 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_context.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_context.c @@ -1,28 +1,13 @@ -#include "main/glheader.h" -#include "glapi/glthread.h" -#include <GL/internal/glcore.h> -#include "utils.h" - -#include "state_tracker/st_public.h" -#include "state_tracker/st_context.h" -#include "pipe/p_defines.h" -#include "pipe/p_context.h" -#include "pipe/p_screen.h" - +#include <pipe/p_defines.h> +#include <pipe/p_context.h> +#include <pipe/p_screen.h> +#include <util/u_memory.h> #include "nouveau_context.h" #include "nouveau_dri.h" #include "nouveau_local.h" #include "nouveau_screen.h" #include "nouveau_winsys_pipe.h" -#ifdef DEBUG -static const struct dri_debug_control debug_control[] = { - { "bo", DEBUG_BO }, - { NULL, 0 } -}; -int __nouveau_debug = 0; -#endif - static void nouveau_channel_context_destroy(struct nouveau_channel_context *nvc) { @@ -87,24 +72,17 @@ nouveau_channel_context_create(struct nouveau_device *dev) return nvc; } -GLboolean -nouveau_context_create(const __GLcontextModes *glVis, - __DRIcontextPrivate *driContextPriv, - void *sharedContextPrivate) +int +nouveau_context_init(struct nouveau_screen *nv_screen, + drm_context_t hHWContext, drmLock *sarea_lock, + struct nouveau_context *nv_share, + struct nouveau_context *nv) { - __DRIscreenPrivate *driScrnPriv = driContextPriv->driScreenPriv; - struct nouveau_screen *nv_screen = driScrnPriv->private; - struct nouveau_context *nv = CALLOC_STRUCT(nouveau_context); struct pipe_context *pipe = NULL; - struct st_context *st_share = NULL; struct nouveau_channel_context *nvc = NULL; struct nouveau_device *dev = nv_screen->device; int i; - if (sharedContextPrivate) { - st_share = ((struct nouveau_context *)sharedContextPrivate)->st; - } - switch (dev->chipset & 0xf0) { case 0x10: case 0x20: @@ -121,27 +99,18 @@ nouveau_context_create(const __GLcontextModes *glVis, break; default: NOUVEAU_ERR("Unsupported chipset: NV%02x\n", dev->chipset); - return GL_FALSE; + return 1; } - driContextPriv->driverPrivate = (void *)nv; nv->nv_screen = nv_screen; - nv->dri_screen = driScrnPriv; { struct nouveau_device_priv *nvdev = nouveau_device(dev); - nvdev->ctx = driContextPriv->hHWContext; - nvdev->lock = (drmLock *)&driScrnPriv->pSAREA->lock; + nvdev->ctx = hHWContext; + nvdev->lock = sarea_lock; } - driParseConfigFiles(&nv->dri_option_cache, &nv_screen->option_cache, - nv->dri_screen->myNum, "nouveau"); -#ifdef DEBUG - __nouveau_debug = driParseDebugString(getenv("NOUVEAU_DEBUG"), - debug_control); -#endif - /*XXX: Hack up a fake region and buffer object for front buffer. * This will go away with TTM, replaced with a simple reference * of the front buffer handle passed to us by the DDX. @@ -185,12 +154,8 @@ nouveau_context_create(const __GLcontextModes *glVis, * a single process. */ nvc = nv_screen->nvc; - if (!nvc && st_share) { - struct nouveau_context *snv = st_share->pipe->priv; - if (snv) { - nvc = snv->nvc; - } - } + if (!nvc && nv_share) + nvc = nv_share->nvc; /*XXX: temporary - disable multi-context/single-channel on pre-NV4x */ switch (dev->chipset & 0xf0) { @@ -211,7 +176,7 @@ nouveau_context_create(const __GLcontextModes *glVis, nvc = nouveau_channel_context_create(dev); if (!nvc) { NOUVEAU_ERR("Failed initialising GPU context\n"); - return GL_FALSE; + return 1; } nv_screen->nvc = nvc; } @@ -241,11 +206,11 @@ nouveau_context_create(const __GLcontextModes *glVis, case 0x80: case 0x90: if (nouveau_surface_init_nv50(nv)) - return GL_FALSE; + return 1; break; default: if (nouveau_surface_init_nv04(nv)) - return GL_FALSE; + return 1; break; } @@ -268,26 +233,22 @@ nouveau_context_create(const __GLcontextModes *glVis, pipe = nouveau_create_softpipe(nv); if (!pipe) { NOUVEAU_ERR("Error creating pipe, bailing\n"); - return GL_FALSE; + return 1; } } pipe->priv = nv; - nv->st = st_create_context(pipe, glVis, st_share); - return GL_TRUE; + + return 0; } void -nouveau_context_destroy(__DRIcontextPrivate *driContextPriv) +nouveau_context_cleanup(struct nouveau_context *nv) { - struct nouveau_context *nv = driContextPriv->driverPrivate; struct nouveau_channel_context *nvc = nv->nvc; assert(nv); - st_finish(nv->st); - st_destroy_context(nv->st); - if (nv->pctx_id >= 0) { nvc->pctx[nv->pctx_id] = NULL; if (--nvc->refcount <= 0) { @@ -295,52 +256,7 @@ nouveau_context_destroy(__DRIcontextPrivate *driContextPriv) nv->nv_screen->nvc = NULL; } } - - free(nv); -} - -GLboolean -nouveau_context_bind(__DRIcontextPrivate *driContextPriv, - __DRIdrawablePrivate *driDrawPriv, - __DRIdrawablePrivate *driReadPriv) -{ - struct nouveau_context *nv; - struct nouveau_framebuffer *draw, *read; - - if (!driContextPriv) { - st_make_current(NULL, NULL, NULL); - return GL_TRUE; - } - - nv = driContextPriv->driverPrivate; - draw = driDrawPriv->driverPrivate; - read = driReadPriv->driverPrivate; - - st_make_current(nv->st, draw->stfb, read->stfb); - - if ((nv->dri_drawable != driDrawPriv) || - (nv->last_stamp != driDrawPriv->lastStamp)) { - nv->dri_drawable = driDrawPriv; - st_resize_framebuffer(draw->stfb, driDrawPriv->w, - driDrawPriv->h); - nv->last_stamp = driDrawPriv->lastStamp; - } - - if (driDrawPriv != driReadPriv) { - st_resize_framebuffer(read->stfb, driReadPriv->w, - driReadPriv->h); - } - - return GL_TRUE; -} - -GLboolean -nouveau_context_unbind(__DRIcontextPrivate *driContextPriv) -{ - struct nouveau_context *nv = driContextPriv->driverPrivate; - (void)nv; - - st_flush(nv->st, 0, NULL); - return GL_TRUE; + + /* XXX: Who cleans up the pipe? */ } diff --git a/src/gallium/winsys/drm/nouveau/nouveau_context.h b/src/gallium/winsys/drm/nouveau/common/nouveau_context.h index 77e2147a2c..b1bdb01bdf 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_context.h +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_context.h @@ -1,17 +1,10 @@ #ifndef __NOUVEAU_CONTEXT_H__ #define __NOUVEAU_CONTEXT_H__ -#include "dri_util.h" -#include "xmlconfig.h" - #include "nouveau/nouveau_winsys.h" #include "nouveau_drmif.h" #include "nouveau_dma.h" -struct nouveau_framebuffer { - struct st_framebuffer *stfb; -}; - struct nouveau_channel_context { struct pipe_screen *pscreen; int refcount; @@ -41,16 +34,7 @@ struct nouveau_channel_context { }; struct nouveau_context { - struct st_context *st; - - /* DRI stuff */ - __DRIscreenPrivate *dri_screen; - __DRIdrawablePrivate *dri_drawable; - unsigned int last_stamp; - driOptionCache dri_option_cache; - drm_context_t drm_context; - drmLock drm_lock; - GLboolean locked; + int locked; struct nouveau_screen *nv_screen; struct pipe_surface *frontbuffer; @@ -76,26 +60,11 @@ struct nouveau_context { unsigned, unsigned, unsigned, unsigned, unsigned); }; -extern GLboolean nouveau_context_create(const __GLcontextModes *, - __DRIcontextPrivate *, void *); -extern void nouveau_context_destroy(__DRIcontextPrivate *); -extern GLboolean nouveau_context_bind(__DRIcontextPrivate *, - __DRIdrawablePrivate *draw, - __DRIdrawablePrivate *read); -extern GLboolean nouveau_context_unbind(__DRIcontextPrivate *); - -#ifdef DEBUG -extern int __nouveau_debug; - -#define DEBUG_BO (1 << 0) - -#define DBG(flag, ...) do { \ - if (__nouveau_debug & (DEBUG_##flag)) \ - NOUVEAU_ERR(__VA_ARGS__); \ -} while(0) -#else -#define DBG(flag, ...) -#endif +extern int nouveau_context_init(struct nouveau_screen *nv_screen, + drm_context_t hHWContext, drmLock *sarea_lock, + struct nouveau_context *nv_share, + struct nouveau_context *nv); +extern void nouveau_context_cleanup(struct nouveau_context *nv); extern void LOCK_HARDWARE(struct nouveau_context *); extern void UNLOCK_HARDWARE(struct nouveau_context *); @@ -110,4 +79,8 @@ extern int nouveau_surface_init_nv50(struct nouveau_context *); extern uint32_t *nouveau_pipe_dma_beginp(struct nouveau_grobj *, int, int); extern void nouveau_pipe_dma_kickoff(struct nouveau_channel *); +/* Must be provided by clients of common code */ +extern void +nouveau_contended_lock(struct nouveau_context *nv); + #endif diff --git a/src/gallium/winsys/drm/nouveau/nouveau_device.c b/src/gallium/winsys/drm/nouveau/common/nouveau_device.c index 0b452fcd02..92b57b834b 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_device.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_device.c @@ -23,7 +23,7 @@ #include <stdio.h> #include <stdlib.h> #include <errno.h> - +#include <util/u_memory.h> #include "nouveau_drmif.h" int @@ -36,7 +36,7 @@ nouveau_device_open_existing(struct nouveau_device **dev, int close, if (!dev || *dev) return -EINVAL; - nvdev = calloc(1, sizeof(*nvdev)); + nvdev = CALLOC_STRUCT(nouveau_device_priv); if (!nvdev) return -ENOMEM; nvdev->fd = fd; @@ -112,7 +112,7 @@ nouveau_device_close(struct nouveau_device **dev) drmDestroyContext(nvdev->fd, nvdev->ctx); drmClose(nvdev->fd); } - free(nvdev); + FREE(nvdev); } int diff --git a/src/gallium/winsys/drm/nouveau/nouveau_dma.c b/src/gallium/winsys/drm/nouveau/common/nouveau_dma.c index f8a8ba04f6..f8a8ba04f6 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_dma.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_dma.c diff --git a/src/gallium/winsys/drm/nouveau/nouveau_dma.h b/src/gallium/winsys/drm/nouveau/common/nouveau_dma.h index cfa6d26e82..cfa6d26e82 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_dma.h +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_dma.h diff --git a/src/gallium/winsys/drm/nouveau/nouveau_dri.h b/src/gallium/winsys/drm/nouveau/common/nouveau_dri.h index 1207c2d609..1207c2d609 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_dri.h +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_dri.h diff --git a/src/gallium/winsys/drm/nouveau/nouveau_drmif.h b/src/gallium/winsys/drm/nouveau/common/nouveau_drmif.h index 5f72800676..5f72800676 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_drmif.h +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_drmif.h diff --git a/src/gallium/winsys/drm/nouveau/nouveau_fence.c b/src/gallium/winsys/drm/nouveau/common/nouveau_fence.c index e7b0b4ff07..e7b0b4ff07 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_fence.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_fence.c diff --git a/src/gallium/winsys/drm/nouveau/nouveau_grobj.c b/src/gallium/winsys/drm/nouveau/common/nouveau_grobj.c index 51523897d5..fb430a25b8 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_grobj.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_grobj.c @@ -22,7 +22,7 @@ #include <stdlib.h> #include <errno.h> - +#include <util/u_memory.h> #include "nouveau_drmif.h" int @@ -37,7 +37,7 @@ nouveau_grobj_alloc(struct nouveau_channel *chan, uint32_t handle, if (!nvdev || !grobj || *grobj) return -EINVAL; - nvgrobj = calloc(1, sizeof(*nvgrobj)); + nvgrobj = CALLOC_STRUCT(nouveau_grobj_priv); if (!nvgrobj) return -ENOMEM; nvgrobj->base.channel = chan; @@ -67,7 +67,7 @@ nouveau_grobj_ref(struct nouveau_channel *chan, uint32_t handle, if (!chan || !grobj || *grobj) return -EINVAL; - nvgrobj = calloc(1, sizeof(struct nouveau_grobj_priv)); + nvgrobj = CALLOC_STRUCT(nouveau_grobj_priv); if (!nvgrobj) return -ENOMEM; nvgrobj->base.channel = chan; @@ -102,6 +102,6 @@ nouveau_grobj_free(struct nouveau_grobj **grobj) drmCommandWrite(nvdev->fd, DRM_NOUVEAU_GPUOBJ_FREE, &f, sizeof(f)); } - free(nvgrobj); + FREE(nvgrobj); } diff --git a/src/gallium/winsys/drm/nouveau/nouveau_local.h b/src/gallium/winsys/drm/nouveau/common/nouveau_local.h index e878a40803..877c7a8c47 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_local.h +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_local.h @@ -5,8 +5,6 @@ #include "nouveau_winsys_pipe.h" #include <stdio.h> -struct pipe_buffer; - /* Debug output */ #define NOUVEAU_MSG(fmt, args...) do { \ fprintf(stdout, "nouveau: "fmt, ##args); \ diff --git a/src/gallium/winsys/drm/nouveau/nouveau_lock.c b/src/gallium/winsys/drm/nouveau/common/nouveau_lock.c index 9adb9ac854..e8cf051ed9 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_lock.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_lock.c @@ -25,34 +25,11 @@ * **************************************************************************/ -#include "main/glheader.h" -#include "glapi/glthread.h" -#include <GL/internal/glcore.h> - +#include <pipe/p_thread.h> #include "nouveau_context.h" #include "nouveau_screen.h" -_glthread_DECLARE_STATIC_MUTEX( lockMutex ); - -static void -nouveau_contended_lock(struct nouveau_context *nv, GLuint flags) -{ - __DRIdrawablePrivate *dPriv = nv->dri_drawable; - __DRIscreenPrivate *sPriv = nv->dri_screen; - struct nouveau_screen *nv_screen = nv->nv_screen; - struct nouveau_device *dev = nv_screen->device; - struct nouveau_device_priv *nvdev = nouveau_device(dev); - - drmGetLock(nvdev->fd, nvdev->ctx, flags); - - /* If the window moved, may need to set a new cliprect now. - * - * NOTE: This releases and regains the hw lock, so all state - * checking must be done *after* this call: - */ - if (dPriv) - DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv); -} +pipe_static_mutex(lockMutex); /* Lock the hardware and validate our state. */ @@ -64,20 +41,21 @@ LOCK_HARDWARE(struct nouveau_context *nv) struct nouveau_device_priv *nvdev = nouveau_device(dev); char __ret=0; - _glthread_LOCK_MUTEX(lockMutex); assert(!nv->locked); - + pipe_mutex_lock(lockMutex); + DRM_CAS(nvdev->lock, nvdev->ctx, (DRM_LOCK_HELD | nvdev->ctx), __ret); - - if (__ret) - nouveau_contended_lock(nv, 0); - nv->locked = GL_TRUE; -} + if (__ret) { + drmGetLock(nvdev->fd, nvdev->ctx, 0); + nouveau_contended_lock(nv); + } + nv->locked = 1; +} - /* Unlock the hardware using the global current context - */ +/* Unlock the hardware using the global current context + */ void UNLOCK_HARDWARE(struct nouveau_context *nv) { @@ -86,9 +64,9 @@ UNLOCK_HARDWARE(struct nouveau_context *nv) struct nouveau_device_priv *nvdev = nouveau_device(dev); assert(nv->locked); - nv->locked = GL_FALSE; + nv->locked = 0; DRM_UNLOCK(nvdev->fd, nvdev->lock, nvdev->ctx); - _glthread_UNLOCK_MUTEX(lockMutex); + pipe_mutex_unlock(lockMutex); } diff --git a/src/gallium/winsys/drm/nouveau/nouveau_notifier.c b/src/gallium/winsys/drm/nouveau/common/nouveau_notifier.c index 01e8f38440..01e8f38440 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_notifier.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_notifier.c diff --git a/src/gallium/winsys/drm/nouveau/nouveau_pushbuf.c b/src/gallium/winsys/drm/nouveau/common/nouveau_pushbuf.c index 815046ba85..7c094eb795 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_pushbuf.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_pushbuf.c @@ -23,7 +23,7 @@ #include <stdlib.h> #include <errno.h> #include <assert.h> - +#include <util/u_memory.h> #include "nouveau_drmif.h" #include "nouveau_dma.h" @@ -97,9 +97,9 @@ nouveau_pushbuf_init(struct nouveau_channel *chan) nouveau_pushbuf_space(chan, 0); chan->pushbuf = &nvchan->pb.base; - nvchan->pb.buffers = calloc(NOUVEAU_PUSHBUF_MAX_BUFFERS, + nvchan->pb.buffers = CALLOC(NOUVEAU_PUSHBUF_MAX_BUFFERS, sizeof(struct nouveau_pushbuf_bo)); - nvchan->pb.relocs = calloc(NOUVEAU_PUSHBUF_MAX_RELOCS, + nvchan->pb.relocs = CALLOC(NOUVEAU_PUSHBUF_MAX_RELOCS, sizeof(struct nouveau_pushbuf_reloc)); return 0; } @@ -268,4 +268,3 @@ nouveau_pushbuf_emit_reloc(struct nouveau_channel *chan, void *ptr, *(uint32_t *)ptr = nouveau_pushbuf_calc_reloc(bo, r); return 0; } - diff --git a/src/gallium/winsys/drm/nouveau/nouveau_resource.c b/src/gallium/winsys/drm/nouveau/common/nouveau_resource.c index 3bbcb5c45e..766fd279fe 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_resource.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_resource.c @@ -22,7 +22,7 @@ #include <stdlib.h> #include <errno.h> - +#include <util/u_memory.h> #include "nouveau_drmif.h" #include "nouveau_local.h" @@ -32,7 +32,7 @@ nouveau_resource_init(struct nouveau_resource **heap, { struct nouveau_resource *r; - r = calloc(1, sizeof(struct nouveau_resource)); + r = CALLOC_STRUCT(nouveau_resource); if (!r) return 1; @@ -53,7 +53,7 @@ nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv, while (heap) { if (!heap->in_use && heap->size >= size) { - r = calloc(1, sizeof(struct nouveau_resource)); + r = CALLOC_STRUCT(nouveau_resource); if (!r) return 1; @@ -73,7 +73,7 @@ nouveau_resource_alloc(struct nouveau_resource *heap, int size, void *priv, *res = r; return 0; } - + heap = heap->next; } @@ -110,7 +110,7 @@ nouveau_resource_free(struct nouveau_resource **res) if (r->next) r->next->prev = r->prev; r->prev->size += r->size; - free(r); + FREE(r); } - + } diff --git a/src/gallium/winsys/drm/nouveau/common/nouveau_screen.c b/src/gallium/winsys/drm/nouveau/common/nouveau_screen.c new file mode 100644 index 0000000000..422fbf0207 --- /dev/null +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_screen.c @@ -0,0 +1,31 @@ +#include <util/u_memory.h> +#include "nouveau_dri.h" +#include "nouveau_local.h" +#include "nouveau_screen.h" + +int +nouveau_screen_init(struct nouveau_dri *nv_dri, int dev_fd, + struct nouveau_screen *nv_screen) +{ + int ret; + + ret = nouveau_device_open_existing(&nv_screen->device, 0, + dev_fd, 0); + if (ret) { + NOUVEAU_ERR("Failed opening nouveau device: %d\n", ret); + return 1; + } + + nv_screen->front_offset = nv_dri->front_offset; + nv_screen->front_pitch = nv_dri->front_pitch * (nv_dri->bpp / 8); + nv_screen->front_cpp = nv_dri->bpp / 8; + nv_screen->front_height = nv_dri->height; + + return 0; +} + +void +nouveau_screen_cleanup(struct nouveau_screen *nv_screen) +{ + nouveau_device_close(&nv_screen->device); +} diff --git a/src/gallium/winsys/drm/nouveau/common/nouveau_screen.h b/src/gallium/winsys/drm/nouveau/common/nouveau_screen.h new file mode 100644 index 0000000000..3e68e219d8 --- /dev/null +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_screen.h @@ -0,0 +1,27 @@ +#ifndef __NOUVEAU_SCREEN_H__ +#define __NOUVEAU_SCREEN_H__ + +#include <stdint.h> + +struct nouveau_device; +struct nouveau_dri; + +struct nouveau_screen { + struct nouveau_device *device; + + uint32_t front_offset; + uint32_t front_pitch; + uint32_t front_cpp; + uint32_t front_height; + + void *nvc; +}; + +int +nouveau_screen_init(struct nouveau_dri *nv_dri, int dev_fd, + struct nouveau_screen *nv_screen); + +void +nouveau_screen_cleanup(struct nouveau_screen *nv_screen); + +#endif diff --git a/src/gallium/winsys/drm/nouveau/nouveau_winsys.c b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys.c index 364340e1d3..364340e1d3 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_winsys.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys.c diff --git a/src/gallium/winsys/drm/nouveau/nouveau_winsys_pipe.c b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.c index fe10479db7..6895137506 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_winsys_pipe.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.c @@ -1,50 +1,23 @@ -#include "pipe/p_winsys.h" -#include "pipe/p_defines.h" -#include "pipe/p_inlines.h" - -#include "util/u_memory.h" - +#include <pipe/p_winsys.h> +#include <pipe/p_defines.h> +#include <pipe/p_inlines.h> +#include <util/u_memory.h> #include "nouveau_context.h" #include "nouveau_local.h" #include "nouveau_screen.h" -#include "nouveau_swapbuffers.h" #include "nouveau_winsys_pipe.h" -static void -nouveau_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surf, - void *context_private) -{ - struct nouveau_context *nv = context_private; - __DRIdrawablePrivate *dPriv = nv->dri_drawable; - - nouveau_copy_buffer(dPriv, surf, NULL); -} - static const char * nouveau_get_name(struct pipe_winsys *pws) { return "Nouveau/DRI"; } -static struct pipe_buffer * -nouveau_pipe_bo_create(struct pipe_winsys *pws, unsigned alignment, - unsigned usage, unsigned size) +static uint32_t +nouveau_flags_from_usage(struct nouveau_context *nv, unsigned usage) { - struct nouveau_pipe_winsys *nvpws = (struct nouveau_pipe_winsys *)pws; - struct nouveau_context *nv = nvpws->nv; struct nouveau_device *dev = nv->nv_screen->device; - struct nouveau_pipe_buffer *nvbuf; - uint32_t flags; - - nvbuf = calloc(1, sizeof(*nvbuf)); - if (!nvbuf) - return NULL; - nvbuf->base.refcount = 1; - nvbuf->base.alignment = alignment; - nvbuf->base.usage = usage; - nvbuf->base.size = size; - - flags = NOUVEAU_BO_LOCAL; + uint32_t flags = NOUVEAU_BO_LOCAL; if (usage & PIPE_BUFFER_USAGE_PIXEL) { if (usage & NOUVEAU_BUFFER_USAGE_TEXTURE) @@ -75,8 +48,31 @@ nouveau_pipe_bo_create(struct pipe_winsys *pws, unsigned alignment, flags |= NOUVEAU_BO_GART; } + return flags; +} + +static struct pipe_buffer * +nouveau_pipe_bo_create(struct pipe_winsys *pws, unsigned alignment, + unsigned usage, unsigned size) +{ + struct nouveau_pipe_winsys *nvpws = (struct nouveau_pipe_winsys *)pws; + struct nouveau_context *nv = nvpws->nv; + struct nouveau_device *dev = nv->nv_screen->device; + struct nouveau_pipe_buffer *nvbuf; + uint32_t flags; + + nvbuf = CALLOC_STRUCT(nouveau_pipe_buffer); + if (!nvbuf) + return NULL; + nvbuf->base.refcount = 1; + nvbuf->base.alignment = alignment; + nvbuf->base.usage = usage; + nvbuf->base.size = size; + + flags = nouveau_flags_from_usage(nv, flags); + if (nouveau_bo_new(dev, flags, alignment, size, &nvbuf->bo)) { - free(nvbuf); + FREE(nvbuf); return NULL; } @@ -90,14 +86,14 @@ nouveau_pipe_bo_user_create(struct pipe_winsys *pws, void *ptr, unsigned bytes) struct nouveau_device *dev = nvpws->nv->nv_screen->device; struct nouveau_pipe_buffer *nvbuf; - nvbuf = calloc(1, sizeof(*nvbuf)); + nvbuf = CALLOC_STRUCT(nouveau_pipe_buffer); if (!nvbuf) return NULL; nvbuf->base.refcount = 1; nvbuf->base.size = bytes; if (nouveau_bo_user(dev, ptr, bytes, &nvbuf->bo)) { - free(nvbuf); + FREE(nvbuf); return NULL; } @@ -110,7 +106,7 @@ nouveau_pipe_bo_del(struct pipe_winsys *ws, struct pipe_buffer *buf) struct nouveau_pipe_buffer *nvbuf = nouveau_buffer(buf); nouveau_bo_del(&nvbuf->bo); - free(nvbuf); + FREE(nvbuf); } static void * @@ -125,6 +121,26 @@ nouveau_pipe_bo_map(struct pipe_winsys *pws, struct pipe_buffer *buf, if (flags & PIPE_BUFFER_USAGE_CPU_WRITE) map_flags |= NOUVEAU_BO_WR; + /* XXX: Technically incorrect. If the client maps a buffer for write-only + * and leaves part of the buffer untouched it probably expects those parts + * to remain intact. This is violated because we allocate a whole new buffer + * and don't copy the previous buffer's contents, so this optimization is + * only valid if the client intends to overwrite the whole buffer. + */ + if ((map_flags & NOUVEAU_BO_RDWR) == NOUVEAU_BO_WR && + !nouveau_bo_busy(nvbuf->bo, map_flags)) { + struct nouveau_pipe_winsys *nvpws = (struct nouveau_pipe_winsys *)pws; + struct nouveau_context *nv = nvpws->nv; + struct nouveau_device *dev = nv->nv_screen->device; + struct nouveau_bo *rename; + uint32_t flags = nouveau_flags_from_usage(nv, buf->usage); + + if (!nouveau_bo_new(dev, flags, buf->alignment, buf->size, &rename)) { + nouveau_bo_del(&nvbuf->bo); + nvbuf->bo = rename; + } + } + if (nouveau_bo_map(nvbuf->bo, map_flags)) return NULL; return nvbuf->bo->map; @@ -176,6 +192,12 @@ nouveau_pipe_fence_finish(struct pipe_winsys *ws, return nouveau_fence_wait(&ref); } +static void +nouveau_destroy(struct pipe_winsys *pws) +{ + FREE(pws); +} + struct pipe_winsys * nouveau_create_pipe_winsys(struct nouveau_context *nv) { @@ -201,7 +223,7 @@ nouveau_create_pipe_winsys(struct nouveau_context *nv) pws->fence_finish = nouveau_pipe_fence_finish; pws->get_name = nouveau_get_name; + pws->destroy = nouveau_destroy; return &nvpws->pws; } - diff --git a/src/gallium/winsys/drm/nouveau/nouveau_winsys_pipe.h b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.h index 6a03ac0d77..14c728690d 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_winsys_pipe.h +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_pipe.h @@ -31,4 +31,9 @@ nouveau_create_softpipe(struct nouveau_context *nv); struct pipe_context * nouveau_pipe_create(struct nouveau_context *nv); +/* Must be provided by clients of common code */ +extern void +nouveau_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surf, + void *context_private); + #endif diff --git a/src/gallium/winsys/drm/nouveau/nouveau_winsys_softpipe.c b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_softpipe.c index 68aade829d..04def600f4 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_winsys_softpipe.c +++ b/src/gallium/winsys/drm/nouveau/common/nouveau_winsys_softpipe.c @@ -29,12 +29,12 @@ * Authors: Keith Whitwell <keithw-at-tungstengraphics-dot-com> */ -#include "imports.h" - -#include "pipe/p_defines.h" -#include "pipe/p_format.h" -#include "softpipe/sp_winsys.h" - +#include <pipe/p_winsys.h> +#include <pipe/p_screen.h> +#include <pipe/p_defines.h> +#include <pipe/p_format.h> +#include <softpipe/sp_winsys.h> +#include <util/u_memory.h> #include "nouveau_context.h" #include "nouveau_winsys_pipe.h" @@ -48,7 +48,7 @@ struct nouveau_softpipe_winsys { */ static boolean nouveau_is_format_supported(struct softpipe_winsys *sws, - enum pipe_format format) + enum pipe_format format) { switch (format) { case PIPE_FORMAT_A8R8G8B8_UNORM: @@ -68,19 +68,34 @@ nouveau_create_softpipe(struct nouveau_context *nv) struct nouveau_softpipe_winsys *nvsws; struct pipe_screen *pscreen; struct pipe_winsys *ws; + struct pipe_context *pipe; ws = nouveau_create_pipe_winsys(nv); if (!ws) return NULL; pscreen = softpipe_create_screen(ws); - + if (!pscreen) { + ws->destroy(ws); + return NULL; + } nvsws = CALLOC_STRUCT(nouveau_softpipe_winsys); - if (!nvsws) + if (!nvsws) { + ws->destroy(ws); + pscreen->destroy(pscreen); return NULL; + } nvsws->sws.is_format_supported = nouveau_is_format_supported; nvsws->nv = nv; - return softpipe_create(pscreen, ws, &nvsws->sws); + pipe = softpipe_create(pscreen, ws, &nvsws->sws); + if (!pipe) { + ws->destroy(ws); + pscreen->destroy(pscreen); + FREE(nvsws); + return NULL; + } + + return pipe; } diff --git a/src/gallium/winsys/drm/nouveau/nv04_surface.c b/src/gallium/winsys/drm/nouveau/common/nv04_surface.c index e9a8a2ac1c..e9a8a2ac1c 100644 --- a/src/gallium/winsys/drm/nouveau/nv04_surface.c +++ b/src/gallium/winsys/drm/nouveau/common/nv04_surface.c diff --git a/src/gallium/winsys/drm/nouveau/nv50_surface.c b/src/gallium/winsys/drm/nouveau/common/nv50_surface.c index c8ab7f690f..c8ab7f690f 100644 --- a/src/gallium/winsys/drm/nouveau/nv50_surface.c +++ b/src/gallium/winsys/drm/nouveau/common/nv50_surface.c diff --git a/src/gallium/winsys/drm/nouveau/dri/Makefile b/src/gallium/winsys/drm/nouveau/dri/Makefile new file mode 100644 index 0000000000..e129e42e97 --- /dev/null +++ b/src/gallium/winsys/drm/nouveau/dri/Makefile @@ -0,0 +1,31 @@ +TOP = ../../../../../.. +include $(TOP)/configs/current + +LIBNAME = nouveau_dri.so + +MINIGLX_SOURCES = + +PIPE_DRIVERS = \ + $(TOP)/src/gallium/drivers/softpipe/libsoftpipe.a \ + $(TOP)/src/gallium/drivers/nv04/libnv04.a \ + $(TOP)/src/gallium/drivers/nv10/libnv10.a \ + $(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 + +DRIVER_SOURCES = \ + nouveau_context_dri.c \ + nouveau_screen_dri.c \ + nouveau_swapbuffers.c \ + ../common/libnouveaudrm.a + +C_SOURCES = \ + $(COMMON_GALLIUM_SOURCES) \ + $(DRIVER_SOURCES) + +ASM_SOURCES = + +include ../../Makefile.template + +symlinks: diff --git a/src/gallium/winsys/drm/nouveau/dri/nouveau_context_dri.c b/src/gallium/winsys/drm/nouveau/dri/nouveau_context_dri.c new file mode 100644 index 0000000000..006978b182 --- /dev/null +++ b/src/gallium/winsys/drm/nouveau/dri/nouveau_context_dri.c @@ -0,0 +1,124 @@ +#include <main/glheader.h> +#include <glapi/glthread.h> +#include <GL/internal/glcore.h> +#include <utils.h> + +#include <state_tracker/st_public.h> +#include <state_tracker/st_context.h> +#include <pipe/p_defines.h> +#include <pipe/p_context.h> +#include <pipe/p_screen.h> + +#include "../common/nouveau_winsys_pipe.h" +#include "../common/nouveau_dri.h" +#include "../common/nouveau_local.h" +#include "nouveau_context_dri.h" +#include "nouveau_screen_dri.h" + +#ifdef DEBUG +static const struct dri_debug_control debug_control[] = { + { "bo", DEBUG_BO }, + { NULL, 0 } +}; +int __nouveau_debug = 0; +#endif + +GLboolean +nouveau_context_create(const __GLcontextModes *glVis, + __DRIcontextPrivate *driContextPriv, + void *sharedContextPrivate) +{ + __DRIscreenPrivate *driScrnPriv = driContextPriv->driScreenPriv; + struct nouveau_screen_dri *nv_screen = driScrnPriv->private; + struct nouveau_context_dri *nv = CALLOC_STRUCT(nouveau_context_dri); + struct st_context *st_share = NULL; + struct nouveau_context_dri *nv_share = NULL; + struct pipe_context *pipe; + + if (sharedContextPrivate) { + st_share = ((struct nouveau_context_dri *)sharedContextPrivate)->st; + nv_share = st_share->pipe->priv; + } + + if (nouveau_context_init(&nv_screen->base, driContextPriv->hHWContext, + (drmLock *)&driScrnPriv->pSAREA->lock, + nv_share, &nv->base)) { + return GL_FALSE; + } + + pipe = nv->base.nvc->pctx[nv->base.pctx_id]; + driContextPriv->driverPrivate = (void *)nv; + //nv->nv_screen = nv_screen; + nv->dri_screen = driScrnPriv; + + driParseConfigFiles(&nv->dri_option_cache, &nv_screen->option_cache, + nv->dri_screen->myNum, "nouveau"); +#ifdef DEBUG + __nouveau_debug = driParseDebugString(getenv("NOUVEAU_DEBUG"), + debug_control); +#endif + + nv->st = st_create_context(pipe, glVis, st_share); + return GL_TRUE; +} + +void +nouveau_context_destroy(__DRIcontextPrivate *driContextPriv) +{ + struct nouveau_context_dri *nv = driContextPriv->driverPrivate; + + assert(nv); + + st_finish(nv->st); + st_destroy_context(nv->st); + + nouveau_context_cleanup(&nv->base); + + FREE(nv); +} + +GLboolean +nouveau_context_bind(__DRIcontextPrivate *driContextPriv, + __DRIdrawablePrivate *driDrawPriv, + __DRIdrawablePrivate *driReadPriv) +{ + struct nouveau_context_dri *nv; + struct nouveau_framebuffer *draw, *read; + + if (!driContextPriv) { + st_make_current(NULL, NULL, NULL); + return GL_TRUE; + } + + nv = driContextPriv->driverPrivate; + draw = driDrawPriv->driverPrivate; + read = driReadPriv->driverPrivate; + + st_make_current(nv->st, draw->stfb, read->stfb); + + if ((nv->dri_drawable != driDrawPriv) || + (nv->last_stamp != driDrawPriv->lastStamp)) { + nv->dri_drawable = driDrawPriv; + st_resize_framebuffer(draw->stfb, driDrawPriv->w, + driDrawPriv->h); + nv->last_stamp = driDrawPriv->lastStamp; + } + + if (driDrawPriv != driReadPriv) { + st_resize_framebuffer(read->stfb, driReadPriv->w, + driReadPriv->h); + } + + return GL_TRUE; +} + +GLboolean +nouveau_context_unbind(__DRIcontextPrivate *driContextPriv) +{ + struct nouveau_context_dri *nv = driContextPriv->driverPrivate; + (void)nv; + + st_flush(nv->st, 0, NULL); + return GL_TRUE; +} + diff --git a/src/gallium/winsys/drm/nouveau/dri/nouveau_context_dri.h b/src/gallium/winsys/drm/nouveau/dri/nouveau_context_dri.h new file mode 100644 index 0000000000..8257790d47 --- /dev/null +++ b/src/gallium/winsys/drm/nouveau/dri/nouveau_context_dri.h @@ -0,0 +1,49 @@ +#ifndef __NOUVEAU_CONTEXT_DRI_H__ +#define __NOUVEAU_CONTEXT_DRI_H__ + +#include <dri_util.h> +#include <xmlconfig.h> +#include <nouveau/nouveau_winsys.h> +#include "../common/nouveau_context.h" +#include "../common/nouveau_drmif.h" +#include "../common/nouveau_dma.h" + +struct nouveau_framebuffer { + struct st_framebuffer *stfb; +}; + +struct nouveau_context_dri { + struct nouveau_context base; + struct st_context *st; + + /* DRI stuff */ + __DRIscreenPrivate *dri_screen; + __DRIdrawablePrivate *dri_drawable; + unsigned int last_stamp; + driOptionCache dri_option_cache; + drm_context_t drm_context; + drmLock drm_lock; +}; + +extern GLboolean nouveau_context_create(const __GLcontextModes *, + __DRIcontextPrivate *, void *); +extern void nouveau_context_destroy(__DRIcontextPrivate *); +extern GLboolean nouveau_context_bind(__DRIcontextPrivate *, + __DRIdrawablePrivate *draw, + __DRIdrawablePrivate *read); +extern GLboolean nouveau_context_unbind(__DRIcontextPrivate *); + +#ifdef DEBUG +extern int __nouveau_debug; + +#define DEBUG_BO (1 << 0) + +#define DBG(flag, ...) do { \ + if (__nouveau_debug & (DEBUG_##flag)) \ + NOUVEAU_ERR(__VA_ARGS__); \ +} while(0) +#else +#define DBG(flag, ...) +#endif + +#endif diff --git a/src/gallium/winsys/drm/nouveau/nouveau_screen.c b/src/gallium/winsys/drm/nouveau/dri/nouveau_screen_dri.c index c6d0c53588..1d7c92376f 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_screen.c +++ b/src/gallium/winsys/drm/nouveau/dri/nouveau_screen_dri.c @@ -1,16 +1,15 @@ -#include "utils.h" -#include "vblank.h" -#include "xmlpool.h" - -#include "pipe/p_context.h" -#include "state_tracker/st_public.h" -#include "state_tracker/st_cb_fbo.h" - -#include "nouveau_context.h" -#include "nouveau_drm.h" -#include "nouveau_dri.h" -#include "nouveau_local.h" -#include "nouveau_screen.h" +#include <utils.h> +#include <vblank.h> +#include <xmlpool.h> + +#include <pipe/p_context.h> +#include <state_tracker/st_public.h> +#include <state_tracker/st_cb_fbo.h> +#include <nouveau_drm.h> +#include "../common/nouveau_dri.h" +#include "../common/nouveau_local.h" +#include "nouveau_context_dri.h" +#include "nouveau_screen_dri.h" #include "nouveau_swapbuffers.h" #if NOUVEAU_DRM_HEADER_PATCHLEVEL != 11 @@ -183,13 +182,12 @@ static const __DRIconfig ** nouveau_screen_create(__DRIscreenPrivate *psp) { struct nouveau_dri *nv_dri = psp->pDevPriv; - struct nouveau_screen *nv_screen; + struct nouveau_screen_dri *nv_screen; static const __DRIversion ddx_expected = { 0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL }; static const __DRIversion dri_expected = { 4, 0, 0 }; static const __DRIversion drm_expected = { 0, 0, NOUVEAU_DRM_HEADER_PATCHLEVEL }; - int ret; if (!driCheckDriDdxDrmVersions2("nouveau", &psp->dri_version, &dri_expected, @@ -209,28 +207,23 @@ nouveau_screen_create(__DRIscreenPrivate *psp) if (psp->devPrivSize != sizeof(struct nouveau_dri)) { NOUVEAU_ERR("DRI struct mismatch between DDX/DRI\n"); - return GL_FALSE; + return NULL; } - nv_screen = CALLOC_STRUCT(nouveau_screen); + nv_screen = CALLOC_STRUCT(nouveau_screen_dri); if (!nv_screen) - return GL_FALSE; - nv_screen->driScrnPriv = psp; - psp->private = (void *)nv_screen; + return NULL; driParseOptionInfo(&nv_screen->option_cache, __driConfigOptions, __driNConfigOptions); - if ((ret = nouveau_device_open_existing(&nv_screen->device, 0, - psp->fd, 0))) { - NOUVEAU_ERR("Failed opening nouveau device: %d\n", ret); - return GL_FALSE; + if (nouveau_screen_init(nv_dri, psp->fd, &nv_screen->base)) { + FREE(nv_screen); + return NULL; } - nv_screen->front_offset = nv_dri->front_offset; - nv_screen->front_pitch = nv_dri->front_pitch * (nv_dri->bpp / 8); - nv_screen->front_cpp = nv_dri->bpp / 8; - nv_screen->front_height = nv_dri->height; + nv_screen->driScrnPriv = psp; + psp->private = (void *)nv_screen; return (const __DRIconfig **) nouveau_fill_in_modes(psp, nv_dri->bpp, @@ -241,9 +234,10 @@ nouveau_screen_create(__DRIscreenPrivate *psp) static void nouveau_screen_destroy(__DRIscreenPrivate *driScrnPriv) { - struct nouveau_screen *nv_screen = driScrnPriv->private; + struct nouveau_screen_dri *nv_screen = driScrnPriv->private; driScrnPriv->private = NULL; + nouveau_screen_cleanup(&nv_screen->base); FREE(nv_screen); } diff --git a/src/gallium/winsys/drm/nouveau/dri/nouveau_screen_dri.h b/src/gallium/winsys/drm/nouveau/dri/nouveau_screen_dri.h new file mode 100644 index 0000000000..1498087819 --- /dev/null +++ b/src/gallium/winsys/drm/nouveau/dri/nouveau_screen_dri.h @@ -0,0 +1,13 @@ +#ifndef __NOUVEAU_SCREEN_DRI_H__ +#define __NOUVEAU_SCREEN_DRI_H__ + +#include "../common/nouveau_screen.h" +#include "xmlconfig.h" + +struct nouveau_screen_dri { + struct nouveau_screen base; + __DRIscreenPrivate *driScrnPriv; + driOptionCache option_cache; +}; + +#endif diff --git a/src/gallium/winsys/drm/nouveau/nouveau_swapbuffers.c b/src/gallium/winsys/drm/nouveau/dri/nouveau_swapbuffers.c index 70e0104e83..38461b2b0c 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_swapbuffers.c +++ b/src/gallium/winsys/drm/nouveau/dri/nouveau_swapbuffers.c @@ -1,34 +1,34 @@ -#include "main/glheader.h" -#include "glapi/glthread.h" +#include <main/glheader.h> +#include <glapi/glthread.h> #include <GL/internal/glcore.h> -#include "pipe/p_context.h" -#include "state_tracker/st_public.h" -#include "state_tracker/st_context.h" -#include "state_tracker/st_cb_fbo.h" +#include <pipe/p_context.h> +#include <state_tracker/st_public.h> +#include <state_tracker/st_context.h> +#include <state_tracker/st_cb_fbo.h> -#include "nouveau_context.h" -#include "nouveau_local.h" -#include "nouveau_screen.h" +#include "../common/nouveau_local.h" +#include "nouveau_context_dri.h" +#include "nouveau_screen_dri.h" #include "nouveau_swapbuffers.h" void nouveau_copy_buffer(__DRIdrawablePrivate *dPriv, struct pipe_surface *surf, const drm_clip_rect_t *rect) { - struct nouveau_context *nv = dPriv->driContextPriv->driverPrivate; + struct nouveau_context_dri *nv = dPriv->driContextPriv->driverPrivate; drm_clip_rect_t *pbox; int nbox, i; - LOCK_HARDWARE(nv); + LOCK_HARDWARE(&nv->base); if (!dPriv->numClipRects) { - UNLOCK_HARDWARE(nv); + UNLOCK_HARDWARE(&nv->base); return; } pbox = dPriv->pClipRects; nbox = dPriv->numClipRects; - nv->surface_copy_prep(nv, nv->frontbuffer, surf); + nv->base.surface_copy_prep(&nv->base, nv->base.frontbuffer, surf); for (i = 0; i < nbox; i++, pbox++) { int sx, sy, dx, dy, w, h; @@ -39,11 +39,11 @@ nouveau_copy_buffer(__DRIdrawablePrivate *dPriv, struct pipe_surface *surf, w = pbox->x2 - pbox->x1; h = pbox->y2 - pbox->y1; - nv->surface_copy(nv, dx, dy, sx, sy, w, h); + nv->base.surface_copy(&nv->base, dx, dy, sx, sy, w, h); } - FIRE_RING(nv->nvc->channel); - UNLOCK_HARDWARE(nv); + FIRE_RING(nv->base.nvc->channel); + UNLOCK_HARDWARE(&nv->base); if (nv->last_stamp != dPriv->lastStamp) { struct nouveau_framebuffer *nvfb = dPriv->driverPrivate; @@ -84,3 +84,29 @@ nouveau_swap_buffers(__DRIdrawablePrivate *dPriv) } } +void +nouveau_flush_frontbuffer(struct pipe_winsys *pws, struct pipe_surface *surf, + void *context_private) +{ + struct nouveau_context_dri *nv = context_private; + __DRIdrawablePrivate *dPriv = nv->dri_drawable; + + nouveau_copy_buffer(dPriv, surf, NULL); +} + +void +nouveau_contended_lock(struct nouveau_context *nv) +{ + struct nouveau_context_dri *nv_sub = (struct nouveau_context_dri*)nv; + __DRIdrawablePrivate *dPriv = nv_sub->dri_drawable; + __DRIscreenPrivate *sPriv = nv_sub->dri_screen; + + /* If the window moved, may need to set a new cliprect now. + * + * NOTE: This releases and regains the hw lock, so all state + * checking must be done *after* this call: + */ + if (dPriv) + DRI_VALIDATE_DRAWABLE_INFO(sPriv, dPriv); +} + diff --git a/src/gallium/winsys/drm/nouveau/nouveau_swapbuffers.h b/src/gallium/winsys/drm/nouveau/dri/nouveau_swapbuffers.h index 825d3da6da..825d3da6da 100644 --- a/src/gallium/winsys/drm/nouveau/nouveau_swapbuffers.h +++ b/src/gallium/winsys/drm/nouveau/dri/nouveau_swapbuffers.h diff --git a/src/gallium/winsys/drm/nouveau/nouveau_screen.h b/src/gallium/winsys/drm/nouveau/nouveau_screen.h deleted file mode 100644 index 388d6be9bb..0000000000 --- a/src/gallium/winsys/drm/nouveau/nouveau_screen.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef __NOUVEAU_SCREEN_H__ -#define __NOUVEAU_SCREEN_H__ - -#include "xmlconfig.h" - -struct nouveau_screen { - __DRIscreenPrivate *driScrnPriv; - driOptionCache option_cache; - - struct nouveau_device *device; - - uint32_t front_offset; - uint32_t front_pitch; - uint32_t front_cpp; - uint32_t front_height; - - void *nvc; -}; - -#endif |