Fixes for bugs that were nailed down when compairing against software vertex shading.
[mesa.git] / src / mesa / drivers / dri / r300 / vertex_shader.h
1 #ifndef __VERTEX_SHADER_H__
2 #define __VERTEX_SHADER_H__
3
4 #include "r300_reg.h"
5
6 typedef struct {
7 CARD32 op;
8 CARD32 src1;
9 CARD32 src2;
10 CARD32 src3;
11 } VERTEX_SHADER_INSTRUCTION;
12
13 #define VSF_FLAG_X 1
14 #define VSF_FLAG_Y 2
15 #define VSF_FLAG_Z 4
16 #define VSF_FLAG_W 8
17 #define VSF_FLAG_XYZ (VSF_FLAG_X | VSF_FLAG_Y | VSF_FLAG_Z)
18 #define VSF_FLAG_ALL 0xf
19 #define VSF_FLAG_NONE 0
20
21 #define VSF_OUT_CLASS_TMP 0
22 #define VSF_OUT_CLASS_RESULT 2
23
24
25 /* first CARD32 of an instruction */
26
27 /* possible operations:
28 DOT, MUL, ADD, MAD, FRC, MAX, MIN, SGE, SLT, EXP, LOG, LIT, POW, RCP, RSQ, EX2,
29 LG2, MAD_2 */
30
31 #define MAKE_VSF_OP(op, out_reg_index, out_reg_fields, class) \
32 ((op) \
33 | ((out_reg_index) << R300_VPI_OUT_REG_INDEX_SHIFT) \
34 | ((out_reg_fields) << 20) \
35 | ( (class) << 8 ) )
36
37 #define EASY_VSF_OP(op, out_reg_index, out_reg_fields, class) \
38 MAKE_VSF_OP(R300_VPI_OUT_OP_##op, out_reg_index, VSF_FLAG_##out_reg_fields, VSF_OUT_CLASS_##class) \
39
40 /* according to Nikolai, the subsequent 3 CARD32 are sources, use same define for each */
41
42 #define VSF_IN_CLASS_TMP 0
43 #define VSF_IN_CLASS_ATTR 1
44 #define VSF_IN_CLASS_PARAM 2
45 #define VSF_IN_CLASS_NONE 9
46
47 #define VSF_IN_COMPONENT_X 0
48 #define VSF_IN_COMPONENT_Y 1
49 #define VSF_IN_COMPONENT_Z 2
50 #define VSF_IN_COMPONENT_W 3
51 #define VSF_IN_COMPONENT_ZERO 4
52 #define VSF_IN_COMPONENT_ONE 5
53
54 #define MAKE_VSF_SOURCE(in_reg_index, comp_x, comp_y, comp_z, comp_w, class, negate) \
55 ( ((in_reg_index)<<R300_VPI_IN_REG_INDEX_SHIFT) \
56 | ((comp_x)<<R300_VPI_IN_X_SHIFT) \
57 | ((comp_y)<<R300_VPI_IN_Y_SHIFT) \
58 | ((comp_z)<<R300_VPI_IN_Z_SHIFT) \
59 | ((comp_w)<<R300_VPI_IN_W_SHIFT) \
60 | ((negate)<<25) | ((class)))
61
62 #define EASY_VSF_SOURCE(in_reg_index, comp_x, comp_y, comp_z, comp_w, class, negate) \
63 MAKE_VSF_SOURCE(in_reg_index, \
64 VSF_IN_COMPONENT_##comp_x, \
65 VSF_IN_COMPONENT_##comp_y, \
66 VSF_IN_COMPONENT_##comp_z, \
67 VSF_IN_COMPONENT_##comp_w, \
68 VSF_IN_CLASS_##class, VSF_FLAG_##negate)
69
70 /* special sources: */
71
72 /* (1.0,1.0,1.0,1.0) vector (ATTR, plain ) */
73 #define VSF_ATTR_UNITY(reg) EASY_VSF_SOURCE(reg, ONE, ONE, ONE, ONE, ATTR, NONE)
74 #define VSF_UNITY(reg) EASY_VSF_SOURCE(reg, ONE, ONE, ONE, ONE, NONE, NONE)
75
76 /* contents of unmodified register */
77 #define VSF_REG(reg) EASY_VSF_SOURCE(reg, X, Y, Z, W, ATTR, NONE)
78
79 /* contents of unmodified parameter */
80 #define VSF_PARAM(reg) EASY_VSF_SOURCE(reg, X, Y, Z, W, PARAM, NONE)
81
82 /* contents of unmodified temporary register */
83 #define VSF_TMP(reg) EASY_VSF_SOURCE(reg, X, Y, Z, W, TMP, NONE)
84
85 /* components of ATTR register */
86 #define VSF_ATTR_X(reg) EASY_VSF_SOURCE(reg, X, X, X, X, ATTR, NONE)
87 #define VSF_ATTR_Y(reg) EASY_VSF_SOURCE(reg, Y, Y, Y, Y, ATTR, NONE)
88 #define VSF_ATTR_Z(reg) EASY_VSF_SOURCE(reg, Z, Z, Z, Z, ATTR, NONE)
89 #define VSF_ATTR_W(reg) EASY_VSF_SOURCE(reg, W, W, W, W, ATTR, NONE)
90
91 #endif