Merge remote branch 'origin/7.8'
[mesa.git] / src / gallium / drivers / cell / spu / spu_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 SPU_EXEC_H
29 #define SPU_EXEC_H
30
31 #include "pipe/p_compiler.h"
32 #include "tgsi/tgsi_exec.h"
33
34 #if defined __cplusplus
35 extern "C" {
36 #endif
37
38 /**
39 * Registers may be treated as float, signed int or unsigned int.
40 */
41 union spu_exec_channel
42 {
43 float f[QUAD_SIZE];
44 int i[QUAD_SIZE];
45 unsigned u[QUAD_SIZE];
46 qword q;
47 };
48
49 /**
50 * A vector[RGBA] of channels[4 pixels]
51 */
52 struct spu_exec_vector
53 {
54 union spu_exec_channel xyzw[NUM_CHANNELS];
55 };
56
57 /**
58 * For fragment programs, information for computing fragment input
59 * values from plane equation of the triangle/line.
60 */
61 struct spu_interp_coef
62 {
63 float a0[NUM_CHANNELS]; /* in an xyzw layout */
64 float dadx[NUM_CHANNELS];
65 float dady[NUM_CHANNELS];
66 };
67
68
69 struct softpipe_tile_cache; /**< Opaque to TGSI */
70
71 /**
72 * Information for sampling textures, which must be implemented
73 * by code outside the TGSI executor.
74 */
75 struct spu_sampler
76 {
77 const struct pipe_sampler_state *state;
78 struct pipe_resource *texture;
79 /** Get samples for four fragments in a quad */
80 void (*get_samples)(struct spu_sampler *sampler,
81 const float s[QUAD_SIZE],
82 const float t[QUAD_SIZE],
83 const float p[QUAD_SIZE],
84 float lodbias,
85 float rgba[NUM_CHANNELS][QUAD_SIZE]);
86 void *pipe; /*XXX temporary*/
87 struct softpipe_tile_cache *cache;
88 };
89
90
91 /**
92 * Run-time virtual machine state for executing TGSI shader.
93 */
94 struct spu_exec_machine
95 {
96 /*
97 * 32 program temporaries
98 * 4 internal temporaries
99 * 1 address
100 */
101 PIPE_ALIGN_VAR(16)
102 struct spu_exec_vector Temps[TGSI_EXEC_NUM_TEMPS
103 + TGSI_EXEC_NUM_TEMP_EXTRAS + 1];
104
105 struct spu_exec_vector *Addrs;
106
107 struct spu_sampler *Samplers;
108
109 float Imms[TGSI_EXEC_NUM_IMMEDIATES][4];
110 unsigned ImmLimit;
111 float (*Consts)[4];
112 struct spu_exec_vector *Inputs;
113 struct spu_exec_vector *Outputs;
114 unsigned Processor;
115
116 /* GEOMETRY processor only. */
117 unsigned *Primitives;
118
119 /* FRAGMENT processor only. */
120 const struct spu_interp_coef *InterpCoefs;
121 struct spu_exec_vector QuadPos;
122
123 /* Conditional execution masks */
124 uint CondMask; /**< For IF/ELSE/ENDIF */
125 uint LoopMask; /**< For BGNLOOP/ENDLOOP */
126 uint ContMask; /**< For loop CONT statements */
127 uint FuncMask; /**< For function calls */
128 uint ExecMask; /**< = CondMask & LoopMask */
129
130 /** Condition mask stack (for nested conditionals) */
131 uint CondStack[TGSI_EXEC_MAX_COND_NESTING];
132 int CondStackTop;
133
134 /** Loop mask stack (for nested loops) */
135 uint LoopStack[TGSI_EXEC_MAX_LOOP_NESTING];
136 int LoopStackTop;
137
138 /** Loop continue mask stack (see comments in tgsi_exec.c) */
139 uint ContStack[TGSI_EXEC_MAX_LOOP_NESTING];
140 int ContStackTop;
141
142 /** Function execution mask stack (for executing subroutine code) */
143 uint FuncStack[TGSI_EXEC_MAX_CALL_NESTING];
144 int FuncStackTop;
145
146 /** Function call stack for saving/restoring the program counter */
147 uint CallStack[TGSI_EXEC_MAX_CALL_NESTING];
148 int CallStackTop;
149
150 struct tgsi_full_instruction *Instructions;
151 uint NumInstructions;
152
153 struct tgsi_full_declaration *Declarations;
154 uint NumDeclarations;
155 };
156
157
158 extern void
159 spu_exec_machine_init(struct spu_exec_machine *mach,
160 uint numSamplers,
161 struct spu_sampler *samplers,
162 unsigned processor);
163
164 extern uint
165 spu_exec_machine_run( struct spu_exec_machine *mach );
166
167
168 #if defined __cplusplus
169 } /* extern "C" */
170 #endif
171
172 #endif /* SPU_EXEC_H */