summaryrefslogtreecommitdiff
path: root/src/gallium/drivers/nv40/nv40_state_emit.c
blob: ce52a3863e7ff869c07d92c7af9e4d2e51910f76 (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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#include "nv40_context.h"
#include "nv40_state.h"

/* Emit relocs for every referenced buffer.
 *
 * This is to ensure the bufmgr has an accurate idea of how
 * the buffer is used.  These relocs appear in the push buffer as
 * NOPs, and will only be turned into state changes if a buffer
 * actually moves.
 */
static void
nv40_state_emit_dummy_relocs(struct nv40_context *nv40)
{
	unsigned i;	
	
	so_emit_reloc_markers(nv40->nvws, nv40->so_framebuffer);
	for (i = 0; i < 16; i++) {
		if (!(nv40->fp_samplers & (1 << i)))
			continue;
		so_emit_reloc_markers(nv40->nvws, nv40->so_fragtex[i]);
	}
	so_emit_reloc_markers(nv40->nvws, nv40->fragprog.active->so);
}

static boolean
nv40_state_scissor_validate(struct nv40_context *nv40)
{
	struct pipe_rasterizer_state *rast = &nv40->rasterizer->pipe;
	struct pipe_scissor_state *s = &nv40->pipe_state.scissor;
	struct nouveau_stateobj *so;

	if (nv40->state.scissor.so &&
	    (rast->scissor == 0 && nv40->state.scissor.enabled == 0))
		return FALSE;

	so = so_new(3, 0);
	so_method(so, nv40->hw->curie, NV40TCL_SCISSOR_HORIZ, 2);
	if (rast->scissor) {
		so_data  (so, ((s->maxx - s->minx) << 16) | s->minx);
		so_data  (so, ((s->maxy - s->miny) << 16) | s->miny);
	} else {
		so_data  (so, 4096 << 16);
		so_data  (so, 4096 << 16);
	}

	so_ref(so, &nv40->state.scissor.so);
	so_ref(NULL, &so);
	return TRUE;
}

static boolean
nv40_state_stipple_validate(struct nv40_context *nv40)
{
	struct pipe_rasterizer_state *rast = &nv40->rasterizer->pipe;
	struct nouveau_grobj *curie = nv40->hw->curie;
	struct nouveau_stateobj *so;

	if (nv40->state.stipple.so && (rast->poly_stipple_enable == 0 &&
				       nv40->state.stipple.enabled == 0))
		return FALSE;

	if (rast->poly_stipple_enable) {
		unsigned i;

		so = so_new(35, 0);
		so_method(so, curie, NV40TCL_POLYGON_STIPPLE_ENABLE, 1);
		so_data  (so, 1);
		so_method(so, curie, NV40TCL_POLYGON_STIPPLE_PATTERN(0), 32);
		for (i = 0; i < 32; i++)
			so_data(so, nv40->pipe_state.stipple[i]);
	} else {
		so = so_new(2, 0);
		so_method(so, curie, NV40TCL_POLYGON_STIPPLE_ENABLE, 1);
		so_data  (so, 0);
	}

	so_ref(so, &nv40->state.stipple.so);
	so_ref(NULL, &so);
	return TRUE;
}

static boolean
nv40_state_clip_validate(struct nv40_context *nv40)
{
	if (nv40->pipe_state.clip.nr)
		nv40->fallback |= NV40_FALLBACK_TNL;
	return FALSE;
}

static struct nv40_state_entry states[] = {
	{
		.validate = nv40_state_scissor_validate,
		.dirty = {
			.pipe = NV40_NEW_SCISSOR | NV40_NEW_RAST,
			.hw = NV40_NEW_SCISSOR,
		}
	},
	{
		.validate = nv40_state_stipple_validate,
		.dirty = {
			.pipe = NV40_NEW_STIPPLE | NV40_NEW_RAST,
			.hw = NV40_NEW_STIPPLE,
		}
	},
	{
		.validate = nv40_state_clip_validate,
		.dirty = {
			.pipe = NV40_NEW_UCP,
			.hw = 0,
		}
	}
};

static void
nv40_state_validate(struct nv40_context *nv40)
{
	unsigned i, last_fallback;

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

	for (i = 0; i < sizeof(states) / sizeof(states[0]); i++) {
		if (nv40->dirty & states[i].dirty.pipe) {
			if (states[i].validate(nv40))
				nv40->hw_dirty |= states[i].dirty.hw;
		}
	}

	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");
	}
}

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

	if (nv40->dirty & NV40_NEW_FB)
		so_emit(nv40->nvws, nv40->so_framebuffer);

	if (nv40->dirty & NV40_NEW_BLEND)
		so_emit(nv40->nvws, nv40->so_blend);

	if (nv40->dirty & NV40_NEW_RAST)
		so_emit(nv40->nvws, nv40->so_rast);

	if (nv40->dirty & NV40_NEW_ZSA)
		so_emit(nv40->nvws, nv40->so_zsa);

	if (nv40->dirty & NV40_NEW_BCOL)
		so_emit(nv40->nvws, nv40->so_bcol);

	if (nv40->hw_dirty & NV40_NEW_SCISSOR) {
		so_emit(nv40->nvws, nv40->state.scissor.so);
		nv40->hw_dirty &= ~NV40_NEW_SCISSOR;
	}

	if (nv40->dirty & NV40_NEW_VIEWPORT)
		so_emit(nv40->nvws, nv40->so_viewport);

	if (nv40->hw_dirty & NV40_NEW_STIPPLE) {
		so_emit(nv40->nvws, nv40->state.stipple.so);
		nv40->hw_dirty &= ~NV40_NEW_STIPPLE;
	}

	if (nv40->dirty & NV40_NEW_FRAGPROG) {
		nv40_fragprog_bind(nv40, nv40->fragprog.current);
		/*XXX: clear NV40_NEW_FRAGPROG if no new program uploaded */
	}

	if (nv40->dirty_samplers || (nv40->dirty & NV40_NEW_FRAGPROG)) {
		nv40_fragtex_bind(nv40);

		BEGIN_RING(curie, NV40TCL_TEX_CACHE_CTL, 1);
		OUT_RING  (2);
		BEGIN_RING(curie, NV40TCL_TEX_CACHE_CTL, 1);
		OUT_RING  (1);
		nv40->dirty &= ~NV40_NEW_FRAGPROG;
	}

	if (nv40->dirty & NV40_NEW_VERTPROG) {
		nv40_vertprog_bind(nv40, nv40->vertprog.current);
		nv40->dirty &= ~NV40_NEW_VERTPROG;
	}

	nv40->dirty_samplers = 0;
	nv40->dirty = 0;

	nv40_state_emit_dummy_relocs(nv40);
}