From d493203045b214770473f8afeaa610542fe42c2a Mon Sep 17 00:00:00 2001
From: Stephane Marchesin <marchesin@icps.u-strasbg.fr>
Date: Sat, 15 Mar 2008 05:37:57 +0100
Subject: nv10.

---
 src/gallium/drivers/nv10/nv10_screen.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
 create mode 100644 src/gallium/drivers/nv10/nv10_screen.h

(limited to 'src/gallium/drivers/nv10/nv10_screen.h')

diff --git a/src/gallium/drivers/nv10/nv10_screen.h b/src/gallium/drivers/nv10/nv10_screen.h
new file mode 100644
index 0000000000..ac8c04072a
--- /dev/null
+++ b/src/gallium/drivers/nv10/nv10_screen.h
@@ -0,0 +1,19 @@
+#ifndef __NV10_SCREEN_H__
+#define __NV10_SCREEN_H__
+
+#include "pipe/p_screen.h"
+
+struct nv10_screen {
+	struct pipe_screen screen;
+
+	struct nouveau_winsys *nvws;
+	unsigned chipset;
+};
+
+static INLINE struct nv10_screen *
+nv10_screen(struct pipe_screen *screen)
+{
+	return (struct nv10_screen *)screen;
+}
+
+#endif
-- 
cgit v1.2.3


From b1a361ba7a565063200c033e4939e6b28c006b13 Mon Sep 17 00:00:00 2001
From: Stephane Marchesin <marchesin@icps.u-strasbg.fr>
Date: Wed, 2 Apr 2008 05:10:18 +0200
Subject: nv10: fix stuff and things.

---
 src/gallium/drivers/nouveau/nouveau_class.h |  24 +++-
 src/gallium/drivers/nv10/nv10_context.c     |  92 +++---------
 src/gallium/drivers/nv10/nv10_context.h     |  31 +++-
 src/gallium/drivers/nv10/nv10_miptree.c     |  28 ++--
 src/gallium/drivers/nv10/nv10_prim_vbuf.c   |  17 ++-
 src/gallium/drivers/nv10/nv10_screen.c      |  70 ++++++---
 src/gallium/drivers/nv10/nv10_screen.h      |   6 +-
 src/gallium/drivers/nv10/nv10_state.c       | 155 ++++----------------
 src/gallium/drivers/nv10/nv10_state_emit.c  | 216 ++++++++++++++++++++++++++--
 9 files changed, 395 insertions(+), 244 deletions(-)

(limited to 'src/gallium/drivers/nv10/nv10_screen.h')

diff --git a/src/gallium/drivers/nouveau/nouveau_class.h b/src/gallium/drivers/nouveau/nouveau_class.h
index dc202086d2..880afe6ce0 100644
--- a/src/gallium/drivers/nouveau/nouveau_class.h
+++ b/src/gallium/drivers/nouveau/nouveau_class.h
@@ -2804,6 +2804,16 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define  NV10TCL_VERTEX_WGH_1F								0x00000ce4
 #define  NV10TCL_EDGEFLAG_ENABLE							0x00000cec
 #define  NV10TCL_VERTEX_ARRAY_VALIDATE							0x00000cf0
+#define  NV10TCL_VERTEX_ARRAY_ATTRIB_OFFSET(x)						(0x00000d00+((x)*8))
+#define  NV10TCL_VERTEX_ARRAY_ATTRIB_OFFSET__SIZE					0x00000008
+#define  NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT(x)						(0x00000d04+((x)*8))
+#define  NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT__SIZE					0x00000008
+#define   NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT_TYPE_SHIFT					0
+#define   NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT_TYPE_MASK					0x0000000f
+#define   NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT_FIELDS_SHIFT				4
+#define   NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT_FIELDS_MASK				0x000000f0
+#define   NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT_STRIDE_SHIFT				8
+#define   NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT_STRIDE_MASK				0x0000ff00
 #define  NV10TCL_VERTEX_ARRAY_OFFSET_POS						0x00000d00
 #define  NV10TCL_VERTEX_ARRAY_FORMAT_POS						0x00000d04
 #define   NV10TCL_VERTEX_ARRAY_FORMAT_POS_TYPE_SHIFT					0
@@ -4249,6 +4259,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define   NV34TCL_VERTEX_ARRAY_FORMAT_TYPE_MASK						0x0000000f
 #define    NV34TCL_VERTEX_ARRAY_FORMAT_TYPE_FLOAT					0x00000002
 #define    NV34TCL_VERTEX_ARRAY_FORMAT_TYPE_UBYTE					0x00000004
+#define    NV34TCL_VERTEX_ARRAY_FORMAT_TYPE_USHORT					0x00000005
 #define   NV34TCL_VERTEX_ARRAY_FORMAT_SIZE_SHIFT					4
 #define   NV34TCL_VERTEX_ARRAY_FORMAT_SIZE_MASK						0x000000f0
 #define   NV34TCL_VERTEX_ARRAY_FORMAT_STRIDE_SHIFT					8
@@ -4963,12 +4974,12 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define  NV40TCL_VP_UPLOAD_INST(x)							(0x00000b80+((x)*4))
 #define  NV40TCL_VP_UPLOAD_INST__SIZE							0x00000004
 #define  NV40TCL_CLIP_PLANE_ENABLE							0x00001478
-#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE0						(1 <<  2)
-#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE1						(1 <<  6)
-#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE2						(1 << 10)
-#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE3						(1 << 14)
-#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE4						(1 << 18)
-#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE5						(1 << 22)
+#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE0						(1 <<  1)
+#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE1						(1 <<  5)
+#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE2						(1 <<  9)
+#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE3						(1 << 13)
+#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE4						(1 << 17)
+#define   NV40TCL_CLIP_PLANE_ENABLE_PLANE5						(1 << 21)
 #define  NV40TCL_POLYGON_STIPPLE_ENABLE							0x0000147c
 #define  NV40TCL_POLYGON_STIPPLE_PATTERN(x)						(0x00001480+((x)*4))
 #define  NV40TCL_POLYGON_STIPPLE_PATTERN__SIZE						0x00000020
@@ -4990,6 +5001,7 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 #define   NV40TCL_VTXFMT_TYPE_MASK							0x0000000f
 #define    NV40TCL_VTXFMT_TYPE_FLOAT							0x00000002
 #define    NV40TCL_VTXFMT_TYPE_UBYTE							0x00000004
+#define    NV40TCL_VTXFMT_TYPE_USHORT							0x00000005
 #define   NV40TCL_VTXFMT_SIZE_SHIFT							4
 #define   NV40TCL_VTXFMT_SIZE_MASK							0x000000f0
 #define   NV40TCL_VTXFMT_STRIDE_SHIFT							8
diff --git a/src/gallium/drivers/nv10/nv10_context.c b/src/gallium/drivers/nv10/nv10_context.c
index 14042fb2fb..42c496b959 100644
--- a/src/gallium/drivers/nv10/nv10_context.c
+++ b/src/gallium/drivers/nv10/nv10_context.c
@@ -12,13 +12,6 @@ nv10_flush(struct pipe_context *pipe, unsigned flags,
 {
 	struct nv10_context *nv10 = nv10_context(pipe);
 
-	if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
-		BEGIN_RING(celsius, 0x1fd8, 1);
-		OUT_RING  (2);
-		BEGIN_RING(celsius, 0x1fd8, 1);
-		OUT_RING  (1);
-	}
-
 	FIRE_RING(fence);
 }
 
@@ -26,36 +19,21 @@ static void
 nv10_destroy(struct pipe_context *pipe)
 {
 	struct nv10_context *nv10 = nv10_context(pipe);
-	struct nouveau_winsys *nvws = nv10->nvws;
 
 	if (nv10->draw)
 		draw_destroy(nv10->draw);
 
-	nvws->res_free(&nv10->vertprog.exec_heap);
-	nvws->res_free(&nv10->vertprog.data_heap);
-
-	nvws->notifier_free(&nv10->sync);
-
-	nvws->grobj_free(&nv10->celsius);
-
-	free(nv10);
+	FREE(nv10);
 }
 
