Tizen 2.0 Release
[profile/ivi/osmesa.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
33 #include "spu_tgsi_exec.h"
34
35 #if defined __cplusplus
36 extern "C" {
37 #endif
38
39 /**
40   * Registers may be treated as float, signed int or unsigned int.
41   */
42 union spu_exec_channel
43 {
44    float    f[QUAD_SIZE];
45    int      i[QUAD_SIZE];
46    unsigned u[QUAD_SIZE];
47    qword    q;
48 };
49
50 /**
51   * A vector[RGBA] of channels[4 pixels]
52   */
53 struct spu_exec_vector
54 {
55    union spu_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 spu_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 spu_sampler
77 {
78    const struct pipe_sampler_state *state;
79    struct pipe_resource *texture;
80    /** Get samples for four fragments in a quad */
81    void (*get_samples)(struct spu_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 /**
93  * Run-time virtual machine state for executing TGSI shader.
94  */
95 struct spu_exec_machine
96 {
97    /*
98     * 32 program temporaries
99     * 4  internal temporaries
100     * 1  address
101     */
102    PIPE_ALIGN_VAR(16)
103    struct spu_exec_vector       Temps[TGSI_EXEC_NUM_TEMPS 
104                                       + TGSI_EXEC_NUM_TEMP_EXTRAS + 1];
105
106    struct spu_exec_vector       *Addrs;
107
108    struct spu_sampler           *Samplers;
109
110    float                         Imms[TGSI_EXEC_NUM_IMMEDIATES][4];
111    unsigned                      ImmLimit;
112    float                         (*Consts)[4];
113    struct spu_exec_vector       *Inputs;
114    struct spu_exec_vector       *Outputs;
115    unsigned                      Processor;
116
117    /* GEOMETRY processor only. */
118    unsigned                      *Primitives;
119
120    /* FRAGMENT processor only. */
121    const struct spu_interp_coef *InterpCoefs;
122    struct spu_exec_vector       QuadPos;
123
124    /* Conditional execution masks */
125    uint CondMask;  /**< For IF/ELSE/ENDIF */
126    uint LoopMask;  /**< For BGNLOOP/ENDLOOP */
127    uint ContMask;  /**< For loop CONT statements */
128    uint FuncMask;  /**< For function calls */
129    uint ExecMask;  /**< = CondMask & LoopMask */
130
131    /** Condition mask stack (for nested conditionals) */
132    uint CondStack[TGSI_EXEC_MAX_COND_NESTING];
133    int CondStackTop;
134
135    /** Loop mask stack (for nested loops) */
136    uint LoopStack[TGSI_EXEC_MAX_LOOP_NESTING];
137    int LoopStackTop;
138
139    /** Loop continue mask stack (see comments in tgsi_exec.c) */
140    uint ContStack[TGSI_EXEC_MAX_LOOP_NESTING];
141    int ContStackTop;
142
143    /** Function execution mask stack (for executing subroutine code) */
144    uint FuncStack[TGSI_EXEC_MAX_CALL_NESTING];
145    int FuncStackTop;
146
147    /** Function call stack for saving/restoring the program counter */
148    uint CallStack[TGSI_EXEC_MAX_CALL_NESTING];
149    int CallStackTop;
150
151    struct tgsi_full_instruction *Instructions;
152    uint NumInstructions;
153
154    struct tgsi_full_declaration *Declarations;
155    uint NumDeclarations;
156 };
157
158
159 extern void
160 spu_exec_machine_init(struct spu_exec_machine *mach,
161                       uint numSamplers,
162                       struct spu_sampler *samplers,
163                       unsigned processor);
164
165 extern uint
166 spu_exec_machine_run( struct spu_exec_machine *mach );
167
168
169 #if defined __cplusplus
170 } /* extern "C" */
171 #endif
172
173 #endif /* SPU_EXEC_H */