Mesa (gallium-resources): nvfx: fix for gallium-resources

Luca Barbieri lb at kemper.freedesktop.org
Tue Mar 23 17:43:35 PDT 2010


Module: Mesa
Branch: gallium-resources
Commit: f236f9660d31b936f54b64ae07e569f8637067bd
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=f236f9660d31b936f54b64ae07e569f8637067bd

Author: Luca Barbieri <luca at luca-barbieri.com>
Date:   Wed Mar 24 01:31:28 2010 +0100

nvfx: fix for gallium-resources

It seems to work with basic applications but almost surely needs more work.

In particular, it probably shouldn't use PIPE_BUFFER_USAGE_* flags
and should use PIPE_TRANSFER_* in several places.

Also, we probably don't want the vtable indirect calls and that ought
to be replaced with something better instead.

---

 src/gallium/drivers/nouveau/nouveau_screen.c |   26 +++++++++++++-------------
 src/gallium/drivers/nvfx/nv30_fragtex.c      |    2 +-
 src/gallium/drivers/nvfx/nv40_fragtex.c      |    2 +-
 src/gallium/drivers/nvfx/nvfx_context.c      |    2 +-
 src/gallium/drivers/nvfx/nvfx_context.h      |    1 -
 src/gallium/drivers/nvfx/nvfx_miptree.c      |    1 +
 src/gallium/drivers/nvfx/nvfx_transfer.c     |    7 +++----
 7 files changed, 20 insertions(+), 21 deletions(-)

diff --git a/src/gallium/drivers/nouveau/nouveau_screen.c b/src/gallium/drivers/nouveau/nouveau_screen.c
index 944d2c0..c27dd15 100644
--- a/src/gallium/drivers/nouveau/nouveau_screen.c
+++ b/src/gallium/drivers/nouveau/nouveau_screen.c
@@ -15,6 +15,7 @@
 
 /* XXX this should go away */
 #include "state_tracker/drm_api.h"
+#include "util/u_simple_screen.h"
 
 static const char *
 nouveau_screen_get_name(struct pipe_screen *pscreen)
@@ -92,20 +93,20 @@ nouveau_screen_bo_user(struct pipe_screen *pscreen, void *ptr, unsigned bytes)
 }
 
 static inline uint32_t
