nouveau: rewrite nouveau_stateobj to use BEGIN_RING properly
[mesa.git] / src / gallium / drivers / nv40 / nv40_state_viewport.c
1 #include "nv40_context.h"
2
3 static boolean
4 nv40_state_viewport_validate(struct nv40_context *nv40)
5 {
6 struct pipe_viewport_state *vpt = &nv40->viewport;
7 struct nouveau_stateobj *so;
8 unsigned bypass;
9
10 if (nv40->render_mode == HW &&
11 !nv40->rasterizer->pipe.bypass_vs_clip_and_viewport)
12 bypass = 0;
13 else
14 bypass = 1;
15
16 if (nv40->state.hw[NV40_STATE_VIEWPORT] &&
17 (bypass || !(nv40->dirty & NV40_NEW_VIEWPORT)) &&
18 nv40->state.viewport_bypass == bypass)
19 return FALSE;
20 nv40->state.viewport_bypass = bypass;
21
22 so = so_new(2, 9, 0);
23 if (!bypass) {
24 so_method(so, nv40->screen->curie,
25 NV40TCL_VIEWPORT_TRANSLATE_X, 8);
26 so_data (so, fui(vpt->translate[0]));
27 so_data (so, fui(vpt->translate[1]));
28 so_data (so, fui(vpt->translate[2]));
29 so_data (so, fui(vpt->translate[3]));
30 so_data (so, fui(vpt->scale[0]));
31 so_data (so, fui(vpt->scale[1]));
32 so_data (so, fui(vpt->scale[2]));
33 so_data (so, fui(vpt->scale[3]));
34 so_method(so, nv40->screen->curie, 0x1d78, 1);
35 so_data (so, 1);
36 } else {
37 so_method(so, nv40->screen->curie,
38 NV40TCL_VIEWPORT_TRANSLATE_X, 8);
39 so_data (so, fui(0.0));
40 so_data (so, fui(0.0));
41 so_data (so, fui(0.0));
42 so_data (so, fui(0.0));
43 so_data (so, fui(1.0));
44 so_data (so, fui(1.0));
45 so_data (so, fui(1.0));
46 so_data (so, fui(0.0));
47 /* Not entirely certain what this is yet. The DDX uses this
48 * value also as it fixes rendering when you pass
49 * pre-transformed vertices to the GPU. My best gusss is that
50 * this bypasses some culling/clipping stage. Might be worth
51 * noting that points/lines are uneffected by whatever this
52 * value fixes, only filled polygons are effected.
53 */
54 so_method(so, nv40->screen->curie, 0x1d78, 1);
55 so_data (so, 0x110);
56 }
57
58 so_ref(so, &nv40->state.hw[NV40_STATE_VIEWPORT]);
59 so_ref(NULL, &so);
60 return TRUE;
61 }
62
63 struct nv40_state_entry nv40_state_viewport = {
64 .validate = nv40_state_viewport_validate,
65 .dirty = {
66 .pipe = NV40_NEW_VIEWPORT | NV40_NEW_RAST,
67 .hw = NV40_STATE_VIEWPORT
68 }
69 };