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 NUM_CHANNELS 4 /* R,G,B,A */
38 #define QUAD_SIZE 4 /* 4 pixel/quad */
41 * Registers may be treated as float, signed int or unsigned int.
43 union tgsi_exec_channel
47 unsigned u
[QUAD_SIZE
];
51 * A vector[RGBA] of channels[4 pixels]
53 struct tgsi_exec_vector
55 union tgsi_exec_channel xyzw
[NUM_CHANNELS
];
59 * For fragment programs, information for computing fragment input
60 * values from plane equation of the triangle/line.
62 struct tgsi_interp_coef
64 float a0
[NUM_CHANNELS
]; /* in an xyzw layout */
65 float dadx
[NUM_CHANNELS
];
66 float dady
[NUM_CHANNELS
];
70 struct softpipe_tile_cache
; /**< Opaque to TGSI */
73 * Information for sampling textures, which must be implemented
74 * by code outside the TGSI executor.
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
],
86 float rgba
[NUM_CHANNELS
][QUAD_SIZE
]);
87 void *pipe
; /*XXX temporary*/
88 struct softpipe_tile_cache
*cache
;
92 * For branching/calling subroutines.
94 struct tgsi_exec_labels
96 unsigned labels
[128][2];
101 * Locations of various utility registers (_I = Index, _C = Channel)
103 #define TGSI_EXEC_TEMP_00000000_I 32
104 #define TGSI_EXEC_TEMP_00000000_C 0
106 #define TGSI_EXEC_TEMP_7FFFFFFF_I 32
107 #define TGSI_EXEC_TEMP_7FFFFFFF_C 1
109 #define TGSI_EXEC_TEMP_80000000_I 32
110 #define TGSI_EXEC_TEMP_80000000_C 2
112 #define TGSI_EXEC_TEMP_FFFFFFFF_I 32
113 #define TGSI_EXEC_TEMP_FFFFFFFF_C 3
115 #define TGSI_EXEC_TEMP_ONE_I 33
116 #define TGSI_EXEC_TEMP_ONE_C 0
118 #define TGSI_EXEC_TEMP_TWO_I 33
119 #define TGSI_EXEC_TEMP_TWO_C 1
121 #define TGSI_EXEC_TEMP_128_I 33
122 #define TGSI_EXEC_TEMP_128_C 2
124 #define TGSI_EXEC_TEMP_MINUS_128_I 33
125 #define TGSI_EXEC_TEMP_MINUS_128_C 3
127 #define TGSI_EXEC_TEMP_KILMASK_I 34
128 #define TGSI_EXEC_TEMP_KILMASK_C 0
130 #define TGSI_EXEC_TEMP_OUTPUT_I 34
131 #define TGSI_EXEC_TEMP_OUTPUT_C 1
133 #define TGSI_EXEC_TEMP_PRIMITIVE_I 34
134 #define TGSI_EXEC_TEMP_PRIMITIVE_C 2
136 #define TGSI_EXEC_TEMP_R0 35
138 #define TGSI_EXEC_NUM_TEMPS (32 + 4)
139 #define TGSI_EXEC_NUM_ADDRS 1
140 #define TGSI_EXEC_NUM_IMMEDIATES 256
142 #define TGSI_EXEC_MAX_COND_NESTING 10
143 #define TGSI_EXEC_MAX_LOOP_NESTING 10
144 #define TGSI_EXEC_MAX_CALL_NESTING 10
147 * Run-time virtual machine state for executing TGSI shader.
149 struct tgsi_exec_machine
152 * 32 program temporaries
153 * 4 internal temporaries
155 * 1 temporary of padding to align to 16 bytes
157 struct tgsi_exec_vector _Temps
[TGSI_EXEC_NUM_TEMPS
+ TGSI_EXEC_NUM_ADDRS
+ 1];
160 * This will point to _Temps after aligning to 16B boundary.
162 struct tgsi_exec_vector
*Temps
;
163 struct tgsi_exec_vector
*Addrs
;
165 struct tgsi_sampler
*Samplers
;
167 float Imms
[TGSI_EXEC_NUM_IMMEDIATES
][4];
170 struct tgsi_exec_vector
*Inputs
;
171 struct tgsi_exec_vector
*Outputs
;
172 const struct tgsi_token
*Tokens
;
175 /* GEOMETRY processor only. */
176 unsigned *Primitives
;
178 /* FRAGMENT processor only. */
179 const struct tgsi_interp_coef
*InterpCoefs
;
180 struct tgsi_exec_vector QuadPos
;
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 */
189 /** Condition mask stack (for nested conditionals) */
190 uint CondStack
[TGSI_EXEC_MAX_COND_NESTING
];
193 /** Loop mask stack (for nested loops) */
194 uint LoopStack
[TGSI_EXEC_MAX_LOOP_NESTING
];
197 /** Loop continue mask stack (see comments in tgsi_exec.c) */
198 uint ContStack
[TGSI_EXEC_MAX_LOOP_NESTING
];
201 /** Function execution mask stack (for executing subroutine code) */
202 uint FuncStack
[TGSI_EXEC_MAX_CALL_NESTING
];
205 /** Function call stack for saving/restoring the program counter */
206 uint CallStack
[TGSI_EXEC_MAX_CALL_NESTING
];
209 struct tgsi_full_instruction
*Instructions
;
210 uint NumInstructions
;
212 struct tgsi_full_declaration
*Declarations
;
213 uint NumDeclarations
;
215 struct tgsi_exec_labels Labels
;
219 tgsi_exec_machine_init(
220 struct tgsi_exec_machine
*mach
);
224 tgsi_exec_machine_bind_shader(
225 struct tgsi_exec_machine
*mach
,
226 const struct tgsi_token
*tokens
,
228 struct tgsi_sampler
*samplers
);
231 tgsi_exec_machine_run(
232 struct tgsi_exec_machine
*mach
);
236 tgsi_exec_machine_free_data(struct tgsi_exec_machine
*mach
);
239 #if defined __cplusplus
243 #endif /* TGSI_EXEC_H */