i915_fpc.h

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2003 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 
00029 #ifndef I915_FPC_H
00030 #define I915_FPC_H
00031 
00032 
00033 #include "i915_context.h"
00034 #include "i915_reg.h"
00035 
00036 
00037 
00038 #define I915_PROGRAM_SIZE 192
00039 
00040 
00041 
00045 struct i915_fp_compile {
00046    struct i915_fragment_shader *shader;  /* the shader we're compiling */
00047 
00048    boolean used_constants[I915_MAX_CONSTANT];
00049 
00051    uint num_immediates;
00052    uint immediates_map[I915_MAX_CONSTANT];
00053    float immediates[I915_MAX_CONSTANT][4];
00054 
00055    boolean first_instruction;
00056 
00057    uint declarations[I915_PROGRAM_SIZE];
00058    uint program[I915_PROGRAM_SIZE];
00059 
00060    uint *csr;            
00062    uint *decl;           
00064    uint decl_s;          
00065    uint decl_t;          
00067    uint temp_flag;       
00068    uint utemp_flag;      
00070    uint nr_tex_indirect;
00071    uint nr_tex_insn;
00072    uint nr_alu_insn;
00073    uint nr_decl_insn;
00074 
00075    boolean error;      
00076    uint wpos_tex;
00077    uint NumNativeInstructions;
00078    uint NumNativeAluInstructions;
00079    uint NumNativeTexInstructions;
00080    uint NumNativeTexIndirections;
00081 };
00082 
00083 
00084 /* Having zero and one in here makes the definition of swizzle a lot
00085  * easier.
00086  */
00087 #define UREG_TYPE_SHIFT               29
00088 #define UREG_NR_SHIFT                 24
00089 #define UREG_CHANNEL_X_NEGATE_SHIFT   23
00090 #define UREG_CHANNEL_X_SHIFT          20
00091 #define UREG_CHANNEL_Y_NEGATE_SHIFT   19
00092 #define UREG_CHANNEL_Y_SHIFT          16
00093 #define UREG_CHANNEL_Z_NEGATE_SHIFT   15
00094 #define UREG_CHANNEL_Z_SHIFT          12
00095 #define UREG_CHANNEL_W_NEGATE_SHIFT   11
00096 #define UREG_CHANNEL_W_SHIFT          8
00097 #define UREG_CHANNEL_ZERO_NEGATE_MBZ  5
00098 #define UREG_CHANNEL_ZERO_SHIFT       4
00099 #define UREG_CHANNEL_ONE_NEGATE_MBZ   1
00100 #define UREG_CHANNEL_ONE_SHIFT        0
00101 
00102 #define UREG_BAD          0xffffffff    /* not a valid ureg */
00103 
00104 #define X    SRC_X
00105 #define Y    SRC_Y
00106 #define Z    SRC_Z
00107 #define W    SRC_W
00108 #define ZERO SRC_ZERO
00109 #define ONE  SRC_ONE
00110 
00111 /* Construct a ureg:
00112  */
00113 #define UREG( type, nr ) (((type)<< UREG_TYPE_SHIFT) |          \
00114                           ((nr)  << UREG_NR_SHIFT) |            \
00115                           (X     << UREG_CHANNEL_X_SHIFT) |     \
00116                           (Y     << UREG_CHANNEL_Y_SHIFT) |     \
00117                           (Z     << UREG_CHANNEL_Z_SHIFT) |     \
00118                           (W     << UREG_CHANNEL_W_SHIFT) |     \
00119                           (ZERO  << UREG_CHANNEL_ZERO_SHIFT) |  \
00120                           (ONE   << UREG_CHANNEL_ONE_SHIFT))
00121 
00122 #define GET_CHANNEL_SRC( reg, channel ) ((reg<<(channel*4)) & (0xf<<20))
00123 #define CHANNEL_SRC( src, channel ) (src>>(channel*4))
00124 
00125 #define GET_UREG_TYPE(reg) (((reg)>>UREG_TYPE_SHIFT)&REG_TYPE_MASK)
00126 #define GET_UREG_NR(reg)   (((reg)>>UREG_NR_SHIFT)&REG_NR_MASK)
00127 
00128 
00129 
00130 #define UREG_XYZW_CHANNEL_MASK 0x00ffff00
00131 
00132 /* One neat thing about the UREG representation:  
00133  */
00134 static INLINE int
00135 swizzle(int reg, uint x, uint y, uint z, uint w)
00136 {
00137    assert(x <= SRC_ONE);
00138    assert(y <= SRC_ONE);
00139    assert(z <= SRC_ONE);
00140    assert(w <= SRC_ONE);
00141    return ((reg & ~UREG_XYZW_CHANNEL_MASK) |
00142            CHANNEL_SRC(GET_CHANNEL_SRC(reg, x), 0) |
00143            CHANNEL_SRC(GET_CHANNEL_SRC(reg, y), 1) |
00144            CHANNEL_SRC(GET_CHANNEL_SRC(reg, z), 2) |
00145            CHANNEL_SRC(GET_CHANNEL_SRC(reg, w), 3));
00146 }
00147 
00148 
00149 
00150 /***********************************************************************
00151  * Public interface for the compiler
00152  */
00153 extern void
00154 i915_translate_fragment_program( struct i915_context *i915,
00155                                  struct i915_fragment_shader *fs);
00156 
00157 
00158 
00159 extern uint i915_get_temp(struct i915_fp_compile *p);
00160 extern uint i915_get_utemp(struct i915_fp_compile *p);
00161 extern void i915_release_utemps(struct i915_fp_compile *p);
00162 
00163 
00164 extern uint i915_emit_texld(struct i915_fp_compile *p,
00165                               uint dest,
00166                               uint destmask,
00167                               uint sampler, uint coord, uint op);
00168 
00169 extern uint i915_emit_arith(struct i915_fp_compile *p,
00170                               uint op,
00171                               uint dest,
00172                               uint mask,
00173                               uint saturate,
00174                               uint src0, uint src1, uint src2);
00175 
00176 extern uint i915_emit_decl(struct i915_fp_compile *p,
00177                              uint type, uint nr, uint d0_flags);
00178 
00179 
00180 extern uint i915_emit_const1f(struct i915_fp_compile *p, float c0);
00181 
00182 extern uint i915_emit_const2f(struct i915_fp_compile *p,
00183                                 float c0, float c1);
00184 
00185 extern uint i915_emit_const4fv(struct i915_fp_compile *p,
00186                                  const float * c);
00187 
00188 extern uint i915_emit_const4f(struct i915_fp_compile *p,
00189                                 float c0, float c1,
00190                                 float c2, float c3);
00191 
00192 
00193 /*======================================================================
00194  * i915_fpc_debug.c
00195  */
00196 extern void i915_disassemble_program(const uint * program, uint sz);
00197 
00198 
00199 /*======================================================================
00200  * i915_fpc_translate.c
00201  */
00202 
00203 extern void
00204 i915_program_error(struct i915_fp_compile *p, const char *msg, ...);
00205 
00206 
00207 #endif

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