[Mesa-dev] [PATCH] dri/nouveau: update nouveau driver for texture map/unmap changes

Francisco Jerez currojerez at riseup.net
Fri Jul 22 17:36:17 PDT 2011


Signed-off-by: Francisco Jerez <currojerez at riseup.net>
---
>[...]
> Coincidentally nouveau's texture handling has always been structured
> around two teximage map/unmap hooks (e.g. compare nouveau_teximage() and
> the look of _mesa_store_teximage2d() after the API change), and AFAICT
> the changes would be for the most part trivial, but still, if no-one
> else wants or knows how to do it (isn't fixing up the drivers the
> responsibility of whoever changes the API?), I'll get back to it as soon
> as I can.

There it goes...

 src/mesa/drivers/dri/nouveau/nouveau_context.c |    2 -
 src/mesa/drivers/dri/nouveau/nouveau_driver.h  |    2 +
 src/mesa/drivers/dri/nouveau/nouveau_span.c    |   17 --
 src/mesa/drivers/dri/nouveau/nouveau_texture.c |  258 +++++++++---------------
 src/mesa/drivers/dri/nouveau/nouveau_texture.h |    2 +-
 5 files changed, 94 insertions(+), 187 deletions(-)

diff --git a/src/mesa/drivers/dri/nouveau/nouveau_context.c b/src/mesa/drivers/dri/nouveau/nouveau_context.c
index 22b9957..5813f10 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_context.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_context.c
@@ -35,8 +35,6 @@
 #include "main/state.h"
 #include "drivers/common/meta.h"
 #include "drivers/common/driverfuncs.h"
-#include "swrast/swrast.h"
-#include "swrast/s_context.h"
 #include "vbo/vbo.h"
 #include "tnl/tnl.h"
 #include "tnl/t_context.h"
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_driver.h b/src/mesa/drivers/dri/nouveau/nouveau_driver.h
index 0018eec..4d7ac1d 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_driver.h
+++ b/src/mesa/drivers/dri/nouveau/nouveau_driver.h
@@ -32,6 +32,8 @@
 #include "main/macros.h"
 #include "main/formats.h"
 #include "main/state.h"
+#include "swrast/swrast.h"
+#include "swrast/s_context.h"
 #include "utils.h"
 #include "dri_util.h"
 
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_span.c b/src/mesa/drivers/dri/nouveau/nouveau_span.c
index 761cc76..3e58e65 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_span.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_span.c
@@ -131,18 +131,6 @@ renderbuffer_map_unmap(struct gl_renderbuffer *rb, GLboolean map)
 }
 
 static void
