new file
[mesa.git] / src / mesa / tnl / t_vb_arbprogram.h
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
4 *
5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file t_arb_program.c
27 * Compile vertex programs to an intermediate representation.
28 * Execute vertex programs over a buffer of vertices.
29 * \author Keith Whitwell, Brian Paul
30 */
31
32
33 #ifndef _T_VB_ARBPROGRAM_H_
34 #define _T_VB_ARBPROGRAM_H_
35
36
37 /* New, internal instructions:
38 */
39 #define RSW (VP_MAX_OPCODE)
40 #define MSK (VP_MAX_OPCODE+1)
41 #define REL (VP_MAX_OPCODE+2)
42
43
44 /* Layout of register file:
45
46 0 -- Scratch (Arg0)
47 1 -- Scratch (Arg1)
48 2 -- Scratch (Result)
49 4 -- Program Temporary 0
50 16 -- Program Temporary 12 (max for NV_VERTEX_PROGRAM)
51 17 -- Output 0
52 31 -- Output 15 (max for NV_VERTEX_PROGRAM) (Last writeable register)
53 32 -- Parameter 0
54 ..
55 127 -- Parameter 63 (max for NV_VERTEX_PROGRAM)
56
57 */
58
59 #define FILE_REG 0
60 #define FILE_LOCAL_PARAM 1
61 #define FILE_ENV_PARAM 2
62 #define FILE_STATE_PARAM 3
63
64
65 #define REG_ARG0 0
66 #define REG_ARG1 1
67 #define REG_ARG2 2
68 #define REG_RES 3
69 #define REG_ADDR 4
70 #define REG_TMP0 5
71 #define REG_TMP11 16
72 #define REG_OUT0 17
73 #define REG_OUT14 31
74 #define REG_IN0 32
75 #define REG_IN15 47
76 #define REG_ID 48 /* 0,0,0,1 */
77 #define REG_MAX 128
78 #define REG_INVALID ~0
79
80 /* ARB_vp instructions are broken down into one or more of the
81 * following micro-instructions, each representable in a 32 bit packed
82 * structure.
83 */
84
85 struct reg {
86 GLuint file:2;
87 GLuint idx:7;
88 };
89
90
91 union instruction {
92 struct {
93 GLuint opcode:6;
94 GLuint dst:5;
95 GLuint file0:2;
96 GLuint idx0:7;
97 GLuint file1:2;
98 GLuint idx1:7;
99 GLuint pad:3;
100 } alu;
101
102 struct {
103 GLuint opcode:6;
104 GLuint dst:5;
105 GLuint file0:2;
106 GLuint idx0:7;
107 GLuint neg:4;
108 GLuint swz:8; /* xyzw only */
109 } rsw;
110
111 struct {
112 GLuint opcode:6;
113 GLuint dst:5;
114 GLuint file:2;
115 GLuint idx:7;
116 GLuint mask:4;
117 GLuint pad:1;
118 } msk;
119
120 GLuint dword;
121 };
122
123 #define RSW_NOOP ((0<<0) | (1<<2) | (2<<4) | (3<<6))
124 #define GET_RSW(swz, idx) (((swz) >> ((idx)*2)) & 0x3)
125
126
127
128 struct compilation {
129 GLuint reg_active;
130 union instruction *csr;
131 struct vertex_buffer *VB; /* for input sizes! */
132 };
133
134 struct input {
135 GLuint idx;
136 GLfloat *data;
137 GLuint stride;
138 GLuint size;
139 };
140
141 struct output {
142 GLuint idx;
143 GLfloat *data;
144 };
145
146 /*--------------------------------------------------------------------------- */
147
148 /*!
149 * Private storage for the vertex program pipeline stage.
150 */
151 struct arb_vp_machine {
152 GLfloat reg[REG_MAX][4]; /* Program temporaries, inputs and outputs */
153 GLfloat (*File[4])[4]; /* All values reference-able from the program. */
154 GLint AddressReg;
155
156 struct input input[16];
157 GLuint nr_inputs;
158
159 struct output output[15];
160 GLuint nr_outputs;
161
162 union instruction store[1024];
163 union instruction *instructions;
164 GLint nr_instructions;
165
166 GLvector4f attribs[VERT_RESULT_MAX]; /**< result vectors. */
167 GLvector4f ndcCoords; /**< normalized device coords */
168 GLubyte *clipmask; /**< clip flags */
169 GLubyte ormask, andmask; /**< for clipping */
170
171 GLuint vtx_nr; /**< loop counter */
172
173 struct vertex_buffer *VB;
174 GLcontext *ctx;
175 };
176
177
178 #endif