st/mesa: fix incorrect RowStride computation
[mesa.git] / src / gallium / drivers / nv40 / nv40_state_emit.c
1 #include "nv40_context.h"
2 #include "nv40_state.h"
3 #include "draw/draw_context.h"
4
5 static struct nv40_state_entry *render_states[] = {
6 &nv40_state_framebuffer,
7 &nv40_state_rasterizer,
8 &nv40_state_scissor,
9 &nv40_state_stipple,
10 &nv40_state_fragprog,
11 &nv40_state_fragtex,
12 &nv40_state_vertprog,
13 &nv40_state_blend,
14 &nv40_state_blend_colour,
15 &nv40_state_zsa,
16 &nv40_state_sr,
17 &nv40_state_viewport,
18 &nv40_state_vbo,
19 NULL
20 };
21
22 static struct nv40_state_entry *swtnl_states[] = {
23 &nv40_state_framebuffer,
24 &nv40_state_rasterizer,
25 &nv40_state_scissor,
26 &nv40_state_stipple,
27 &nv40_state_fragprog,
28 &nv40_state_fragtex,
29 &nv40_state_vertprog,
30 &nv40_state_blend,
31 &nv40_state_blend_colour,
32 &nv40_state_zsa,
33 &nv40_state_sr,
34 &nv40_state_viewport,
35 &nv40_state_vtxfmt,
36 NULL
37 };
38
39 static void
40 nv40_state_do_validate(struct nv40_context *nv40,
41 struct nv40_state_entry **states)
42 {
43 while (*states) {
44 struct nv40_state_entry *e = *states;
45
46 if (nv40->dirty & e->dirty.pipe) {
47 if (e->validate(nv40))
48 nv40->state.dirty |= (1ULL << e->dirty.hw);
49 }
50
51 states++;
52 }
53 nv40->dirty = 0;
54 }
55
56 void
57 nv40_state_emit(struct nv40_context *nv40)
58 {
59 struct nv40_state *state = &nv40->state;
60 struct nv40_screen *screen = nv40->screen;
61 struct nouveau_channel *chan = screen->base.channel;
62 struct nouveau_grobj *curie = screen->curie;
63 unsigned i;
64 uint64_t states;
65
66 /* XXX: race conditions
67 */
68 if (nv40 != screen->cur_ctx) {
69 for (i = 0; i < NV40_STATE_MAX; i++) {
70 if (state->hw[i] && screen->state[i] != state->hw[i])
71 state->dirty |= (1ULL << i);
72 }
73
74 screen->cur_ctx = nv40;
75 }
76
77 for (i = 0, states = state->dirty; states; i++) {
78 if (!(states & (1ULL << i)))
79 continue;
80 so_ref (state->hw[i], &nv40->screen->state[i]);
81 if (state->hw[i])
82 so_emit(chan, nv40->screen->state[i]);
83 states &= ~(1ULL << i);
84 }
85
86 if (state->dirty & ((1ULL << NV40_STATE_FRAGPROG) |
87 (1ULL << NV40_STATE_FRAGTEX0))) {
88 BEGIN_RING(chan, curie, NV40TCL_TEX_CACHE_CTL, 1);
89 OUT_RING (chan, 2);
90 BEGIN_RING(chan, curie, NV40TCL_TEX_CACHE_CTL, 1);
91 OUT_RING (chan, 1);
92 }
93
94 state->dirty = 0;
95 }
96
97 void
98 nv40_state_flush_notify(struct nouveau_channel *chan)
99 {
100 struct nv40_context *nv40 = chan->user_private;
101 struct nv40_state *state = &nv40->state;
102 unsigned i, samplers;
103
104 so_emit_reloc_markers(chan, state->hw[NV40_STATE_FB]);
105 for (i = 0, samplers = state->fp_samplers; i < 16 && samplers; i++) {
106 if (!(samplers & (1 << i)))
107 continue;
108 so_emit_reloc_markers(chan,
109 state->hw[NV40_STATE_FRAGTEX0+i]);
110 samplers &= ~(1ULL << i);
111 }
112 so_emit_reloc_markers(chan, state->hw[NV40_STATE_FRAGPROG]);
113 if (state->hw[NV40_STATE_VTXBUF] && nv40->render_mode == HW)
114 so_emit_reloc_markers(chan, state->hw[NV40_STATE_VTXBUF]);
115 }
116
117 boolean
118 nv40_state_validate(struct nv40_context *nv40)
119 {
120 boolean was_sw = nv40->fallback_swtnl ? TRUE : FALSE;
121
122 if (nv40->render_mode != HW) {
123 /* Don't even bother trying to go back to hw if none
124 * of the states that caused swtnl previously have changed.
125 */
126 if ((nv40->fallback_swtnl & nv40->dirty)
127 != nv40->fallback_swtnl)
128 return FALSE;
129
130 /* Attempt to go to hwtnl again */
131 nv40->pipe.flush(&nv40->pipe, 0, NULL);
132 nv40->dirty |= (NV40_NEW_VIEWPORT |
133 NV40_NEW_VERTPROG |
134 NV40_NEW_ARRAYS);
135 nv40->render_mode = HW;
136 }
137
138 nv40_state_do_validate(nv40, render_states);
139 if (nv40->fallback_swtnl || nv40->fallback_swrast)
140 return FALSE;
141
142 if (was_sw)
143 NOUVEAU_ERR("swtnl->hw\n");
144
145 return TRUE;
146 }
147
148 boolean
149 nv40_state_validate_swtnl(struct nv40_context *nv40)
150 {
151 struct draw_context *draw = nv40->draw;
152
153 /* Setup for swtnl */
154 if (nv40->render_mode == HW) {
155 NOUVEAU_ERR("hw->swtnl 0x%08x\n", nv40->fallback_swtnl);
156 nv40->pipe.flush(&nv40->pipe, 0, NULL);
157 nv40->dirty |= (NV40_NEW_VIEWPORT |
158 NV40_NEW_VERTPROG |
159 NV40_NEW_ARRAYS);
160 nv40->render_mode = SWTNL;
161 }
162
163 if (nv40->draw_dirty & NV40_NEW_VERTPROG)
164 draw_bind_vertex_shader(draw, nv40->vertprog->draw);
165
166 if (nv40->draw_dirty & NV40_NEW_RAST)
167 draw_set_rasterizer_state(draw, &nv40->rasterizer->pipe, nv40->rasterizer);
168
169 if (nv40->draw_dirty & NV40_NEW_UCP)
170 draw_set_clip_state(draw, &nv40->clip);
171
172 if (nv40->draw_dirty & NV40_NEW_VIEWPORT)
173 draw_set_viewport_state(draw, &nv40->viewport);
174
175 if (nv40->draw_dirty & NV40_NEW_ARRAYS) {
176 draw_set_vertex_buffers(draw, nv40->vtxbuf_nr, nv40->vtxbuf);
177 draw_set_vertex_elements(draw, nv40->vtxelt_nr, nv40->vtxelt);
178 }
179
180 nv40_state_do_validate(nv40, swtnl_states);
181 if (nv40->fallback_swrast) {
182 NOUVEAU_ERR("swtnl->swrast 0x%08x\n", nv40->fallback_swrast);
183 return FALSE;
184 }
185
186 nv40->draw_dirty = 0;
187 return TRUE;
188 }
189