nvfx: move stuff around
[mesa.git] / src / gallium / drivers / nvfx / nvfx_context.c
1 #include "draw/draw_context.h"
2 #include "pipe/p_defines.h"
3 #include "util/u_framebuffer.h"
4
5 #include "nvfx_context.h"
6 #include "nvfx_screen.h"
7 #include "nvfx_resource.h"
8
9 static void
10 nvfx_flush(struct pipe_context *pipe, unsigned flags,
11 struct pipe_fence_handle **fence)
12 {
13 struct nvfx_context *nvfx = nvfx_context(pipe);
14 struct nvfx_screen *screen = nvfx->screen;
15 struct nouveau_channel *chan = screen->base.channel;
16 struct nouveau_grobj *eng3d = screen->eng3d;
17
18 /* XXX: we need to actually be intelligent here */
19 if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
20 BEGIN_RING(chan, eng3d, 0x1fd8, 1);
21 OUT_RING (chan, 2);
22 BEGIN_RING(chan, eng3d, 0x1fd8, 1);
23 OUT_RING (chan, 1);
24 }
25
26 FIRE_RING(chan);
27 if (fence)
28 *fence = NULL;
29 }
30
31 static void
32 nvfx_destroy(struct pipe_context *pipe)
33 {
34 struct nvfx_context *nvfx = nvfx_context(pipe);
35
36 for(unsigned i = 0; i < nvfx->vtxbuf_nr; ++i)
37 pipe_resource_reference(&nvfx->vtxbuf[i].buffer, 0);
38 pipe_resource_reference(&nvfx->idxbuf.buffer, 0);
39 util_unreference_framebuffer_state(&nvfx->framebuffer);
40 for(unsigned i = 0; i < PIPE_MAX_SAMPLERS; ++i)
41 pipe_sampler_view_reference(&nvfx->fragment_sampler_views[i], 0);
42
43 if (nvfx->draw)
44 draw_destroy(nvfx->draw);
45 FREE(nvfx);
46 }
47
48 struct pipe_context *
49 nvfx_create(struct pipe_screen *pscreen, void *priv)
50 {
51 struct nvfx_screen *screen = nvfx_screen(pscreen);
52 struct pipe_winsys *ws = pscreen->winsys;
53 struct nvfx_context *nvfx;
54 struct nouveau_winsys *nvws = screen->nvws;
55
56 nvfx = CALLOC(1, sizeof(struct nvfx_context));
57 if (!nvfx)
58 return NULL;
59 nvfx->screen = screen;
60
61 nvfx->nvws = nvws;
62
63 nvfx->pipe.winsys = ws;
64 nvfx->pipe.screen = pscreen;
65 nvfx->pipe.priv = priv;
66 nvfx->pipe.destroy = nvfx_destroy;
67 nvfx->pipe.draw_vbo = nvfx_draw_vbo;
68 nvfx->pipe.clear = nvfx_clear;
69 nvfx->pipe.flush = nvfx_flush;
70
71 screen->base.channel->user_private = nvfx;
72
73 nvfx->is_nv4x = screen->is_nv4x;
74
75 nvfx_init_query_functions(nvfx);
76 nvfx_init_surface_functions(nvfx);
77 nvfx_init_state_functions(nvfx);
78 nvfx_init_sampling_functions(nvfx);
79 nvfx_init_vbo_functions(nvfx);
80 nvfx_init_fragprog_functions(nvfx);
81 nvfx_init_vertprog_functions(nvfx);
82 nvfx_init_resource_functions(&nvfx->pipe);
83 nvfx_init_transfer_functions(&nvfx->pipe);
84
85 /* Create, configure, and install fallback swtnl path */
86 nvfx->draw = draw_create(&nvfx->pipe);
87 draw_wide_point_threshold(nvfx->draw, 9999999.0);
88 draw_wide_line_threshold(nvfx->draw, 9999999.0);
89 draw_enable_line_stipple(nvfx->draw, FALSE);
90 draw_enable_point_sprites(nvfx->draw, FALSE);
91 draw_set_rasterize_stage(nvfx->draw, nvfx_draw_render_stage(nvfx));
92
93 /* set these to that we init them on first validation */
94 nvfx->state.scissor_enabled = ~0;
95 nvfx->hw_pointsprite_control = -1;
96 nvfx->hw_vp_output = -1;
97 nvfx->use_vertex_buffers = -1;
98
99 LIST_INITHEAD(&nvfx->render_cache);
100
101 return &nvfx->pipe;
102 }