xref: /aosp_15_r20/external/mesa3d/src/mesa/program/prog_instruction.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Mesa 3-D graphics library
3  *
4  * Copyright (C) 1999-2008  Brian Paul   All Rights Reserved.
5  *
6  * Permission is hereby granted, free of charge, to any person obtaining a
7  * copy of this software and associated documentation files (the "Software"),
8  * to deal in the Software without restriction, including without limitation
9  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10  * and/or sell copies of the Software, and to permit persons to whom the
11  * Software is furnished to do so, subject to the following conditions:
12  *
13  * The above copyright notice and this permission notice shall be included
14  * in all copies or substantial portions of the Software.
15  *
16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
19  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22  * OTHER DEALINGS IN THE SOFTWARE.
23  */
24 
25 
26 /**
27  * \file prog_instruction.h
28  *
29  * Vertex/fragment program instruction datatypes and constants.
30  *
31  * \author Brian Paul
32  * \author Keith Whitwell
33  * \author Ian Romanick <[email protected]>
34  */
35 
36 
37 #ifndef PROG_INSTRUCTION_H
38 #define PROG_INSTRUCTION_H
39 
40 
41 #include "util/glheader.h"
42 
43 
44 /**
45  * Swizzle indexes.
46  * Do not change!
47  */
48 /*@{*/
49 #define SWIZZLE_X    0
50 #define SWIZZLE_Y    1
51 #define SWIZZLE_Z    2
52 #define SWIZZLE_W    3
53 #define SWIZZLE_ZERO 4   /**< For SWZ instruction only */
54 #define SWIZZLE_ONE  5   /**< For SWZ instruction only */
55 #define SWIZZLE_NIL  7   /**< used during shader code gen (undefined value) */
56 /*@}*/
57 
58 #define MAKE_SWIZZLE4(a,b,c,d) (((a)<<0) | ((b)<<3) | ((c)<<6) | ((d)<<9))
59 #define SWIZZLE_NOOP           MAKE_SWIZZLE4(0,1,2,3)
60 #define GET_SWZ(swz, idx)      (((swz) >> ((idx)*3)) & 0x7)
61 #define GET_BIT(msk, idx)      (((msk) >> (idx)) & 0x1)
62 /** Determine if swz contains SWIZZLE_ZERO/ONE/NIL for any components. */
63 #define HAS_EXTENDED_SWIZZLE(swz) (swz & 0x924)
64 
65 #define SWIZZLE_XYZW MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_Y, SWIZZLE_Z, SWIZZLE_W)
66 #define SWIZZLE_XXXX MAKE_SWIZZLE4(SWIZZLE_X, SWIZZLE_X, SWIZZLE_X, SWIZZLE_X)
67 #define SWIZZLE_YYYY MAKE_SWIZZLE4(SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y, SWIZZLE_Y)
68 #define SWIZZLE_ZZZZ MAKE_SWIZZLE4(SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z, SWIZZLE_Z)
69 #define SWIZZLE_WWWW MAKE_SWIZZLE4(SWIZZLE_W, SWIZZLE_W, SWIZZLE_W, SWIZZLE_W)
70 
71 /**
72  * Per-component negation masks
73  */
74 /*@{*/
75 #define NEGATE_X    0x1
76 #define NEGATE_Y    0x2
77 #define NEGATE_Z    0x4
78 #define NEGATE_W    0x8
79 #define NEGATE_XYZ  0x7
80 #define NEGATE_XYZW 0xf
81 #define NEGATE_NONE 0x0
82 /*@}*/
83 
84 
85 /**
86  * Program instruction opcodes for vertex, fragment and geometry programs.
87  */
88 enum prog_opcode {
89                      /* ARB_vp   ARB_fp   NV_vp   NV_fp     GLSL */
90                      /*------------------------------------------*/
91    OPCODE_NOP = 0,   /*                                      X   */
92    OPCODE_ABS,       /*   X        X       1.1               X   */
93    OPCODE_ADD,       /*   X        X       X       X         X   */
94    OPCODE_ARL,       /*   X                X                 X   */
95    OPCODE_CMP,       /*            X                         X   */
96    OPCODE_COS,       /*            X       2       X         X   */
97    OPCODE_DDX,       /*                            X         X   */
98    OPCODE_DDY,       /*                            X         X   */
99    OPCODE_DP2,       /*                            2         X   */
100    OPCODE_DP3,       /*   X        X       X       X         X   */
101    OPCODE_DP4,       /*   X        X       X       X         X   */
102    OPCODE_DPH,       /*   X        X       1.1                   */
103    OPCODE_DST,       /*   X        X       X       X             */
104    OPCODE_END,       /*   X        X       X       X        opt  */
105    OPCODE_EX2,       /*   X        X       2       X         X   */
106    OPCODE_EXP,       /*   X                X                     */
107    OPCODE_FLR,       /*   X        X       2       X         X   */
108    OPCODE_FRC,       /*   X        X       2       X         X   */
109    OPCODE_KIL,       /*            X                         X   */
110    OPCODE_LG2,       /*   X        X       2       X         X   */
111    OPCODE_LIT,       /*   X        X       X       X             */
112    OPCODE_LOG,       /*   X                X                     */
113    OPCODE_LRP,       /*            X               X             */
114    OPCODE_MAD,       /*   X        X       X       X         X   */
115    OPCODE_MAX,       /*   X        X       X       X         X   */
116    OPCODE_MIN,       /*   X        X       X       X         X   */
117    OPCODE_MOV,       /*   X        X       X       X         X   */
118    OPCODE_MUL,       /*   X        X       X       X         X   */
119    OPCODE_POW,       /*   X        X               X         X   */
120    OPCODE_RCP,       /*   X        X       X       X         X   */
121    OPCODE_RSQ,       /*   X        X       X       X         X   */
122    OPCODE_SCS,       /*            X                         X   */
123    OPCODE_SGE,       /*   X        X       X       X         X   */
124    OPCODE_SIN,       /*            X       2       X         X   */
125    OPCODE_SLT,       /*   X        X       X       X         X   */
126    OPCODE_SSG,       /*                    2                 X   */
127    OPCODE_SUB,       /*   X        X       1.1     X         X   */
128    OPCODE_SWZ,       /*   X        X                         X   */
129    OPCODE_TEX,       /*            X       3       X         X   */
130    OPCODE_TXB,       /*            X       3                 X   */
131    OPCODE_TXD,       /*                            X         X   */
132    OPCODE_TXL,       /*                    3       2         X   */
133    OPCODE_TXP,       /*            X                         X   */
134    OPCODE_XPD,       /*   X        X                             */
135    MAX_OPCODE
136 };
137 
138 
139 /**
140  * Number of bits for the src/dst register Index field.
141  * This limits the size of temp/uniform register files.
142  */
143 #define INST_INDEX_BITS 12
144 
145 
146 /**
147  * Instruction source register.
148  */
149 struct prog_src_register
150 {
151    GLuint File:4;	/**< One of the PROGRAM_* register file values. */
152    GLint Index:(INST_INDEX_BITS+1); /**< Extra bit here for sign bit.
153                                      * May be negative for relative addressing.
154                                      */
155    GLuint Swizzle:12;
156    GLuint RelAddr:1;
157 
158    /**
159     * Negation.
160     * This will either be NEGATE_NONE or NEGATE_XYZW, except for the SWZ
161     * instruction which allows per-component negation.
162     */
163    GLuint Negate:4;
164 };
165 
166 
167 /**
168  * Instruction destination register.
169  */
170 struct prog_dst_register
171 {
172    GLuint File:4;      /**< One of the PROGRAM_* register file values */
173    GLuint Index:INST_INDEX_BITS;  /**< Unsigned, never negative */
174    GLuint WriteMask:4;
175    GLuint RelAddr:1;
176 };
177 
178 
179 /**
180  * Vertex/fragment program instruction.
181  */
182 struct prog_instruction
183 {
184    enum prog_opcode Opcode;
185    struct prog_src_register SrcReg[3];
186    struct prog_dst_register DstReg;
187 
188    /**
189     * Saturate each value of the vectored result to the range [0,1].
190     *
191     * \since
192     * ARB_fragment_program
193     */
194    GLuint Saturate:1;
195 
196    /**
197     * \name Extra fields for TEX, TXB, TXD, TXL, TXP instructions.
198     */
199    /*@{*/
200    /** Source texture unit. */
201    GLuint TexSrcUnit:5;
202 
203    /** Source texture target, one of TEXTURE_{1D,2D,3D,CUBE,RECT}_INDEX */
204    GLuint TexSrcTarget:4;
205 
206    /** True if tex instruction should do shadow comparison */
207    GLuint TexShadow:1;
208    /*@}*/
209 };
210 
211 
212 #ifdef __cplusplus
213 extern "C" {
214 #endif
215 
216 struct gl_program;
217 
218 extern void
219 _mesa_init_instructions(struct prog_instruction *inst, GLuint count);
220 
221 extern GLuint
222 _mesa_num_inst_src_regs(enum prog_opcode opcode);
223 
224 extern GLuint
225 _mesa_num_inst_dst_regs(enum prog_opcode opcode);
226 
227 extern const char *
228 _mesa_opcode_string(enum prog_opcode opcode);
229 
230 
231 #ifdef __cplusplus
232 } /* extern "C" */
233 #endif
234 
235 #endif /* PROG_INSTRUCTION_H */
236