-static boolean
-nv10_init_hwctx(struct nv10_context *nv10, int celsius_class)
+static void nv10_init_hwctx(struct nv10_context *nv10)
 {
-	struct nouveau_winsys *nvws = nv10->nvws;
-	int ret;
+	struct nv10_screen *screen = nv10->screen;
+	struct nouveau_winsys *nvws = screen->nvws;
 	int i;
 
-	ret = nvws->grobj_alloc(nvws, celsius_class, &nv10->celsius);
-	if (ret) {
-		NOUVEAU_ERR("Error creating 3D object: %d\n", ret);
-		return FALSE;
-	}
-
 	BEGIN_RING(celsius, NV10TCL_DMA_NOTIFY, 1);
-	OUT_RING  (nv10->sync->handle);
+	OUT_RING  (screen->sync->handle);
 	BEGIN_RING(celsius, NV10TCL_DMA_IN_MEMORY0, 2);
 	OUT_RING  (nvws->channel->vram->handle);
 	OUT_RING  (nvws->channel->gart->handle);
@@ -90,7 +68,7 @@ nv10_init_hwctx(struct nv10_context *nv10, int celsius_class)
 	BEGIN_RING(celsius, NV10TCL_NOP, 1);
 	OUT_RING  (0);
 
-	if (celsius_class != NV10TCL) {
+	if (nv10->screen->celsius->grclass != NV10TCL) {
 		/* For nv11, nv17 */
 		BEGIN_RING(celsius, 0x120, 3);
 		OUT_RING  (0);
@@ -243,72 +221,44 @@ nv10_init_hwctx(struct nv10_context *nv10, int celsius_class)
 
 
 	FIRE_RING (NULL);
-	return TRUE;
 }
 
 struct pipe_context *
-nv10_create(struct pipe_screen *screen, unsigned pctx_id)
+nv10_create(struct pipe_screen *pscreen, unsigned pctx_id)
 {
-	struct pipe_winsys *pipe_winsys = screen->winsys;
-	struct nouveau_winsys *nvws = nv10_screen(screen)->nvws;
-	unsigned chipset = nv10_screen(screen)->chipset;
+	struct nv10_screen *screen = nv10_screen(pscreen);
+	struct pipe_winsys *ws = pscreen->winsys;
 	struct nv10_context *nv10;
-	int celsius_class = 0, ret;
-
-	if (chipset>=0x20)
-		celsius_class=NV11TCL;
-	else if (chipset>=0x17)
-		celsius_class=NV17TCL;
-	else if (chipset>=0x11)
-		celsius_class=NV11TCL;
-	else
-		celsius_class=NV10TCL;
-
-	nv10 = CALLOC_STRUCT(nv10_context);
+	unsigned chipset = screen->chipset;
+	struct nouveau_winsys *nvws = screen->nvws;
+
+	nv10 = CALLOC(1, sizeof(struct nv10_context));
 	if (!nv10)
 		return NULL;
+	nv10->screen = screen;
+	nv10->pctx_id = pctx_id;
+
 	nv10->chipset = chipset;
 	nv10->nvws = nvws;
 
-	/* Notifier for sync purposes */
-	ret = nvws->notifier_alloc(nvws, 1, &nv10->sync);
-	if (ret) {
-		NOUVEAU_ERR("Error creating notifier object: %d\n", ret);
-		nv10_destroy(&nv10->pipe);
-		return NULL;
-	}
-
-	/* Vtxprog resources */
-	if (nvws->res_init(&nv10->vertprog.exec_heap, 0, 512) ||
-	    nvws->res_init(&nv10->vertprog.data_heap, 0, 256)) {
-		nv10_destroy(&nv10->pipe);
-		return NULL;
-	}
-
-	/* Static celsius initialisation */
-	if (!nv10_init_hwctx(nv10, celsius_class)) {
-		nv10_destroy(&nv10->pipe);
-		return NULL;
-	}
-
-	/* Pipe context setup */
-	nv10->pipe.winsys = pipe_winsys;
-
+	nv10->pipe.winsys = ws;
+	nv10->pipe.screen = pscreen;
 	nv10->pipe.destroy = nv10_destroy;
-
 	nv10->pipe.draw_arrays = nv10_draw_arrays;
 	nv10->pipe.draw_elements = nv10_draw_elements;
 	nv10->pipe.clear = nv10_clear;
-
 	nv10->pipe.flush = nv10_flush;
 
 	nv10_init_surface_functions(nv10);
 	nv10_init_state_functions(nv10);
+	nv10_init_miptree_functions(nv10);
 
 	nv10->draw = draw_create();
 	assert(nv10->draw);
 	draw_set_rasterize_stage(nv10->draw, nv10_draw_vbuf_stage(nv10));
 
+	nv10_init_hwctx(nv10);
+
 	return &nv10->pipe;
 }
 
diff --git a/src/gallium/drivers/nv10/nv10_context.h b/src/gallium/drivers/nv10/nv10_context.h
index 386138556e..61eb4e6a93 100644
--- a/src/gallium/drivers/nv10/nv10_context.h
+++ b/src/gallium/drivers/nv10/nv10_context.h
@@ -11,7 +11,7 @@
 #include "nouveau/nouveau_gldefs.h"
 
 #define NOUVEAU_PUSH_CONTEXT(ctx)                                              \
-	struct nv10_context *ctx = nv10
+	struct nv10_screen *ctx = nv10->screen
 #include "nouveau/nouveau_push.h"
 
 #include "nv10_state.h"
@@ -24,17 +24,27 @@
 #define NV10_NEW_VERTPROG	(1 << 1)
 #define NV10_NEW_FRAGPROG	(1 << 2)
 #define NV10_NEW_ARRAYS		(1 << 3)
-#define NV10_NEW_VBO		(1 << 4)
+#define NV10_NEW_VTXFMT		(1 << 4)
+#define NV10_NEW_BLEND		(1 << 5)
+#define NV10_NEW_BLENDCOL	(1 << 6)
+#define NV10_NEW_RAST 		(1 << 7)
+#define NV10_NEW_DSA  		(1 << 8)
+#define NV10_NEW_VIEWPORT	(1 << 9)
+#define NV10_NEW_SCISSOR	(1 << 9)
+#define NV10_NEW_FRAMEBUFFER	(1 << 10)
+
+#include "nv10_screen.h"
 
 struct nv10_context {
 	struct pipe_context pipe;
+
 	struct nouveau_winsys *nvws;
+	struct nv10_screen *screen;
+	unsigned pctx_id;
 
 	struct draw_context *draw;
 
 	int chipset;
-	struct nouveau_grobj *celsius;
-	struct nouveau_notifier *sync;
 
 	uint32_t dirty;
 
@@ -49,6 +59,14 @@ struct nv10_context {
 	struct pipe_buffer *zeta;
 	uint32_t lma_offset;
 
+	struct nv10_blend_state *blend;
+	struct pipe_blend_color *blend_color;
+	struct nv10_rasterizer_state *rast;
+	struct nv10_depth_stencil_alpha_state *dsa;
+	struct pipe_viewport_state *viewport;
+	struct pipe_scissor_state *scissor;
+	struct pipe_framebuffer_state *framebuffer;
+
 	struct {
 		struct pipe_buffer *buffer;
 		uint32_t format;
@@ -91,7 +109,9 @@ nv10_context(struct pipe_context *pipe)
 
 extern void nv10_init_state_functions(struct nv10_context *nv10);
 extern void nv10_init_surface_functions(struct nv10_context *nv10);
-extern void nv10_init_miptree_functions(struct pipe_screen *screen);
+extern void nv10_init_miptree_functions(struct nv10_context *nv10);
+
+extern void nv10_screen_init_miptree_functions(struct pipe_screen *pscreen);
 
 /* nv10_clear.c */
 extern void nv10_clear(struct pipe_context *pipe, struct pipe_surface *ps,
@@ -111,6 +131,7 @@ extern void nv10_fragtex_bind(struct nv10_context *);
 
 /* nv10_prim_vbuf.c */
 struct draw_stage *nv10_draw_vbuf_stage( struct nv10_context *nv10 );
+extern void nv10_vtxbuf_bind(struct nv10_context* nv10);
 
 /* nv10_state.c and friends */
 extern void nv10_emit_hw_state(struct nv10_context *nv10);
diff --git a/src/gallium/drivers/nv10/nv10_miptree.c b/src/gallium/drivers/nv10/nv10_miptree.c
index 7b7f39b80c..4dfc675a6b 100644
--- a/src/gallium/drivers/nv10/nv10_miptree.c
+++ b/src/gallium/drivers/nv10/nv10_miptree.c
@@ -69,7 +69,7 @@ nv10_miptree_create(struct pipe_screen *screen, struct pipe_texture *pt)
 	mt->buffer = ws->buffer_create(ws, 256, PIPE_BUFFER_USAGE_PIXEL,
 					   mt->total_size);
 	if (!mt->buffer) {
-		free(mt);
+		FREE(mt);
 		return NULL;
 	}
 	
@@ -90,12 +90,19 @@ nv10_miptree_release(struct pipe_screen *screen, struct pipe_texture **pt)
 		pipe_buffer_reference(ws, &nv10mt->buffer, NULL);
 		for (l = 0; l <= mt->last_level; l++) {
 			if (nv10mt->level[l].image_offset)
-				free(nv10mt->level[l].image_offset);
+				FREE(nv10mt->level[l].image_offset);
 		}
-		free(nv10mt);
+		FREE(nv10mt);
 	}
 }
 
+static void
+nv10_miptree_update(struct pipe_context *pipe, struct pipe_texture *mt,
+		    uint face, uint levels)
+{
+}
+
+
 static struct pipe_surface *
 nv10_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt,
 			 unsigned face, unsigned level, unsigned zslice)
@@ -122,13 +129,16 @@ nv10_miptree_surface_get(struct pipe_screen *screen, struct pipe_texture *pt,
 
 	return ps;
 }
-void
-nv10_init_miptree_functions(struct pipe_screen *screen)
+
+void nv10_init_miptree_functions(struct nv10_context *nv10)
 {
-	struct nv10_screen *nv10screen = nv10_screen(screen);
+	nv10->pipe.texture_update = nv10_miptree_update;
+}
 
-	nv10screen->screen.texture_create = nv10_miptree_create;
-	nv10screen->screen.texture_release = nv10_miptree_release;
-	nv10screen->screen.get_tex_surface = nv10_miptree_surface_get;
+void nv10_screen_init_miptree_functions(struct pipe_screen *pscreen)
+{
+	pscreen->texture_create = nv10_miptree_create;
+	pscreen->texture_release = nv10_miptree_release;
+	pscreen->get_tex_surface = nv10_miptree_surface_get;
 }
 
diff --git a/src/gallium/drivers/nv10/nv10_prim_vbuf.c b/src/gallium/drivers/nv10/nv10_prim_vbuf.c
index 1526891223..bbcfe1a2fd 100644
--- a/src/gallium/drivers/nv10/nv10_prim_vbuf.c
+++ b/src/gallium/drivers/nv10/nv10_prim_vbuf.c
@@ -67,6 +67,17 @@ struct nv10_vbuf_render {
 };
 
 
+void nv10_vtxbuf_bind( struct nv10_context* nv10 )
+{
+	int i;
+	for(i = 0; i < 8; i++) {
+		BEGIN_RING(celsius, NV10TCL_VERTEX_ARRAY_ATTRIB_OFFSET(i), 1);
+		OUT_RING(0/*nv10->vtxbuf*/);
+		BEGIN_RING(celsius, NV10TCL_VERTEX_ARRAY_ATTRIB_FORMAT(i) ,1);
+		OUT_RING(0/*XXX*/);
+	}
+}
+
 /**
  * Basically a cast wrapper.
  */
@@ -100,7 +111,7 @@ nv10_vbuf_render_allocate_vertices( struct vbuf_render *render,
 	assert(!nv10_render->buffer);
 	nv10_render->buffer = winsys->buffer_create(winsys, 64, PIPE_BUFFER_USAGE_VERTEX, size);
 
-	nv10->dirty |= NV10_NEW_VBO;
+	nv10->dirty |= NV10_NEW_ARRAYS;
 
 	return winsys->buffer_map(winsys, 
 			nv10_render->buffer, 
@@ -139,8 +150,8 @@ nv10_vbuf_render_draw( struct vbuf_render *render,
 	}
 
 	while (nr_indices) {
-		// XXX too big ?
-		push = MIN2(nr_indices, 2047 * 2);
+		// XXX too big/small ? check the size
+		push = MIN2(nr_indices, 1200 * 2);
 
 		BEGIN_RING_NI(celsius, NV10TCL_VB_ELEMENT_U16, push >> 1);
 		for (i = 0; i < push; i+=2)
diff --git a/src/gallium/drivers/nv10/nv10_screen.c b/src/gallium/drivers/nv10/nv10_screen.c
index 4d8e0b05cc..80676ead1a 100644
--- a/src/gallium/drivers/nv10/nv10_screen.c
+++ b/src/gallium/drivers/nv10/nv10_screen.c
@@ -116,35 +116,71 @@ nv10_screen_is_format_supported(struct pipe_screen *screen,
 }
 
 static void
-nv10_screen_destroy(struct pipe_screen *screen)
+nv10_screen_destroy(struct pipe_screen *pscreen)
 {
-	FREE(screen);
+	struct nv10_screen *screen = nv10_screen(pscreen);
+	struct nouveau_winsys *nvws = screen->nvws;
+
+	nvws->notifier_free(&screen->sync);
+	nvws->grobj_free(&screen->celsius);
+
+	FREE(pscreen);
 }
 
 struct pipe_screen *
-nv10_screen_create(struct pipe_winsys *winsys, struct nouveau_winsys *nvws,
+nv10_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws,
 		   unsigned chipset)
 {
-	struct nv10_screen *nv10screen = CALLOC_STRUCT(nv10_screen);
+	struct nv10_screen *screen = CALLOC_STRUCT(nv10_screen);
+	unsigned celsius_class;
+	int ret;
 
-	if (!nv10screen)
+	if (!screen)
+		return NULL;
+	screen->chipset = chipset;
+	screen->nvws = nvws;
+
+	/* 3D object */
+	if (chipset>=0x20)
+		celsius_class=NV11TCL;
+	else if (chipset>=0x17)
+		celsius_class=NV17TCL;
+	else if (chipset>=0x11)
+		celsius_class=NV11TCL;
+	else
+		celsius_class=NV10TCL;
+
+	if (!celsius_class) {
+		NOUVEAU_ERR("Unknown nv1x chipset: nv%02x\n", chipset);
 		return NULL;
+	}
+
+	ret = nvws->grobj_alloc(nvws, celsius_class, &screen->celsius);
+	if (ret) {
+		NOUVEAU_ERR("Error creating 3D object: %d\n", ret);
+		return FALSE;
+	}
+
+	/* Notifier for sync purposes */
+	ret = nvws->notifier_alloc(nvws, 1, &screen->sync);
+	if (ret) {
+		NOUVEAU_ERR("Error creating notifier object: %d\n", ret);
+		nv10_screen_destroy(&screen->pipe);
+		return NULL;
+	}
 
-	nv10screen->chipset = chipset;
-	nv10screen->nvws = nvws;
+	screen->pipe.winsys = ws;
+	screen->pipe.destroy = nv10_screen_destroy;
 
-	nv10screen->screen.winsys = winsys;
+	screen->pipe.get_name = nv10_screen_get_name;
+	screen->pipe.get_vendor = nv10_screen_get_vendor;
+	screen->pipe.get_param = nv10_screen_get_param;
+	screen->pipe.get_paramf = nv10_screen_get_paramf;
 
-	nv10screen->screen.destroy = nv10_screen_destroy;
+	screen->pipe.is_format_supported = nv10_screen_is_format_supported;
 
-	nv10screen->screen.get_name = nv10_screen_get_name;
-	nv10screen->screen.get_vendor = nv10_screen_get_vendor;
-	nv10screen->screen.get_param = nv10_screen_get_param;
-	nv10screen->screen.get_paramf = nv10_screen_get_paramf;
-	nv10screen->screen.is_format_supported = 
-		nv10_screen_is_format_supported;
+	nv10_screen_init_miptree_functions(&screen->pipe);
 
-	nv10_init_miptree_functions(&nv10screen->screen);
-	return &nv10screen->screen;
+	return &screen->pipe;
 }
 
diff --git a/src/gallium/drivers/nv10/nv10_screen.h b/src/gallium/drivers/nv10/nv10_screen.h
index ac8c04072a..4192fe11ef 100644
--- a/src/gallium/drivers/nv10/nv10_screen.h
+++ b/src/gallium/drivers/nv10/nv10_screen.h
@@ -4,10 +4,14 @@
 #include "pipe/p_screen.h"
 
 struct nv10_screen {
-	struct pipe_screen screen;
+	struct pipe_screen pipe;
 
 	struct nouveau_winsys *nvws;
 	unsigned chipset;
+
+	/* HW graphics objects */
+	struct nouveau_grobj *celsius;
+	struct nouveau_notifier *sync;
 };
 
 static INLINE struct nv10_screen *
diff --git a/src/gallium/drivers/nv10/nv10_state.c b/src/gallium/drivers/nv10/nv10_state.c
index 1ff01de106..12722709f6 100644
--- a/src/gallium/drivers/nv10/nv10_state.c
+++ b/src/gallium/drivers/nv10/nv10_state.c
@@ -35,6 +35,8 @@ static void nv10_vertex_layout(struct pipe_context* pipe)
 		}
 	}
 	draw_compute_vertex_size(&vinfo);
+
+	nv10->dirty |= NV10_NEW_VTXFMT;
 }
 
 static void *
@@ -62,27 +64,19 @@ nv10_blend_state_create(struct pipe_context *pipe,
 }
 
 static void
-nv10_blend_state_bind(struct pipe_context *pipe, void *hwcso)
+nv10_blend_state_bind(struct pipe_context *pipe, void *blend)
 {
 	struct nv10_context *nv10 = nv10_context(pipe);
-	struct nv10_blend_state *cb = hwcso;
-
-	BEGIN_RING(celsius, NV10TCL_DITHER_ENABLE, 1);
-	OUT_RING  (cb->d_enable);
 
-	BEGIN_RING(celsius, NV10TCL_BLEND_FUNC_ENABLE, 3);
-	OUT_RING  (cb->b_enable);
-	OUT_RING  (cb->b_srcfunc);
-	OUT_RING  (cb->b_dstfunc);
+	nv10->blend = (struct nv10_blend_state*)blend;
 
-	BEGIN_RING(celsius, NV10TCL_COLOR_MASK, 1);
-	OUT_RING  (cb->c_mask);
+	nv10->dirty |= NV10_NEW_BLEND;
 }
 
 static void
 nv10_blend_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-	free(hwcso);
+	FREE(hwcso);
 }
 
 
@@ -255,7 +249,7 @@ nv10_sampler_state_bind(struct pipe_context *pipe, unsigned nr, void **sampler)
 static void
 nv10_sampler_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-	free(hwcso);
+	FREE(hwcso);
 }
 
 static void
@@ -347,43 +341,19 @@ nv10_rasterizer_state_create(struct pipe_context *pipe,
 }
 
 static void
-nv10_rasterizer_state_bind(struct pipe_context *pipe, void *hwcso)
+nv10_rasterizer_state_bind(struct pipe_context *pipe, void *rast)
 {
 	struct nv10_context *nv10 = nv10_context(pipe);
-	struct nv10_rasterizer_state *rs = hwcso;
-
-	BEGIN_RING(celsius, NV10TCL_SHADE_MODEL, 2);
-	OUT_RING  (rs->shade_model);
-	OUT_RING  (rs->line_width);
-
-
-	BEGIN_RING(celsius, NV10TCL_POINT_SIZE, 1);
-	OUT_RING  (rs->point_size);
-
-	BEGIN_RING(celsius, NV10TCL_POLYGON_MODE_FRONT, 2);
-	OUT_RING  (rs->poly_mode_front);
-	OUT_RING  (rs->poly_mode_back);
-
 
-	BEGIN_RING(celsius, NV10TCL_CULL_FACE, 2);
-	OUT_RING  (rs->cull_face);
-	OUT_RING  (rs->front_face);
+	nv10->rast = (struct nv10_rasterizer_state*)rast;
 
-	BEGIN_RING(celsius, NV10TCL_LINE_SMOOTH_ENABLE, 2);
-	OUT_RING  (rs->line_smooth_en);
-	OUT_RING  (rs->poly_smooth_en);
-
-	BEGIN_RING(celsius, NV10TCL_CULL_FACE_ENABLE, 1);
-	OUT_RING  (rs->cull_face_en);
-
-/*	BEGIN_RING(celsius, NV10TCL_POINT_SPRITE, 1);
-	OUT_RING  (rs->point_sprite);*/
+	nv10->dirty |= NV10_NEW_RAST;
 }
 
 static void
 nv10_rasterizer_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-	free(hwcso);
+	FREE(hwcso);
 }
 
 static void *
