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