Mesa (master): nv50: create textures with nouveau_bo, for flexibility with tiling later

Ben Skeggs darktama at kemper.freedesktop.org
Fri Jun 5 12:58:30 UTC 2009


Module: Mesa
Branch: master
Commit: 1a92c71a66dd9d785906cdb78c107e63dcf48672
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=1a92c71a66dd9d785906cdb78c107e63dcf48672

Author: Ben Skeggs <bskeggs at redhat.com>
Date:   Fri Jun  5 20:32:32 2009 +1000

nv50: create textures with nouveau_bo, for flexibility with tiling later

---

 src/gallium/drivers/nv50/nv50_context.h        |   10 +-----
 src/gallium/drivers/nv50/nv50_miptree.c        |   22 +++++++-----
 src/gallium/drivers/nv50/nv50_state_validate.c |    6 ++-
 src/gallium/drivers/nv50/nv50_surface.c        |    2 +-
 src/gallium/drivers/nv50/nv50_tex.c            |    6 +--
 src/gallium/drivers/nv50/nv50_transfer.c       |   41 ++++++++++++++----------
 6 files changed, 46 insertions(+), 41 deletions(-)

diff --git a/src/gallium/drivers/nv50/nv50_context.h b/src/gallium/drivers/nv50/nv50_context.h
index 7b67a75..c3ffdcc 100644
--- a/src/gallium/drivers/nv50/nv50_context.h
+++ b/src/gallium/drivers/nv50/nv50_context.h
@@ -70,7 +70,8 @@ struct nv50_miptree_level {
 
 struct nv50_miptree {
 	struct pipe_texture base;
-	struct pipe_buffer *buffer;
+
+	struct nouveau_bo *bo;
 
 	struct nv50_miptree_level level[PIPE_MAX_TEXTURE_LEVELS];
 	int image_nr;
@@ -93,13 +94,6 @@ nv50_surface(struct pipe_surface *pt)
 	return (struct nv50_surface *)pt;
 }
 
-static INLINE struct pipe_buffer *
-nv50_surface_buffer(struct pipe_surface *surface)
-{
-	struct nv50_miptree *mt = (struct nv50_miptree *)surface->texture;
-	return mt->buffer;
-}
-
 struct nv50_state {
 	unsigned dirty;
 
diff --git a/src/gallium/drivers/nv50/nv50_miptree.c b/src/gallium/drivers/nv50/nv50_miptree.c
index f79a7ca..2fbedb6 100644
--- a/src/gallium/drivers/nv50/nv50_miptree.c
+++ b/src/gallium/drivers/nv50/nv50_miptree.c
@@ -29,23 +29,25 @@
 static struct pipe_texture *
 nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *tmp)
 {
+	struct nouveau_device *dev = nouveau_screen(pscreen)->device;
 	struct nv50_miptree *mt = CALLOC_STRUCT(nv50_miptree);
 	struct pipe_texture *pt = &mt->base;
-	unsigned usage, width = tmp->width[0], height = tmp->height[0];
+	unsigned width = tmp->width[0], height = tmp->height[0];
 	unsigned depth = tmp->depth[0];
-	int i, l;
+	uint32_t tile_mode = 0, tile_flags = 0;
+	int ret, i, l;
 
 	mt->base = *tmp;
 	pipe_reference_init(&mt->base.reference, 1);
 	mt->base.screen = pscreen;
 
-	usage = PIPE_BUFFER_USAGE_PIXEL;
 	switch (pt->format) {
 	case PIPE_FORMAT_Z24S8_UNORM:
 	case PIPE_FORMAT_Z16_UNORM:
-		usage |= NOUVEAU_BUFFER_USAGE_ZETA;
+		tile_flags = 0x2800;
 		break;
 	default:
+		tile_flags = 0x7000;
 		break;
 	}
 
@@ -93,12 +95,13 @@ nv50_miptree_create(struct pipe_screen *pscreen, const struct pipe_texture *tmp)
 		}
 	}
 
-	mt->buffer = pscreen->buffer_create(pscreen, 256, usage, mt->total_size);
-	if (!mt->buffer) {
+	ret = nouveau_bo_new_tile(dev, NOUVEAU_BO_VRAM, 256, mt->total_size,
+				  tile_mode, tile_flags, &mt->bo);
+	if (ret) {
 		FREE(mt);
 		return NULL;
 	}
-
+			     
 	return &mt->base;
 }
 