@@ -415,25 +385,19 @@ nv10_depth_stencil_alpha_state_create(struct pipe_context *pipe,
 }
 
 static void
-nv10_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *hwcso)
+nv10_depth_stencil_alpha_state_bind(struct pipe_context *pipe, void *dsa)
 {
 	struct nv10_context *nv10 = nv10_context(pipe);
-	struct nv10_depth_stencil_alpha_state *hw = hwcso;
-
-	BEGIN_RING(celsius, NV10TCL_DEPTH_FUNC, 3);
-	OUT_RINGp ((uint32_t *)&hw->depth, 3);
-	BEGIN_RING(celsius, NV10TCL_STENCIL_ENABLE, 1);
-	OUT_RING (hw->stencil.enable);
-	BEGIN_RING(celsius, NV10TCL_STENCIL_MASK, 7);
-	OUT_RINGp ((uint32_t *)&(hw->stencil.wmask), 7);
-	BEGIN_RING(celsius, NV10TCL_ALPHA_FUNC_ENABLE, 3);
-	OUT_RINGp ((uint32_t *)&hw->alpha.enabled, 3);
+
+	nv10->dsa = (struct nv10_depth_stencil_alpha_state*)dsa;
+
+	nv10->dirty |= NV10_NEW_DSA;
 }
 
 static void
 nv10_depth_stencil_alpha_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-	free(hwcso);
