Merge branch 'master' of ssh://git.freedesktop.org/git/mesa/mesa
[mesa.git] / src / gallium / drivers / nv40 / nv40_context.c
1 #include "draw/draw_context.h"
2 #include "pipe/p_defines.h"
3 #include "pipe/internal/p_winsys_screen.h"
4
5 #include "nv40_context.h"
6 #include "nv40_screen.h"
7
8 static void
9 nv40_flush(struct pipe_context *pipe, unsigned flags,
10 struct pipe_fence_handle **fence)
11 {
12 struct nv40_context *nv40 = nv40_context(pipe);
13
14 if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
15 BEGIN_RING(curie, 0x1fd8, 1);
16 OUT_RING (2);
17 BEGIN_RING(curie, 0x1fd8, 1);
18 OUT_RING (1);
19 }
20
21 FIRE_RING(fence);
22 }
23
24 static void
25 nv40_destroy(struct pipe_context *pipe)
26 {
27 struct nv40_context *nv40 = nv40_context(pipe);
28
29 if (nv40->draw)
30 draw_destroy(nv40->draw);
31 FREE(nv40);
32 }
33
34 static unsigned int
35 nv40_is_texture_referenced( struct pipe_context *pipe,
36 struct pipe_texture *texture,
37 unsigned face, unsigned level)
38 {
39 /**
40 * FIXME: Return the correct result. We can't always return referenced
41 * since it causes a double flush within the vbo module.
42 */
43 #if 0
44 return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
45 #else
46 return 0;
47 #endif
48 }
49
50 static unsigned int
51 nv40_is_buffer_referenced( struct pipe_context *pipe,
52 struct pipe_buffer *buf)
53 {
54 /**
55 * FIXME: Return the correct result. We can't always return referenced
56 * since it causes a double flush within the vbo module.
57 */
58 #if 0
59 return PIPE_REFERENCED_FOR_READ | PIPE_REFERENCED_FOR_WRITE;
60 #else
61 return 0;
62 #endif
63 }
64
65 struct pipe_context *
66 nv40_create(struct pipe_screen *pscreen, unsigned pctx_id)
67 {
68 struct nv40_screen *screen = nv40_screen(pscreen);
69 struct pipe_winsys *ws = pscreen->winsys;
70 struct nv40_context *nv40;
71 struct nouveau_winsys *nvws = screen->nvws;
72
73 nv40 = CALLOC(1, sizeof(struct nv40_context));
74 if (!nv40)
75 return NULL;
76 nv40->screen = screen;
77 nv40->pctx_id = pctx_id;
78
79 nv40->nvws = nvws;
80
81 nv40->pipe.winsys = ws;
82 nv40->pipe.screen = pscreen;
83 nv40->pipe.destroy = nv40_destroy;
84 nv40->pipe.draw_arrays = nv40_draw_arrays;
85 nv40->pipe.draw_elements = nv40_draw_elements;
86 nv40->pipe.clear = nv40_clear;
87 nv40->pipe.flush = nv40_flush;
88
89 nv40->pipe.is_texture_referenced = nv40_is_texture_referenced;
90 nv40->pipe.is_buffer_referenced = nv40_is_buffer_referenced;
91
92 nv40_init_query_functions(nv40);
93 nv40_init_surface_functions(nv40);
94 nv40_init_state_functions(nv40);
95
96 /* Create, configure, and install fallback swtnl path */
97 nv40->draw = draw_create();
98 draw_wide_point_threshold(nv40->draw, 9999999.0);
99 draw_wide_line_threshold(nv40->draw, 9999999.0);
100 draw_enable_line_stipple(nv40->draw, FALSE);
101 draw_enable_point_sprites(nv40->draw, FALSE);
102 draw_set_rasterize_stage(nv40->draw, nv40_draw_render_stage(nv40));
103
104 return &nv40->pipe;
105 }