sp_fs_sse.c

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 
00029 #include "sp_context.h"
00030 #include "sp_state.h"
00031 #include "sp_fs.h"
00032 #include "sp_headers.h"
00033 
00034 
00035 #include "pipe/p_state.h"
00036 #include "pipe/p_defines.h"
00037 #include "util/u_memory.h"
00038 #include "pipe/p_inlines.h"
00039 #include "tgsi/tgsi_exec.h"
00040 #include "tgsi/tgsi_sse2.h"
00041 
00042 
00043 #ifdef PIPE_ARCH_X86
00044 
00045 #include "rtasm/rtasm_x86sse.h"
00046 
00047 /* Surely this should be defined somewhere in a tgsi header:
00048  */
00049 typedef void (PIPE_CDECL *codegen_function)(
00050    const struct tgsi_exec_vector *input,
00051    struct tgsi_exec_vector *output,
00052    const float (*constant)[4],
00053    struct tgsi_exec_vector *temporary,
00054    const struct tgsi_interp_coef *coef,
00055    float (*immediates)[4]
00056    //, const struct tgsi_exec_vector *quadPos
00057  );
00058 
00059 
00060 struct sp_sse_fragment_shader {
00061    struct sp_fragment_shader base;
00062    struct x86_function             sse2_program;
00063    codegen_function func;
00064    float immediates[TGSI_EXEC_NUM_IMMEDIATES][4];
00065 };
00066 
00067 
00068 
00069 static void
00070 fs_sse_prepare( const struct sp_fragment_shader *base,
00071                 struct tgsi_exec_machine *machine,
00072                 struct tgsi_sampler *samplers )
00073 {
00074 }
00075 
00076 
00077 /* TODO: codegenerate the whole run function, skip this wrapper.
00078  * TODO: break dependency on tgsi_exec_machine struct
00079  * TODO: push Position calculation into the generated shader
00080  * TODO: process >1 quad at a time
00081  */
00082 static unsigned 
00083 fs_sse_run( const struct sp_fragment_shader *base,
00084             struct tgsi_exec_machine *machine,
00085             struct quad_header *quad )
00086 {
00087    struct sp_sse_fragment_shader *shader = (struct sp_sse_fragment_shader *) base;
00088 
00089    /* Compute X, Y, Z, W vals for this quad -- place in temp[0] for now */
00090    sp_setup_pos_vector(quad->posCoef, 
00091                        (float)quad->input.x0, (float)quad->input.y0, 
00092                        machine->Temps);
00093 
00094    /* init kill mask */
00095    tgsi_set_kill_mask(machine, 0x0);
00096    tgsi_set_exec_mask(machine, 1, 1, 1, 1);
00097 
00098    shader->func( machine->Inputs,
00099                  machine->Outputs,
00100                  machine->Consts,
00101                  machine->Temps,
00102                  machine->InterpCoefs,
00103                  shader->immediates
00104                  //      , &machine->QuadPos
00105       );
00106 
00107    return ~(machine->Temps[TGSI_EXEC_TEMP_KILMASK_I].xyzw[TGSI_EXEC_TEMP_KILMASK_C].u[0]);
00108 }
00109 
00110 
00111 static void 
00112 fs_sse_delete( struct sp_fragment_shader *base )
00113 {
00114    struct sp_sse_fragment_shader *shader = (struct sp_sse_fragment_shader *) base;
00115 
00116    x86_release_func( &shader->sse2_program );
00117    FREE(shader);
00118 }
00119 
00120 
00121 struct sp_fragment_shader *
00122 softpipe_create_fs_sse(struct softpipe_context *softpipe,
00123                        const struct pipe_shader_state *templ)
00124 {
00125    struct sp_sse_fragment_shader *shader;
00126 
00127    if (!softpipe->use_sse)
00128       return NULL;
00129 
00130    shader = CALLOC_STRUCT(sp_sse_fragment_shader);
00131    if (!shader)
00132       return NULL;
00133 
00134    x86_init_func( &shader->sse2_program );
00135    
00136    if (!tgsi_emit_sse2( templ->tokens, &shader->sse2_program,
00137                         shader->immediates, FALSE )) {
00138       FREE(shader);
00139       return NULL;
00140    }
00141 
00142    shader->func = (codegen_function) x86_get_func( &shader->sse2_program );
00143    if (!shader->func) {
00144       x86_release_func( &shader->sse2_program );
00145       FREE(shader);
00146       return NULL;
00147    }
00148 
00149    shader->base.shader = *templ;
00150    shader->base.prepare = fs_sse_prepare;
00151    shader->base.run = fs_sse_run;
00152    shader->base.delete = fs_sse_delete;
00153 
00154    return &shader->base;
00155 }
00156 
00157 
00158 #else
00159 
00160 /* Maybe put this varient in the header file.
00161  */
00162 struct sp_fragment_shader *
00163 softpipe_create_fs_sse(struct softpipe_context *softpipe,
00164                        const struct pipe_shader_state *templ)
00165 {
00166    return NULL;
00167 }
00168 
00169 #endif

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