+	FREE(hwcso);
 }
 
 static void *
@@ -461,11 +425,11 @@ nv10_vp_state_bind(struct pipe_context *pipe, void *hwcso)
 static void
 nv10_vp_state_delete(struct pipe_context *pipe, void *hwcso)
 {
-	struct nv10_context *nv10 = nv10_context(pipe);
+	//struct nv10_context *nv10 = nv10_context(pipe);
 	struct nv10_vertex_program *vp = hwcso;
 
 	//nv10_vertprog_destroy(nv10, vp);
-	free(vp);
+	FREE(vp);
 }
 
 static void *
@@ -499,7 +463,7 @@ nv10_fp_state_delete(struct pipe_context *pipe, void *hwcso)
 	struct nv10_fragment_program *fp = hwcso;
 
 	nv10_fragprog_destroy(nv10, fp);
-	free(fp);
+	FREE(fp);
 }
 
 static void
@@ -508,11 +472,9 @@ nv10_set_blend_color(struct pipe_context *pipe,
 {
 	struct nv10_context *nv10 = nv10_context(pipe);
 
-	BEGIN_RING(celsius, NV10TCL_BLEND_COLOR, 1);
-	OUT_RING  ((float_to_ubyte(bcol->color[3]) << 24) |
-		   (float_to_ubyte(bcol->color[0]) << 16) |
-		   (float_to_ubyte(bcol->color[1]) <<  8) |
-		   (float_to_ubyte(bcol->color[2]) <<  0));
+	nv10->blend_color = (struct pipe_blend_color*)bcol;
+
+	nv10->dirty |= NV10_NEW_BLENDCOL;
 }
 
 static void
@@ -542,58 +504,10 @@ nv10_set_framebuffer_state(struct pipe_context *pipe,
 			   const struct pipe_framebuffer_state *fb)
 {
 	struct nv10_context *nv10 = nv10_context(pipe);
-	struct pipe_surface *rt, *zeta;
-	uint32_t rt_format, w, h;
-	int i, colour_format = 0, zeta_format = 0;
-
-	w = fb->cbufs[0]->width;
-	h = fb->cbufs[0]->height;
-	colour_format = fb->cbufs[0]->format;
-	rt = fb->cbufs[0];
-
-	if (fb->zsbuf) {
-		if (colour_format) {
-			assert(w == fb->zsbuf->width);
-			assert(h == fb->zsbuf->height);
-		} else {
-			w = fb->zsbuf->width;
-			h = fb->zsbuf->height;
-		}
-
-		zeta_format = fb->zsbuf->format;
-		zeta = fb->zsbuf;
-	}
 
-	rt_format = NV10TCL_RT_FORMAT_TYPE_LINEAR;
+	nv10->framebuffer = (struct pipe_framebuffer_state*)fb;
 
-	switch (colour_format) {
-	case PIPE_FORMAT_A8R8G8B8_UNORM:
-	case 0:
-		rt_format |= NV10TCL_RT_FORMAT_COLOR_A8R8G8B8;
-		break;
-	case PIPE_FORMAT_R5G6B5_UNORM:
-		rt_format |= NV10TCL_RT_FORMAT_COLOR_R5G6B5;
-		break;
-	default:
-		assert(0);
-	}
-
-	BEGIN_RING(celsius, NV10TCL_RT_PITCH, 1);
-	OUT_RING  ( (rt->pitch * rt->cpp) | ( (zeta->pitch * zeta->cpp) << 16) );
-	nv10->rt[0] = rt->buffer;
-
-	if (zeta_format)
-	{
-		nv10->zeta = zeta->buffer;
-	}
-
-	BEGIN_RING(celsius, NV10TCL_RT_HORIZ, 3);
-	OUT_RING  ((w << 16) | 0);
-	OUT_RING  ((h << 16) | 0);
-	OUT_RING  (rt_format);
-	BEGIN_RING(celsius, NV10TCL_VIEWPORT_CLIP_HORIZ(0), 2);
-	OUT_RING  (((w - 1) << 16) | 0);
-	OUT_RING  (((h - 1) << 16) | 0);
+	nv10->dirty |= NV10_NEW_FRAMEBUFFER;
 }
 
 static void
@@ -609,10 +523,9 @@ nv10_set_scissor_state(struct pipe_context *pipe,
 {
 	struct nv10_context *nv10 = nv10_context(pipe);
 
-	// XXX
-/*	BEGIN_RING(celsius, NV10TCL_SCISSOR_HORIZ, 2);
-	OUT_RING  (((s->maxx - s->minx) << 16) | s->minx);
-	OUT_RING  (((s->maxy - s->miny) << 16) | s->miny);*/
+	nv10->scissor = (struct pipe_scissor_state*)s;
+
+	nv10->dirty |= NV10_NEW_SCISSOR;
 }
 
 static void
@@ -621,15 +534,9 @@ nv10_set_viewport_state(struct pipe_context *pipe,
 {
 	struct nv10_context *nv10 = nv10_context(pipe);
 
-/*	OUT_RINGf (vpt->translate[0]);
-	OUT_RINGf (vpt->translate[1]);
-	OUT_RINGf (vpt->translate[2]);
-	OUT_RINGf (vpt->translate[3]);*/
-	BEGIN_RING(celsius, NV10TCL_VIEWPORT_SCALE_X, 4);
-	OUT_RINGf (vpt->scale[0]);
-	OUT_RINGf (vpt->scale[1]);
-	OUT_RINGf (vpt->scale[2]);
-	OUT_RINGf (vpt->scale[3]);
+	nv10->viewport = (struct pipe_viewport_state*)vpt;
+
+	nv10->dirty |= NV10_NEW_VIEWPORT;
 }
 
 static void
diff --git a/src/gallium/drivers/nv10/nv10_state_emit.c b/src/gallium/drivers/nv10/nv10_state_emit.c
index 8bf0bd2d68..0c52496389 100644
--- a/src/gallium/drivers/nv10/nv10_state_emit.c
+++ b/src/gallium/drivers/nv10/nv10_state_emit.c
@@ -1,14 +1,174 @@
+#include "pipe/p_util.h"
+
 #include "nv10_context.h"
 #include "nv10_state.h"
 
+static void nv10_state_emit_blend(struct nv10_context* nv10)
+{
+	struct nv10_blend_state *b = nv10->blend;
+
+	BEGIN_RING(celsius, NV10TCL_DITHER_ENABLE, 1);
+	OUT_RING  (b->d_enable);
+
+	BEGIN_RING(celsius, NV10TCL_BLEND_FUNC_ENABLE, 3);
+	OUT_RING  (b->b_enable);
+	OUT_RING  (b->b_srcfunc);
+	OUT_RING  (b->b_dstfunc);
+
+	BEGIN_RING(celsius, NV10TCL_COLOR_MASK, 1);
+	OUT_RING  (b->c_mask);
+}
+
+static void nv10_state_emit_blend_color(struct nv10_context* nv10)
+{
+	struct pipe_blend_color *c = nv10->blend_color;
+
+	BEGIN_RING(celsius, NV10TCL_BLEND_COLOR, 1);
+	OUT_RING  ((float_to_ubyte(c->color[3]) << 24)|
+		   (float_to_ubyte(c->color[0]) << 16)|
+		   (float_to_ubyte(c->color[1]) << 8) |
+		   (float_to_ubyte(c->color[2]) << 0));
+}
+
+static void nv10_state_emit_rast(struct nv10_context* nv10)
+{
+	struct nv10_rasterizer_state *r = nv10->rast;
+
+	BEGIN_RING(celsius, NV10TCL_SHADE_MODEL, 2);
+	OUT_RING  (r->shade_model);
+	OUT_RING  (r->line_width);
+
+
+	BEGIN_RING(celsius, NV10TCL_POINT_SIZE, 1);
+	OUT_RING  (r->point_size);
+
+	BEGIN_RING(celsius, NV10TCL_POLYGON_MODE_FRONT, 2);
+	OUT_RING  (r->poly_mode_front);
+	OUT_RING  (r->poly_mode_back);
+
+
+	BEGIN_RING(celsius, NV10TCL_CULL_FACE, 2);
+	OUT_RING  (r->cull_face);
+	OUT_RING  (r->front_face);
+
+	BEGIN_RING(celsius, NV10TCL_LINE_SMOOTH_ENABLE, 2);
+	OUT_RING  (r->line_smooth_en);
+	OUT_RING  (r->poly_smooth_en);
+
+	BEGIN_RING(celsius, NV10TCL_CULL_FACE_ENABLE, 1);
+	OUT_RING  (r->cull_face_en);
+}
+
+static void nv10_state_emit_dsa(struct nv10_context* nv10)
+{
+	struct nv10_depth_stencil_alpha_state *d = nv10->dsa;
+
+	BEGIN_RING(celsius, NV10TCL_DEPTH_FUNC, 3);
+	OUT_RINGp ((uint32_t *)&d->depth, 3);
+	BEGIN_RING(celsius, NV10TCL_STENCIL_ENABLE, 1);
+	OUT_RING (d->stencil.enable);
+	BEGIN_RING(celsius, NV10TCL_STENCIL_MASK, 7);
+	OUT_RINGp ((uint32_t *)&(d->stencil.wmask), 7);
+	BEGIN_RING(celsius, NV10TCL_ALPHA_FUNC_ENABLE, 3);
+	OUT_RINGp ((uint32_t *)&d->alpha.enabled, 3);
+}
+
+static void nv10_state_emit_viewport(struct nv10_context* nv10)
+{
+	struct pipe_viewport_state *vpt = nv10->viewport;
+
+/*	OUT_RINGf (vpt->translate[0]);
+	OUT_RINGf (vpt->translate[1]);
+	OUT_RINGf (vpt->translate[2]);
+	OUT_RINGf (vpt->translate[3]);*/
+	BEGIN_RING(celsius, NV10TCL_VIEWPORT_SCALE_X, 4);
+	OUT_RINGf (vpt->scale[0]);
+	OUT_RINGf (vpt->scale[1]);
+	OUT_RINGf (vpt->scale[2]);
+	OUT_RINGf (vpt->scale[3]);
+}
+
+static void nv10_state_emit_scissor(struct nv10_context* nv10)
+{
+	// XXX this is so not working
+/*	struct pipe_scissor_state *s = nv10->scissor;
+	BEGIN_RING(celsius, NV10TCL_SCISSOR_HORIZ, 2);
+	OUT_RING  (((s->maxx - s->minx) << 16) | s->minx);
+	OUT_RING  (((s->maxy - s->miny) << 16) | s->miny);*/
+}
+
+static void nv10_state_emit_framebuffer(struct nv10_context* nv10)
+{
+	struct pipe_framebuffer_state* fb = nv10->framebuffer;
+	struct pipe_surface *rt, *zeta;
+	uint32_t rt_format, w, h;
+	int colour_format = 0, zeta_format = 0;
+
+	w = fb->cbufs[0]->width;
+	h = fb->cbufs[0]->height;
+	colour_format = fb->cbufs[0]->format;
+	rt = fb->cbufs[0];
+
+	if (fb->zsbuf) {
+		if (colour_format) {
+			assert(w == fb->zsbuf->width);
+			assert(h == fb->zsbuf->height);
+		} else {
+			w = fb->zsbuf->width;
+			h = fb->zsbuf->height;
+		}
+
+		zeta_format = fb->zsbuf->format;
+		zeta = fb->zsbuf;
+	}
+
+	rt_format = NV10TCL_RT_FORMAT_TYPE_LINEAR;
+
+	switch (colour_format) {
+	case PIPE_FORMAT_A8R8G8B8_UNORM:
+	case 0:
+		rt_format |= NV10TCL_RT_FORMAT_COLOR_A8R8G8B8;
+		break;
+	case PIPE_FORMAT_R5G6B5_UNORM:
+		rt_format |= NV10TCL_RT_FORMAT_COLOR_R5G6B5;
+		break;
+	default:
+		assert(0);
+	}
+
+	BEGIN_RING(celsius, NV10TCL_RT_PITCH, 1);
+	OUT_RING  ( (rt->pitch * rt->cpp) | ( (zeta->pitch * zeta->cpp) << 16) );
+	nv10->rt[0] = rt->buffer;
+
+	if (zeta_format)
+	{
+		nv10->zeta = zeta->buffer;
+	}
+
+	BEGIN_RING(celsius, NV10TCL_RT_HORIZ, 3);
+	OUT_RING  ((w << 16) | 0);
+	OUT_RING  ((h << 16) | 0);
+	OUT_RING  (rt_format);
+	BEGIN_RING(celsius, NV10TCL_VIEWPORT_CLIP_HORIZ(0), 2);
+	OUT_RING  (((w - 1) << 16) | 0);
+	OUT_RING  (((h - 1) << 16) | 0);
+}
+
 void
 nv10_emit_hw_state(struct nv10_context *nv10)
 {
 	int i;
 
+	if (nv10->dirty & NV10_NEW_VERTPROG) {
+		//nv10_vertprog_bind(nv10, nv10->vertprog.current);
+		nv10->dirty &= ~NV10_NEW_VERTPROG;
+	}
+
 	if (nv10->dirty & NV10_NEW_FRAGPROG) {
 		nv10_fragprog_bind(nv10, nv10->fragprog.current);
 		/*XXX: clear NV10_NEW_FRAGPROG if no new program uploaded */
+		nv10->dirty_samplers |= (1<<10);
+		nv10->dirty_samplers = 0;
 	}
 
 	if (nv10->dirty_samplers || (nv10->dirty & NV10_NEW_FRAGPROG)) {
@@ -16,16 +176,50 @@ nv10_emit_hw_state(struct nv10_context *nv10)
 		nv10->dirty &= ~NV10_NEW_FRAGPROG;
 	}
 
-	if (nv10->dirty & NV10_NEW_VERTPROG) {
-		//nv10_vertprog_bind(nv10, nv10->vertprog.current);
-		nv10->dirty &= ~NV10_NEW_VERTPROG;
+	if (nv10->dirty & NV10_NEW_ARRAYS) {
+		nv10->dirty &= ~NV10_NEW_ARRAYS;
+		// array state will be put here once it's not emitted at each frame
 	}
 
-	if (nv10->dirty & NV10_NEW_VBO) {
-		
+	if (nv10->dirty & NV10_NEW_VTXFMT) {
+		nv10->dirty &= ~NV10_NEW_VTXFMT;
+		nv10_vtxbuf_bind(nv10);
 	}
 
-	nv10->dirty_samplers = 0;
+	if (nv10->dirty & NV10_NEW_BLEND) {
+		nv10->dirty &= ~NV10_NEW_BLEND;
+		nv10_state_emit_blend(nv10);
+	}
+
+	if (nv10->dirty & NV10_NEW_BLENDCOL) {
+		nv10->dirty &= ~NV10_NEW_BLENDCOL;
+		nv10_state_emit_blend_color(nv10);
+	}
+
+	if (nv10->dirty & NV10_NEW_RAST) {
+		nv10->dirty &= ~NV10_NEW_RAST;
+		nv10_state_emit_rast(nv10);
+	}
+
+	if (nv10->dirty & NV10_NEW_DSA) {
+		nv10->dirty &= ~NV10_NEW_DSA;
+		nv10_state_emit_dsa(nv10);
+	}
+
+ 	if (nv10->dirty & NV10_NEW_VIEWPORT) {
+		nv10->dirty &= ~NV10_NEW_VIEWPORT;
+		nv10_state_emit_viewport(nv10);
+	}
+
+ 	if (nv10->dirty & NV10_NEW_SCISSOR) {
+		nv10->dirty &= ~NV10_NEW_SCISSOR;
+		nv10_state_emit_scissor(nv10);
+	}
+
+ 	if (nv10->dirty & NV10_NEW_FRAMEBUFFER) {
+		nv10->dirty &= ~NV10_NEW_FRAMEBUFFER;
+		nv10_state_emit_framebuffer(nv10);
+	}
 
 	/* Emit relocs for every referenced buffer.
 	 * This is to ensure the bufmgr has an accurate idea of how
@@ -48,10 +242,16 @@ nv10_emit_hw_state(struct nv10_context *nv10)
 		BEGIN_RING(celsius, NV10TCL_ZETA_OFFSET, 1);
 		OUT_RELOCl(nv10->zeta, 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
 		/* XXX for when we allocate LMA on nv17 */
-/*		BEGIN_RING(celsius, NV10TCL_LMA_DEPTH_OFFSET, 1);
-		OUT_RELOCl(nv10->zeta+lma_offset);*/
+/*		BEGIN_RING(celsius, NV10TCL_LMA_DEPTH_BUFFER_OFFSET, 1);
+		OUT_RELOCl(nv10->zeta + lma_offset);*/
 	}
 
+	/* Vertex buffer */
+	BEGIN_RING(celsius, NV10TCL_DMA_VTXBUF0, 1);
+	OUT_RELOCo(nv10->rt[0], NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
+	BEGIN_RING(celsius, NV10TCL_COLOR_OFFSET, 1);
+	OUT_RELOCl(nv10->rt[0], 0, NOUVEAU_BO_VRAM | NOUVEAU_BO_WR);
+
 	/* Texture images */
 	for (i = 0; i < 2; i++) {
 		if (!(nv10->fp_samplers & (1 << i)))
-- 
cgit v1.2.3


From 1ef08564d2a201a422db772a6bb23d1129888304 Mon Sep 17 00:00:00 2001
From: Ben Skeggs <skeggsb@gmail.com>
Date: Tue, 13 May 2008 12:16:35 +1000
Subject: nouveau: remove chipset fields in all nv pipe driver context/screen
 structs.

---
 src/gallium/drivers/nouveau/nouveau_winsys.h    | 13 +++++--------
 src/gallium/drivers/nv10/nv10_context.c         |  2 --
 src/gallium/drivers/nv10/nv10_context.h         |  2 --
 src/gallium/drivers/nv10/nv10_screen.c          |  8 ++++----
 src/gallium/drivers/nv10/nv10_screen.h          |  1 -
 src/gallium/drivers/nv30/nv30_context.c         |  2 --
 src/gallium/drivers/nv30/nv30_context.h         |  2 --
 src/gallium/drivers/nv30/nv30_screen.c          |  8 ++++----
 src/gallium/drivers/nv30/nv30_screen.h          |  1 -
 src/gallium/drivers/nv40/nv40_context.c         |  2 --
 src/gallium/drivers/nv40/nv40_context.h         |  2 --
 src/gallium/drivers/nv40/nv40_screen.c          |  8 ++++----
 src/gallium/drivers/nv40/nv40_screen.h          |  1 -
 src/gallium/drivers/nv50/nv50_screen.c          |  8 ++++----
 src/gallium/drivers/nv50/nv50_screen.h          |  1 -
 src/gallium/winsys/dri/nouveau/nouveau_winsys.c |  5 ++---
 16 files changed, 23 insertions(+), 43 deletions(-)

(limited to 'src/gallium/drivers/nv10/nv10_screen.h')

diff --git a/src/gallium/drivers/nouveau/nouveau_winsys.h b/src/gallium/drivers/nouveau/nouveau_winsys.h
index fbde7adc6a..07a41dcf4a 100644
--- a/src/gallium/drivers/nouveau/nouveau_winsys.h
+++ b/src/gallium/drivers/nouveau/nouveau_winsys.h
@@ -8,6 +8,7 @@
 #include "nouveau/nouveau_bo.h"
 #include "nouveau/nouveau_channel.h"
 #include "nouveau/nouveau_class.h"
+#include "nouveau/nouveau_device.h"
 #include "nouveau/nouveau_grobj.h"
 #include "nouveau/nouveau_notifier.h"
 #include "nouveau/nouveau_resource.h"
@@ -56,29 +57,25 @@ struct nouveau_winsys {
 };
 
 extern struct pipe_screen *
-nv10_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *,
-		   unsigned chipset);
+nv10_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *);
 
 extern struct pipe_context *
 nv10_create(struct pipe_screen *, unsigned pctx_id);
 
 extern struct pipe_screen *
-nv30_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *,
-		   unsigned chipset);
+nv30_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *);
 
 extern struct pipe_context *
 nv30_create(struct pipe_screen *, unsigned pctx_id);
 
 extern struct pipe_screen *
-nv40_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *,
-		   unsigned chipset);
+nv40_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *);
 
 extern struct pipe_context *
 nv40_create(struct pipe_screen *, unsigned pctx_id);
 
 extern struct pipe_screen *
-nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *,
-		   unsigned chipset);
+nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *);
 
 extern struct pipe_context *
 nv50_create(struct pipe_screen *, unsigned pctx_id);
