diff options
Diffstat (limited to 'src/gallium/drivers')
-rw-r--r-- | src/gallium/drivers/nouveau/nouveau_screen.c | 242 | ||||
-rw-r--r-- | src/gallium/drivers/nouveau/nouveau_screen.h | 24 | ||||
-rw-r--r-- | src/gallium/drivers/nv50/nv50_context.h | 2 | ||||
-rw-r--r-- | src/gallium/drivers/nv50/nv50_query.c | 2 | ||||
-rw-r--r-- | src/gallium/drivers/nv50/nv50_screen.c | 83 | ||||
-rw-r--r-- | src/gallium/drivers/nv50/nv50_screen.h | 4 | ||||
-rw-r--r-- | src/gallium/drivers/nv50/nv50_surface.c | 6 | ||||
-rw-r--r-- | src/gallium/drivers/nv50/nv50_transfer.c | 4 |
8 files changed, 307 insertions, 60 deletions
diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c new file mode 100644 index 0000000000..3cab83eec0 --- /dev/null +++ b/src/gallium/drivers/nouveau/nouveau_screen.c @@ -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 index 0000000000..cffba11762 --- /dev/null +++ b/src/gallium/drivers/nouveau/nouveau_screen.h @@ -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 diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h index d960657066..7b67a75439 100644 --- a/src/gallium/drivers/nv50/nv50_context.h +++ b/src/gallium/drivers/nv50/nv50_context.h @@ -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 diff --git a/src/gallium/drivers/nv50/nv50_query.c b/src/gallium/drivers/nv50/nv50_query.c index 35cebdbdc3..4d05eeac2c 100644 --- a/src/gallium/drivers/nv50/nv50_query.c +++ b/src/gallium/drivers/nv50/nv50_query.c @@ -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); diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c index b7e9df77db..3b830847ca 100644 --- a/src/gallium/drivers/nv50/nv50_screen.c +++ b/src/gallium/drivers/nv50/nv50_screen.c @@ -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; } diff --git a/src/gallium/drivers/nv50/nv50_screen.h b/src/gallium/drivers/nv50/nv50_screen.h index fa7d8d0f0d..61e24a5b57 100644 --- a/src/gallium/drivers/nv50/nv50_screen.h +++ b/src/gallium/drivers/nv50/nv50_screen.h @@ -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; diff --git a/src/gallium/drivers/nv50/nv50_surface.c b/src/gallium/drivers/nv50/nv50_surface.c index c0f0efe158..121eddfc83 100644 --- a/src/gallium/drivers/nv50/nv50_surface.c +++ b/src/gallium/drivers/nv50/nv50_surface.c @@ -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; diff --git a/src/gallium/drivers/nv50/nv50_transfer.c b/src/gallium/drivers/nv50/nv50_transfer.c index 28e7edd144..5f1e430ad1 100644 --- a/src/gallium/drivers/nv50/nv50_transfer.c +++ b/src/gallium/drivers/nv50/nv50_transfer.c @@ -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; |