Correct test for attenuation.
[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 #define FILE_REG 0
44 #define FILE_LOCAL_PARAM 1
45 #define FILE_ENV_PARAM 2
46 #define FILE_STATE_PARAM 3
47
48 #define REG_ARG0 0
49 #define REG_ARG1 1
50 #define REG_ARG2 2
51 #define REG_RES 3
52 #define REG_ADDR 4
53 #define REG_TMP0 5
54 #define REG_TMP11 16
55 #define REG_OUT0 17
56 #define REG_OUT14 31
57 #define REG_IN0 32
58 #define REG_IN31 63
59 #define REG_ID 64 /* 0,0,0,1 */
60 #define REG_ONES 65 /* 1,1,1,1 */
61 #define REG_SWZ 66 /* -1,1,0,0 */
62 #define REG_NEG 67 /* -1,-1,-1,-1 */
63 #define REG_UNDEF 127 /* special case - never used */
64 #define REG_MAX 128
65 #define REG_INVALID ~0
66
67 /* ARB_vp instructions are broken down into one or more of the
68 * following micro-instructions, each representable in a 32 bit packed
69 * structure.
70 */
71 struct reg {
72 GLuint file:2;
73 GLuint idx:7;
74 };
75
76
77 union instruction {
78 struct {
79 GLuint opcode:6;
80 GLuint dst:5;
81 GLuint file0:2;
82 GLuint idx0:7;
83 GLuint file1:2;
84 GLuint idx1:7;
85 GLuint pad:3;
86 } alu;
87
88 struct {
89 GLuint opcode:6;
90 GLuint dst:5;
91 GLuint file0:2;
92 GLuint idx0:7;
93 GLuint neg:4;
94 GLuint swz:8; /* xyzw only */
95 } rsw;
96
97 struct {
98 GLuint opcode:6;
99 GLuint dst:5;
100 GLuint file:2;
101 GLuint idx:7;
102 GLuint mask:4;
103 GLuint pad:1;
104 } msk;
105
106 GLuint dword;
107 };
108
109 #define RSW_NOOP ((0<<0) | (1<<2) | (2<<4) | (3<<6))
110 #define GET_RSW(swz, idx) (((swz) >> ((idx)*2)) & 0x3)
111
112
113 struct input {
114 GLuint idx;
115 GLfloat *data;
116 GLuint stride;
117 GLuint size;
118 };
119
120 struct output {
121 GLuint idx;
122 GLfloat *data;
123 };
124
125
126
127 /*--------------------------------------------------------------------------- */
128
129 /*!
130 * Private storage for the vertex program pipeline stage.
131 */
132 struct arb_vp_machine {
133 GLfloat (*File[4])[4]; /* All values referencable from the program. */
134
135 struct input input[_TNL_ATTRIB_MAX];
136 GLuint nr_inputs;
137
138 struct output output[15];
139 GLuint nr_outputs;
140
141 GLvector4f attribs[VERT_RESULT_MAX]; /**< result vectors. */
142 GLvector4f ndcCoords; /**< normalized device coords */
143 GLubyte *clipmask; /**< clip flags */
144 GLubyte ormask, andmask; /**< for clipping */
145
146 GLuint vtx_nr; /**< loop counter */
147
148 struct vertex_buffer *VB;
149 GLcontext *ctx;
150
151 GLboolean try_codegen;
152 };
153
154 struct tnl_compiled_program {
155 union instruction instructions[1024];
156 GLint nr_instructions;
157 void (*compiled_func)( struct arb_vp_machine * ); /**< codegen'd program */
158 };
159
160 void _tnl_program_string_change( struct vertex_program * );
161 void _tnl_program_destroy( struct vertex_program * );
162
163 void _tnl_disassem_vba_insn( union instruction op );
164
165 GLboolean _tnl_sse_codegen_vertex_program(struct tnl_compiled_program *p);
166
167 #endif