-texture_unit_map_unmap(struct gl_context *ctx, struct gl_texture_unit *u, GLboolean map)
-{
-	if (!u->_ReallyEnabled)
-		return;
-
-	if (map)
-		ctx->Driver.MapTexture(ctx, u->_Current);
-	else
-		ctx->Driver.UnmapTexture(ctx, u->_Current);
-}
-
-static void
 framebuffer_map_unmap(struct gl_framebuffer *fb, GLboolean map)
 {
 	int i;
@@ -159,15 +147,10 @@ framebuffer_map_unmap(struct gl_framebuffer *fb, GLboolean map)
 static void
 span_map_unmap(struct gl_context *ctx, GLboolean map)
 {
-	int i;
-
 	framebuffer_map_unmap(ctx->DrawBuffer, map);
 
 	if (ctx->ReadBuffer != ctx->DrawBuffer)
 		framebuffer_map_unmap(ctx->ReadBuffer, map);
-
-	for (i = 0; i < ctx->Const.MaxTextureUnits; i++)
-		texture_unit_map_unmap(ctx, &ctx->Texture.Unit[i], map);
 }
 
 static void
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.c b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
index 993afa6..5fbfcc5 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_texture.c
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.c
@@ -37,7 +37,6 @@
 #include "main/texcompress.h"
 #include "main/texgetimage.h"
 #include "main/mipmap.h"
-#include "main/texfetch.h"
 #include "main/teximage.h"
 #include "drivers/common/meta.h"
 
@@ -68,11 +67,39 @@ nouveau_teximage_new(struct gl_context *ctx)
 {
 	struct nouveau_teximage *nti = CALLOC_STRUCT(nouveau_teximage);
 
-	return &nti->base;
+	return &nti->base.Base;
+}
+
+static unsigned
+get_teximage_placement(struct gl_texture_image *ti)
+{
+	if (ti->TexFormat == MESA_FORMAT_A8 ||
+	    ti->TexFormat == MESA_FORMAT_L8 ||
+	    ti->TexFormat == MESA_FORMAT_I8)
+		/* 1 cpp formats will have to be swizzled by the CPU,
+		 * so leave them in system RAM for now. */
+		return NOUVEAU_BO_MAP;
+	else
+		return NOUVEAU_BO_GART | NOUVEAU_BO_MAP;
+}
+
+static GLboolean
+nouveau_teximage_buffer_alloc(struct gl_context *ctx,
+			      struct gl_texture_image *ti,
+			      gl_format format, GLsizei width,
+			      GLsizei height, GLsizei depth)
+{
+	struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
+
+	nouveau_surface_alloc(ctx, s, LINEAR, get_teximage_placement(ti),
+			      format, width, height);
+
+	return GL_TRUE;
 }
 
 static void
-nouveau_teximage_free(struct gl_context *ctx, struct gl_texture_image *ti)
+nouveau_teximage_buffer_free(struct gl_context *ctx,
+			     struct gl_texture_image *ti)
 {
 	struct nouveau_teximage *nti = to_nouveau_teximage(ti);
 
@@ -81,51 +108,52 @@ nouveau_teximage_free(struct gl_context *ctx, struct gl_texture_image *ti)
 
 static void
 nouveau_teximage_map(struct gl_context *ctx, struct gl_texture_image *ti,
-		     int access, int x, int y, int w, int h)
+		     GLuint slice, GLuint x, GLuint y, GLuint w, GLuint h,
+		     GLbitfield access, GLubyte **pmap, GLint *pstride)
 {
 	struct nouveau_teximage *nti = to_nouveau_teximage(ti);
 	struct nouveau_surface *s = &nti->surface;
 	struct nouveau_surface *st = &nti->transfer.surface;
 
-	if (s->bo) {
-		if (!(access & GL_MAP_READ_BIT) &&
-		    nouveau_bo_pending(s->bo)) {
-			/*
-			 * Heuristic: use a bounce buffer to pipeline
-			 * teximage transfers.
-			 */
-			st->layout = LINEAR;
-			st->format = s->format;
-			st->cpp = s->cpp;
-			st->width = w;
-			st->height = h;
-			st->pitch = s->pitch;
-			nti->transfer.x = x;
-			nti->transfer.y = y;
-
-			ti->Data = nouveau_get_scratch(ctx, st->pitch * h,
-						       &st->bo, &st->offset);
-
-		} else {
-			int ret, flags = 0;
-
-			if (access & GL_MAP_READ_BIT)
-				flags |= NOUVEAU_BO_RD;
-			if (access & GL_MAP_WRITE_BIT)
-				flags |= NOUVEAU_BO_WR;
-
-			if (!s->bo->map) {
-				ret = nouveau_bo_map(s->bo, flags);
-				assert(!ret);
-			}
-
-			ti->Data = s->bo->map + y * s->pitch + x * s->cpp;
+	if (!(access & GL_MAP_READ_BIT) &&
+	    nouveau_bo_pending(s->bo)) {
+		/*
+		 * Heuristic: use a bounce buffer to pipeline
+		 * teximage transfers.
+		 */
+		st->layout = LINEAR;
+		st->format = s->format;
+		st->cpp = s->cpp;
+		st->width = w;
+		st->height = h;
+		st->pitch = s->pitch;
+		nti->transfer.x = x;
+		nti->transfer.y = y;
+
+		*pmap = nouveau_get_scratch(ctx, st->pitch * h,
+					    &st->bo, &st->offset);
+	} else {
+		int ret, flags = 0;
+
+		if (access & GL_MAP_READ_BIT)
+			flags |= NOUVEAU_BO_RD;
+		if (access & GL_MAP_WRITE_BIT)
+			flags |= NOUVEAU_BO_WR;
+
+		if (!s->bo->map) {
+			ret = nouveau_bo_map(s->bo, flags);
+			assert(!ret);
 		}
+
+		*pmap = s->bo->map + y * s->pitch + x * s->cpp;
 	}
+
+	*pstride = s->pitch;
 }
 
 static void
-nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti)
+nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti,
+		       GLuint slice)
 {
 	struct nouveau_teximage *nti = to_nouveau_teximage(ti);
 	struct nouveau_surface *s = &nti->surface;
@@ -137,11 +165,9 @@ nouveau_teximage_unmap(struct gl_context *ctx, struct gl_texture_image *ti)
 					       st->width, st->height);
 		nouveau_surface_ref(NULL, st);
 
-	} else if (s->bo) {
+	} else {
 		nouveau_bo_unmap(s->bo);
 	}
