sp_fs_exec.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_parse.h"
00041 
00042 struct sp_exec_fragment_shader {
00043    struct sp_fragment_shader base;
00044 };
00045 
00046 
00047 
00053 void
00054 sp_setup_pos_vector(const struct tgsi_interp_coef *coef,
00055                     float x, float y,
00056                     struct tgsi_exec_vector *quadpos)
00057 {
00058    uint chan;
00059    /* do X */
00060    quadpos->xyzw[0].f[0] = x;
00061    quadpos->xyzw[0].f[1] = x + 1;
00062    quadpos->xyzw[0].f[2] = x;
00063    quadpos->xyzw[0].f[3] = x + 1;
00064 
00065    /* do Y */
00066    quadpos->xyzw[1].f[0] = y;
00067    quadpos->xyzw[1].f[1] = y;
00068    quadpos->xyzw[1].f[2] = y + 1;
00069    quadpos->xyzw[1].f[3] = y + 1;
00070 
00071    /* do Z and W for all fragments in the quad */
00072    for (chan = 2; chan < 4; chan++) {
00073       const float dadx = coef->dadx[chan];
00074       const float dady = coef->dady[chan];
00075       const float a0 = coef->a0[chan] + dadx * x + dady * y;
00076       quadpos->xyzw[chan].f[0] = a0;
00077       quadpos->xyzw[chan].f[1] = a0 + dadx;
00078       quadpos->xyzw[chan].f[2] = a0 + dady;
00079       quadpos->xyzw[chan].f[3] = a0 + dadx + dady;
00080    }
00081 }
00082 
00083 
00084 static void
00085 exec_prepare( const struct sp_fragment_shader *base,
00086               struct tgsi_exec_machine *machine,
00087               struct tgsi_sampler *samplers )
00088 {
00089    tgsi_exec_machine_bind_shader( machine,
00090                                   base->shader.tokens,
00091                                   PIPE_MAX_SAMPLERS,
00092                                   samplers );
00093 }
00094 
00095 
00096 
00097 
00098 /* TODO: hide the machine struct in here somewhere, remove from this
00099  * interface:
00100  */
00101 static unsigned 
00102 exec_run( const struct sp_fragment_shader *base,
00103           struct tgsi_exec_machine *machine,
00104           struct quad_header *quad )
00105 {
00106 
00107    /* Compute X, Y, Z, W vals for this quad */
00108    sp_setup_pos_vector(quad->posCoef, 
00109                        (float)quad->input.x0, (float)quad->input.y0, 
00110                        &machine->QuadPos);
00111    
00112    return tgsi_exec_machine_run( machine );
00113 }
00114 
00115 
00116 
00117 static void 
00118 exec_delete( struct sp_fragment_shader *base )
00119 {
00120    FREE((void *) base->shader.tokens);
00121    FREE(base);
00122 }
00123 
00124 
00125 
00126 
00127 
00128 struct sp_fragment_shader *
00129 softpipe_create_fs_exec(struct softpipe_context *softpipe,
00130                         const struct pipe_shader_state *templ)
00131 {
00132    struct sp_exec_fragment_shader *shader;
00133 
00134    /* Decide whether we'll be codegenerating this shader and if so do
00135     * that now.
00136     */
00137 
00138    shader = CALLOC_STRUCT(sp_exec_fragment_shader);
00139    if (!shader)
00140       return NULL;
00141 
00142    /* we need to keep a local copy of the tokens */
00143    shader->base.shader.tokens = tgsi_dup_tokens(templ->tokens);
00144    shader->base.prepare = exec_prepare;
00145    shader->base.run = exec_run;
00146    shader->base.delete = exec_delete;
00147 
00148    return &shader->base;
00149 }
00150 

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