draw_vs_aos.h

Go to the documentation of this file.
00001 /**************************************************************************
00002  * 
00003  * Copyright 2007 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 /* Authors:  Keith Whitwell <keith@tungstengraphics.com>
00029  */
00030 
00031 #ifndef DRAW_VS_AOS_H
00032 #define DRAW_VS_AOS_H
00033 
00034 #include "pipe/p_config.h"
00035 
00036 #ifdef PIPE_ARCH_X86
00037 
00038 struct tgsi_token;
00039 struct x86_function;
00040 
00041 #include "pipe/p_state.h"
00042 #include "rtasm/rtasm_x86sse.h"
00043 
00044 
00045 
00046 
00047 
00048 #define X    0
00049 #define Y    1
00050 #define Z    2
00051 #define W    3
00052 
00053 #define MAX_INPUTS     PIPE_MAX_ATTRIBS
00054 #define MAX_OUTPUTS    PIPE_MAX_SHADER_OUTPUTS
00055 #define MAX_TEMPS      TGSI_EXEC_NUM_TEMPS
00056 #define MAX_CONSTANTS  1024  
00057 #define MAX_IMMEDIATES 1024  
00058 #define MAX_INTERNALS  8     
00060 #define AOS_FILE_INTERNAL TGSI_FILE_COUNT
00061 
00062 #define FPU_RND_NEG    1
00063 #define FPU_RND_NEAREST 2
00064 
00065 struct aos_machine;
00066 typedef void (PIPE_CDECL *lit_func)( struct aos_machine *,
00067                                     float *result,
00068                                     const float *in,
00069                                     unsigned count );
00070 
00071 void PIPE_CDECL aos_do_lit( struct aos_machine *machine,
00072                             float *result,
00073                             const float *in,
00074                             unsigned count );
00075 
00076 struct shine_tab {
00077    float exponent;
00078    float values[258];
00079    unsigned last_used;
00080 };
00081 
00082 struct lit_info {
00083    lit_func func;
00084    struct shine_tab *shine_tab;
00085 };
00086 
00087 #define MAX_SHINE_TAB    4
00088 #define MAX_LIT_INFO     16
00089 
00090 struct aos_buffer {
00091    const void *base_ptr;
00092    unsigned stride;
00093    void *ptr;                   /* updated per vertex */
00094 };
00095 
00096 
00097 
00098 
00099 /* This is the temporary storage used by all the aos_sse vs varients.
00100  * Create one per context and reuse by passing a pointer in at
00101  * vs_varient creation??
00102  */
00103 struct aos_machine {
00104    float input    [MAX_INPUTS    ][4];
00105    float output   [MAX_OUTPUTS   ][4];
00106    float temp     [MAX_TEMPS     ][4];
00107    float internal [MAX_INTERNALS ][4];
00108 
00109    float scale[4];              /* viewport */
00110    float translate[4];          /* viewport */
00111 
00112    float tmp[2][4];             /* scratch space for LIT */
00113 
00114    struct shine_tab shine_tab[MAX_SHINE_TAB];
00115    struct lit_info  lit_info[MAX_LIT_INFO];
00116    unsigned now;
00117    
00118 
00119    ushort fpu_rnd_nearest;
00120    ushort fpu_rnd_neg_inf;
00121    ushort fpu_restore;
00122    ushort fpucntl;              /* one of FPU_* above */
00123 
00124    const float (*immediates)[4];     /* points to shader data */
00125    const float (*constants)[4];      /* points to draw data */
00126 
00127    const struct aos_buffer *buffer; /* points to ? */
00128 };
00129 
00130 
00131 
00132 
00133 struct aos_compilation {
00134    struct x86_function *func;
00135    struct draw_vs_varient_aos_sse *vaos;
00136 
00137    unsigned insn_counter;
00138    unsigned num_immediates;
00139    unsigned count;
00140    unsigned lit_count;
00141 
00142    struct {
00143       unsigned idx:16;
00144       unsigned file:8;
00145       unsigned dirty:8;
00146       unsigned last_used;
00147    } xmm[8];
00148 
00149    unsigned x86_reg[2];                /* one of X86_* */
00150 
00151    boolean input_fetched[PIPE_MAX_ATTRIBS];
00152    unsigned output_last_write[PIPE_MAX_ATTRIBS];
00153 
00154    boolean have_sse2;
00155    boolean error;
00156    short fpucntl;
00157 
00158    /* these are actually known values, but putting them in a struct
00159     * like this is helpful to keep them in sync across the file.
00160     */
00161    struct x86_reg tmp_EAX;
00162    struct x86_reg idx_EBX;     /* either start+i or &elt[i] */
00163    struct x86_reg outbuf_ECX;
00164    struct x86_reg machine_EDX;
00165    struct x86_reg count_ESI;    /* decrements to zero */
00166    struct x86_reg temp_EBP;
00167    struct x86_reg stack_ESP;
00168 };
00169 
00170 struct x86_reg aos_get_xmm_reg( struct aos_compilation *cp );
00171 void aos_release_xmm_reg( struct aos_compilation *cp, unsigned idx );
00172 
00173 void aos_adopt_xmm_reg( struct aos_compilation *cp,
00174                         struct x86_reg reg,
00175                         unsigned file,
00176                         unsigned idx,
00177                         unsigned dirty );
00178 
00179 void aos_spill_all( struct aos_compilation *cp );
00180 
00181 struct x86_reg aos_get_shader_reg( struct aos_compilation *cp, 
00182                                    unsigned file,
00183                                    unsigned idx );
00184 
00185 boolean aos_init_inputs( struct aos_compilation *cp, boolean linear );
00186 boolean aos_fetch_inputs( struct aos_compilation *cp, boolean linear );
00187 boolean aos_incr_inputs( struct aos_compilation *cp, boolean linear );
00188 
00189 boolean aos_emit_outputs( struct aos_compilation *cp );
00190 
00191 
00192 #define IMM_ONES     0              /* 1, 1,1,1 */
00193 #define IMM_SWZ      1              /* 1,-1,0, 0xffffffff */
00194 #define IMM_IDENTITY 2              /* 0, 0,0,1 */
00195 #define IMM_INV_255  3              /* 1/255, 1/255, 1/255, 1/255 */
00196 #define IMM_255      4              /* 255, 255, 255, 255 */
00197 #define IMM_NEGS     5              /* -1,-1,-1,-1 */
00198 #define IMM_RSQ      6              /* -.5,1.5,_,_ */
00199 #define IMM_PSIZE    7              /* not really an immediate - updated each run */
00200 
00201 struct x86_reg aos_get_internal( struct aos_compilation *cp,
00202                                  unsigned imm );
00203 struct x86_reg aos_get_internal_xmm( struct aos_compilation *cp,
00204                                      unsigned imm );
00205 
00206 
00207 #define ERROR(cp, msg)                                                  \
00208 do {                                                                    \
00209    if (0) debug_printf("%s: x86 translation failed: %s\n", __FUNCTION__, msg); \
00210    cp->error = 1;                                                       \
00211 } while (0)
00212 
00213 
00214 #define X86_NULL       0
00215 #define X86_IMMEDIATES 1
00216 #define X86_CONSTANTS  2
00217 #define X86_BUFFERS    3
00218 
00219 struct x86_reg aos_get_x86( struct aos_compilation *cp,
00220                             unsigned which_reg,
00221                             unsigned value );
00222 
00223 
00224 typedef void (PIPE_CDECL *vaos_run_elts_func)( struct aos_machine *,
00225                                                const unsigned *elts,
00226                                                unsigned count,
00227                                                void *output_buffer);
00228 
00229 typedef void (PIPE_CDECL *vaos_run_linear_func)( struct aos_machine *,
00230                                                 unsigned start,
00231                                                 unsigned count,
00232                                                 void *output_buffer);
00233 
00234 
00235 struct draw_vs_varient_aos_sse {
00236    struct draw_vs_varient base;
00237    struct draw_context *draw;
00238 
00239    struct aos_buffer *buffer;
00240    unsigned nr_vb;
00241 
00242    vaos_run_linear_func gen_run_linear;
00243    vaos_run_elts_func gen_run_elts;
00244 
00245 
00246    struct x86_function func[2];
00247 };
00248 
00249 
00250 #endif
00251 
00252 #endif 
00253 

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