Merge branch '7.8'
[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 #include "nvfx_resource.h"
7
8 static void
9 nvfx_flush(struct pipe_context *pipe, unsigned flags,
10 struct pipe_fence_handle **fence)
11 {
12 struct nvfx_context *nvfx = nvfx_context(pipe);
13 struct nvfx_screen *screen = nvfx->screen;
14 struct nouveau_channel *chan = screen->base.channel;
15 struct nouveau_grobj *eng3d = screen->eng3d;
16
17 if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
18 BEGIN_RING(chan, eng3d, 0x1fd8, 1);
19 OUT_RING (chan, 2);
20 BEGIN_RING(chan, eng3d, 0x1fd8, 1);
21 OUT_RING (chan, 1);
22 }
23
24 FIRE_RING(chan);
25 if (fence)
26 *fence = NULL;
27 }
28
29 static void
30 nvfx_destroy(struct pipe_context *pipe)
31 {
32 struct nvfx_context *nvfx = nvfx_context(pipe);
33
34 if (nvfx->draw)
35 draw_destroy(nvfx->draw);
36 FREE(nvfx);
37 }
38
39 struct pipe_context *
40 nvfx_create(struct pipe_screen *pscreen, void *priv)
41 {
42 struct nvfx_screen *screen = nvfx_screen(pscreen);
43 struct pipe_winsys *ws = pscreen->winsys;
44 struct nvfx_context *nvfx;
45 struct nouveau_winsys *nvws = screen->nvws;
46
47 nvfx = CALLOC(1, sizeof(struct nvfx_context));
48 if (!nvfx)
49 return NULL;
50 nvfx->screen = screen;
51
52 nvfx->nvws = nvws;
53
54 nvfx->pipe.winsys = ws;
55 nvfx->pipe.screen = pscreen;
56 nvfx->pipe.priv = priv;
57 nvfx->pipe.destroy = nvfx_destroy;
58 nvfx->pipe.draw_arrays = nvfx_draw_arrays;
59 nvfx->pipe.draw_elements = nvfx_draw_elements;
60 nvfx->pipe.clear = nvfx_clear;
61 nvfx->pipe.flush = nvfx_flush;
62
63 screen->base.channel->user_private = nvfx;
64
65 nvfx->is_nv4x = screen->is_nv4x;
66
67 nvfx_init_query_functions(nvfx);
68 nvfx_init_surface_functions(nvfx);
69 nvfx_init_state_functions(nvfx);
70 nvfx_init_resource_functions(&nvfx->pipe);
71
72 /* Create, configure, and install fallback swtnl path */
73 nvfx->draw = draw_create(&nvfx->pipe);
74 draw_wide_point_threshold(nvfx->draw, 9999999.0);
75 draw_wide_line_threshold(nvfx->draw, 9999999.0);
76 draw_enable_line_stipple(nvfx->draw, FALSE);
77 draw_enable_point_sprites(nvfx->draw, FALSE);
78 draw_set_rasterize_stage(nvfx->draw, nvfx_draw_render_stage(nvfx));
79
80 /* set these to that we init them on first validation */
81 nvfx->state.scissor_enabled = ~0;
82 nvfx->state.stipple_enabled = ~0;
83 return &nvfx->pipe;
84 }