1 /**************************************************************************
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
28 #if !defined TGSI_EXEC_H
31 #include "pipe/p_compiler.h"
33 #if defined __cplusplus
37 #define MAX_LABELS 1024
39 #define NUM_CHANNELS 4 /* R,G,B,A */
40 #define QUAD_SIZE 4 /* 4 pixel/quad */
43 * Registers may be treated as float, signed int or unsigned int.
45 union tgsi_exec_channel
49 unsigned u
[QUAD_SIZE
];
53 * A vector[RGBA] of channels[4 pixels]
55 struct tgsi_exec_vector
57 union tgsi_exec_channel xyzw
[NUM_CHANNELS
];
61 * For fragment programs, information for computing fragment input
62 * values from plane equation of the triangle/line.
64 struct tgsi_interp_coef
66 float a0
[NUM_CHANNELS
]; /* in an xyzw layout */
67 float dadx
[NUM_CHANNELS
];
68 float dady
[NUM_CHANNELS
];
72 struct softpipe_tile_cache
; /**< Opaque to TGSI */
75 * Information for sampling textures, which must be implemented
76 * by code outside the TGSI executor.
80 const struct pipe_sampler_state
*state
;
81 struct pipe_texture
*texture
;
82 /** Get samples for four fragments in a quad */
83 void (*get_samples
)(struct tgsi_sampler
*sampler
,
84 const float s
[QUAD_SIZE
],
85 const float t
[QUAD_SIZE
],
86 const float p
[QUAD_SIZE
],
88 float rgba
[NUM_CHANNELS
][QUAD_SIZE
]);
89 void *pipe
; /*XXX temporary*/
90 struct softpipe_tile_cache
*cache
;
94 * For branching/calling subroutines.
96 struct tgsi_exec_labels
98 unsigned labels
[MAX_LABELS
][2];
103 #define TGSI_EXEC_NUM_TEMPS 128
104 #define TGSI_EXEC_NUM_TEMP_EXTRAS 6
105 #define TGSI_EXEC_NUM_IMMEDIATES 256
108 * Locations of various utility registers (_I = Index, _C = Channel)
110 #define TGSI_EXEC_TEMP_00000000_I (TGSI_EXEC_NUM_TEMPS + 0)
111 #define TGSI_EXEC_TEMP_00000000_C 0
113 #define TGSI_EXEC_TEMP_7FFFFFFF_I (TGSI_EXEC_NUM_TEMPS + 0)
114 #define TGSI_EXEC_TEMP_7FFFFFFF_C 1
116 #define TGSI_EXEC_TEMP_80000000_I (TGSI_EXEC_NUM_TEMPS + 0)
117 #define TGSI_EXEC_TEMP_80000000_C 2
119 #define TGSI_EXEC_TEMP_FFFFFFFF_I (TGSI_EXEC_NUM_TEMPS + 0)
120 #define TGSI_EXEC_TEMP_FFFFFFFF_C 3
122 #define TGSI_EXEC_TEMP_ONE_I (TGSI_EXEC_NUM_TEMPS + 1)
123 #define TGSI_EXEC_TEMP_ONE_C 0
125 #define TGSI_EXEC_TEMP_TWO_I (TGSI_EXEC_NUM_TEMPS + 1)
126 #define TGSI_EXEC_TEMP_TWO_C 1
128 #define TGSI_EXEC_TEMP_128_I (TGSI_EXEC_NUM_TEMPS + 1)
129 #define TGSI_EXEC_TEMP_128_C 2
131 #define TGSI_EXEC_TEMP_MINUS_128_I (TGSI_EXEC_NUM_TEMPS + 1)
132 #define TGSI_EXEC_TEMP_MINUS_128_C 3
134 #define TGSI_EXEC_TEMP_KILMASK_I (TGSI_EXEC_NUM_TEMPS + 2)
135 #define TGSI_EXEC_TEMP_KILMASK_C 0
137 #define TGSI_EXEC_TEMP_OUTPUT_I (TGSI_EXEC_NUM_TEMPS + 2)
138 #define TGSI_EXEC_TEMP_OUTPUT_C 1
140 #define TGSI_EXEC_TEMP_PRIMITIVE_I (TGSI_EXEC_NUM_TEMPS + 2)
141 #define TGSI_EXEC_TEMP_PRIMITIVE_C 2
143 #define TGSI_EXEC_TEMP_THREE_I (TGSI_EXEC_NUM_TEMPS + 2)
144 #define TGSI_EXEC_TEMP_THREE_C 3
146 #define TGSI_EXEC_TEMP_HALF_I (TGSI_EXEC_NUM_TEMPS + 3)
147 #define TGSI_EXEC_TEMP_HALF_C 0
149 #define TGSI_EXEC_TEMP_R0 (TGSI_EXEC_NUM_TEMPS + 4)
151 #define TGSI_EXEC_TEMP_ADDR (TGSI_EXEC_NUM_TEMPS + 5)
154 #define TGSI_EXEC_MAX_COND_NESTING 20
155 #define TGSI_EXEC_MAX_LOOP_NESTING 20
156 #define TGSI_EXEC_MAX_CALL_NESTING 20
159 * Run-time virtual machine state for executing TGSI shader.
161 struct tgsi_exec_machine
163 /* Total = program temporaries + internal temporaries
164 * + 1 padding to align to 16 bytes
166 struct tgsi_exec_vector _Temps
[TGSI_EXEC_NUM_TEMPS
+
167 TGSI_EXEC_NUM_TEMP_EXTRAS
+ 1];
170 * This will point to _Temps after aligning to 16B boundary.
172 struct tgsi_exec_vector
*Temps
;
173 struct tgsi_exec_vector
*Addrs
;
175 struct tgsi_sampler
*Samplers
;
177 float Imms
[TGSI_EXEC_NUM_IMMEDIATES
][4];
179 const float (*Consts
)[4];
180 struct tgsi_exec_vector
*Inputs
;
181 struct tgsi_exec_vector
*Outputs
;
182 const struct tgsi_token
*Tokens
;
185 /* GEOMETRY processor only. */
186 unsigned *Primitives
;
188 /* FRAGMENT processor only. */
189 const struct tgsi_interp_coef
*InterpCoefs
;
190 struct tgsi_exec_vector QuadPos
;
192 /* Conditional execution masks */
193 uint CondMask
; /**< For IF/ELSE/ENDIF */
194 uint LoopMask
; /**< For BGNLOOP/ENDLOOP */
195 uint ContMask
; /**< For loop CONT statements */
196 uint FuncMask
; /**< For function calls */
197 uint ExecMask
; /**< = CondMask & LoopMask */
199 /** Condition mask stack (for nested conditionals) */
200 uint CondStack
[TGSI_EXEC_MAX_COND_NESTING
];
203 /** Loop mask stack (for nested loops) */
204 uint LoopStack
[TGSI_EXEC_MAX_LOOP_NESTING
];
207 /** Loop continue mask stack (see comments in tgsi_exec.c) */
208 uint ContStack
[TGSI_EXEC_MAX_LOOP_NESTING
];
211 /** Function execution mask stack (for executing subroutine code) */
212 uint FuncStack
[TGSI_EXEC_MAX_CALL_NESTING
];
215 /** Function call stack for saving/restoring the program counter */
216 uint CallStack
[TGSI_EXEC_MAX_CALL_NESTING
];
219 struct tgsi_full_instruction
*Instructions
;
220 uint NumInstructions
;
222 struct tgsi_full_declaration
*Declarations
;
223 uint NumDeclarations
;
225 struct tgsi_exec_labels Labels
;
229 tgsi_exec_machine_init(
230 struct tgsi_exec_machine
*mach
);
234 tgsi_exec_machine_bind_shader(
235 struct tgsi_exec_machine
*mach
,
236 const struct tgsi_token
*tokens
,
238 struct tgsi_sampler
*samplers
);
241 tgsi_exec_machine_run(
242 struct tgsi_exec_machine
*mach
);
246 tgsi_exec_machine_free_data(struct tgsi_exec_machine
*mach
);
249 #if defined __cplusplus
253 #endif /* TGSI_EXEC_H */