-
-	ti->Data = NULL;
 }
 
 static gl_format
@@ -368,19 +394,6 @@ nouveau_texture_reallocate(struct gl_context *ctx, struct gl_texture_object *t)
 	}
 }
 
-static unsigned
-get_teximage_placement(struct gl_texture_image *ti)
-{
-	if (ti->TexFormat == MESA_FORMAT_A8 ||
-	    ti->TexFormat == MESA_FORMAT_L8 ||
-	    ti->TexFormat == MESA_FORMAT_I8)
-		/* 1 cpp formats will have to be swizzled by the CPU,
-		 * so leave them in system RAM for now. */
-		return NOUVEAU_BO_MAP;
-	else
-		return NOUVEAU_BO_GART | NOUVEAU_BO_MAP;
-}
-
 static void
 nouveau_teximage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
 		 GLint internalFormat,
@@ -391,30 +404,27 @@ nouveau_teximage(struct gl_context *ctx, GLint dims, GLenum target, GLint level,
 		 struct gl_texture_image *ti)
 {
 	struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
-	int ret;
+	unsigned char *map;
+	int stride, ret;
 
 	/* Allocate a new bo for the image. */
-	nouveau_surface_alloc(ctx, s, LINEAR, get_teximage_placement(ti),
-			      ti->TexFormat, width, height);
-	ti->RowStride = s->pitch / s->cpp;
-
+	nouveau_teximage_buffer_alloc(ctx, ti, ti->TexFormat, width, height,
+				      depth);
 	pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
 					     format, type, pixels, packing,
 					     "glTexImage");
 	if (pixels) {
 		/* Store the pixel data. */
-		nouveau_teximage_map(ctx, ti, GL_MAP_WRITE_BIT,
-				     0, 0, width, height);
+		nouveau_teximage_map(ctx, ti, 0, 0, 0, width, height,
+				     GL_MAP_WRITE_BIT, &map, &stride);
 
 		ret = _mesa_texstore(ctx, dims, ti->_BaseFormat,
-				     ti->TexFormat, ti->Data,
-				     0, 0, 0, s->pitch,
-				     ti->ImageOffsets,
-				     width, height, depth,
+				     ti->TexFormat, map, 0, 0, 0, stride,
+				     (unsigned []) { 0 }, width, height, depth,
 				     format, type, pixels, packing);
 		assert(ret);
 
-		nouveau_teximage_unmap(ctx, ti);
+		nouveau_teximage_unmap(ctx, ti, 0);
 		_mesa_unmap_teximage_pbo(ctx, packing);
 
 		if (!validate_teximage(ctx, t, level, 0, 0, 0,
@@ -485,22 +495,24 @@ nouveau_texsubimage(struct gl_context *ctx, GLint dims, GLenum target, GLint lev
 		    struct gl_texture_image *ti)
 {
 	struct nouveau_surface *s = &to_nouveau_teximage(ti)->surface;
-	int ret;
+	unsigned char *map;
+	int stride, ret;
 
 	pixels = _mesa_validate_pbo_teximage(ctx, dims, width, height, depth,
 					     format, type, pixels, packing,
 					     "glTexSubImage");
 	if (pixels) {
-		nouveau_teximage_map(ctx, ti, GL_MAP_WRITE_BIT,
-				     xoffset, yoffset, width, height);
+		nouveau_teximage_map(ctx, ti, 0, xoffset, yoffset,
+				     width, height, GL_MAP_WRITE_BIT,
+				     &map, &stride);
 
-		ret = _mesa_texstore(ctx, 3, ti->_BaseFormat, ti->TexFormat,
-				     ti->Data, 0, 0, 0, s->pitch,
-				     ti->ImageOffsets, width, height, depth,
+		ret = _mesa_texstore(ctx, 3, ti->_BaseFormat,
+				     ti->TexFormat, map, 0, 0, 0, stride,
+				     (unsigned []) { 0 }, width, height, depth,
 				     format, type, pixels, packing);
 		assert(ret);
 
-		nouveau_teximage_unmap(ctx, ti);
+		nouveau_teximage_unmap(ctx, ti, 0);
 		_mesa_unmap_teximage_pbo(ctx, packing);
 	}
 
@@ -551,19 +563,6 @@ nouveau_texsubimage_1d(struct gl_context *ctx, GLenum target, GLint level,
 }
 
 static void
-nouveau_get_teximage(struct gl_context *ctx, GLenum target, GLint level,
-		     GLenum format, GLenum type, GLvoid *pixels,
-		     struct gl_texture_object *t,
-		     struct gl_texture_image *ti)
-{
-	nouveau_teximage_map(ctx, ti, GL_MAP_READ_BIT,
-			     0, 0, ti->Width, ti->Height);
-	_mesa_get_teximage(ctx, target, level, format, type, pixels,
-			   t, ti);
-	nouveau_teximage_unmap(ctx, ti);
-}
-
-static void
 nouveau_bind_texture(struct gl_context *ctx, GLenum target,
 		     struct gl_texture_object *t)
 {
@@ -611,7 +610,6 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
 	/* Update the image fields. */
 	_mesa_init_teximage_fields(ctx, ti, s->width, s->height,
 				   1, 0, s->cpp, s->format);
-	ti->RowStride = s->pitch / s->cpp;
 
 	/* Try to validate it. */
 	if (!validate_teximage(ctx, t, 0, 0, 0, 0, s->width, s->height, 1))
@@ -623,88 +621,14 @@ nouveau_set_texbuffer(__DRIcontext *dri_ctx,
 	_mesa_unlock_texture(ctx, t);
 }
 
-static void
-nouveau_texture_map(struct gl_context *ctx, struct gl_texture_object *t)
-{
-	int i;
-
-	for (i = t->BaseLevel; i < t->_MaxLevel; i++) {
-		struct gl_texture_image *ti = t->Image[0][i];
-
-		if (ti)
-			nouveau_teximage_map(ctx, ti, GL_MAP_READ_BIT,
-					     0, 0, ti->Width, ti->Height);
-	}
-}
-
-static void
-nouveau_texture_unmap(struct gl_context *ctx, struct gl_texture_object *t)
-{
-	int i;
-
-	for (i = t->BaseLevel; i < t->_MaxLevel; i++) {
-		if (t->Image[0][i])
-			nouveau_teximage_unmap(ctx, t->Image[0][i]);
-	}
-}
-
-static void
-store_mipmap(struct gl_context *ctx, GLenum target, int first, int last,
-	     struct gl_texture_object *t)
-{
-	struct gl_pixelstore_attrib packing = {
-		.BufferObj = ctx->Shared->NullBufferObj,
-		.Alignment = 1
-	};
-	GLenum format = t->Image[0][t->BaseLevel]->TexFormat;
-	unsigned base_format, type, comps;
-	int i;
-
-	base_format = _mesa_get_format_base_format(format);
-	_mesa_format_to_type_and_comps(format, &type, &comps);
-
-	for (i = first; i <= last; i++) {
-		struct gl_texture_image *ti = t->Image[0][i];
-		void *data = ti->Data;
-
-		nouveau_teximage(ctx, 3, target, i, ti->InternalFormat,
-				 ti->Width, ti->Height, ti->Depth,
-				 ti->Border, base_format, type, data,
-				 &packing, t, ti);
-
-		_mesa_free_texmemory(data);
-	}
-}
-
-static void
-nouveau_generate_mipmap(struct gl_context *ctx, GLenum target,
-			struct gl_texture_object *t)
-{
-	if (_mesa_meta_check_generate_mipmap_fallback(ctx, target, t)) {
-		struct gl_texture_image *base = t->Image[0][t->BaseLevel];
-
-		nouveau_teximage_map(ctx, base, GL_MAP_READ_BIT,
-				     0, 0, base->Width, base->Height);
-		_mesa_generate_mipmap(ctx, target, t);
-		nouveau_teximage_unmap(ctx, base);
-
-		if (!_mesa_is_format_compressed(base->TexFormat)) {
-			store_mipmap(ctx, target, t->BaseLevel + 1,
-				     get_last_level(t), t);
-		}
-
-	} else {
-		_mesa_meta_GenerateMipmap(ctx, target, t);
-	}
-}
-
 void
 nouveau_texture_functions_init(struct dd_function_table *functions)
 {
 	functions->NewTextureObject = nouveau_texture_new;
 	functions->DeleteTexture = nouveau_texture_free;
 	functions->NewTextureImage = nouveau_teximage_new;
-	functions->FreeTexImageData = nouveau_teximage_free;
+	functions->AllocTextureImageBuffer = nouveau_teximage_buffer_alloc;
+	functions->FreeTextureImageBuffer = nouveau_teximage_buffer_free;
 	functions->ChooseTextureFormat = nouveau_choose_tex_format;
 	functions->TexImage1D = nouveau_teximage_1d;
 	functions->TexImage2D = nouveau_teximage_2d;
@@ -712,9 +636,9 @@ nouveau_texture_functions_init(struct dd_function_table *functions)
 	functions->TexSubImage1D = nouveau_texsubimage_1d;
 	functions->TexSubImage2D = nouveau_texsubimage_2d;
 	functions->TexSubImage3D = nouveau_texsubimage_3d;
-	functions->GetTexImage = nouveau_get_teximage;
+	functions->GetTexImage = _mesa_get_teximage;
 	functions->BindTexture = nouveau_bind_texture;
-	functions->MapTexture = nouveau_texture_map;
-	functions->UnmapTexture = nouveau_texture_unmap;
-	functions->GenerateMipmap = nouveau_generate_mipmap;
+	functions->MapTextureImage = nouveau_teximage_map;
+	functions->UnmapTextureImage = nouveau_teximage_unmap;
+	functions->GenerateMipmap = _mesa_meta_GenerateMipmap;
 }
diff --git a/src/mesa/drivers/dri/nouveau/nouveau_texture.h b/src/mesa/drivers/dri/nouveau/nouveau_texture.h
index 56e61c7..5089ed7 100644
--- a/src/mesa/drivers/dri/nouveau/nouveau_texture.h
+++ b/src/mesa/drivers/dri/nouveau/nouveau_texture.h
@@ -28,7 +28,7 @@
 #define __NOUVEAU_TEXTURE_H__
 
 struct nouveau_teximage {
-	struct gl_texture_image base;
+	struct swrast_texture_image base;
 	struct nouveau_surface surface;
 	struct {
 		struct nouveau_surface surface;
-- 
1.7.3.4



More information about the mesa-dev mailing list