Merge branch 'radeon-rewrite' of git+ssh://agd5f@git.freedesktop.org/git/mesa/mesa...
[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 nv30_state *state = &nv30->state;
42 struct nv30_screen *screen = nv30->screen;
43 unsigned i, samplers;
44 uint64_t states;
45
46 if (nv30->pctx_id != screen->cur_pctx) {
47 for (i = 0; i < NV30_STATE_MAX; i++) {
48 if (state->hw[i] && screen->state[i] != state->hw[i])
49 state->dirty |= (1ULL << i);
50 }
51
52 screen->cur_pctx = nv30->pctx_id;
53 }
54
55 for (i = 0, states = state->dirty; states; i++) {
56 if (!(states & (1ULL << i)))
57 continue;
58 so_ref (state->hw[i], &nv30->screen->state[i]);
59 if (state->hw[i])
60 so_emit(nv30->nvws, nv30->screen->state[i]);
61 states &= ~(1ULL << i);
62 }
63
64 state->dirty = 0;
65
66 so_emit_reloc_markers(nv30->nvws, state->hw[NV30_STATE_FB]);
67 for (i = 0, samplers = state->fp_samplers; i < 16 && samplers; i++) {
68 if (!(samplers & (1 << i)))
69 continue;
70 so_emit_reloc_markers(nv30->nvws,
71 state->hw[NV30_STATE_FRAGTEX0+i]);
72 samplers &= ~(1ULL << i);
73 }
74 so_emit_reloc_markers(nv30->nvws, state->hw[NV30_STATE_FRAGPROG]);
75 if (state->hw[NV30_STATE_VTXBUF] /*&& nv30->render_mode == HW*/)
76 so_emit_reloc_markers(nv30->nvws, state->hw[NV30_STATE_VTXBUF]);
77 }
78
79 boolean
80 nv30_state_validate(struct nv30_context *nv30)
81 {
82 #if 0
83 boolean was_sw = nv30->fallback_swtnl ? TRUE : FALSE;
84
85 if (nv30->render_mode != HW) {
86 /* Don't even bother trying to go back to hw if none
87 * of the states that caused swtnl previously have changed.
88 */
89 if ((nv30->fallback_swtnl & nv30->dirty)
90 != nv30->fallback_swtnl)
91 return FALSE;
92
93 /* Attempt to go to hwtnl again */
94 nv30->pipe.flush(&nv30->pipe, 0, NULL);
95 nv30->dirty |= (NV30_NEW_VIEWPORT |
96 NV30_NEW_VERTPROG |
97 NV30_NEW_ARRAYS);
98 nv30->render_mode = HW;
99 }
100 #endif
101 nv30_state_do_validate(nv30, render_states);
102 #if 0
103 if (nv30->fallback_swtnl || nv30->fallback_swrast)
104 return FALSE;
105
106 if (was_sw)
107 NOUVEAU_ERR("swtnl->hw\n");
108 #endif
109 return TRUE;
110 }