1bf215546Sopenharmony_ci#ifndef __NV40_SHADER_H__
2bf215546Sopenharmony_ci#define __NV40_SHADER_H__
3bf215546Sopenharmony_ci
4bf215546Sopenharmony_ci/* Vertex programs instruction set
5bf215546Sopenharmony_ci *
6bf215546Sopenharmony_ci * The NV40 instruction set is very similar to NV30.  Most fields are in
7bf215546Sopenharmony_ci * a slightly different position in the instruction however.
8bf215546Sopenharmony_ci *
9bf215546Sopenharmony_ci * Merged instructions
10bf215546Sopenharmony_ci *     In some cases it is possible to put two instructions into one opcode
11bf215546Sopenharmony_ci *     slot.  The rules for when this is OK is not entirely clear to me yet.
12bf215546Sopenharmony_ci *
13bf215546Sopenharmony_ci *     There are separate writemasks and dest temp register fields for each
14bf215546Sopenharmony_ci *     grouping of instructions.  There is however only one field with the
15bf215546Sopenharmony_ci *     ID of a result register.  Writing to temp/result regs is selected by
16bf215546Sopenharmony_ci *     setting VEC_RESULT/SCA_RESULT.
17bf215546Sopenharmony_ci *
18bf215546Sopenharmony_ci * Temporary registers
19bf215546Sopenharmony_ci *     The source/dest temp register fields have been extended by 1 bit, to
20bf215546Sopenharmony_ci *     give a total of 32 temporary registers.
21bf215546Sopenharmony_ci *
22bf215546Sopenharmony_ci * Relative Addressing
23bf215546Sopenharmony_ci *     NV40 can use an address register to index into vertex attribute regs.
24bf215546Sopenharmony_ci *     This is done by putting the offset value into INPUT_SRC and setting
25bf215546Sopenharmony_ci *     the INDEX_INPUT flag.
26bf215546Sopenharmony_ci *
27bf215546Sopenharmony_ci * Conditional execution (see NV_vertex_program{2,3} for details)
28bf215546Sopenharmony_ci *     There is a second condition code register on NV40, it's use is enabled
29bf215546Sopenharmony_ci *     by setting the COND_REG_SELECT_1 flag.
30bf215546Sopenharmony_ci *
31bf215546Sopenharmony_ci * Texture lookup
32bf215546Sopenharmony_ci *     TODO
33bf215546Sopenharmony_ci */
34bf215546Sopenharmony_ci
35bf215546Sopenharmony_ci/* ---- OPCODE BITS 127:96 / data DWORD 0 --- */
36bf215546Sopenharmony_ci#define NV40_VP_INST_VEC_RESULT                                        (1 << 30)
37bf215546Sopenharmony_ci/* uncertain.. */
38bf215546Sopenharmony_ci#define NV40_VP_INST_COND_UPDATE_ENABLE                        ((1 << 14)|1<<29)
39bf215546Sopenharmony_ci/* use address reg as index into attribs */
40bf215546Sopenharmony_ci#define NV40_VP_INST_INDEX_INPUT                                       (1 << 27)
41bf215546Sopenharmony_ci#define NV40_VP_INST_SATURATE                                          (1 << 26)
42bf215546Sopenharmony_ci#define NV40_VP_INST_COND_REG_SELECT_1                                 (1 << 25)
43bf215546Sopenharmony_ci#define NV40_VP_INST_ADDR_REG_SELECT_1                                 (1 << 24)
44bf215546Sopenharmony_ci#define NV40_VP_INST_SRC2_ABS                                          (1 << 23)
45bf215546Sopenharmony_ci#define NV40_VP_INST_SRC1_ABS                                          (1 << 22)
46bf215546Sopenharmony_ci#define NV40_VP_INST_SRC0_ABS                                          (1 << 21)
47bf215546Sopenharmony_ci#define NV40_VP_INST_VEC_DEST_TEMP_SHIFT                                      15
48bf215546Sopenharmony_ci#define NV40_VP_INST_VEC_DEST_TEMP_MASK                             (0x3F << 15)
49bf215546Sopenharmony_ci#define NV40_VP_INST_COND_TEST_ENABLE                                  (1 << 13)
50bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SHIFT                                               10
51bf215546Sopenharmony_ci#define NV40_VP_INST_COND_MASK                                       (0x7 << 10)
52bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_X_SHIFT                                          8
53bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_X_MASK                                    (3 << 8)
54bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_Y_SHIFT                                          6
55bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_Y_MASK                                    (3 << 6)
56bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_Z_SHIFT                                          4
57bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_Z_MASK                                    (3 << 4)
58bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_W_SHIFT                                          2
59bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_W_MASK                                    (3 << 2)
60bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_ALL_SHIFT                                        2
61bf215546Sopenharmony_ci#define NV40_VP_INST_COND_SWZ_ALL_MASK                               (0xFF << 2)
62bf215546Sopenharmony_ci#define NV40_VP_INST_ADDR_SWZ_SHIFT                                            0
63bf215546Sopenharmony_ci#define NV40_VP_INST_ADDR_SWZ_MASK                                   (0x03 << 0)
64bf215546Sopenharmony_ci#define NV40_VP_INST0_KNOWN ( \
65bf215546Sopenharmony_ci                NV40_VP_INST_INDEX_INPUT | \
66bf215546Sopenharmony_ci                NV40_VP_INST_COND_REG_SELECT_1 | \
67bf215546Sopenharmony_ci                NV40_VP_INST_ADDR_REG_SELECT_1 | \
68bf215546Sopenharmony_ci                NV40_VP_INST_SRC2_ABS | \
69bf215546Sopenharmony_ci                NV40_VP_INST_SRC1_ABS | \
70bf215546Sopenharmony_ci                NV40_VP_INST_SRC0_ABS | \
71bf215546Sopenharmony_ci                NV40_VP_INST_VEC_DEST_TEMP_MASK | \
72bf215546Sopenharmony_ci                NV40_VP_INST_COND_TEST_ENABLE | \
73bf215546Sopenharmony_ci                NV40_VP_INST_COND_MASK | \
74bf215546Sopenharmony_ci                NV40_VP_INST_COND_SWZ_ALL_MASK | \
75bf215546Sopenharmony_ci                NV40_VP_INST_ADDR_SWZ_MASK)
76bf215546Sopenharmony_ci
77bf215546Sopenharmony_ci/* ---- OPCODE BITS 95:64 / data DWORD 1 --- */
78bf215546Sopenharmony_ci#define NV40_VP_INST_VEC_OPCODE_SHIFT                                         22
79bf215546Sopenharmony_ci#define NV40_VP_INST_VEC_OPCODE_MASK                                (0x1F << 22)
80bf215546Sopenharmony_ci#define NV40_VP_INST_SCA_OPCODE_SHIFT                                         27
81bf215546Sopenharmony_ci#define NV40_VP_INST_SCA_OPCODE_MASK                                (0x1F << 27)
82bf215546Sopenharmony_ci#define NV40_VP_INST_CONST_SRC_SHIFT                                          12
83bf215546Sopenharmony_ci#define NV40_VP_INST_CONST_SRC_MASK                                 (0xFF << 12)
84bf215546Sopenharmony_ci#define NV40_VP_INST_INPUT_SRC_SHIFT                                           8
85bf215546Sopenharmony_ci#define NV40_VP_INST_INPUT_SRC_MASK                                  (0x0F << 8)
86bf215546Sopenharmony_ci#define NV40_VP_INST_SRC0H_SHIFT                                               0
87bf215546Sopenharmony_ci#define NV40_VP_INST_SRC0H_MASK                                      (0xFF << 0)
88bf215546Sopenharmony_ci#define NV40_VP_INST1_KNOWN ( \
89bf215546Sopenharmony_ci                NV40_VP_INST_VEC_OPCODE_MASK | \
90bf215546Sopenharmony_ci                NV40_VP_INST_SCA_OPCODE_MASK | \
91bf215546Sopenharmony_ci                NV40_VP_INST_CONST_SRC_MASK  | \
92bf215546Sopenharmony_ci                NV40_VP_INST_INPUT_SRC_MASK  | \
93bf215546Sopenharmony_ci                NV40_VP_INST_SRC0H_MASK \
94bf215546Sopenharmony_ci                )
95bf215546Sopenharmony_ci
96bf215546Sopenharmony_ci/* ---- OPCODE BITS 63:32 / data DWORD 2 --- */
97bf215546Sopenharmony_ci#define NV40_VP_INST_SRC0L_SHIFT                                              23
98bf215546Sopenharmony_ci#define NV40_VP_INST_SRC0L_MASK                                    (0x1FF << 23)
99bf215546Sopenharmony_ci#define NV40_VP_INST_SRC1_SHIFT                                                6
100bf215546Sopenharmony_ci#define NV40_VP_INST_SRC1_MASK                                    (0x1FFFF << 6)
101bf215546Sopenharmony_ci#define NV40_VP_INST_SRC2H_SHIFT                                               0
102bf215546Sopenharmony_ci#define NV40_VP_INST_SRC2H_MASK                                      (0x3F << 0)
103bf215546Sopenharmony_ci#define NV40_VP_INST_IADDRH_SHIFT                                              0
104bf215546Sopenharmony_ci#define NV40_VP_INST_IADDRH_MASK                                     (0x3F << 0)
105bf215546Sopenharmony_ci
106bf215546Sopenharmony_ci/* ---- OPCODE BITS 31:0 / data DWORD 3 --- */
107bf215546Sopenharmony_ci#define NV40_VP_INST_IADDRL_SHIFT                                             29
108bf215546Sopenharmony_ci#define NV40_VP_INST_IADDRL_MASK                                       (7 << 29)
109bf215546Sopenharmony_ci#define NV40_VP_INST_SRC2L_SHIFT                                              21
110bf215546Sopenharmony_ci#define NV40_VP_INST_SRC2L_MASK                                    (0x7FF << 21)
111bf215546Sopenharmony_ci#define NV40_VP_INST_SCA_WRITEMASK_SHIFT                                      17
112bf215546Sopenharmony_ci#define NV40_VP_INST_SCA_WRITEMASK_MASK                              (0xF << 17)
113bf215546Sopenharmony_ci#    define NV40_VP_INST_SCA_WRITEMASK_X                               (1 << 20)
114bf215546Sopenharmony_ci#    define NV40_VP_INST_SCA_WRITEMASK_Y                               (1 << 19)
115bf215546Sopenharmony_ci#    define NV40_VP_INST_SCA_WRITEMASK_Z                               (1 << 18)
116bf215546Sopenharmony_ci#    define NV40_VP_INST_SCA_WRITEMASK_W                               (1 << 17)
117bf215546Sopenharmony_ci#define NV40_VP_INST_VEC_WRITEMASK_SHIFT                                      13
118bf215546Sopenharmony_ci#define NV40_VP_INST_VEC_WRITEMASK_MASK                              (0xF << 13)
119bf215546Sopenharmony_ci#    define NV40_VP_INST_VEC_WRITEMASK_X                               (1 << 16)
120bf215546Sopenharmony_ci#    define NV40_VP_INST_VEC_WRITEMASK_Y                               (1 << 15)
121bf215546Sopenharmony_ci#    define NV40_VP_INST_VEC_WRITEMASK_Z                               (1 << 14)
122bf215546Sopenharmony_ci#    define NV40_VP_INST_VEC_WRITEMASK_W                               (1 << 13)
123bf215546Sopenharmony_ci#define NV40_VP_INST_SCA_RESULT                                        (1 << 12)
124bf215546Sopenharmony_ci#define NV40_VP_INST_SCA_DEST_TEMP_SHIFT                                       7
125bf215546Sopenharmony_ci#define NV40_VP_INST_SCA_DEST_TEMP_MASK                              (0x1F << 7)
126bf215546Sopenharmony_ci#define NV40_VP_INST_DEST_SHIFT                                                2
127bf215546Sopenharmony_ci#define NV40_VP_INST_DEST_MASK                                         (31 << 2)
128bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_POS                                              0
129bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_COL0                                             1
130bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_COL1                                             2
131bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_BFC0                                             3
132bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_BFC1                                             4
133bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_FOGC                                             5
134bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_PSZ                                              6
135bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_TC0                                              7
136bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_TC(n)                                        (7+n)
137bf215546Sopenharmony_ci#    define NV40_VP_INST_DEST_TEMP                                          0x1F
138bf215546Sopenharmony_ci#define NV40_VP_INST_INDEX_CONST                                        (1 << 1)
139bf215546Sopenharmony_ci#define NV40_VP_INST3_KNOWN ( \
140bf215546Sopenharmony_ci                NV40_VP_INST_SRC2L_MASK |\
141bf215546Sopenharmony_ci                NV40_VP_INST_SCA_WRITEMASK_MASK |\
142bf215546Sopenharmony_ci                NV40_VP_INST_VEC_WRITEMASK_MASK |\
143bf215546Sopenharmony_ci                NV40_VP_INST_SCA_DEST_TEMP_MASK |\
144bf215546Sopenharmony_ci                NV40_VP_INST_DEST_MASK |\
145bf215546Sopenharmony_ci                NV40_VP_INST_INDEX_CONST)
146bf215546Sopenharmony_ci
147bf215546Sopenharmony_ci/* Useful to split the source selection regs into their pieces */
148bf215546Sopenharmony_ci#define NV40_VP_SRC0_HIGH_SHIFT                                                9
149bf215546Sopenharmony_ci#define NV40_VP_SRC0_HIGH_MASK                                        0x0001FE00
150bf215546Sopenharmony_ci#define NV40_VP_SRC0_LOW_MASK                                         0x000001FF
151bf215546Sopenharmony_ci#define NV40_VP_SRC2_HIGH_SHIFT                                               11
152bf215546Sopenharmony_ci#define NV40_VP_SRC2_HIGH_MASK                                        0x0001F800
153bf215546Sopenharmony_ci#define NV40_VP_SRC2_LOW_MASK                                         0x000007FF
154bf215546Sopenharmony_ci
155bf215546Sopenharmony_ci/* Source selection - these are the bits you fill NV40_VP_INST_SRCn with */
156bf215546Sopenharmony_ci#define NV40_VP_SRC_NEGATE                                             (1 << 16)
157bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_X_SHIFT                                               14
158bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_X_MASK                                         (3 << 14)
159bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_Y_SHIFT                                               12
160bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_Y_MASK                                         (3 << 12)
161bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_Z_SHIFT                                               10
162bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_Z_MASK                                         (3 << 10)
163bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_W_SHIFT                                                8
164bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_W_MASK                                          (3 << 8)
165bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_ALL_SHIFT                                              8
166bf215546Sopenharmony_ci#define NV40_VP_SRC_SWZ_ALL_MASK                                     (0xFF << 8)
167bf215546Sopenharmony_ci#define NV40_VP_SRC_TEMP_SRC_SHIFT                                             2
168bf215546Sopenharmony_ci#define NV40_VP_SRC_TEMP_SRC_MASK                                    (0x1F << 2)
169bf215546Sopenharmony_ci#define NV40_VP_SRC_REG_TYPE_SHIFT                                             0
170bf215546Sopenharmony_ci#define NV40_VP_SRC_REG_TYPE_MASK                                       (3 << 0)
171bf215546Sopenharmony_ci#    define NV40_VP_SRC_REG_TYPE_UNK0                                          0
172bf215546Sopenharmony_ci#    define NV40_VP_SRC_REG_TYPE_TEMP                                          1
173bf215546Sopenharmony_ci#    define NV40_VP_SRC_REG_TYPE_INPUT                                         2
174bf215546Sopenharmony_ci#    define NV40_VP_SRC_REG_TYPE_CONST                                         3
175bf215546Sopenharmony_ci
176bf215546Sopenharmony_ci#include "nv30/nvfx_shader.h"
177bf215546Sopenharmony_ci
178bf215546Sopenharmony_ci#endif
179