Merge branch '7.8'
[mesa.git] / src / gallium / drivers / nv50 / nv50_context.c
1 /*
2 * Copyright 2008 Ben Skeggs
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
18 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
19 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 * SOFTWARE.
21 */
22
23 #include "draw/draw_context.h"
24 #include "pipe/p_defines.h"
25
26 #include "nv50_context.h"
27 #include "nv50_screen.h"
28 #include "nv50_resource.h"
29
30 static void
31 nv50_flush(struct pipe_context *pipe, unsigned flags,
32 struct pipe_fence_handle **fence)
33 {
34 struct nv50_context *nv50 = nv50_context(pipe);
35 struct nouveau_channel *chan = nv50->screen->base.channel;
36
37 if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
38 BEGIN_RING(chan, nv50->screen->tesla, 0x1338, 1);
39 OUT_RING (chan, 0x20);
40 }
41
42 if (flags & PIPE_FLUSH_FRAME)
43 FIRE_RING(chan);
44 }
45
46 static void
47 nv50_destroy(struct pipe_context *pipe)
48 {
49 struct nv50_context *nv50 = nv50_context(pipe);
50 int i;
51
52 for (i = 0; i < 64; i++) {
53 if (!nv50->state.hw[i])
54 continue;
55 so_ref(NULL, &nv50->state.hw[i]);
56 }
57
58 draw_destroy(nv50->draw);
59
60 if (nv50->screen->cur_ctx == nv50)
61 nv50->screen->cur_ctx = NULL;
62
63 FREE(nv50);
64 }
65
66
67 struct pipe_context *
68 nv50_create(struct pipe_screen *pscreen, void *priv)
69 {
70 struct pipe_winsys *pipe_winsys = pscreen->winsys;
71 struct nv50_screen *screen = nv50_screen(pscreen);
72 struct nv50_context *nv50;
73
74 nv50 = CALLOC_STRUCT(nv50_context);
75 if (!nv50)
76 return NULL;
77 nv50->screen = screen;
78
79 nv50->pipe.winsys = pipe_winsys;
80 nv50->pipe.screen = pscreen;
81 nv50->pipe.priv = priv;
82
83 nv50->pipe.destroy = nv50_destroy;
84
85 nv50->pipe.draw_arrays = nv50_draw_arrays;
86 nv50->pipe.draw_arrays_instanced = nv50_draw_arrays_instanced;
87 nv50->pipe.draw_elements = nv50_draw_elements;
88 nv50->pipe.draw_elements_instanced = nv50_draw_elements_instanced;
89 nv50->pipe.clear = nv50_clear;
90
91 nv50->pipe.flush = nv50_flush;
92
93 screen->base.channel->user_private = nv50;
94
95 nv50_init_surface_functions(nv50);
96 nv50_init_state_functions(nv50);
97 nv50_init_query_functions(nv50);
98 nv50_init_resource_functions(&nv50->pipe);
99
100 nv50->draw = draw_create(&nv50->pipe);
101 assert(nv50->draw);
102 draw_set_rasterize_stage(nv50->draw, nv50_draw_render_stage(nv50));
103
104 return &nv50->pipe;
105 }