Remove GetMSC DriverAPI function.
[mesa.git] / src / mesa / drivers / dri / nouveau / nv30_shader.h
1 #ifndef __NV30_SHADER_H__
2 #define __NV30_SHADER_H__
3
4 /* Vertex programs instruction set
5 *
6 * 128bit opcodes, split into 4 32-bit ones for ease of use.
7 *
8 * Non-native instructions
9 * ABS - MOV + NV40_VP_INST0_DEST_ABS
10 * POW - EX2 + MUL + LG2
11 * SUB - ADD, second source negated
12 * SWZ - MOV
13 * XPD -
14 *
15 * Register access
16 * - Only one INPUT can be accessed per-instruction (move extras into TEMPs)
17 * - Only one CONST can be accessed per-instruction (move extras into TEMPs)
18 *
19 * Relative Addressing
20 * According to the value returned for MAX_PROGRAM_NATIVE_ADDRESS_REGISTERS_ARB
21 * there are only two address registers available. The destination in the ARL
22 * instruction is set to TEMP <n> (The temp isn't actually written).
23 *
24 * When using vanilla ARB_v_p, the proprietary driver will squish both the available
25 * ADDRESS regs into the first hardware reg in the X and Y components.
26 *
27 * To use an address reg as an index into consts, the CONST_SRC is set to
28 * (const_base + offset) and INDEX_CONST is set.
29 *
30 * To access the second address reg use ADDR_REG_SELECT_1. A particular component
31 * of the address regs is selected with ADDR_SWZ.
32 *
33 * Only one address register can be accessed per instruction.
34 *
35 * Conditional execution (see NV_vertex_program{2,3} for details)
36 * Conditional execution of an instruction is enabled by setting COND_TEST_ENABLE, and
37 * selecting the condition which will allow the test to pass with COND_{FL,LT,...}.
38 * It is possible to swizzle the values in the condition register, which allows for
39 * testing against an individual component.
40 *
41 * Branching
42 * The BRA/CAL instructions seem to follow a slightly different opcode layout. The
43 * destination instruction ID (IADDR) overlaps a source field. Instruction ID's seem to
44 * be numbered based on the UPLOAD_FROM_ID FIFO command, and is incremented automatically
45 * on each UPLOAD_INST FIFO command.
46 *
47 * Conditional branching is achieved by using the condition tests described above.
48 * There doesn't appear to be dedicated looping instructions, but this can be done
49 * using a temp reg + conditional branching.
50 *
51 * Subroutines may be uploaded before the main program itself, but the first executed
52 * instruction is determined by the PROGRAM_START_ID FIFO command.
53 *
54 */
55
56 /* DWORD 0 */
57 #define NV30_VP_INST_ADDR_REG_SELECT_1 (1 << 24)
58 #define NV30_VP_INST_SRC2_ABS (1 << 23) /* guess */
59 #define NV30_VP_INST_SRC1_ABS (1 << 22) /* guess */
60 #define NV30_VP_INST_SRC0_ABS (1 << 21) /* guess */
61 #define NV30_VP_INST_OUT_RESULT (1 << 20)
62 #define NV30_VP_INST_DEST_TEMP_ID_SHIFT 16
63 #define NV30_VP_INST_DEST_TEMP_ID_MASK (0x0F << 16)
64 #define NV30_VP_INST_COND_UPDATE_ENABLE (1<<15)
65 #define NV30_VP_INST_COND_TEST_ENABLE (1<<14)
66 #define NV30_VP_INST_COND_SHIFT 11
67 #define NV30_VP_INST_COND_MASK (0x07 << 11)
68 # define NV30_VP_INST_COND_FL 0 /* guess */
69 # define NV30_VP_INST_COND_LT 1
70 # define NV30_VP_INST_COND_EQ 2
71 # define NV30_VP_INST_COND_LE 3
72 # define NV30_VP_INST_COND_GT 4
73 # define NV30_VP_INST_COND_NE 5
74 # define NV30_VP_INST_COND_GE 6
75 # define NV30_VP_INST_COND_TR 7 /* guess */
76 #define NV30_VP_INST_COND_SWZ_X_SHIFT 9
77 #define NV30_VP_INST_COND_SWZ_X_MASK (0x03 << 9)
78 #define NV30_VP_INST_COND_SWZ_Y_SHIFT 7
79 #define NV30_VP_INST_COND_SWZ_Y_MASK (0x03 << 7)
80 #define NV30_VP_INST_COND_SWZ_Z_SHIFT 5
81 #define NV30_VP_INST_COND_SWZ_Z_MASK (0x03 << 5)
82 #define NV30_VP_INST_COND_SWZ_W_SHIFT 3
83 #define NV30_VP_INST_COND_SWZ_W_MASK (0x03 << 3)
84 #define NV30_VP_INST_COND_SWZ_ALL_SHIFT 3
85 #define NV30_VP_INST_COND_SWZ_ALL_MASK (0xFF << 3)
86 #define NV30_VP_INST_ADDR_SWZ_SHIFT 1
87 #define NV30_VP_INST_ADDR_SWZ_MASK (0x03 << 1)
88 #define NV30_VP_INST_SCA_OPCODEH_SHIFT 0
89 #define NV30_VP_INST_SCA_OPCODEH_MASK (0x01 << 0)
90
91 /* DWORD 1 */
92 #define NV30_VP_INST_SCA_OPCODEL_SHIFT 28
93 #define NV30_VP_INST_SCA_OPCODEL_MASK (0x0F << 28)
94 # define NV30_VP_INST_OP_NOP 0x00
95 # define NV30_VP_INST_OP_RCP 0x02
96 # define NV30_VP_INST_OP_RCC 0x03
97 # define NV30_VP_INST_OP_RSQ 0x04
98 # define NV30_VP_INST_OP_EXP 0x05
99 # define NV30_VP_INST_OP_LOG 0x06
100 # define NV30_VP_INST_OP_LIT 0x07
101 # define NV30_VP_INST_OP_BRA 0x09
102 # define NV30_VP_INST_OP_CAL 0x0B
103 # define NV30_VP_INST_OP_RET 0x0C
104 # define NV30_VP_INST_OP_LG2 0x0D
105 # define NV30_VP_INST_OP_EX2 0x0E
106 # define NV30_VP_INST_OP_SIN 0x0F
107 # define NV30_VP_INST_OP_COS 0x10
108 #define NV30_VP_INST_VEC_OPCODE_SHIFT 23
109 #define NV30_VP_INST_VEC_OPCODE_MASK (0x1F << 23)
110 # define NV30_VP_INST_OP_NOPV 0x00
111 # define NV30_VP_INST_OP_MOV 0x01
112 # define NV30_VP_INST_OP_MUL 0x02
113 # define NV30_VP_INST_OP_ADD 0x03
114 # define NV30_VP_INST_OP_MAD 0x04
115 # define NV30_VP_INST_OP_DP3 0x05
116 # define NV30_VP_INST_OP_DP4 0x07
117 # define NV30_VP_INST_OP_DPH 0x06
118 # define NV30_VP_INST_OP_DST 0x08
119 # define NV30_VP_INST_OP_MIN 0x09
120 # define NV30_VP_INST_OP_MAX 0x0A
121 # define NV30_VP_INST_OP_SLT 0x0B
122 # define NV30_VP_INST_OP_SGE 0x0C
123 # define NV30_VP_INST_OP_ARL 0x0D
124 # define NV30_VP_INST_OP_FRC 0x0E
125 # define NV30_VP_INST_OP_FLR 0x0F
126 # define NV30_VP_INST_OP_SEQ 0x10
127 # define NV30_VP_INST_OP_SFL 0x11
128 # define NV30_VP_INST_OP_SGT 0x12
129 # define NV30_VP_INST_OP_SLE 0x13
130 # define NV30_VP_INST_OP_SNE 0x14
131 # define NV30_VP_INST_OP_STR 0x15
132 # define NV30_VP_INST_OP_SSG 0x16
133 # define NV30_VP_INST_OP_ARR 0x17
134 # define NV30_VP_INST_OP_ARA 0x18
135 #define NV30_VP_INST_CONST_SRC_SHIFT 14
136 #define NV30_VP_INST_CONST_SRC_MASK (0xFF << 14)
137 #define NV30_VP_INST_INPUT_SRC_SHIFT 9 /*NV20*/
138 #define NV30_VP_INST_INPUT_SRC_MASK (0x0F << 9) /*NV20*/
139 # define NV30_VP_INST_IN_POS 0 /* These seem to match the bindings specified in */
140 # define NV30_VP_INST_IN_WEIGHT 1 /* the ARB_v_p spec (2.14.3.1) */
141 # define NV30_VP_INST_IN_NORMAL 2
142 # define NV30_VP_INST_IN_COL0 3 /* Should probably confirm them all though */
143 # define NV30_VP_INST_IN_COL1 4
144 # define NV30_VP_INST_IN_FOGC 5
145 # define NV30_VP_INST_IN_TC0 8
146 # define NV30_VP_INST_IN_TC(n) (8+n)
147 #define NV30_VP_INST_SRC0H_SHIFT 0 /*NV20*/
148 #define NV30_VP_INST_SRC0H_MASK (0x1FF << 0) /*NV20*/
149
150 /* DWORD 2 */
151 #define NV30_VP_INST_SRC0L_SHIFT 26 /*NV20*/
152 #define NV30_VP_INST_SRC0L_MASK (0x3F <<26) /*NV20*/
153 #define NV30_VP_INST_SRC1_SHIFT 11 /*NV20*/
154 #define NV30_VP_INST_SRC1_MASK (0x7FFF<<11) /*NV20*/
155 #define NV30_VP_INST_SRC2H_SHIFT 0 /*NV20*/
156 #define NV30_VP_INST_SRC2H_MASK (0x7FF << 0) /*NV20*/
157 #define NV30_VP_INST_IADDR_SHIFT 2
158 #define NV30_VP_INST_IADDR_MASK (0xFF << 2) /* guess */
159
160 /* DWORD 3 */
161 #define NV30_VP_INST_SRC2L_SHIFT 28 /*NV20*/
162 #define NV30_VP_INST_SRC2L_MASK (0x0F <<28) /*NV20*/
163 #define NV30_VP_INST_STEMP_WRITEMASK_SHIFT 24
164 #define NV30_VP_INST_STEMP_WRITEMASK_MASK (0x0F << 24)
165 #define NV30_VP_INST_VTEMP_WRITEMASK_SHIFT 20
166 #define NV30_VP_INST_VTEMP_WRITEMASK_MASK (0x0F << 20)
167 #define NV30_VP_INST_SDEST_WRITEMASK_SHIFT 16
168 #define NV30_VP_INST_SDEST_WRITEMASK_MASK (0x0F << 16)
169 #define NV30_VP_INST_VDEST_WRITEMASK_SHIFT 12 /*NV20*/
170 #define NV30_VP_INST_VDEST_WRITEMASK_MASK (0x0F << 12) /*NV20*/
171 #define NV30_VP_INST_DEST_ID_SHIFT 2
172 #define NV30_VP_INST_DEST_ID_MASK (0x0F << 2)
173 # define NV30_VP_INST_DEST_POS 0
174 # define NV30_VP_INST_DEST_COL0 3
175 # define NV30_VP_INST_DEST_COL1 4
176 # define NV30_VP_INST_DEST_TC(n) (8+n)
177
178 /* Source-register definition - matches NV20 exactly */
179 #define NV30_VP_SRC_REG_NEGATE (1<<14)
180 #define NV30_VP_SRC_REG_SWZ_X_SHIFT 12
181 #define NV30_VP_SRC_REG_SWZ_X_MASK (0x03 <<12)
182 #define NV30_VP_SRC_REG_SWZ_Y_SHIFT 10
183 #define NV30_VP_SRC_REG_SWZ_Y_MASK (0x03 <<10)
184 #define NV30_VP_SRC_REG_SWZ_Z_SHIFT 8
185 #define NV30_VP_SRC_REG_SWZ_Z_MASK (0x03 << 8)
186 #define NV30_VP_SRC_REG_SWZ_W_SHIFT 6
187 #define NV30_VP_SRC_REG_SWZ_W_MASK (0x03 << 6)
188 #define NV30_VP_SRC_REG_SWZ_ALL_SHIFT 6
189 #define NV30_VP_SRC_REG_SWZ_ALL_MASK (0xFF << 6)
190 #define NV30_VP_SRC_REG_TEMP_ID_SHIFT 2
191 #define NV30_VP_SRC_REG_TEMP_ID_MASK (0x0F << 0)
192 #define NV30_VP_SRC_REG_TYPE_SHIFT 0
193 #define NV30_VP_SRC_REG_TYPE_MASK (0x03 << 0)
194 #define NV30_VP_SRC_REG_TYPE_TEMP 1
195 #define NV30_VP_SRC_REG_TYPE_INPUT 2
196 #define NV30_VP_SRC_REG_TYPE_CONST 3 /* guess */
197
198 /*
199 * Each fragment program opcode appears to be comprised of 4 32-bit values.
200 *
201 * 0 - Opcode, output reg/mask, ATTRIB source
202 * 1 - Source 0
203 * 2 - Source 1
204 * 3 - Source 2
205 *
206 * There appears to be no special difference between result regs and temp regs.
207 * result.color == R0.xyzw
208 * result.depth == R1.z
209 * When the fragprog contains instructions to write depth, NV30_TCL_PRIMITIVE_3D_UNK1D78=0
210 * otherwise it is set to 1.
211 *
212 * Constants are inserted directly after the instruction that uses them.
213 *
214 * It appears that it's not possible to use two input registers in one
215 * instruction as the input sourcing is done in the instruction dword
216 * and not the source selection dwords. As such instructions such as:
217 *
218 * ADD result.color, fragment.color, fragment.texcoord[0];
219 *
220 * must be split into two MOV's and then an ADD (nvidia does this) but
221 * I'm not sure why it's not just one MOV and then source the second input
222 * in the ADD instruction..
223 *
224 * Negation of the full source is done with NV30_FP_REG_NEGATE, arbitrary
225 * negation requires multiplication with a const.
226 *
227 * Arbitrary swizzling is supported with the exception of SWIZZLE_ZERO/SWIZZLE_ONE
228 * The temp/result regs appear to be initialised to (0.0, 0.0, 0.0, 0.0) as SWIZZLE_ZERO
229 * is implemented simply by not writing to the relevant components of the destination.
230 *
231 * Conditional execution
232 * TODO
233 *
234 * Non-native instructions:
235 * LIT
236 * LRP - MAD+MAD
237 * SUB - ADD, negate second source
238 * RSQ - LG2 + EX2
239 * POW - LG2 + MUL + EX2
240 * SCS - COS + SIN
241 * XPD
242 */
243
244 //== Opcode / Destination selection ==
245 #define NV30_FP_OP_PROGRAM_END (1 << 0)
246 #define NV30_FP_OP_OUT_REG_SHIFT 1
247 #define NV30_FP_OP_OUT_REG_MASK (31 << 1) /* uncertain */
248 /* Needs to be set when writing outputs to get expected result.. */
249 #define NV30_FP_OP_UNK0_7 (1 << 7)
250 #define NV30_FP_OP_COND_WRITE_ENABLE (1 << 8)
251 #define NV30_FP_OP_OUTMASK_SHIFT 9
252 #define NV30_FP_OP_OUTMASK_MASK (0xF << 9)
253 # define NV30_FP_OP_OUT_X (1<<9)
254 # define NV30_FP_OP_OUT_Y (1<<10)
255 # define NV30_FP_OP_OUT_Z (1<<11)
256 # define NV30_FP_OP_OUT_W (1<<12)
257 /* Uncertain about these, especially the input_src values.. it's possible that
258 * they can be dynamically changed.
259 */
260 #define NV30_FP_OP_INPUT_SRC_SHIFT 13
261 #define NV30_FP_OP_INPUT_SRC_MASK (15 << 13)
262 # define NV30_FP_OP_INPUT_SRC_POSITION 0x0
263 # define NV30_FP_OP_INPUT_SRC_COL0 0x1
264 # define NV30_FP_OP_INPUT_SRC_COL1 0x2
265 # define NV30_FP_OP_INPUT_SRC_FOGC 0x3
266 # define NV30_FP_OP_INPUT_SRC_TC0 0x4
267 # define NV30_FP_OP_INPUT_SRC_TC(n) (0x4 + n)
268 #define NV30_FP_OP_TEX_UNIT_SHIFT 17
269 #define NV30_FP_OP_TEX_UNIT_MASK (0xF << 17) /* guess */
270 #define NV30_FP_OP_PRECISION_SHIFT 22
271 #define NV30_FP_OP_PRECISION_MASK (3 << 22)
272 # define NV30_FP_PRECISION_FP32 0
273 # define NV30_FP_PRECISION_FP16 1
274 # define NV30_FP_PRECISION_FX12 2
275 #define NV30_FP_OP_OPCODE_SHIFT 24
276 #define NV30_FP_OP_OPCODE_MASK (0x3F << 24)
277 # define NV30_FP_OP_OPCODE_NOP 0x00
278 # define NV30_FP_OP_OPCODE_MOV 0x01
279 # define NV30_FP_OP_OPCODE_MUL 0x02
280 # define NV30_FP_OP_OPCODE_ADD 0x03
281 # define NV30_FP_OP_OPCODE_MAD 0x04
282 # define NV30_FP_OP_OPCODE_DP3 0x05
283 # define NV30_FP_OP_OPCODE_DP4 0x06
284 # define NV30_FP_OP_OPCODE_DST 0x07
285 # define NV30_FP_OP_OPCODE_MIN 0x08
286 # define NV30_FP_OP_OPCODE_MAX 0x09
287 # define NV30_FP_OP_OPCODE_SLT 0x0A
288 # define NV30_FP_OP_OPCODE_SGE 0x0B
289 # define NV30_FP_OP_OPCODE_SLE 0x0C
290 # define NV30_FP_OP_OPCODE_SGT 0x0D
291 # define NV30_FP_OP_OPCODE_SNE 0x0E
292 # define NV30_FP_OP_OPCODE_SEQ 0x0F
293 # define NV30_FP_OP_OPCODE_FRC 0x10
294 # define NV30_FP_OP_OPCODE_FLR 0x11
295 # define NV30_FP_OP_OPCODE_KIL 0x12
296 # define NV30_FP_OP_OPCODE_PK4B 0x13
297 # define NV30_FP_OP_OPCODE_UP4B 0x14
298 # define NV30_FP_OP_OPCODE_DDX 0x15 /* can only write XY */
299 # define NV30_FP_OP_OPCODE_DDY 0x16 /* can only write XY */
300 # define NV30_FP_OP_OPCODE_TEX 0x17
301 # define NV30_FP_OP_OPCODE_TXP 0x18
302 # define NV30_FP_OP_OPCODE_TXD 0x19
303 # define NV30_FP_OP_OPCODE_RCP 0x1A
304 # define NV30_FP_OP_OPCODE_RSQ 0x1B
305 # define NV30_FP_OP_OPCODE_EX2 0x1C
306 # define NV30_FP_OP_OPCODE_LG2 0x1D
307 # define NV30_FP_OP_OPCODE_LIT 0x1E
308 # define NV30_FP_OP_OPCODE_LRP 0x1F
309 # define NV30_FP_OP_OPCODE_COS 0x22
310 # define NV30_FP_OP_OPCODE_SIN 0x23
311 # define NV30_FP_OP_OPCODE_PK2H 0x24
312 # define NV30_FP_OP_OPCODE_UP2H 0x25
313 # define NV30_FP_OP_OPCODE_POW 0x26
314 # define NV30_FP_OP_OPCODE_PK4UB 0x27
315 # define NV30_FP_OP_OPCODE_UP4UB 0x28
316 # define NV30_FP_OP_OPCODE_PK2US 0x29
317 # define NV30_FP_OP_OPCODE_UP2US 0x2A
318 # define NV30_FP_OP_OPCODE_DP2A 0x2E
319 # define NV30_FP_OP_OPCODE_TXB 0x31
320 # define NV30_FP_OP_OPCODE_RFL 0x36
321 #define NV30_FP_OP_OUT_SAT (1 << 31)
322
323 /* high order bits of SRC0 */
324 #define NV30_FP_OP_OUT_ABS (1 << 29)
325 #define NV30_FP_OP_COND_SWZ_W_SHIFT 27
326 #define NV30_FP_OP_COND_SWZ_W_MASK (3 << 27)
327 #define NV30_FP_OP_COND_SWZ_Z_SHIFT 25
328 #define NV30_FP_OP_COND_SWZ_Z_MASK (3 << 25)
329 #define NV30_FP_OP_COND_SWZ_Y_SHIFT 23
330 #define NV30_FP_OP_COND_SWZ_Y_MASK (3 << 23)
331 #define NV30_FP_OP_COND_SWZ_X_SHIFT 21
332 #define NV30_FP_OP_COND_SWZ_X_MASK (3 << 21)
333 #define NV30_FP_OP_COND_SWZ_ALL_SHIFT 21
334 #define NV30_FP_OP_COND_SWZ_ALL_MASK (0xFF << 21)
335 #define NV30_FP_OP_COND_SHIFT 18
336 #define NV30_FP_OP_COND_MASK (0x07 << 18)
337 # define NV30_FP_OP_COND_FL 0
338 # define NV30_FP_OP_COND_LT 1
339 # define NV30_FP_OP_COND_EQ 2
340 # define NV30_FP_OP_COND_LE 3
341 # define NV30_FP_OP_COND_GT 4
342 # define NV30_FP_OP_COND_NE 5
343 # define NV30_FP_OP_COND_GE 6
344 # define NV30_FP_OP_COND_TR 7
345
346 /* high order bits of SRC1 */
347 #define NV30_FP_OP_SRC_SCALE_SHIFT 28
348 #define NV30_FP_OP_SRC_SCALE_MASK (3 << 28)
349
350 /* high order bits of SRC2 */
351 #define NV30_FP_OP_INDEX_INPUT (1 << 30)
352
353 //== Register selection ==
354 #define NV30_FP_REG_ALL_MASK (0x1FFFF<<0)
355 #define NV30_FP_REG_TYPE_SHIFT 0
356 #define NV30_FP_REG_TYPE_MASK (3 << 0)
357 # define NV30_FP_REG_TYPE_TEMP 0
358 # define NV30_FP_REG_TYPE_INPUT 1
359 # define NV30_FP_REG_TYPE_CONST 2
360 #define NV30_FP_REG_SRC_SHIFT 2 /* uncertain */
361 #define NV30_FP_REG_SRC_MASK (31 << 2)
362 #define NV30_FP_REG_UNK_0 (1 << 8)
363 #define NV30_FP_REG_SWZ_ALL_SHIFT 9
364 #define NV30_FP_REG_SWZ_ALL_MASK (255 << 9)
365 #define NV30_FP_REG_SWZ_X_SHIFT 9
366 #define NV30_FP_REG_SWZ_X_MASK (3 << 9)
367 #define NV30_FP_REG_SWZ_Y_SHIFT 11
368 #define NV30_FP_REG_SWZ_Y_MASK (3 << 11)
369 #define NV30_FP_REG_SWZ_Z_SHIFT 13
370 #define NV30_FP_REG_SWZ_Z_MASK (3 << 13)
371 #define NV30_FP_REG_SWZ_W_SHIFT 15
372 #define NV30_FP_REG_SWZ_W_MASK (3 << 15)
373 # define NV30_FP_SWIZZLE_X 0
374 # define NV30_FP_SWIZZLE_Y 1
375 # define NV30_FP_SWIZZLE_Z 2
376 # define NV30_FP_SWIZZLE_W 3
377 #define NV30_FP_REG_NEGATE (1 << 17)
378
379 #endif