summaryrefslogtreecommitdiff
path: root/src/nv30_shaders.c
blob: 6a72d8ded0772eb5f5e1620aa9e82a028f8f1c42 (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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
/*
 * Copyright 2007 Nouveau Project
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE AUTHORS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */


#include "nv30_shaders.h"

#include "hwdefs/nv30-40_3d.xml.h"
#include "nv04_accel.h"

void NV30_UploadFragProg(NVPtr pNv, nv_shader_t *shader, int *hw_offset)
{
	uint32_t data, i;
	uint32_t *map;

	shader->hw_id = *hw_offset;

	map = pNv->scratch->map + *hw_offset;
	for (i = 0; i < shader->size; i++) {
		data = shader->data[i];
#if (X_BYTE_ORDER != X_LITTLE_ENDIAN)
		data = ((data >> 16) | ((data & 0xffff) << 16));
#endif
		map[i] = data;
	}

	*hw_offset += (shader->size * sizeof(uint32_t));
	*hw_offset = (*hw_offset + 63) & ~63;
}

void NV40_UploadVtxProg(NVPtr pNv, nv_shader_t *shader, int *hw_id)
{
	struct nouveau_pushbuf *push = pNv->pushbuf;
	int i;

	shader->hw_id = *hw_id;

	BEGIN_NV04(push, NV30_3D(VP_UPLOAD_FROM_ID), 1);
	PUSH_DATA (push, (shader->hw_id));
	for (i=0; i<shader->size; i+=4) {
		BEGIN_NV04(push, NV30_3D(VP_UPLOAD_INST(0)), 4);
		PUSH_DATA (push, shader->data[i + 0]);
		PUSH_DATA (push, shader->data[i + 1]);
		PUSH_DATA (push, shader->data[i + 2]);
		PUSH_DATA (push, shader->data[i + 3]);
		(*hw_id)++;
	}
}

Bool
NV30_LoadFragProg(ScrnInfoPtr pScrn, nv_shader_t *shader)
{
	NVPtr pNv = NVPTR(pScrn);
	struct nouveau_pushbuf *push = pNv->pushbuf;

	BEGIN_NV04(push, NV30_3D(FP_ACTIVE_PROGRAM), 1);
	PUSH_MTHD (push, NV30_3D(FP_ACTIVE_PROGRAM), pNv->scratch,
			 shader->hw_id, NOUVEAU_BO_VRAM | NOUVEAU_BO_RD |
			 NOUVEAU_BO_LOW | NOUVEAU_BO_OR,
			 NV30_3D_FP_ACTIVE_PROGRAM_DMA0,
			 NV30_3D_FP_ACTIVE_PROGRAM_DMA1);
	BEGIN_NV04(push, NV30_3D(FP_REG_CONTROL), 1);
	PUSH_DATA (push, (1 << 16) | 0xf);
	BEGIN_NV04(push, NV30_3D(MULTISAMPLE_CONTROL), 1);
	PUSH_DATA (push, 0xffff0000);
	BEGIN_NV04(push, NV30_3D(FP_CONTROL),1);
	PUSH_DATA (push, (shader->card_priv.NV30FP.num_regs - 1) / 2);

	return TRUE;
}

void
NV40_LoadVtxProg(ScrnInfoPtr pScrn, nv_shader_t *shader)
{
	NVPtr pNv = NVPTR(pScrn);
	struct nouveau_pushbuf *push = pNv->pushbuf;

	BEGIN_NV04(push, NV30_3D(VP_START_FROM_ID), 1);
	PUSH_DATA (push, (shader->hw_id));
	BEGIN_NV04(push, NV40_3D(VP_ATTRIB_EN), 2);
	PUSH_DATA (push, shader->card_priv.NV30VP.vp_in_reg);
	PUSH_DATA (push, shader->card_priv.NV30VP.vp_out_reg);
}

Bool
NV40_LoadFragProg(ScrnInfoPtr pScrn, nv_shader_t *shader)
{
	NVPtr pNv = NVPTR(pScrn);
	struct nouveau_pushbuf *push = pNv->pushbuf;

	BEGIN_NV04(push, NV30_3D(FP_ACTIVE_PROGRAM), 1);
	PUSH_MTHD (push, NV30_3D(FP_ACTIVE_PROGRAM), pNv->scratch,
			 shader->hw_id, NOUVEAU_BO_VRAM | NOUVEAU_BO_GART |
			 NOUVEAU_BO_RD | NOUVEAU_BO_LOW | NOUVEAU_BO_OR,
			 NV30_3D_FP_ACTIVE_PROGRAM_DMA0,
			 NV30_3D_FP_ACTIVE_PROGRAM_DMA1);
	BEGIN_NV04(push, NV30_3D(FP_CONTROL), 1);
	PUSH_DATA (push, shader->card_priv.NV30FP.num_regs <<
			 NV40_3D_FP_CONTROL_TEMP_COUNT__SHIFT);

	return TRUE;
}

/*******************************************************************************
 * NV40/G70 vertex shaders
 */

nv_shader_t nv40_vp_exa_render = {
	.card_priv.NV30VP.vp_in_reg  = 0x00000309,
	.card_priv.NV30VP.vp_out_reg = 0x0000c001,
	.size = (3*4),
	.data = {
		/* MOV result.position, vertex.position */
		0x40041c6c, 0x0040000d, 0x8106c083, 0x6041ff80,
		/* MOV result.texcoord[0], vertex.texcoord[0] */
		0x401f9c6c, 0x0040080d, 0x8106c083, 0x6041ff9c,
		/* MOV result.texcoord[1], vertex.texcoord[1] */
		0x401f9c6c, 0x0040090d, 0x8106c083, 0x6041ffa1,
	}
};

/*******************************************************************************
 * NV30/NV40/G70 fragment shaders
 */

nv_shader_t nv30_fp_pass_col0 = {
	.card_priv.NV30FP.num_regs = 2,
	.size = (1*4),
	.data = {
		/* MOV R0, fragment.color */
		0x01403e81, 0x1c9dc801, 0x0001c800, 0x3fe1c800, 
	}
};

nv_shader_t nv30_fp_pass_tex0 = {
	.card_priv.NV30FP.num_regs = 2,
	.size = (2*4),
	.data = {
		/* TEX R0, fragment.texcoord[0], texture[0], 2D */
		0x17009e00, 0x1c9dc801, 0x0001c800, 0x3fe1c800,
		/* MOV R0, R0 */
		0x01401e81, 0x1c9dc800, 0x0001c800, 0x0001c800,
	}
};

nv_shader_t nv30_fp_composite_mask = {
	.card_priv.NV30FP.num_regs = 2,
	.size = (3*4),
	.data = {
		/* TEXC0 R1.w         , fragment.texcoord[1], texture[1], 2D */
		0x1702b102, 0x1c9dc801, 0x0001c800, 0x3fe1c800,
		/* TEX   R0 (NE0.wwww), fragment.texcoord[0], texture[0], 2D */
		0x17009e00, 0x1ff5c801, 0x0001c800, 0x3fe1c800,
		/* MUL   R0           , R0, R1.w */
		0x02001e81, 0x1c9dc800, 0x0001fe04, 0x0001c800,
	}
};

nv_shader_t nv30_fp_composite_mask_sa_ca = {
	.card_priv.NV30FP.num_regs = 2,
	.size = (3*4),
	.data = {
		/* TEXC0 R1.w         , fragment.texcoord[0], texture[0], 2D */
		0x17009102, 0x1c9dc801, 0x0001c800, 0x3fe1c800,
		/* TEX   R0 (NE0.wwww), fragment.texcoord[1], texture[1], 2D */
		0x1702be00, 0x1ff5c801, 0x0001c800, 0x3fe1c800,
		/* MUL   R0           , R1,wwww, R0 */
		0x02001e81, 0x1c9dfe04, 0x0001c800, 0x0001c800,
	}
};

nv_shader_t nv30_fp_composite_mask_ca = {
	.card_priv.NV30FP.num_regs = 2,
	.size = (3*4),
	.data = {
		/* TEXC0 R0           , fragment.texcoord[0], texture[0], 2D */
		0x17009f00, 0x1c9dc801, 0x0001c800, 0x3fe1c800,
		/* TEX   R1 (NE0.xyzw), fragment.texcoord[1], texture[1], 2D */
		0x1702be02, 0x1c95c801, 0x0001c800, 0x3fe1c800,
		/* MUL   R0           , R0, R1 */
		0x02001e81, 0x1c9dc800, 0x0001c804, 0x0001c800,
	}
};

nv_shader_t nv40_vp_video = {
	.card_priv.NV30VP.vp_in_reg  = 0x00000309,
	.card_priv.NV30VP.vp_out_reg = 0x0000c001,
	.size = (3*4),
	.data = {
		/* MOV result.position, vertex.position */
		0x40041c6c, 0x0040000d, 0x8106c083, 0x6041ff80,
		/* MOV result.texcoord[0], vertex.texcoord[0] */
		0x401f9c6c, 0x0040080d, 0x8106c083, 0x6041ff9c,
		/* MOV result.texcoord[1], vertex.texcoord[1] */
		0x401f9c6c, 0x0040090d, 0x8106c083, 0x6041ffa1,
	}
};

nv_shader_t nv40_fp_yv12_bicubic = {
	.card_priv.NV30FP.num_regs = 4,
	.size = (29*4),
	.data = {
		/* INST 0: MOVR R0.xy (TR0.xyzw), attrib.texcoord[0] */
		0x01008600, 0x1c9dc801, 0x0001c800, 0x3fe1c800,
		/* INST 1: ADDR R0.z (TR0.xyzw), R0.yyyy, { 0.50, 0.00, 0.00, 0.00 }.xxxx */
		0x03000800, 0x1c9caa00, 0x00000002, 0x0001c800,
		0x3f000000, 0x00000000, 0x00000000, 0x00000000,
		/* INST 2: ADDR R1.x (TR0.xyzw), R0, { 0.50, 0.00, 0.00, 0.00 }.xxxx */
		0x03000202, 0x1c9dc800, 0x00000002, 0x0001c800,
		0x3f000000, 0x00000000, 0x00000000, 0x00000000,
		/* INST 3: TEXRC0 R1.xyz (TR0.xyzw), R0.zzzz, texture[0] */
		0x17000f82, 0x1c9d5400, 0x0001c800, 0x0001c800,
		/* INST 4: MULR R2.yw (TR0.xyzw), R1.xxyy, { -1.00, 1.00, 0.00, 0.00 }.xxyy */
		0x02001404, 0x1c9ca104, 0x0000a002, 0x0001c800,
		0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
		/* INST 5: TEXR R3.xyz (TR0.xyzw), R1, texture[0] */
		0x17000e86, 0x1c9dc804, 0x0001c800, 0x0001c800,
		/* INST 6: MULR R2.xz (TR0.xyzw), R3.xxyy, { -1.00, 1.00, 0.00, 0.00 }.xxyy */
		0x02000a04, 0x1c9ca10c, 0x0000a002, 0x0001c800,
		0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
		/* INST 7: ADDR R2 (TR0.xyzw), R0.xyxy, R2 */
		0x03001e04, 0x1c9c8800, 0x0001c808, 0x0001c800,
		/* INST 8: TEXR R1.y (TR0.xyzw), R2.zwzz, -texture[1] */
		0x17020402, 0x1c9d5c08, 0x0001c800, 0x0001c800,
		/* INST 9: MADH R1.x (TR0.xyzw), -R1.zzzz, R1.yyyy, R1.yyyy */
		0x04400282, 0x1c9f5504, 0x0000aa04, 0x0000aa04,
		/* INST 10: TEXR R0.y (TR0.xyzw), R2.xwxw, -texture[1] */
		0x17020400, 0x1c9d9808, 0x0001c800, 0x0001c800,
		/* INST 11: MADH R0.w (TR0.xyzw), -R1.zzzz, R0.yyyy, R0.yyyy */
		0x04401080, 0x1c9f5504, 0x0000aa00, 0x0000aa00,
		/* INST 12: TEXR R0.x (TR0.xyzw), R2.zyxy, texture[1] */
		0x17020200, 0x1c9c8c08, 0x0001c800, 0x0001c800,
		/* INST 13: MADH R1.x (TR0.xyzw), R1.zzzz, R0, R1 */
		0x04400282, 0x1c9d5504, 0x0001c800, 0x0001c904,
		/* INST 14: TEXR R0.x (NE0.zzzz), R2, texture[1] */
		0x17020200, 0x1555c808, 0x0001c800, 0x0001c800,
		/* INST 15: MADH R0.x (TR0.xyzw), R1.zzzz, R0, R0.wwww */
		0x04400280, 0x1c9d5504, 0x0001c800, 0x0001ff00,
		/* INST 16: MADH R0.w (TR0.xyzw), -R3.zzzz, R1.xxxx, R1.xxxx */
		0x04401080, 0x1c9f550c, 0x00000104, 0x00000104,
		/* INST 17: TEXR R0.yz (TR0.xyzw), attrib.texcoord[1], abs(texture[2]) */
		0x1704ac80, 0x1c9dc801, 0x0001c800, 0x3fe1c800,
		/* INST 18: MADH R0.x (TR0.xyzw), R3.zzzz, R0, R0.wwww */
		0x04400280, 0x1c9d550c, 0x0001c900, 0x0001ff00,
		/* INST 19: MADH R1.xyz (TR0.xyzw), R0.xxxx, { 1.16, -0.87, 0.53, -1.08 }.xxxx, { 1.16, -0.87, 0.53, -1.08 }.yzww */
		0x04400e82, 0x1c9c0100, 0x00000002, 0x0001f202,
		0x3f9507c8, 0xbf5ee393, 0x3f078fef, 0xbf8a6762,
		/* INST 20: MADH R1.xyz (TR0.xyzw), R0.yyyy, { 0.00, -0.39, 2.02, 0.00 }, R1 */
		0x04400e82, 0x1c9cab00, 0x0001c802, 0x0001c904,
		0x00000000, 0xbec890d6, 0x40011687, 0x00000000,
		/* INST 21: MADH R0.xyz (TR0.xyzw), R0.zzzz, { 1.60, -0.81, 0.00, 0.00 }, R1 + END */
		0x04400e81, 0x1c9d5500, 0x0001c802, 0x0001c904,
		0x3fcc432d, 0xbf501a37, 0x00000000, 0x00000000,
	}
};

nv_shader_t nv30_fp_yv12_bicubic = {
	.card_priv.NV30FP.num_regs = 4,
	.size = (24*4),
	.data = {
		/* INST 0: MOVR R2.xy (TR0.xyzw), attrib.texcoord[0] */
		0x01008604, 0x1c9dc801, 0x0001c800, 0x0001c800,
		/* INST 1: ADDR R0.xy (TR0.xyzw), R2, { 0.50, 0.00, 0.00, 0.00 }.xxxx */
		0x03000600, 0x1c9dc808, 0x00000002, 0x0001c800,
		0x3f000000, 0x00000000, 0x00000000, 0x00000000,
		/* INST 2: TEXR R3.xyz (TR0.xyzw), R0, texture[0] */
		0x17000e06, 0x1c9dc800, 0x0001c800, 0x0001c800,
		/* INST 3: TEXR R0.xyz (TR0.xyzw), R0.yyyy, texture[0] */
		0x17000e00, 0x1c9caa00, 0x0001c800, 0x0001c800,
		/* INST 4: MULR R1.xz (TR0.xyzw), R3.xxyy, { -1.00, 1.00, 0.00, 0.00 }.xxyy */
		0x02000a02, 0x1c9ca00c, 0x0000a002, 0x0001c800,
		0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
		/* INST 5: MULR R1.yw (TR0.xyzw), R0.xxyy, { -1.00, 1.00, 0.00, 0.00 }.xxyy */
		0x02001402, 0x1c9ca000, 0x0000a002, 0x0001c800,
		0xbf800000, 0x3f800000, 0x00000000, 0x00000000,
		/* INST 6: ADDR R2 (TR0.xyzw), R2.xyxy, R1 */
		0x03001e04, 0x1c9c8808, 0x0001c804, 0x0001c800,
		/* INST 7: TEXR R0.x (TR0.xyzw), R2, texture[1] */
		0x17020200, 0x1c9dc808, 0x0001c800, 0x0001c800,
		/* INST 8: TEXR R1.y (TR0.xyzw), R2.xwxw, texture[1] */
		0x17020402, 0x1c9d9808, 0x0001c800, 0x0001c800,
		/* INST 9: TEXR R1.x (TR0.xyzw), R2.zyxy, texture[1] */
		0x17020202, 0x1c9c8c08, 0x0001c800, 0x0001c800,
		/* INST 10: LRPH R0.x (TR0.xyzw), R0.zzzz, R0, R1.yyyy */
		0x1f400280, 0x1c9d5400, 0x0001c800, 0x0000aa04,
		/* INST 11: TEXR R0.y (TR0.xyzw), R2.zwzz, texture[1] */
		0x17020400, 0x1c9d5c08, 0x0001c800, 0x0001c800,
		/* INST 12: LRPH R0.y (TR0.xyzw), R0.zzzz, R1.xxxx, R0 */
		0x1f400480, 0x1c9d5400, 0x00000004, 0x0001c800,
		/* INST 13: LRPH R0.x (TR0.xyzw), R3.zzzz, R0, R0.yyyy */
		0x1f400280, 0x1c9d540c, 0x0001c900, 0x0000ab00,
		/* INST 14: MADH R0.xyz (TR0.xyzw), R0.xxxx, { 1.16, -0.87, 0.53, -1.08 }.xxxx, { 1.16, -0.87, 0.53, -1.08 }.yzww */
		0x04400e80, 0x1c9c0100, 0x00000002, 0x0001f202,
		0x3f9507c8, 0xbf5ee393, 0x3f078fef, 0xbf8a6762,
		/* INST 15: TEXR R1.yz (TR0.xyzw), attrib.texcoord[1], abs(texture[2]) */
		0x1704ac02, 0x1c9dc801, 0x0001c800, 0x0001c800,
		/* INST 16: MADH R0.xyz (TR0.xyzw), R1.yyyy, { 0.00, -0.39, 2.02, 0.00 }, R0 */
		0x04400e80, 0x1c9caa04, 0x0001c802, 0x0001c900,
		0x00000000, 0xbec890d6, 0x40011687, 0x00000000,
		/* INST 17: MADH R0.xyz (TR0.xyzw), R1.zzzz, { 1.60, -0.81, 0.00, 0.00 }, R0 + END */
		0x04400e81, 0x1c9d5404, 0x0001c802, 0x0001c900,
		0x3fcc432d, 0xbf501a37, 0x00000000, 0x00000000,
	}
};

nv_shader_t nv30_fp_yv12_bilinear = {
	.card_priv.NV30FP.num_regs = 2,
	.size = (8*4),
	.data = {
		/* INST 0: TEXR R0.x (TR0.xyzw), attrib.texcoord[0], abs(texture[1]) */
		0x17028200, 0x1c9dc801, 0x0001c800, 0x3fe1c800,
		/* INST 1: MADR R1.xyz (TR0.xyzw), R0.xxxx, { 1.16, -0.87, 0.53, -1.08 }.xxxx, { 1.16, -0.87, 0.53, -1.08 }.yzww */
		0x04000e02, 0x1c9c0000, 0x00000002, 0x0001f202,
		0x3f9507c8, 0xbf5ee393, 0x3f078fef, 0xbf8a6762,
		/* INST 2: TEXR R0.yz (TR0.xyzw), attrib.texcoord[1], abs(texture[2]) */
		0x1704ac80, 0x1c9dc801, 0x0001c800, 0x3fe1c800,
		/* INST 3: MADR R1.xyz (TR0.xyzw), R0.yyyy, { 0.00, -0.39, 2.02, 0.00 }, R1 */
		0x04000e02, 0x1c9cab00, 0x0001c802, 0x0001c804,
		0x00000000, 0xbec890d6, 0x40011687, 0x00000000,
		/* INST 4: MADR R0.xyz (TR0.xyzw), R0.zzzz, { 1.60, -0.81, 0.00, 0.00 }, R1 + END */
		0x04000e81, 0x1c9d5500, 0x0001c802, 0x0001c804,
		0x3fcc432d, 0xbf501a37, 0x00000000, 0x00000000,
	}
};