Merge branch 'mesa_7_5_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, samplers;
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 so_emit_reloc_markers(chan, state->hw[NV30_STATE_FB]);
68 for (i = 0, samplers = state->fp_samplers; i < 16 && samplers; i++) {
69 if (!(samplers & (1 << i)))
70 continue;
71 so_emit_reloc_markers(chan,
72 state->hw[NV30_STATE_FRAGTEX0+i]);
73 samplers &= ~(1ULL << i);
74 }
75 so_emit_reloc_markers(chan, state->hw[NV30_STATE_FRAGPROG]);
76 if (state->hw[NV30_STATE_VTXBUF] /*&& nv30->render_mode == HW*/)
77 so_emit_reloc_markers(chan, state->hw[NV30_STATE_VTXBUF]);
78 }
79
80 boolean
81 nv30_state_validate(struct nv30_context *nv30)
82 {
83 #if 0
84 boolean was_sw = nv30->fallback_swtnl ? TRUE : FALSE;
85
86 if (nv30->render_mode != HW) {
87 /* Don't even bother trying to go back to hw if none
88 * of the states that caused swtnl previously have changed.
89 */
90 if ((nv30->fallback_swtnl & nv30->dirty)
91 != nv30->fallback_swtnl)
92 return FALSE;
93
94 /* Attempt to go to hwtnl again */
95 nv30->pipe.flush(&nv30->pipe, 0, NULL);
96 nv30->dirty |= (NV30_NEW_VIEWPORT |
97 NV30_NEW_VERTPROG |
98 NV30_NEW_ARRAYS);
99 nv30->render_mode = HW;
100 }
101 #endif
102 nv30_state_do_validate(nv30, render_states);
103 #if 0
104 if (nv30->fallback_swtnl || nv30->fallback_swrast)
105 return FALSE;
106
107 if (was_sw)
108 NOUVEAU_ERR("swtnl->hw\n");
109 #endif
110 return TRUE;
111 }