Merge remote branch 'origin/master' into nv50-compiler
[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 if(nvfx->dummy_fs)
37 pipe->delete_fs_state(pipe, nvfx->dummy_fs);
38
39 for(unsigned i = 0; i < nvfx->vtxbuf_nr; ++i)
40 pipe_resource_reference(&nvfx->vtxbuf[i].buffer, 0);
41 pipe_resource_reference(&nvfx->idxbuf.buffer, 0);
42 util_unreference_framebuffer_state(&nvfx->framebuffer);
43 for(unsigned i = 0; i < PIPE_MAX_SAMPLERS; ++i)
44 pipe_sampler_view_reference(&nvfx->fragment_sampler_views[i], 0);
45
46 if (nvfx->draw)
47 draw_destroy(nvfx->draw);
48
49 if(nvfx->screen->cur_ctx == nvfx)
50 nvfx->screen->cur_ctx = NULL;
51
52 FREE(nvfx);
53 }
54
55 struct pipe_context *
56 nvfx_create(struct pipe_screen *pscreen, void *priv)
57 {
58 struct nvfx_screen *screen = nvfx_screen(pscreen);
59 struct pipe_winsys *ws = pscreen->winsys;
60 struct nvfx_context *nvfx;
61 struct nouveau_winsys *nvws = screen->nvws;
62
63 nvfx = CALLOC(1, sizeof(struct nvfx_context));
64 if (!nvfx)
65 return NULL;
66 nvfx->screen = screen;
67
68 nvfx->nvws = nvws;
69
70 nvfx->pipe.winsys = ws;
71 nvfx->pipe.screen = pscreen;
72 nvfx->pipe.priv = priv;
73 nvfx->pipe.destroy = nvfx_destroy;
74 nvfx->pipe.draw_vbo = nvfx_draw_vbo;
75 nvfx->pipe.clear = nvfx_clear;
76 nvfx->pipe.flush = nvfx_flush;
77
78 nvfx->is_nv4x = screen->is_nv4x;
79 /* TODO: it seems that nv30 might have fixed function clipping usable with vertex programs
80 * However, my code for that doesn't work, so use vp clipping for all cards, which works.
81 */
82 nvfx->use_vp_clipping = TRUE;
83
84 nvfx_init_query_functions(nvfx);
85 nvfx_init_surface_functions(nvfx);
86 nvfx_init_state_functions(nvfx);
87 nvfx_init_sampling_functions(nvfx);
88 nvfx_init_vbo_functions(nvfx);
89 nvfx_init_fragprog_functions(nvfx);
90 nvfx_init_vertprog_functions(nvfx);
91 nvfx_init_resource_functions(&nvfx->pipe);
92 nvfx_init_transfer_functions(&nvfx->pipe);
93
94 /* Create, configure, and install fallback swtnl path */
95 nvfx->draw = draw_create(&nvfx->pipe);
96 draw_wide_point_threshold(nvfx->draw, 9999999.0);
97 draw_wide_line_threshold(nvfx->draw, 9999999.0);
98 draw_enable_line_stipple(nvfx->draw, FALSE);
99 draw_enable_point_sprites(nvfx->draw, FALSE);
100 draw_set_rasterize_stage(nvfx->draw, nvfx_draw_render_stage(nvfx));
101
102 /* set these to that we init them on first validation */
103 nvfx->state.scissor_enabled = ~0;
104 nvfx->hw_pointsprite_control = -1;
105 nvfx->hw_vp_output = -1;
106 nvfx->use_vertex_buffers = -1;
107 nvfx->relocs_needed = NVFX_RELOCATE_ALL;
108
109 LIST_INITHEAD(&nvfx->render_cache);
110
111 return &nvfx->pipe;
112 }