diff --git a/src/gallium/drivers/nv10/nv10_context.c b/src/gallium/drivers/nv10/nv10_context.c
index a25c082a5d..79253f8a2b 100644
--- a/src/gallium/drivers/nv10/nv10_context.c
+++ b/src/gallium/drivers/nv10/nv10_context.c
@@ -264,7 +264,6 @@ nv10_create(struct pipe_screen *pscreen, unsigned pctx_id)
 	struct nv10_screen *screen = nv10_screen(pscreen);
 	struct pipe_winsys *ws = pscreen->winsys;
 	struct nv10_context *nv10;
-	unsigned chipset = screen->chipset;
 	struct nouveau_winsys *nvws = screen->nvws;
 
 	nv10 = CALLOC(1, sizeof(struct nv10_context));
@@ -273,7 +272,6 @@ nv10_create(struct pipe_screen *pscreen, unsigned pctx_id)
 	nv10->screen = screen;
 	nv10->pctx_id = pctx_id;
 
-	nv10->chipset = chipset;
 	nv10->nvws = nvws;
 
 	nv10->pipe.winsys = ws;
diff --git a/src/gallium/drivers/nv10/nv10_context.h b/src/gallium/drivers/nv10/nv10_context.h
index 1b794c1872..433d04dc2a 100644
--- a/src/gallium/drivers/nv10/nv10_context.h
+++ b/src/gallium/drivers/nv10/nv10_context.h
@@ -43,8 +43,6 @@ struct nv10_context {
 
 	struct draw_context *draw;
 
-	int chipset;
-
 	uint32_t dirty;
 
 	struct nv10_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
diff --git a/src/gallium/drivers/nv10/nv10_screen.c b/src/gallium/drivers/nv10/nv10_screen.c
index cf6b2fac84..fad96058b8 100644
--- a/src/gallium/drivers/nv10/nv10_screen.c
+++ b/src/gallium/drivers/nv10/nv10_screen.c
@@ -8,9 +8,10 @@ static const char *
 nv10_screen_get_name(struct pipe_screen *screen)
 {
 	struct nv10_screen *nv10screen = nv10_screen(screen);
+	struct nouveau_device *dev = nv10screen->nvws->channel->device;
 	static char buffer[128];
 
-	snprintf(buffer, sizeof(buffer), "NV%02X", nv10screen->chipset);
+	snprintf(buffer, sizeof(buffer), "NV%02X", dev->chipset);
 	return buffer;
 }
 
@@ -129,16 +130,15 @@ nv10_screen_destroy(struct pipe_screen *pscreen)
 }
 
 struct pipe_screen *
