summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/nv40/nv40_state_emit.c
blob: af09ed47d6e354f6c1c91f4fd7cb42f4a2987aee (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
#include "nv40_context.h"
#include "nv40_state.h"

static struct nv40_state_entry *render_states[] = {
	&nv40_state_framebuffer,
	&nv40_state_rasterizer,
	&nv40_state_clip,
	&nv40_state_scissor,
	&nv40_state_stipple,
	&nv40_state_fragprog,
	&nv40_state_fragtex,
	&nv40_state_vertprog,
	&nv40_state_blend,
	&nv40_state_blend_colour,
	&nv40_state_zsa,
	&nv40_state_viewport,
	NULL
};

static void
nv40_state_validate(struct nv40_context *nv40)
{
	struct nv40_state_entry **states = render_states;
	unsigned last_fallback;

	last_fallback = nv40->fallback;
	nv40->fallback = 0;

	while (*states) {
		struct nv40_state_entry *e = *states;

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

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

	if (nv40->fallback & NV40_FALLBACK_TNL &&
	    !(last_fallback & NV40_FALLBACK_TNL)) {
		NOUVEAU_ERR("XXX: hwtnl->swtnl\n");
	} else
	if (last_fallback & NV40_FALLBACK_TNL &&
	    !(nv40->fallback & NV40_FALLBACK_TNL)) {
		NOUVEAU_ERR("XXX: swtnl->hwtnl\n");
	}

	if (nv40->fallback & NV40_FALLBACK_RAST &&
	    !(last_fallback & NV40_FALLBACK_RAST)) {
		NOUVEAU_ERR("XXX: hwrast->swrast\n");
	} else
	if (last_fallback & NV40_FALLBACK_RAST &&
	    !(nv40->fallback & NV40_FALLBACK_RAST)) {
		NOUVEAU_ERR("XXX: swrast->hwrast\n");
	}
}

static void
nv40_state_emit(struct nv40_context *nv40)
{
	struct nv40_state *state = &nv40->state;
	unsigned i, samplers;

	while (state->dirty) {
		unsigned idx = ffs(state->dirty) - 1;

		so_ref (state->hw[idx], &nv40->hw->state[idx]);
		so_emit(nv40->nvws, nv40->hw->state[idx]);
		state->dirty &= ~(1 << idx);
	}

	so_emit_reloc_markers(nv40->nvws, state->hw[NV40_STATE_FB]);
	for (i = 0, samplers = state->fp_samplers; i < 16 && samplers; i++) {
		so_emit_reloc_markers(nv40->nvws,
				      state->hw[NV40_STATE_FRAGTEX0+i]);
		samplers &= ~(1 << i);
	}
	so_emit_reloc_markers(nv40->nvws, state->hw[NV40_STATE_FRAGPROG]);
}

void
nv40_emit_hw_state(struct nv40_context *nv40)
{
	nv40_state_validate(nv40);
	nv40_state_emit(nv40);

	BEGIN_RING(curie, NV40TCL_TEX_CACHE_CTL, 1);
	OUT_RING  (2);
	BEGIN_RING(curie, NV40TCL_TEX_CACHE_CTL, 1);
	OUT_RING  (1);
}