summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/nv30/nv30_state_emit.c
blob: c18be20a32779d7e848047702745175b70e00060 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#include "nv30_context.h"
#include "nv30_state.h"

static struct nv30_state_entry *render_states[] = {
	&nv30_state_framebuffer,
	&nv30_state_rasterizer,
	&nv30_state_scissor,
	&nv30_state_stipple,
	&nv30_state_fragprog,
	&nv30_state_fragtex,
	&nv30_state_vertprog,
	&nv30_state_blend,
	&nv30_state_blend_colour,
	&nv30_state_zsa,
	&nv30_state_viewport,
	&nv30_state_vbo,
	NULL
};

static void
nv30_state_do_validate(struct nv30_context *nv30,
		       struct nv30_state_entry **states)
{
	while (*states) {
		struct nv30_state_entry *e = *states;

		if (nv30->dirty & e->dirty.pipe) {
			if (e->validate(nv30)) {
				nv30->state.dirty |= (1ULL << e->dirty.hw);
			}
		}

		states++;
	}
	nv30->dirty = 0;
}

void
nv30_state_emit(struct nv30_context *nv30)
{
	struct nv30_state *state = &nv30->state;
	struct nv30_screen *screen = nv30->screen;
	unsigned i, samplers;
	uint64_t states;

	if (nv30->pctx_id != screen->cur_pctx) {
		for (i = 0; i < NV30_STATE_MAX; i++) {
			if (state->hw[i] && screen->state[i] != state->hw[i])
				state->dirty |= (1ULL << i);
		}

		screen->cur_pctx = nv30->pctx_id;
	}

	for (i = 0, states = state->dirty; states; i++) {
		if (!(states & (1ULL << i)))
			continue;
		so_ref (state->hw[i], &nv30->screen->state[i]);
		if (state->hw[i])
			so_emit(nv30->nvws, nv30->screen->state[i]);
		states &= ~(1ULL << i);
	}

	state->dirty = 0;

	so_emit_reloc_markers(nv30->nvws, state->hw[NV30_STATE_FB]);
	for (i = 0, samplers = state->fp_samplers; i < 16 && samplers; i++) {
		if (!(samplers & (1 << i)))
			continue;
		so_emit_reloc_markers(nv30->nvws,
				      state->hw[NV30_STATE_FRAGTEX0+i]);
		samplers &= ~(1ULL << i);
	}
	so_emit_reloc_markers(nv30->nvws, state->hw[NV30_STATE_FRAGPROG]);
	if (state->hw[NV30_STATE_VTXBUF] /*&& nv30->render_mode == HW*/)
		so_emit_reloc_markers(nv30->nvws, state->hw[NV30_STATE_VTXBUF]);
}

boolean
nv30_state_validate(struct nv30_context *nv30)
{
#if 0
	boolean was_sw = nv30->fallback_swtnl ? TRUE : FALSE;

	if (nv30->render_mode != HW) {
		/* Don't even bother trying to go back to hw if none
		 * of the states that caused swtnl previously have changed.
		 */
		if ((nv30->fallback_swtnl & nv30->dirty)
				!= nv30->fallback_swtnl)
			return FALSE;

		/* Attempt to go to hwtnl again */
		nv30->pipe.flush(&nv30->pipe, 0, NULL);
		nv30->dirty |= (NV30_NEW_VIEWPORT |
				NV30_NEW_VERTPROG |
				NV30_NEW_ARRAYS);
		nv30->render_mode = HW;
	}
#endif
	nv30_state_do_validate(nv30, render_states);
#if 0
	if (nv30->fallback_swtnl || nv30->fallback_swrast)
		return FALSE;
	
	if (was_sw)
		NOUVEAU_ERR("swtnl->hw\n");
#endif
	return TRUE;
}