fc3cbdb558f5aa2f51f096b109bd74928d4217c7
[mesa.git] / src / gallium / drivers / nvfx / nvfx_context.c
1 #include "draw/draw_context.h"
2 #include "pipe/p_defines.h"
3
4 #include "nvfx_context.h"
5 #include "nvfx_screen.h"
6
7 static void
8 nvfx_flush(struct pipe_context *pipe, unsigned flags,
9 struct pipe_fence_handle **fence)
10 {
11 struct nvfx_context *nvfx = nvfx_context(pipe);
12 struct nvfx_screen *screen = nvfx->screen;
13 struct nouveau_channel *chan = screen->base.channel;
14 struct nouveau_grobj *eng3d = screen->eng3d;
15
16 if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
17 BEGIN_RING(chan, eng3d, 0x1fd8, 1);
18 OUT_RING (chan, 2);
19 BEGIN_RING(chan, eng3d, 0x1fd8, 1);
20 OUT_RING (chan, 1);
21 }
22
23 FIRE_RING(chan);
24 if (fence)
25 *fence = NULL;
26 }
27
28 static void
29 nvfx_destroy(struct pipe_context *pipe)
30 {
31 struct nvfx_context *nvfx = nvfx_context(pipe);
32 unsigned i;
33
34 for (i = 0; i < NVFX_STATE_MAX; i++) {
35 if (nvfx->state.hw[i])
36 so_ref(NULL, &nvfx->state.hw[i]);
37 }
38
39 if (nvfx->draw)
40 draw_destroy(nvfx->draw);
41 FREE(nvfx);
42 }
43
44 struct pipe_context *
45 nvfx_create(struct pipe_screen *pscreen, void *priv)
46 {
47 struct nvfx_screen *screen = nvfx_screen(pscreen);
48 struct pipe_winsys *ws = pscreen->winsys;
49 struct nvfx_context *nvfx;
50 struct nouveau_winsys *nvws = screen->nvws;
51
52 nvfx = CALLOC(1, sizeof(struct nvfx_context));
53 if (!nvfx)
54 return NULL;
55 nvfx->screen = screen;
56
57 nvfx->nvws = nvws;
58
59 nvfx->pipe.winsys = ws;
60 nvfx->pipe.screen = pscreen;
61 nvfx->pipe.priv = priv;
62 nvfx->pipe.destroy = nvfx_destroy;
63 nvfx->pipe.draw_arrays = nvfx_draw_arrays;
64 nvfx->pipe.draw_elements = nvfx_draw_elements;
65 nvfx->pipe.clear = nvfx_clear;
66 nvfx->pipe.flush = nvfx_flush;
67
68 nvfx->pipe.is_texture_referenced = nouveau_is_texture_referenced;
69 nvfx->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
70
71 screen->base.channel->user_private = nvfx;
72 screen->base.channel->flush_notify = nvfx_state_flush_notify;
73
74 nvfx->is_nv4x = screen->is_nv4x;
75
76 nvfx_init_query_functions(nvfx);
77 nvfx_init_surface_functions(nvfx);
78 nvfx_init_state_functions(nvfx);
79 nvfx_init_transfer_functions(nvfx);
80
81 /* Create, configure, and install fallback swtnl path */
82 nvfx->draw = draw_create();
83 draw_wide_point_threshold(nvfx->draw, 9999999.0);
84 draw_wide_line_threshold(nvfx->draw, 9999999.0);
85 draw_enable_line_stipple(nvfx->draw, FALSE);
86 draw_enable_point_sprites(nvfx->draw, FALSE);
87 draw_set_rasterize_stage(nvfx->draw, nvfx_draw_render_stage(nvfx));
88
89 return &nvfx->pipe;
90 }