gallium: reorganize fragment shader execution, unbreak sse
[mesa.git] / src / mesa / pipe / tgsi / exec / tgsi_exec.h
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * 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
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 #if !defined TGSI_EXEC_H
29 #define TGSI_EXEC_H
30
31 #include "pipe/p_compiler.h"
32
33 #if defined __cplusplus
34 extern "C" {
35 #endif
36
37 #define NUM_CHANNELS 4 /* R,G,B,A */
38 #define QUAD_SIZE 4 /* 4 pixel/quad */
39
40 /**
41 * Registers may be treated as float, signed int or unsigned int.
42 */
43 union tgsi_exec_channel
44 {
45 float f[QUAD_SIZE];
46 int i[QUAD_SIZE];
47 unsigned u[QUAD_SIZE];
48 };
49
50 /**
51 * A vector[RGBA] of channels[4 pixels]
52 */
53 struct tgsi_exec_vector
54 {
55 union tgsi_exec_channel xyzw[NUM_CHANNELS];
56 };
57
58 /**
59 * For fragment programs, information for computing fragment input
60 * values from plane equation of the triangle/line.
61 */
62 struct tgsi_interp_coef
63 {
64 float a0[NUM_CHANNELS]; /* in an xyzw layout */
65 float dadx[NUM_CHANNELS];
66 float dady[NUM_CHANNELS];
67 };
68
69
70 struct softpipe_tile_cache; /**< Opaque to TGSI */
71
72 /**
73 * Information for sampling textures, which must be implemented
74 * by code outside the TGSI executor.
75 */
76 struct tgsi_sampler
77 {
78 const struct pipe_sampler_state *state;
79 struct pipe_texture *texture;
80 /** Get samples for four fragments in a quad */
81 void (*get_samples)(struct tgsi_sampler *sampler,
82 const float s[QUAD_SIZE],
83 const float t[QUAD_SIZE],
84 const float p[QUAD_SIZE],
85 float lodbias,
86 float rgba[NUM_CHANNELS][QUAD_SIZE]);
87 void *pipe; /*XXX temporary*/
88 struct softpipe_tile_cache *cache;
89 };
90
91 /**
92 * For branching/calling subroutines.
93 */
94 struct tgsi_exec_labels
95 {
96 unsigned labels[128][2];
97 unsigned count;
98 };
99
100 /*
101 * Locations of various utility registers (_I = Index, _C = Channel)
102 */
103 #define TGSI_EXEC_TEMP_00000000_I 32
104 #define TGSI_EXEC_TEMP_00000000_C 0
105
106 #define TGSI_EXEC_TEMP_7FFFFFFF_I 32
107 #define TGSI_EXEC_TEMP_7FFFFFFF_C 1
108
109 #define TGSI_EXEC_TEMP_80000000_I 32
110 #define TGSI_EXEC_TEMP_80000000_C 2
111
112 #define TGSI_EXEC_TEMP_FFFFFFFF_I 32
113 #define TGSI_EXEC_TEMP_FFFFFFFF_C 3
114
115 #define TGSI_EXEC_TEMP_ONE_I 33
116 #define TGSI_EXEC_TEMP_ONE_C 0
117
118 #define TGSI_EXEC_TEMP_TWO_I 33
119 #define TGSI_EXEC_TEMP_TWO_C 1
120
121 #define TGSI_EXEC_TEMP_128_I 33
122 #define TGSI_EXEC_TEMP_128_C 2
123
124 #define TGSI_EXEC_TEMP_MINUS_128_I 33
125 #define TGSI_EXEC_TEMP_MINUS_128_C 3
126
127 #define TGSI_EXEC_TEMP_KILMASK_I 34
128 #define TGSI_EXEC_TEMP_KILMASK_C 0
129
130 #define TGSI_EXEC_TEMP_OUTPUT_I 34
131 #define TGSI_EXEC_TEMP_OUTPUT_C 1
132
133 #define TGSI_EXEC_TEMP_PRIMITIVE_I 34
134 #define TGSI_EXEC_TEMP_PRIMITIVE_C 2
135
136 #define TGSI_EXEC_TEMP_R0 35
137
138 #define TGSI_EXEC_NUM_TEMPS (32 + 4)
139 #define TGSI_EXEC_NUM_ADDRS 1
140 #define TGSI_EXEC_NUM_IMMEDIATES 256
141
142 #define TGSI_EXEC_MAX_COND_NESTING 10
143 #define TGSI_EXEC_MAX_LOOP_NESTING 10
144 #define TGSI_EXEC_MAX_CALL_NESTING 10
145
146 /**
147 * Run-time virtual machine state for executing TGSI shader.
148 */
149 struct tgsi_exec_machine
150 {
151 /*
152 * 32 program temporaries
153 * 4 internal temporaries
154 * 1 address
155 * 1 temporary of padding to align to 16 bytes
156 */
157 struct tgsi_exec_vector _Temps[TGSI_EXEC_NUM_TEMPS + TGSI_EXEC_NUM_ADDRS + 1];
158
159 /*
160 * This will point to _Temps after aligning to 16B boundary.
161 */
162 struct tgsi_exec_vector *Temps;
163 struct tgsi_exec_vector *Addrs;
164
165 struct tgsi_sampler *Samplers;
166
167 float Imms[TGSI_EXEC_NUM_IMMEDIATES][4];
168 unsigned ImmLimit;
169 float (*Consts)[4];
170 struct tgsi_exec_vector *Inputs;
171 struct tgsi_exec_vector *Outputs;
172 const struct tgsi_token *Tokens;
173 unsigned Processor;
174
175 /* GEOMETRY processor only. */
176 unsigned *Primitives;
177
178 /* FRAGMENT processor only. */
179 const struct tgsi_interp_coef *InterpCoefs;
180 struct tgsi_exec_vector QuadPos;
181
182 /* Conditional execution masks */
183 uint CondMask; /**< For IF/ELSE/ENDIF */
184 uint LoopMask; /**< For BGNLOOP/ENDLOOP */
185 uint ContMask; /**< For loop CONT statements */
186 uint FuncMask; /**< For function calls */
187 uint ExecMask; /**< = CondMask & LoopMask */
188
189 /** Condition mask stack (for nested conditionals) */
190 uint CondStack[TGSI_EXEC_MAX_COND_NESTING];
191 int CondStackTop;
192
193 /** Loop mask stack (for nested loops) */
194 uint LoopStack[TGSI_EXEC_MAX_LOOP_NESTING];
195 int LoopStackTop;
196
197 /** Loop continue mask stack (see comments in tgsi_exec.c) */
198 uint ContStack[TGSI_EXEC_MAX_LOOP_NESTING];
199 int ContStackTop;
200
201 /** Function execution mask stack (for executing subroutine code) */
202 uint FuncStack[TGSI_EXEC_MAX_CALL_NESTING];
203 int FuncStackTop;
204
205 /** Function call stack for saving/restoring the program counter */
206 uint CallStack[TGSI_EXEC_MAX_CALL_NESTING];
207 int CallStackTop;
208
209 struct tgsi_full_instruction *Instructions;
210 uint NumInstructions;
211
212 struct tgsi_full_declaration *Declarations;
213 uint NumDeclarations;
214
215 struct tgsi_exec_labels Labels;
216 };
217
218 void
219 tgsi_exec_machine_init(
220 struct tgsi_exec_machine *mach );
221
222
223 void
224 tgsi_exec_machine_bind_shader(
225 struct tgsi_exec_machine *mach,
226 const struct tgsi_token *tokens,
227 uint numSamplers,
228 struct tgsi_sampler *samplers);
229
230 uint
231 tgsi_exec_machine_run(
232 struct tgsi_exec_machine *mach );
233
234
235 void
236 tgsi_exec_machine_free_data(struct tgsi_exec_machine *mach);
237
238
239 #if defined __cplusplus
240 } /* extern "C" */
241 #endif
242
243 #endif /* TGSI_EXEC_H */