tgsi_exec.h

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007-2008 Tungsten Graphics, Inc., Cedar Park, Texas.
00004  * All Rights Reserved.
00005  * 
00006  * Permission is hereby granted, free of charge, to any person obtaining a
00007  * copy of this software and associated documentation files (the
00008  * "Software"), to deal in the Software without restriction, including
00009  * without limitation the rights to use, copy, modify, merge, publish,
00010  * distribute, sub license, and/or sell copies of the Software, and to
00011  * permit persons to whom the Software is furnished to do so, subject to
00012  * the following conditions:
00013  * 
00014  * The above copyright notice and this permission notice (including the
00015  * next paragraph) shall be included in all copies or substantial portions
00016  * of the Software.
00017  * 
00018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
00019  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
00020  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
00021  * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
00022  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
00023  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
00024  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00025  * 
00026  **************************************************************************/
00027 
00028 #ifndef TGSI_EXEC_H
00029 #define TGSI_EXEC_H
00030 
00031 #include "pipe/p_compiler.h"
00032 
00033 #if defined __cplusplus
00034 extern "C" {
00035 #endif
00036 
00037 #define MAX_LABELS 1024
00038 
00039 #define NUM_CHANNELS 4  /* R,G,B,A */
00040 #define QUAD_SIZE    4  /* 4 pixel/quad */
00041 
00045 union tgsi_exec_channel
00046 {
00047    float    f[QUAD_SIZE];
00048    int      i[QUAD_SIZE];
00049    unsigned u[QUAD_SIZE];
00050 };
00051 
00055 struct tgsi_exec_vector
00056 {
00057    union tgsi_exec_channel xyzw[NUM_CHANNELS];
00058 };
00059 
00064 struct tgsi_interp_coef
00065 {
00066    float a0[NUM_CHANNELS];      /* in an xyzw layout */
00067    float dadx[NUM_CHANNELS];
00068    float dady[NUM_CHANNELS];
00069 };
00070 
00071 
00072 struct softpipe_tile_cache;  
00078 struct tgsi_sampler
00079 {
00080    const struct pipe_sampler_state *state;
00081    struct pipe_texture *texture;
00083    void (*get_samples)(struct tgsi_sampler *sampler,
00084                        const float s[QUAD_SIZE],
00085                        const float t[QUAD_SIZE],
00086                        const float p[QUAD_SIZE],
00087                        float lodbias,
00088                        float rgba[NUM_CHANNELS][QUAD_SIZE]);
00089    void *pipe; /*XXX temporary*/
00090    struct softpipe_tile_cache *cache;
00091 };
00092 
00096 struct tgsi_exec_labels
00097 {
00098    unsigned labels[MAX_LABELS][2];
00099    unsigned count;
00100 };
00101 
00102 
00103 #define TGSI_EXEC_NUM_TEMPS       128
00104 #define TGSI_EXEC_NUM_TEMP_EXTRAS   6
00105 #define TGSI_EXEC_NUM_IMMEDIATES  256
00106 
00107 /*
00108  * Locations of various utility registers (_I = Index, _C = Channel)
00109  */
00110 #define TGSI_EXEC_TEMP_00000000_I   (TGSI_EXEC_NUM_TEMPS + 0)
00111 #define TGSI_EXEC_TEMP_00000000_C   0
00112 
00113 #define TGSI_EXEC_TEMP_7FFFFFFF_I   (TGSI_EXEC_NUM_TEMPS + 0)
00114 #define TGSI_EXEC_TEMP_7FFFFFFF_C   1
00115 
00116 #define TGSI_EXEC_TEMP_80000000_I   (TGSI_EXEC_NUM_TEMPS + 0)
00117 #define TGSI_EXEC_TEMP_80000000_C   2
00118 
00119 #define TGSI_EXEC_TEMP_FFFFFFFF_I   (TGSI_EXEC_NUM_TEMPS + 0)
00120 #define TGSI_EXEC_TEMP_FFFFFFFF_C   3
00121 
00122 #define TGSI_EXEC_TEMP_ONE_I        (TGSI_EXEC_NUM_TEMPS + 1)
00123 #define TGSI_EXEC_TEMP_ONE_C        0
00124 
00125 #define TGSI_EXEC_TEMP_TWO_I        (TGSI_EXEC_NUM_TEMPS + 1)
00126 #define TGSI_EXEC_TEMP_TWO_C        1
00127 
00128 #define TGSI_EXEC_TEMP_128_I        (TGSI_EXEC_NUM_TEMPS + 1)
00129 #define TGSI_EXEC_TEMP_128_C        2
00130 
00131 #define TGSI_EXEC_TEMP_MINUS_128_I  (TGSI_EXEC_NUM_TEMPS + 1)
00132 #define TGSI_EXEC_TEMP_MINUS_128_C  3
00133 
00134 #define TGSI_EXEC_TEMP_KILMASK_I    (TGSI_EXEC_NUM_TEMPS + 2)
00135 #define TGSI_EXEC_TEMP_KILMASK_C    0
00136 
00137 #define TGSI_EXEC_TEMP_OUTPUT_I     (TGSI_EXEC_NUM_TEMPS + 2)
00138 #define TGSI_EXEC_TEMP_OUTPUT_C     1
00139 
00140 #define TGSI_EXEC_TEMP_PRIMITIVE_I  (TGSI_EXEC_NUM_TEMPS + 2)
00141 #define TGSI_EXEC_TEMP_PRIMITIVE_C  2
00142 
00143 /* NVIDIA condition code (CC) vector
00144  */
00145 #define TGSI_EXEC_CC_GT       0x01
00146 #define TGSI_EXEC_CC_EQ       0x02
00147 #define TGSI_EXEC_CC_LT       0x04
00148 #define TGSI_EXEC_CC_UN       0x08
00149 
00150 #define TGSI_EXEC_CC_X_MASK   0x000000ff
00151 #define TGSI_EXEC_CC_X_SHIFT  0
00152 #define TGSI_EXEC_CC_Y_MASK   0x0000ff00
00153 #define TGSI_EXEC_CC_Y_SHIFT  8
00154 #define TGSI_EXEC_CC_Z_MASK   0x00ff0000
00155 #define TGSI_EXEC_CC_Z_SHIFT  16
00156 #define TGSI_EXEC_CC_W_MASK   0xff000000
00157 #define TGSI_EXEC_CC_W_SHIFT  24
00158 
00159 #define TGSI_EXEC_TEMP_CC_I         (TGSI_EXEC_NUM_TEMPS + 2)
00160 #define TGSI_EXEC_TEMP_CC_C         3
00161 
00162 #define TGSI_EXEC_TEMP_THREE_I      (TGSI_EXEC_NUM_TEMPS + 3)
00163 #define TGSI_EXEC_TEMP_THREE_C      0
00164 
00165 #define TGSI_EXEC_TEMP_HALF_I       (TGSI_EXEC_NUM_TEMPS + 3)
00166 #define TGSI_EXEC_TEMP_HALF_C       1
00167 
00168 /* execution mask, each value is either 0 or ~0 */
00169 #define TGSI_EXEC_MASK_I            (TGSI_EXEC_NUM_TEMPS + 3)
00170 #define TGSI_EXEC_MASK_C            2
00171 
00172 #define TGSI_EXEC_TEMP_R0           (TGSI_EXEC_NUM_TEMPS + 4)
00173 
00174 #define TGSI_EXEC_TEMP_ADDR         (TGSI_EXEC_NUM_TEMPS + 5)
00175 
00176 
00177 #define TGSI_EXEC_MAX_COND_NESTING  20
00178 #define TGSI_EXEC_MAX_LOOP_NESTING  20
00179 #define TGSI_EXEC_MAX_CALL_NESTING  20
00180 
00181 
00183 struct tgsi_call_record
00184 {
00185    uint CondStackTop;
00186    uint LoopStackTop;
00187    uint ContStackTop;
00188    uint ReturnAddr;
00189 };
00190 
00191 
00195 struct tgsi_exec_machine
00196 {
00197    /* Total = program temporaries + internal temporaries
00198     *         + 1 padding to align to 16 bytes
00199     */
00200    struct tgsi_exec_vector       _Temps[TGSI_EXEC_NUM_TEMPS +
00201                                         TGSI_EXEC_NUM_TEMP_EXTRAS + 1];
00202 
00203    /*
00204     * This will point to _Temps after aligning to 16B boundary.
00205     */
00206    struct tgsi_exec_vector       *Temps;
00207    struct tgsi_exec_vector       *Addrs;
00208 
00209    struct tgsi_sampler           *Samplers;
00210 
00211    float                         Imms[TGSI_EXEC_NUM_IMMEDIATES][4];
00212    unsigned                      ImmLimit;
00213    const float                   (*Consts)[4];
00214    struct tgsi_exec_vector       *Inputs;
00215    struct tgsi_exec_vector       *Outputs;
00216    const struct tgsi_token       *Tokens;
00217    unsigned                      Processor;
00218 
00219    /* GEOMETRY processor only. */
00220    unsigned                      *Primitives;
00221 
00222    /* FRAGMENT processor only. */
00223    const struct tgsi_interp_coef *InterpCoefs;
00224    struct tgsi_exec_vector       QuadPos;
00225 
00226    /* Conditional execution masks */
00227    uint CondMask;  
00228    uint LoopMask;  
00229    uint ContMask;  
00230    uint FuncMask;  
00231    uint ExecMask;  
00234    uint CondStack[TGSI_EXEC_MAX_COND_NESTING];
00235    int CondStackTop;
00236 
00238    uint LoopStack[TGSI_EXEC_MAX_LOOP_NESTING];
00239    int LoopStackTop;
00240 
00242    uint LoopLabelStack[TGSI_EXEC_MAX_LOOP_NESTING];
00243    int LoopLabelStackTop;
00244 
00246    struct tgsi_exec_vector LoopCounterStack[TGSI_EXEC_MAX_LOOP_NESTING];
00247    int LoopCounterStackTop;
00248    
00250    uint ContStack[TGSI_EXEC_MAX_LOOP_NESTING];
00251    int ContStackTop;
00252 
00254    uint FuncStack[TGSI_EXEC_MAX_CALL_NESTING];
00255    int FuncStackTop;
00256 
00258    struct tgsi_call_record CallStack[TGSI_EXEC_MAX_CALL_NESTING];
00259    int CallStackTop;
00260 
00261    struct tgsi_full_instruction *Instructions;
00262    uint NumInstructions;
00263 
00264    struct tgsi_full_declaration *Declarations;
00265    uint NumDeclarations;
00266 
00267    struct tgsi_exec_labels Labels;
00268 };
00269 
00270 void
00271 tgsi_exec_machine_init(
00272    struct tgsi_exec_machine *mach );
00273 
00274 
00275 void 
00276 tgsi_exec_machine_bind_shader(
00277    struct tgsi_exec_machine *mach,
00278    const struct tgsi_token *tokens,
00279    uint numSamplers,
00280    struct tgsi_sampler *samplers);
00281 
00282 uint
00283 tgsi_exec_machine_run(
00284    struct tgsi_exec_machine *mach );
00285 
00286 
00287 void
00288 tgsi_exec_machine_free_data(struct tgsi_exec_machine *mach);
00289 
00290 
00291 static INLINE void
00292 tgsi_set_kill_mask(struct tgsi_exec_machine *mach, unsigned mask)
00293 {
00294    mach->Temps[TGSI_EXEC_TEMP_KILMASK_I].xyzw[TGSI_EXEC_TEMP_KILMASK_C].u[0] =
00295       mask;
00296 }
00297 
00298 
00300 static INLINE void
00301 tgsi_set_exec_mask(struct tgsi_exec_machine *mach,
00302                    boolean ch0, boolean ch1, boolean ch2, boolean ch3)
00303 {
00304    int *mask = mach->Temps[TGSI_EXEC_MASK_I].xyzw[TGSI_EXEC_MASK_C].i;
00305    mask[0] = ch0 ? ~0 : 0;
00306    mask[1] = ch1 ? ~0 : 0;
00307    mask[2] = ch2 ? ~0 : 0;
00308    mask[3] = ch3 ? ~0 : 0;
00309 }
00310 
00311 
00312 #if defined __cplusplus
00313 } /* extern "C" */
00314 #endif
00315 
00316 #endif /* TGSI_EXEC_H */

Generated on Tue Sep 29 06:25:15 2009 for Gallium3D by  doxygen 1.5.4