summaryrefslogtreecommitdiffstats
path: root/src/gallium/drivers/nv50/nv50_state_validate.c
blob: 68d419f9fc85b8aff28d6ad17cab94dec4ec6309 (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
#include "nv50_context.h"
#include "nouveau/nouveau_stateobj.h"

static void
nv50_state_validate_fb(struct nv50_context *nv50)
{
	struct nouveau_grobj *tesla = nv50->screen->tesla;
	struct nouveau_stateobj *so = so_new(128, 18);
	struct pipe_framebuffer_state *fb = &nv50->framebuffer;
	unsigned i, w, h, gw = 0;

	for (i = 0; i < fb->num_cbufs; i++) {
		if (!gw) {
			w = fb->cbufs[i]->width;
			h = fb->cbufs[i]->height;
			gw = 1;
		} else {
			assert(w != fb->cbufs[i]->width);
			assert(h != fb->cbufs[i]->height);
		}

		so_method(so, tesla, NV50TCL_RT_HORIZ(i), 2);
		so_data  (so, fb->cbufs[i]->width);
		so_data  (so, fb->cbufs[i]->height);

		so_method(so, tesla, NV50TCL_RT_ADDRESS_HIGH(i), 5);
		so_reloc (so, fb->cbufs[i]->buffer, fb->cbufs[i]->offset,
			  NOUVEAU_BO_VRAM | NOUVEAU_BO_HIGH, 0, 0);
		so_reloc (so, fb->cbufs[i]->buffer, fb->cbufs[i]->offset,
			  NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW, 0, 0);
		switch (fb->cbufs[i]->format) {
		case PIPE_FORMAT_A8R8G8B8_UNORM:
			so_data(so, 0xcf);
			break;
		case PIPE_FORMAT_R5G6B5_UNORM:
			so_data(so, 0xe8);
			break;
		default:
			{
				char fmt[128];
				pf_sprint_name(fmt, fb->cbufs[i]->format);
				NOUVEAU_ERR("AIIII unknown format %s\n", fmt);
			}		    
			so_data(so, 0xe6);
			break;
		}
		so_data(so, 0x00000040);
		so_data(so, 0x00000000);
	}

	if (fb->zsbuf) {
		if (!gw) {
			w = fb->zsbuf->width;
			h = fb->zsbuf->height;
			gw = 1;
		} else {
			assert(w != fb->zsbuf->width);
			assert(h != fb->zsbuf->height);
		}

		so_method(so, tesla, NV50TCL_RT_ADDRESS_HIGH(i), 5);
		so_reloc (so, fb->zsbuf->buffer, fb->zsbuf->offset,
			  NOUVEAU_BO_VRAM | NOUVEAU_BO_HIGH, 0, 0);
		so_reloc (so, fb->zsbuf->buffer, fb->zsbuf->offset,
			  NOUVEAU_BO_VRAM | NOUVEAU_BO_LOW, 0, 0);
		switch (fb->zsbuf->format) {
		case PIPE_FORMAT_Z24S8_UNORM:
			so_data(so, 0x16);
			break;
		default:
			{
				char fmt[128];
				pf_sprint_name(fmt, fb->zsbuf->format);
				NOUVEAU_ERR("AIIII unknown format %s\n", fmt);
			}		    
			so_data(so, 0x16);
			break;
		}
		so_data(so, 0x00000040);
		so_data(so, 0x00000000);
	}

	so_method(so, tesla, NV50TCL_VIEWPORT_HORIZ, 2);
	so_data  (so, w << 16);
	so_data  (so, h << 16);
	so_method(so, tesla, 0xff0, 2);
	so_data  (so, w << 16);
	so_data  (so, h << 16);

	so_emit(nv50->screen->nvws, so);
	so_ref(NULL, &so);
}

boolean
nv50_state_validate(struct nv50_context *nv50)
{
	struct nouveau_winsys *nvws = nv50->screen->nvws;
	struct nouveau_grobj *tesla = nv50->screen->tesla;
	struct nouveau_stateobj *so;
	unsigned i;

	if (nv50->dirty & NV50_NEW_FRAMEBUFFER)
		nv50_state_validate_fb(nv50);

	if (nv50->dirty & NV50_NEW_BLEND)
		so_emit(nvws, nv50->blend->so);

	if (nv50->dirty & NV50_NEW_ZSA)
		so_emit(nvws, nv50->zsa->so);

	if (nv50->dirty & NV50_NEW_RASTERIZER)
		so_emit(nvws, nv50->rasterizer->so);

	if (nv50->dirty & NV50_NEW_BLEND_COLOUR) {
		so = so_new(5, 0);
		so_method(so, tesla, NV50TCL_BLEND_COLOR(0), 8);
		so_data  (so, fui(nv50->blend_colour.color[3]));
		so_data  (so, fui(nv50->blend_colour.color[0]));
		so_data  (so, fui(nv50->blend_colour.color[1]));
		so_data  (so, fui(nv50->blend_colour.color[2]));
		so_emit(nvws, so);
		so_ref(NULL, &so);
	}

	if (nv50->dirty & NV50_NEW_STIPPLE) {
		so = so_new(33, 0);
		so_method(so, tesla, NV50TCL_POLYGON_STIPPLE_PATTERN(0), 32);
		for (i = 0; i < 32; i++)
			so_data(so, nv50->stipple.stipple[i]);
		so_emit(nvws, so);
		so_ref(NULL, &so);
	}

	if (nv50->dirty & NV50_NEW_SCISSOR) {
		so = so_new(3, 0);
		so_method(so, tesla, NV50TCL_SCISSOR_HORIZ, 2);
		so_data  (so, (nv50->scissor.maxx << 16) |
			       nv50->scissor.minx);
		so_data  (so, (nv50->scissor.maxy << 16) |
			       nv50->scissor.miny);
		so_emit(nvws, so);
		so_ref(NULL, &so);
	}

	if (nv50->dirty & NV50_NEW_VIEWPORT) {
		so = so_new(8, 0);
		so_method(so, tesla, NV50TCL_VIEWPORT_UNK0(0), 3);
		so_data  (so, fui(nv50->viewport.translate[0]));
		so_data  (so, fui(nv50->viewport.translate[1]));
		so_data  (so, fui(nv50->viewport.translate[2]));
		so_method(so, tesla, NV50TCL_VIEWPORT_UNK1(0), 3);
		so_data  (so, fui(nv50->viewport.scale[0]));
		so_data  (so, fui(nv50->viewport.scale[1]));
		so_data  (so, fui(nv50->viewport.scale[2]));
		so_emit(nvws, so);
		so_ref(NULL, &so);
	}

	nv50->dirty = 0;
	return TRUE;
}