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