Merge branch 'mesa_7_7_branch'
[mesa.git] / src / gallium / drivers / nv30 / nv30_state_emit.c
1 #include "nv30_context.h"
2 #include "nv30_state.h"
3
4 static struct nv30_state_entry *render_states[] = {
5 &nv30_state_framebuffer,
6 &nv30_state_rasterizer,
7 &nv30_state_scissor,
8 &nv30_state_stipple,
9 &nv30_state_fragprog,
10 &nv30_state_fragtex,
11 &nv30_state_vertprog,
12 &nv30_state_blend,
13 &nv30_state_blend_colour,
14 &nv30_state_zsa,
15 &nv30_state_viewport,
16 &nv30_state_vbo,
17 NULL
18 };
19
20 static void
21 nv30_state_do_validate(struct nv30_context *nv30,
22 struct nv30_state_entry **states)
23 {
24 while (*states) {
25 struct nv30_state_entry *e = *states;
26
27 if (nv30->dirty & e->dirty.pipe) {
28 if (e->validate(nv30)) {
29 nv30->state.dirty |= (1ULL << e->dirty.hw);
30 }
31 }
32
33 states++;
34 }
35 nv30->dirty = 0;
36 }
37
38 void
39 nv30_state_emit(struct nv30_context *nv30)
40 {
41 struct nouveau_channel *chan = nv30->screen->base.channel;
42 struct nv30_state *state = &nv30->state;
43 struct nv30_screen *screen = nv30->screen;
44 unsigned i;
45 uint64_t states;
46
47 if (nv30->pctx_id != screen->cur_pctx) {
48 for (i = 0; i < NV30_STATE_MAX; i++) {
49 if (state->hw[i] && screen->state[i] != state->hw[i])
50 state->dirty |= (1ULL << i);
51 }
52
53 screen->cur_pctx = nv30->pctx_id;
54 }
55
56 for (i = 0, states = state->dirty; states; i++) {
57 if (!(states & (1ULL << i)))
58 continue;
59 so_ref (state->hw[i], &nv30->screen->state[i]);
60 if (state->hw[i])
61 so_emit(chan, nv30->screen->state[i]);
62 states &= ~(1ULL << i);
63 }
64
65 state->dirty = 0;
66 }
67
68 void
69 nv30_state_flush_notify(struct nouveau_channel *chan)
70 {
71 struct nv30_context *nv30 = chan->user_private;
72 struct nv30_state *state = &nv30->state;
73 unsigned i, samplers;
74
75 so_emit_reloc_markers(chan, state->hw[NV30_STATE_FB]);
76 for (i = 0, samplers = state->fp_samplers; i < 16 && samplers; i++) {
77 if (!(samplers & (1 << i)))
78 continue;
79 so_emit_reloc_markers(chan,
80 state->hw[NV30_STATE_FRAGTEX0+i]);
81 samplers &= ~(1ULL << i);
82 }
83 so_emit_reloc_markers(chan, state->hw[NV30_STATE_FRAGPROG]);
84 if (state->hw[NV30_STATE_VTXBUF] /*&& nv30->render_mode == HW*/)
85 so_emit_reloc_markers(chan, state->hw[NV30_STATE_VTXBUF]);
86 }
87
88 boolean
89 nv30_state_validate(struct nv30_context *nv30)
90 {
91 #if 0
92 boolean was_sw = nv30->fallback_swtnl ? TRUE : FALSE;
93
94 if (nv30->render_mode != HW) {
95 /* Don't even bother trying to go back to hw if none
96 * of the states that caused swtnl previously have changed.
97 */
98 if ((nv30->fallback_swtnl & nv30->dirty)
99 != nv30->fallback_swtnl)
100 return FALSE;
101
102 /* Attempt to go to hwtnl again */
103 nv30->pipe.flush(&nv30->pipe, 0, NULL);
104 nv30->dirty |= (NV30_NEW_VIEWPORT |
105 NV30_NEW_VERTPROG |
106 NV30_NEW_ARRAYS);
107 nv30->render_mode = HW;
108 }
109 #endif
110 nv30_state_do_validate(nv30, render_states);
111 #if 0
112 if (nv30->fallback_swtnl || nv30->fallback_swrast)
113 return FALSE;
114
115 if (was_sw)
116 NOUVEAU_ERR("swtnl->hw\n");
117 #endif
118 return TRUE;
119 }