Merge branch 'master' into instanced-arrays
[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 unsigned i;
29
30 for (i = 0; i < NV40_STATE_MAX; i++) {
31 if (nv40->state.hw[i])
32 so_ref(NULL, &nv40->state.hw[i]);
33 }
34
35 if (nv40->draw)
36 draw_destroy(nv40->draw);
37 FREE(nv40);
38 }
39
40 struct pipe_context *
41 nv40_create(struct pipe_screen *pscreen, unsigned pctx_id)
42 {
43 struct nv40_screen *screen = nv40_screen(pscreen);
44 struct pipe_winsys *ws = pscreen->winsys;
45 struct nv40_context *nv40;
46 struct nouveau_winsys *nvws = screen->nvws;
47
48 nv40 = CALLOC(1, sizeof(struct nv40_context));
49 if (!nv40)
50 return NULL;
51 nv40->screen = screen;
52 nv40->pctx_id = pctx_id;
53
54 nv40->nvws = nvws;
55
56 nv40->pipe.winsys = ws;
57 nv40->pipe.screen = pscreen;
58 nv40->pipe.destroy = nv40_destroy;
59 nv40->pipe.draw_arrays = nv40_draw_arrays;
60 nv40->pipe.draw_elements = nv40_draw_elements;
61 nv40->pipe.clear = nv40_clear;
62 nv40->pipe.flush = nv40_flush;
63
64 nv40->pipe.is_texture_referenced = nouveau_is_texture_referenced;
65 nv40->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
66
67 screen->base.channel->user_private = nv40;
68 screen->base.channel->flush_notify = nv40_state_flush_notify;
69
70 nv40_init_query_functions(nv40);
71 nv40_init_surface_functions(nv40);
72 nv40_init_state_functions(nv40);
73
74 /* Create, configure, and install fallback swtnl path */
75 nv40->draw = draw_create();
76 draw_wide_point_threshold(nv40->draw, 9999999.0);
77 draw_wide_line_threshold(nv40->draw, 9999999.0);
78 draw_enable_line_stipple(nv40->draw, FALSE);
79 draw_enable_point_sprites(nv40->draw, FALSE);
80 draw_set_rasterize_stage(nv40->draw, nv40_draw_render_stage(nv40));
81
82 return &nv40->pipe;
83 }