Merge branch 'gallium-0.2' of git+ssh://marcheu@git.freedesktop.org/git/nouveau/mesa...
[mesa.git] / src / gallium / drivers / nv10 / nv10_context.c
index 2599acf28618e24896a079253efbc8539a4dabe8..e9b61daae7f9ed0b4a8493bcb06c3cd1f2f04bcc 100644 (file)
@@ -1,72 +1,41 @@
 #include "draw/draw_context.h"
 #include "pipe/p_defines.h"
 #include "pipe/p_winsys.h"
-#include "pipe/p_util.h"
 
 #include "nv10_context.h"
 #include "nv10_screen.h"
 
 static void
-nv10_flush(struct pipe_context *pipe, unsigned flags)
+nv10_flush(struct pipe_context *pipe, unsigned flags,
+          struct pipe_fence_handle **fence)
 {
        struct nv10_context *nv10 = nv10_context(pipe);
-       struct nouveau_winsys *nvws = nv10->nvws;
 
-       if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
-               BEGIN_RING(celsius, 0x1fd8, 1);
-               OUT_RING  (2);
-               BEGIN_RING(celsius, 0x1fd8, 1);
-               OUT_RING  (1);
-       }
+       draw_flush(nv10->draw);
 
-       if (flags & PIPE_FLUSH_WAIT) {
-               nvws->notifier_reset(nv10->sync, 0);
-               BEGIN_RING(celsius, 0x104, 1);
-               OUT_RING  (0);
-               BEGIN_RING(celsius, 0x100, 1);
-               OUT_RING  (0);
-       }
-
-       FIRE_RING();
-
-       if (flags & PIPE_FLUSH_WAIT)
-               nvws->notifier_wait(nv10->sync, 0, 0, 2000);
+       FIRE_RING(fence);
 }
 
 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;
-       }
+       float projectionmatrix[16];
 
        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);
@@ -101,7 +70,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);
@@ -126,13 +95,21 @@ nv10_init_hwctx(struct nv10_context *nv10, int celsius_class)
        BEGIN_RING(celsius, NV10TCL_TX_ENABLE(0), 2);
        OUT_RING  (0);
        OUT_RING  (0);
-       BEGIN_RING(celsius, NV10TCL_RC_OUT_ALPHA(0), 6);
+
+       BEGIN_RING(celsius, NV10TCL_RC_IN_ALPHA(0), 12);
+       OUT_RING  (0x30141010);
+       OUT_RING  (0);
+       OUT_RING  (0x20040000);
+       OUT_RING  (0);
+       OUT_RING  (0);
+       OUT_RING  (0);
        OUT_RING  (0x00000c00);
        OUT_RING  (0);
        OUT_RING  (0x00000c00);
        OUT_RING  (0x18000000);
-       OUT_RING  (0x300c0000);
-       OUT_RING  (0x00001c80);
+       OUT_RING  (0x300e0300);
+       OUT_RING  (0x0c091c80);
+
        BEGIN_RING(celsius, NV10TCL_BLEND_FUNC_ENABLE, 1);
        OUT_RING  (0);
        BEGIN_RING(celsius, NV10TCL_DITHER_ENABLE, 2);
@@ -252,65 +229,57 @@ nv10_init_hwctx(struct nv10_context *nv10, int celsius_class)
        BEGIN_RING(celsius, NV10TCL_EDGEFLAG_ENABLE, 1);
        OUT_RING  (1);
 
+       memset(projectionmatrix, 0, sizeof(projectionmatrix));
+       BEGIN_RING(celsius, NV10TCL_PROJECTION_MATRIX(0), 16);
+       projectionmatrix[0*4+0] = 1.0;
+       projectionmatrix[1*4+1] = 1.0;
+       projectionmatrix[2*4+2] = 1.0;
+       projectionmatrix[3*4+3] = 1.0;
+       for (i=0;i<16;i++) {
+               OUT_RINGf  (projectionmatrix[i]);
+       }
+
+       BEGIN_RING(celsius, NV10TCL_DEPTH_RANGE_NEAR, 2);
+       OUT_RING  (0.0);
+       OUT_RINGf  (16777216.0);
 
-       FIRE_RING ();
-       return TRUE;
+       BEGIN_RING(celsius, NV10TCL_VIEWPORT_SCALE_X, 4);
+       OUT_RINGf  (-2048.0);
+       OUT_RINGf  (-2048.0);
+       OUT_RINGf  (16777215.0 * 0.5);
+       OUT_RING  (0);
+
+       FIRE_RING (NULL);
+}
+
+static void
+nv10_set_edgeflags(struct pipe_context *pipe, const unsigned *bitfield)
+{
 }
 
 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);
-       if (!nv10)
-               return NULL;
-       nv10->chipset = chipset;
-       nv10->nvws = nvws;
+       struct nouveau_winsys *nvws = screen->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);
+       nv10 = CALLOC(1, sizeof(struct nv10_context));
+       if (!nv10)
                return NULL;
-       }
+       nv10->screen = screen;
+       nv10->pctx_id = pctx_id;
 
-       /* Pipe context setup */
-       nv10->pipe.winsys = pipe_winsys;
+       nv10->nvws = nvws;
 
+       nv10->pipe.winsys = ws;
+       nv10->pipe.screen = pscreen;
        nv10->pipe.destroy = nv10_destroy;
-
+       nv10->pipe.set_edgeflags = nv10_set_edgeflags;
        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);
@@ -320,6 +289,8 @@ nv10_create(struct pipe_screen *screen, unsigned pctx_id)
        assert(nv10->draw);
        draw_set_rasterize_stage(nv10->draw, nv10_draw_vbuf_stage(nv10));
 
+       nv10_init_hwctx(nv10);
+
        return &nv10->pipe;
 }