gallium/draw: use correct rasterization state for wide/AA points/lines
[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
29 static void
30 nv50_flush(struct pipe_context *pipe, unsigned flags,
31 struct pipe_fence_handle **fence)
32 {
33 struct nv50_context *nv50 = nv50_context(pipe);
34 struct nouveau_channel *chan = nv50->screen->base.channel;
35
36 if (flags & PIPE_FLUSH_TEXTURE_CACHE) {
37 BEGIN_RING(chan, nv50->screen->tesla, 0x1338, 1);
38 OUT_RING (chan, 0x20);
39 }
40
41 if (flags & PIPE_FLUSH_FRAME)
42 FIRE_RING(chan);
43 }
44
45 static void
46 nv50_destroy(struct pipe_context *pipe)
47 {
48 struct nv50_context *nv50 = nv50_context(pipe);
49
50 if (nv50->state.fb)
51 so_ref(NULL, &nv50->state.fb);
52 if (nv50->state.blend)
53 so_ref(NULL, &nv50->state.blend);
54 if (nv50->state.blend_colour)
55 so_ref(NULL, &nv50->state.blend_colour);
56 if (nv50->state.zsa)
57 so_ref(NULL, &nv50->state.zsa);
58 if (nv50->state.rast)
59 so_ref(NULL, &nv50->state.rast);
60 if (nv50->state.stipple)
61 so_ref(NULL, &nv50->state.stipple);
62 if (nv50->state.scissor)
63 so_ref(NULL, &nv50->state.scissor);
64 if (nv50->state.viewport)
65 so_ref(NULL, &nv50->state.viewport);
66 if (nv50->state.tsc_upload)
67 so_ref(NULL, &nv50->state.tsc_upload);
68 if (nv50->state.tic_upload)
69 so_ref(NULL, &nv50->state.tic_upload);
70 if (nv50->state.vertprog)
71 so_ref(NULL, &nv50->state.vertprog);
72 if (nv50->state.fragprog)
73 so_ref(NULL, &nv50->state.fragprog);
74 if (nv50->state.geomprog)
75 so_ref(NULL, &nv50->state.geomprog);
76 if (nv50->state.fp_linkage)
77 so_ref(NULL, &nv50->state.fp_linkage);
78 if (nv50->state.gp_linkage)
79 so_ref(NULL, &nv50->state.gp_linkage);
80 if (nv50->state.vtxfmt)
81 so_ref(NULL, &nv50->state.vtxfmt);
82 if (nv50->state.vtxbuf)
83 so_ref(NULL, &nv50->state.vtxbuf);
84 if (nv50->state.vtxattr)
85 so_ref(NULL, &nv50->state.vtxattr);
86
87 draw_destroy(nv50->draw);
88
89 if (nv50->screen->cur_ctx == nv50)
90 nv50->screen->cur_ctx = NULL;
91
92 FREE(nv50);
93 }
94
95
96 struct pipe_context *
97 nv50_create(struct pipe_screen *pscreen, void *priv)
98 {
99 struct pipe_winsys *pipe_winsys = pscreen->winsys;
100 struct nv50_screen *screen = nv50_screen(pscreen);
101 struct nv50_context *nv50;
102
103 nv50 = CALLOC_STRUCT(nv50_context);
104 if (!nv50)
105 return NULL;
106 nv50->screen = screen;
107
108 nv50->pipe.winsys = pipe_winsys;
109 nv50->pipe.screen = pscreen;
110 nv50->pipe.priv = priv;
111
112 nv50->pipe.destroy = nv50_destroy;
113
114 nv50->pipe.draw_arrays = nv50_draw_arrays;
115 nv50->pipe.draw_arrays_instanced = nv50_draw_arrays_instanced;
116 nv50->pipe.draw_elements = nv50_draw_elements;
117 nv50->pipe.draw_elements_instanced = nv50_draw_elements_instanced;
118 nv50->pipe.clear = nv50_clear;
119
120 nv50->pipe.flush = nv50_flush;
121
122 nv50->pipe.is_texture_referenced = nouveau_is_texture_referenced;
123 nv50->pipe.is_buffer_referenced = nouveau_is_buffer_referenced;
124
125 screen->base.channel->user_private = nv50;
126 screen->base.channel->flush_notify = nv50_state_flush_notify;
127
128 nv50_init_surface_functions(nv50);
129 nv50_init_state_functions(nv50);
130 nv50_init_query_functions(nv50);
131
132 nv50->draw = draw_create(&nv50->pipe);
133 assert(nv50->draw);
134 draw_set_rasterize_stage(nv50->draw, nv50_draw_render_stage(nv50));
135
136 return &nv50->pipe;
137 }