-nouveau_screen_map_flags(unsigned pipe)
+nouveau_screen_map_flags(unsigned usage)
 {
 	uint32_t flags = 0;
 
-	if (pipe & PIPE_BUFFER_USAGE_CPU_READ)
+	if (usage & PIPE_TRANSFER_READ)
 		flags |= NOUVEAU_BO_RD;
-	if (pipe & PIPE_BUFFER_USAGE_CPU_WRITE)
+	if (usage & PIPE_TRANSFER_WRITE)
 		flags |= NOUVEAU_BO_WR;
-	if (pipe & PIPE_BUFFER_USAGE_DISCARD)
+	if (usage & PIPE_TRANSFER_DISCARD)
 		flags |= NOUVEAU_BO_INVAL;
-	if (pipe & PIPE_BUFFER_USAGE_DONTBLOCK)
+	if (usage & PIPE_TRANSFER_DONTBLOCK)
 		flags |= NOUVEAU_BO_NOWAIT;
 	else
-	if (pipe & PIPE_BUFFER_USAGE_UNSYNCHRONIZED)
+	if (usage & PIPE_TRANSFER_UNSYNCHRONIZED)
 		flags |= NOUVEAU_BO_NOSYNC;
 
 	return flags;
@@ -113,10 +114,9 @@ nouveau_screen_map_flags(unsigned pipe)
 
 void *
 nouveau_screen_bo_map(struct pipe_screen *pscreen,
-		      struct nouveau_bo *pb,
+		      struct nouveau_bo *bo,
 		      unsigned usage)
 {
-	struct nouveau_screen *nscreen = nouveau_screen(pscreen);
 	int ret;
 
 	ret = nouveau_bo_map(bo, nouveau_screen_map_flags(usage));
@@ -132,7 +132,6 @@ void *
 nouveau_screen_bo_map_range(struct pipe_screen *pscreen, struct nouveau_bo *bo,
 			    unsigned offset, unsigned length, unsigned usage)
 {
-	struct nouveau_screen *nscreen = nouveau_screen(pscreen);
 	uint32_t flags = nouveau_screen_map_flags(usage);
 	int ret;
 
@@ -197,7 +196,8 @@ nouveau_screen_bo_from_handle(struct pipe_screen *pscreen,
 			      unsigned *out_stride)
 {
 	struct nouveau_device *dev = nouveau_screen(pscreen)->device;
-	struct nouveau_bo *bo;
+	struct nouveau_bo *bo = 0;
+	int ret;
  
 	ret = nouveau_bo_handle_ref(dev, whandle->handle, &bo);
 	if (ret) {
@@ -217,12 +217,12 @@ nouveau_screen_bo_get_handle(struct pipe_screen *pscreen,
 			     unsigned stride,
 			     struct winsys_handle *whandle)
 {
-	whandle->stride = util_format_get_stride(mt->base.format, mt->base.width0);
+	whandle->stride = stride;
 
 	if (whandle->type == DRM_API_HANDLE_TYPE_SHARED) { 
-		return nouveau_bo_handle_get(mt->bo, &whandle->handle) == 0;
+		return nouveau_bo_handle_get(bo, &whandle->handle) == 0;
 	} else if (whandle->type == DRM_API_HANDLE_TYPE_KMS) {
-		whandle->handle = mt->bo->handle;
+		whandle->handle = bo->handle;
 		return TRUE;
 	} else {
 		return FALSE;
diff --git a/src/gallium/drivers/nvfx/nv30_fragtex.c b/src/gallium/drivers/nvfx/nv30_fragtex.c
index 40cdde3..9783dc5 100644
--- a/src/gallium/drivers/nvfx/nv30_fragtex.c
+++ b/src/gallium/drivers/nvfx/nv30_fragtex.c
@@ -92,7 +92,7 @@ struct nouveau_stateobj *
 nv30_fragtex_build(struct nvfx_context *nvfx, int unit)
 {
 	struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
-	struct nvfx_miptree *nv30mt = nvfx->tex_miptree[unit];
+	struct nvfx_miptree *nv30mt = (struct nvfx_miptree *)nvfx->fragment_sampler_views[unit]->texture;
 	struct pipe_resource *pt = &nv30mt->base.base;
 	struct nouveau_bo *bo = nv30mt->base.bo;
 	struct nv30_texture_format *tf;
diff --git a/src/gallium/drivers/nvfx/nv40_fragtex.c b/src/gallium/drivers/nvfx/nv40_fragtex.c
index 3f03afe..03d161e 100644
--- a/src/gallium/drivers/nvfx/nv40_fragtex.c
+++ b/src/gallium/drivers/nvfx/nv40_fragtex.c
@@ -110,7 +110,7 @@ struct nouveau_stateobj *
 nv40_fragtex_build(struct nvfx_context *nvfx, int unit)
 {
 	struct nvfx_sampler_state *ps = nvfx->tex_sampler[unit];
-	struct nvfx_miptree *nv40mt = nvfx->tex_miptree[unit];
+	struct nvfx_miptree *nv40mt = (struct nvfx_miptree *)nvfx->fragment_sampler_views[unit]->texture;
 	struct nouveau_bo *bo = nv40mt->base.bo;
 	struct pipe_resource *pt = &nv40mt->base.base;
 	struct nv40_texture_format *tf;
diff --git a/src/gallium/drivers/nvfx/nvfx_context.c b/src/gallium/drivers/nvfx/nvfx_context.c
index 1420484..34eb8cb 100644
--- a/src/gallium/drivers/nvfx/nvfx_context.c
+++ b/src/gallium/drivers/nvfx/nvfx_context.c
@@ -73,7 +73,7 @@ nvfx_create(struct pipe_screen *pscreen, void *priv)
 	nvfx_init_query_functions(nvfx);
 	nvfx_init_surface_functions(nvfx);
 	nvfx_init_state_functions(nvfx);
-	nvfx_init_transfer_functions(nvfx);
+	nvfx_init_resource_functions(nvfx);
 
 	/* Create, configure, and install fallback swtnl path */
 	nvfx->draw = draw_create();
diff --git a/src/gallium/drivers/nvfx/nvfx_context.h b/src/gallium/drivers/nvfx/nvfx_context.h
index 63d66a7..9d988b0 100644
--- a/src/gallium/drivers/nvfx/nvfx_context.h
+++ b/src/gallium/drivers/nvfx/nvfx_context.h
@@ -157,7 +157,6 @@ struct nvfx_context {
 	struct pipe_resource *idxbuf;
 	unsigned idxbuf_format;
 	struct nvfx_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
-	struct nvfx_miptree *tex_miptree[PIPE_MAX_SAMPLERS];
 	struct pipe_sampler_view *fragment_sampler_views[PIPE_MAX_SAMPLERS];
 	unsigned nr_samplers;
 	unsigned nr_textures;
diff --git a/src/gallium/drivers/nvfx/nvfx_miptree.c b/src/gallium/drivers/nvfx/nvfx_miptree.c
index 0999dd9..abb9d19 100644
--- a/src/gallium/drivers/nvfx/nvfx_miptree.c
+++ b/src/gallium/drivers/nvfx/nvfx_miptree.c
@@ -132,6 +132,7 @@ nvfx_miptree_create(struct pipe_screen *pscreen, const struct pipe_resource *pt)
 		return NULL;
 
 	mt->base.base = *pt;
+	mt->base.vtbl = &nvfx_miptree_vtbl;
 	pipe_reference_init(&mt->base.base.reference, 1);
 	mt->base.base.screen = pscreen;
 
diff --git a/src/gallium/drivers/nvfx/nvfx_transfer.c b/src/gallium/drivers/nvfx/nvfx_transfer.c
index 4bcfe73..bdf2487 100644
--- a/src/gallium/drivers/nvfx/nvfx_transfer.c
+++ b/src/gallium/drivers/nvfx/nvfx_transfer.c
@@ -76,7 +76,7 @@ nvfx_miptree_transfer_new(struct pipe_context *pcontext,
 		tx->surface = pscreen->get_tex_surface(pscreen, pt,
 	                                               sr.face, sr.level,
 						       box->z,
-	                                               pipe_transfer_buffer_flags(&tx->base));
+	                                               usage);
 		return &tx->base;
 	}
 
@@ -95,7 +95,7 @@ nvfx_miptree_transfer_new(struct pipe_context *pcontext,
 
 	tx->surface = pscreen->get_tex_surface(pscreen, tx_tex,
 	                                       0, 0, 0,
-	                                       pipe_transfer_buffer_flags(&tx->base));
+	                                       tx->base.usage);
 
 	pipe_resource_reference(&tx_tex, NULL);
 
@@ -167,8 +167,7 @@ nvfx_miptree_transfer_map(struct pipe_context *pcontext, struct pipe_transfer *p
 	struct nvfx_transfer *tx = (struct nvfx_transfer *)ptx;
 	struct nv04_surface *ns = (struct nv04_surface *)tx->surface;
 	struct nvfx_miptree *mt = (struct nvfx_miptree *)tx->surface->texture;
-	uint8_t *map = nouveau_screen_bo_map(pscreen, mt->base.bo,
-					  pipe_transfer_buffer_flags(ptx));
+	uint8_t *map = nouveau_screen_bo_map(pscreen, mt->base.bo, ptx->usage);
 
 	if(!tx->direct)
 		return map + ns->base.offset;



More information about the mesa-commit mailing list