@@ -106,6 +109,7 @@ static struct pipe_texture *
 nv50_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
 		     const unsigned *stride, struct pipe_buffer *pb)
 {
+	struct nouveau_bo *bo = nouveau_bo(pb);
 	struct nv50_miptree *mt;
 
 	/* Only supports 2D, non-mipmapped textures for the moment */
@@ -124,7 +128,7 @@ nv50_miptree_blanket(struct pipe_screen *pscreen, const struct pipe_texture *pt,
 	mt->level[0].pitch = *stride;
 	mt->level[0].image_offset = CALLOC(1, sizeof(unsigned));
 
-	pipe_buffer_reference(&mt->buffer, pb);
+	nouveau_bo_ref(bo, &mt->bo);
 	return &mt->base;
 }
 
@@ -133,7 +137,7 @@ nv50_miptree_destroy(struct pipe_texture *pt)
 {
 	struct nv50_miptree *mt = nv50_miptree(pt);
 
-        pipe_buffer_reference(&mt->buffer, NULL);
+	nouveau_bo_ref(NULL, &mt->bo);
         FREE(mt);
 }
 
diff --git a/src/gallium/drivers/nv50/nv50_state_validate.c b/src/gallium/drivers/nv50/nv50_state_validate.c
index 9e70d4b..1788f76 100644
--- a/src/gallium/drivers/nv50/nv50_state_validate.c
+++ b/src/gallium/drivers/nv50/nv50_state_validate.c
@@ -32,7 +32,8 @@ nv50_state_validate_fb(struct nv50_context *nv50)
 	unsigned i, w, h, gw = 0;
 
 	for (i = 0; i < fb->nr_cbufs; i++) {
-		struct nouveau_bo *bo = nouveau_bo(nv50_surface_buffer(fb->cbufs[i]));
+		struct pipe_texture *pt = fb->cbufs[i]->texture;
+		struct nouveau_bo *bo = nv50_miptree(pt)->bo;
 
 		if (!gw) {
 			w = fb->cbufs[i]->width;
@@ -73,7 +74,8 @@ nv50_state_validate_fb(struct nv50_context *nv50)
 	}
 
 	if (fb->zsbuf) {
-		struct nouveau_bo *bo = nouveau_bo(nv50_surface_buffer(fb->zsbuf));
+		struct pipe_texture *pt = fb->zsbuf->texture;
+		struct nouveau_bo *bo = nv50_miptree(pt)->bo;
 
 		if (!gw) {
 			w = fb->zsbuf->width;
diff --git a/src/gallium/drivers/nv50/nv50_surface.c b/src/gallium/drivers/nv50/nv50_surface.c
index 936fe43..8db3b6d 100644
--- a/src/gallium/drivers/nv50/nv50_surface.c
+++ b/src/gallium/drivers/nv50/nv50_surface.c
@@ -54,7 +54,7 @@ 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->eng2d->channel;
 	struct nouveau_grobj *eng2d = screen->eng2d;
-	struct nouveau_bo *bo = nouveau_bo(nv50_miptree(ps->texture)->buffer);
+	struct nouveau_bo *bo = nv50_miptree(ps->texture)->bo;
  	int format, mthd = dst ? NV50_2D_DST_FORMAT : NV50_2D_SRC_FORMAT;
  	int flags = NOUVEAU_BO_VRAM | (dst ? NOUVEAU_BO_WR : NOUVEAU_BO_RD);
 
diff --git a/src/gallium/drivers/nv50/nv50_tex.c b/src/gallium/drivers/nv50/nv50_tex.c
index 5539a79..8bb8139 100644
--- a/src/gallium/drivers/nv50/nv50_tex.c
+++ b/src/gallium/drivers/nv50/nv50_tex.c
@@ -29,8 +29,6 @@ static int
 nv50_tex_construct(struct nv50_context *nv50, struct nouveau_stateobj *so,
 		   struct nv50_miptree *mt)
 {
-	struct nouveau_bo *bo = nouveau_bo(mt->buffer);
-
 	switch (mt->base.format) {
 	case PIPE_FORMAT_A8R8G8B8_UNORM:
 		so_data(so, NV50TIC_0_0_MAPA_C3 | NV50TIC_0_0_TYPEA_UNORM |
@@ -120,9 +118,9 @@ nv50_tex_construct(struct nv50_context *nv50, struct nouveau_stateobj *so,
 		return 1;
 	}
 
-	so_reloc(so, bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW |
+	so_reloc(so, mt->bo, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW |
 		     NOUVEAU_BO_RD, 0, 0);
-	so_data (so, 0xd0005000 | bo->tile_mode << 22);
+	so_data (so, 0xd0005000 | mt->bo->tile_mode << 22);
 	so_data (so, 0x00300000);
 	so_data (so, mt->base.width[0]);
 	so_data (so, (mt->base.last_level << 28) |
diff --git a/src/gallium/drivers/nv50/nv50_transfer.c b/src/gallium/drivers/nv50/nv50_transfer.c
index babb35a..d0b7f0b 100644
--- a/src/gallium/drivers/nv50/nv50_transfer.c
+++ b/src/gallium/drivers/nv50/nv50_transfer.c
@@ -6,7 +6,7 @@
 
 struct nv50_transfer {
 	struct pipe_transfer base;
-	struct pipe_buffer *buffer;
+	struct nouveau_bo *bo;
 	unsigned level_offset;
 	int level_pitch;
 	int level_width;
@@ -16,9 +16,9 @@ struct nv50_transfer {
 };
 
 static void
-nv50_transfer_rect_m2mf(struct pipe_screen *pscreen, struct pipe_buffer *src,
+nv50_transfer_rect_m2mf(struct pipe_screen *pscreen, struct nouveau_bo *src_bo,
 			unsigned src_offset, int src_pitch, int sx, int sy,
-			int sw, int sh, struct pipe_buffer *dst,
+			int sw, int sh, struct nouveau_bo *dst_bo,
 			unsigned dst_offset, int dst_pitch, int dx, int dy,
 			int dw, int dh, int cpp, int width, int height,
 			unsigned src_reloc, unsigned dst_reloc)
@@ -26,8 +26,6 @@ nv50_transfer_rect_m2mf(struct pipe_screen *pscreen, struct pipe_buffer *src,
 	struct nv50_screen *screen = nv50_screen(pscreen);
 	struct nouveau_channel *chan = screen->m2mf->channel;
 	struct nouveau_grobj *m2mf = screen->m2mf;
-	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;
@@ -107,10 +105,12 @@ nv50_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
 		  enum pipe_transfer_usage usage,
 		  unsigned x, unsigned y, unsigned w, unsigned h)
 {
+	struct nouveau_device *dev = nouveau_screen(pscreen)->device;
 	struct nv50_miptree *mt = nv50_miptree(pt);
 	struct nv50_miptree_level *lvl = &mt->level[level];
 	struct nv50_transfer *tx;
 	unsigned image = 0;
+	int ret;
 
 	if (pt->target == PIPE_TEXTURE_CUBE)
 		image = face;
@@ -138,14 +138,17 @@ nv50_transfer_new(struct pipe_screen *pscreen, struct pipe_texture *pt,
 	tx->level_offset = lvl->image_offset[image];
 	tx->level_x = x;
 	tx->level_y = y;
-	tx->buffer =
-		pipe_buffer_create(pscreen, 0, NOUVEAU_BUFFER_USAGE_TRANSFER,
-				   w * tx->base.block.size * h);
+	ret = nouveau_bo_new(dev, NOUVEAU_BO_GART | NOUVEAU_BO_MAP, 0,
+			     w * pt->block.size * h, &tx->bo);
+	if (ret) {
+		FREE(tx);
+		return NULL;
+	}
 
 	if (usage != PIPE_TRANSFER_WRITE) {
-		nv50_transfer_rect_m2mf(pscreen, mt->buffer, tx->level_offset,
+		nv50_transfer_rect_m2mf(pscreen, mt->bo, tx->level_offset,
 					tx->level_pitch, x, y, tx->level_width,
-					tx->level_height, tx->buffer, 0,
+					tx->level_height, tx->bo, 0,
 					tx->base.stride, 0, 0,
 					tx->base.width, tx->base.height,
 					tx->base.block.size, w, h,
@@ -164,9 +167,9 @@ nv50_transfer_del(struct pipe_transfer *ptx)
 
 	if (ptx->usage != PIPE_TRANSFER_READ) {
 		struct pipe_screen *pscreen = ptx->texture->screen;
-		nv50_transfer_rect_m2mf(pscreen, tx->buffer, 0, tx->base.stride,
+		nv50_transfer_rect_m2mf(pscreen, tx->bo, 0, tx->base.stride,
 					0, 0, tx->base.width, tx->base.height,
-					mt->buffer, tx->level_offset,
+					mt->bo, tx->level_offset,
 					tx->level_pitch, tx->level_x,
 					tx->level_y, tx->level_width,
 					tx->level_height, tx->base.block.size,
@@ -175,7 +178,7 @@ nv50_transfer_del(struct pipe_transfer *ptx)
 					NOUVEAU_BO_GART);
 	}
 
-	pipe_buffer_reference(&tx->buffer, NULL);
+	nouveau_bo_ref(NULL, &tx->bo);
 	pipe_texture_reference(&ptx->texture, NULL);
 	FREE(ptx);
 }
@@ -185,13 +188,17 @@ nv50_transfer_map(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
 {
 	struct nv50_transfer *tx = (struct nv50_transfer *)ptx;
 	unsigned flags = 0;
+	int ret;
 
 	if (ptx->usage & PIPE_TRANSFER_WRITE)
-		flags |= PIPE_BUFFER_USAGE_CPU_WRITE;
+		flags |= NOUVEAU_BO_WR;
 	if (ptx->usage & PIPE_TRANSFER_READ)
-		flags |= PIPE_BUFFER_USAGE_CPU_READ;
+		flags |= NOUVEAU_BO_RD;
 
-	return pipe_buffer_map(pscreen, tx->buffer, flags);
+	ret = nouveau_bo_map(tx->bo, flags);
+	if (ret)
+		return NULL;
+	return tx->bo->map;
 }
 
 static void
@@ -199,7 +206,7 @@ nv50_transfer_unmap(struct pipe_screen *pscreen, struct pipe_transfer *ptx)
 {
 	struct nv50_transfer *tx = (struct nv50_transfer *)ptx;
 
-	pipe_buffer_unmap(pscreen, tx->buffer);
+	nouveau_bo_unmap(tx->bo);
 }
 
 void




More information about the mesa-commit mailing list