-nv10_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws,
-		   unsigned chipset)
+nv10_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
 {
 	struct nv10_screen *screen = CALLOC_STRUCT(nv10_screen);
 	unsigned celsius_class;
+	unsigned chipset = nvws->channel->device->chipset;
 	int ret;
 
 	if (!screen)
 		return NULL;
-	screen->chipset = chipset;
 	screen->nvws = nvws;
 
 	/* 3D object */
diff --git a/src/gallium/drivers/nv10/nv10_screen.h b/src/gallium/drivers/nv10/nv10_screen.h
index 4192fe11ef..3f8750a13f 100644
--- a/src/gallium/drivers/nv10/nv10_screen.h
+++ b/src/gallium/drivers/nv10/nv10_screen.h
@@ -7,7 +7,6 @@ struct nv10_screen {
 	struct pipe_screen pipe;
 
 	struct nouveau_winsys *nvws;
-	unsigned chipset;
 
 	/* HW graphics objects */
 	struct nouveau_grobj *celsius;
diff --git a/src/gallium/drivers/nv30/nv30_context.c b/src/gallium/drivers/nv30/nv30_context.c
index 4b0892971e..7a2fee7875 100644
--- a/src/gallium/drivers/nv30/nv30_context.c
+++ b/src/gallium/drivers/nv30/nv30_context.c
@@ -44,7 +44,6 @@ nv30_create(struct pipe_screen *pscreen, unsigned pctx_id)
 	struct nv30_screen *screen = nv30_screen(pscreen);
 	struct pipe_winsys *ws = pscreen->winsys;
 	struct nv30_context *nv30;
-	unsigned chipset = screen->chipset;
 	struct nouveau_winsys *nvws = screen->nvws;
 
 	nv30 = CALLOC(1, sizeof(struct nv30_context));
@@ -53,7 +52,6 @@ nv30_create(struct pipe_screen *pscreen, unsigned pctx_id)
 	nv30->screen = screen;
 	nv30->pctx_id = pctx_id;
 
-	nv30->chipset = chipset;
 	nv30->nvws = nvws;
 
 	nv30->pipe.winsys = ws;
diff --git a/src/gallium/drivers/nv30/nv30_context.h b/src/gallium/drivers/nv30/nv30_context.h
index 1a016405e6..f49450f82d 100644
--- a/src/gallium/drivers/nv30/nv30_context.h
+++ b/src/gallium/drivers/nv30/nv30_context.h
@@ -85,8 +85,6 @@ struct nv30_context {
 
 	struct draw_context *draw;
 
-	int chipset;
-
 	uint32_t dirty;
 
 	struct nv30_sampler_state *tex_sampler[PIPE_MAX_SAMPLERS];
diff --git a/src/gallium/drivers/nv30/nv30_screen.c b/src/gallium/drivers/nv30/nv30_screen.c
index 1de4507904..9b0ac55ff8 100644
--- a/src/gallium/drivers/nv30/nv30_screen.c
+++ b/src/gallium/drivers/nv30/nv30_screen.c
@@ -12,9 +12,10 @@ static const char *
 nv30_screen_get_name(struct pipe_screen *pscreen)
 {
 	struct nv30_screen *screen = nv30_screen(pscreen);
+	struct nouveau_device *dev = screen->nvws->channel->device;
 	static char buffer[128];
 
-	snprintf(buffer, sizeof(buffer), "NV%02X", screen->chipset);
+	snprintf(buffer, sizeof(buffer), "NV%02X", dev->chipset);
 	return buffer;
 }
 
@@ -140,17 +141,16 @@ nv30_screen_destroy(struct pipe_screen *pscreen)
 }
 
 struct pipe_screen *
-nv30_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws,
-		   unsigned chipset)
+nv30_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
 {
 	struct nv30_screen *screen = CALLOC_STRUCT(nv30_screen);
 	struct nouveau_stateobj *so;
 	unsigned rankine_class = 0;
+	unsigned chipset = nvws->channel->device->chipset;
 	int ret, i;
 
 	if (!screen)
 		return NULL;
-	screen->chipset = chipset;
 	screen->nvws = nvws;
 
 	/* 3D object */
diff --git a/src/gallium/drivers/nv30/nv30_screen.h b/src/gallium/drivers/nv30/nv30_screen.h
index 56f8776a17..816ece94c4 100644
--- a/src/gallium/drivers/nv30/nv30_screen.h
+++ b/src/gallium/drivers/nv30/nv30_screen.h
@@ -7,7 +7,6 @@ struct nv30_screen {
 	struct pipe_screen pipe;
 
 	struct nouveau_winsys *nvws;
-	unsigned chipset;
 
 	/* HW graphics objects */
 	struct nouveau_grobj *rankine;
diff --git a/src/gallium/drivers/nv40/nv40_context.c b/src/gallium/drivers/nv40/nv40_context.c
index f9c93f7a2d..d9d9accea8 100644
--- a/src/gallium/drivers/nv40/nv40_context.c
+++ b/src/gallium/drivers/nv40/nv40_context.c
@@ -38,7 +38,6 @@ nv40_create(struct pipe_screen *pscreen, unsigned pctx_id)
 	struct nv40_screen *screen = nv40_screen(pscreen);
 	struct pipe_winsys *ws = pscreen->winsys;
 	struct nv40_context *nv40;
-	unsigned chipset = screen->chipset;
 	struct nouveau_winsys *nvws = screen->nvws;
 
 	nv40 = CALLOC(1, sizeof(struct nv40_context));
@@ -47,7 +46,6 @@ nv40_create(struct pipe_screen *pscreen, unsigned pctx_id)
 	nv40->screen = screen;
 	nv40->pctx_id = pctx_id;
 
-	nv40->chipset = chipset;
 	nv40->nvws = nvws;
 
 	nv40->pipe.winsys = ws;
diff --git a/src/gallium/drivers/nv40/nv40_context.h b/src/gallium/drivers/nv40/nv40_context.h
index 24e8cd2337..77b3da0ab9 100644
--- a/src/gallium/drivers/nv40/nv40_context.h
+++ b/src/gallium/drivers/nv40/nv40_context.h
@@ -111,8 +111,6 @@ struct nv40_context {
 
 	struct draw_context *draw;
 
-	int chipset;
-
 	/* HW state derived from pipe states */
 	struct nv40_state state;
 	struct {
diff --git a/src/gallium/drivers/nv40/nv40_screen.c b/src/gallium/drivers/nv40/nv40_screen.c
index 7f68539a85..1bf0931e4d 100644
--- a/src/gallium/drivers/nv40/nv40_screen.c
+++ b/src/gallium/drivers/nv40/nv40_screen.c
@@ -12,9 +12,10 @@ static const char *
 nv40_screen_get_name(struct pipe_screen *pscreen)
 {
 	struct nv40_screen *screen = nv40_screen(pscreen);
+	struct nouveau_device *dev = screen->nvws->channel->device;
 	static char buffer[128];
 
-	snprintf(buffer, sizeof(buffer), "NV%02X", screen->chipset);
+	snprintf(buffer, sizeof(buffer), "NV%02X", dev->chipset);
 	return buffer;
 }
 
@@ -149,17 +150,16 @@ nv40_screen_destroy(struct pipe_screen *pscreen)
 }
 
 struct pipe_screen *
-nv40_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws,
-		   unsigned chipset)
+nv40_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
 {
 	struct nv40_screen *screen = CALLOC_STRUCT(nv40_screen);
 	struct nouveau_stateobj *so;
 	unsigned curie_class;
+	unsigned chipset = nvws->channel->device;
 	int ret;
 
 	if (!screen)
 		return NULL;
-	screen->chipset = chipset;
 	screen->nvws = nvws;
 
 	/* 3D object */
diff --git a/src/gallium/drivers/nv40/nv40_screen.h b/src/gallium/drivers/nv40/nv40_screen.h
index 3ea78aadfd..c04a1275a0 100644
--- a/src/gallium/drivers/nv40/nv40_screen.h
+++ b/src/gallium/drivers/nv40/nv40_screen.h
@@ -7,7 +7,6 @@ struct nv40_screen {
 	struct pipe_screen pipe;
 
 	struct nouveau_winsys *nvws;
-	unsigned chipset;
 
 	unsigned cur_pctx;
 
diff --git a/src/gallium/drivers/nv50/nv50_screen.c b/src/gallium/drivers/nv50/nv50_screen.c
index e4ca72c717..d069639dc4 100644
--- a/src/gallium/drivers/nv50/nv50_screen.c
+++ b/src/gallium/drivers/nv50/nv50_screen.c
@@ -45,9 +45,10 @@ 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", screen->chipset);
+	snprintf(buffer, sizeof(buffer), "NV%02X", dev->chipset);
 	return buffer;
 }
 
@@ -123,17 +124,16 @@ nv50_screen_destroy(struct pipe_screen *pscreen)
 }
 
 struct pipe_screen *
-nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws,
-		   unsigned chipset)
+nv50_screen_create(struct pipe_winsys *ws, struct nouveau_winsys *nvws)
 {
 	struct nv50_screen *screen = CALLOC_STRUCT(nv50_screen);
 	struct nouveau_stateobj *so;
 	unsigned tesla_class = 0, ret;
+	unsigned chipset = nvws->channel->device->chipset;
 	int i;
 
 	if (!screen)
 		return NULL;
-	screen->chipset = chipset;
 	screen->nvws = nvws;
 
 	/* 3D object */
diff --git a/src/gallium/drivers/nv50/nv50_screen.h b/src/gallium/drivers/nv50/nv50_screen.h
index 6e4120d669..5a2732e37f 100644
--- a/src/gallium/drivers/nv50/nv50_screen.h
+++ b/src/gallium/drivers/nv50/nv50_screen.h
@@ -7,7 +7,6 @@ struct nv50_screen {
 	struct pipe_screen pipe;
 
 	struct nouveau_winsys *nvws;
-	unsigned chipset;
 
 	unsigned cur_pctx;
 
diff --git a/src/gallium/winsys/dri/nouveau/nouveau_winsys.c b/src/gallium/winsys/dri/nouveau/nouveau_winsys.c
index 635fd478a9..5eabbc8893 100644
--- a/src/gallium/winsys/dri/nouveau/nouveau_winsys.c
+++ b/src/gallium/winsys/dri/nouveau/nouveau_winsys.c
@@ -91,8 +91,7 @@ nouveau_pipe_create(struct nouveau_context *nv)
 	struct nouveau_channel_context *nvc = nv->nvc;
 	struct nouveau_winsys *nvws = CALLOC_STRUCT(nouveau_winsys);
 	struct pipe_screen *(*hws_create)(struct pipe_winsys *,
-					  struct nouveau_winsys *,
-					  unsigned chipset);
+					  struct nouveau_winsys *);
 	struct pipe_context *(*hw_create)(struct pipe_screen *, unsigned);
 	struct pipe_winsys *ws;
 	unsigned chipset = nv->nv_screen->device->chipset;
@@ -152,7 +151,7 @@ nouveau_pipe_create(struct nouveau_context *nv)
 	ws = nouveau_create_pipe_winsys(nv);
 
 	if (!nvc->pscreen)
-		nvc->pscreen = hws_create(ws, nvws, chipset);
+		nvc->pscreen = hws_create(ws, nvws);
 	nvc->pctx[nv->pctx_id] = hw_create(nvc->pscreen, nv->pctx_id);
 	return nvc->pctx[nv->pctx_id];
 }
-- 
cgit v1.2.3