nv40: simple swtnl path (half broken, but getting there)
[mesa.git] / src / gallium / drivers / nv40 / nv40_context.c
1 #include "draw/draw_context.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/p_winsys.h"
4 #include "pipe/p_util.h"
5
6 #include "nv40_context.h"
7 #include "nv40_screen.h"
8
9 static void
10 nv40_flush(struct pipe_context *pipe, unsigned flags)
11 {
12 struct nv40_context *nv40 = nv40_context(pipe);
13 struct nouveau_winsys *nvws = nv40->nvws;
14
15 if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
16 BEGIN_RING(curie, 0x1fd8, 1);
17 OUT_RING (2);
18 BEGIN_RING(curie, 0x1fd8, 1);
19 OUT_RING (1);
20 }
21
22 if (flags & PIPE_FLUSH_WAIT) {
23 nvws->notifier_reset(nv40->screen->sync, 0);
24 BEGIN_RING(curie, 0x104, 1);
25 OUT_RING (0);
26 BEGIN_RING(curie, 0x100, 1);
27 OUT_RING (0);
28 }
29
30 FIRE_RING();
31
32 if (flags & PIPE_FLUSH_WAIT)
33 nvws->notifier_wait(nv40->screen->sync, 0, 0, 2000);
34 }
35
36 static void
37 nv40_destroy(struct pipe_context *pipe)
38 {
39 struct nv40_context *nv40 = nv40_context(pipe);
40
41 if (nv40->draw)
42 draw_destroy(nv40->draw);
43 free(nv40);
44 }
45
46 struct pipe_context *
47 nv40_create(struct pipe_screen *pscreen, unsigned pctx_id)
48 {
49 struct nv40_screen *screen = nv40_screen(pscreen);
50 struct pipe_winsys *ws = pscreen->winsys;
51 struct nv40_context *nv40;
52 unsigned chipset = screen->chipset;
53 struct nouveau_winsys *nvws = screen->nvws;
54
55 nv40 = CALLOC(1, sizeof(struct nv40_context));
56 if (!nv40)
57 return NULL;
58 nv40->screen = screen;
59 nv40->pctx_id = pctx_id;
60
61 nv40->chipset = chipset;
62 nv40->nvws = nvws;
63
64 nv40->pipe.winsys = ws;
65 nv40->pipe.screen = pscreen;
66 nv40->pipe.destroy = nv40_destroy;
67 nv40->pipe.draw_arrays = nv40_draw_arrays;
68 nv40->pipe.draw_elements = nv40_draw_elements;
69 nv40->pipe.clear = nv40_clear;
70 nv40->pipe.flush = nv40_flush;
71
72 nv40_init_query_functions(nv40);
73 nv40_init_surface_functions(nv40);
74 nv40_init_state_functions(nv40);
75 nv40_init_miptree_functions(nv40);
76
77 /* Create, configure, and install fallback swtnl path */
78 nv40->draw = draw_create();
79 draw_wide_point_threshold(nv40->draw, 9999999.0);
80 draw_wide_line_threshold(nv40->draw, 9999999.0);
81 draw_enable_line_stipple(nv40->draw, FALSE);
82 draw_enable_point_sprites(nv40->draw, FALSE);
83 draw_set_rasterize_stage(nv40->draw, nv40_draw_render_stage(nv40));
84
85 return &nv40->pipe;
86 }
87