sp_state_derived.c

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 #include "util/u_math.h"
00029 #include "util/u_memory.h"
00030 #include "pipe/p_shader_tokens.h"
00031 #include "draw/draw_context.h"
00032 #include "draw/draw_vertex.h"
00033 #include "draw/draw_private.h"
00034 #include "sp_context.h"
00035 #include "sp_state.h"
00036 
00037 
00043 static void
00044 invalidate_vertex_layout(struct softpipe_context *softpipe)
00045 {
00046    softpipe->vertex_info.num_attribs =  0;
00047 }
00048 
00049 
00058 struct vertex_info *
00059 softpipe_get_vertex_info(struct softpipe_context *softpipe)
00060 {
00061    struct vertex_info *vinfo = &softpipe->vertex_info;
00062 
00063    if (vinfo->num_attribs == 0) {
00064       /* compute vertex layout now */
00065       const struct sp_fragment_shader *spfs = softpipe->fs;
00066       const enum interp_mode colorInterp
00067          = softpipe->rasterizer->flatshade ? INTERP_CONSTANT : INTERP_LINEAR;
00068       uint i;
00069 
00070       if (softpipe->vbuf) {
00071          /* if using the post-transform vertex buffer, tell draw_vbuf to
00072           * simply emit the whole post-xform vertex as-is:
00073           */
00074          struct vertex_info *vinfo_vbuf = &softpipe->vertex_info_vbuf;
00075          const uint num = draw_num_vs_outputs(softpipe->draw);
00076          uint i;
00077 
00078          /* No longer any need to try and emit draw vertex_header info.
00079           */
00080          vinfo_vbuf->num_attribs = 0;
00081          for (i = 0; i < num; i++) {
00082             draw_emit_vertex_attr(vinfo_vbuf, EMIT_4F, INTERP_PERSPECTIVE, i);
00083          }
00084          draw_compute_vertex_size(vinfo_vbuf);
00085       }
00086 
00087       /*
00088        * Loop over fragment shader inputs, searching for the matching output
00089        * from the vertex shader.
00090        */
00091       vinfo->num_attribs = 0;
00092       for (i = 0; i < spfs->info.num_inputs; i++) {
00093          int src;
00094          switch (spfs->info.input_semantic_name[i]) {
00095          case TGSI_SEMANTIC_POSITION:
00096             src = draw_find_vs_output(softpipe->draw,
00097                                       TGSI_SEMANTIC_POSITION, 0);
00098             draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_POS, src);
00099             break;
00100 
00101          case TGSI_SEMANTIC_COLOR:
00102             src = draw_find_vs_output(softpipe->draw, TGSI_SEMANTIC_COLOR, 
00103                                  spfs->info.input_semantic_index[i]);
00104             draw_emit_vertex_attr(vinfo, EMIT_4F, colorInterp, src);
00105             break;
00106 
00107          case TGSI_SEMANTIC_FOG:
00108             src = draw_find_vs_output(softpipe->draw, TGSI_SEMANTIC_FOG, 0);
00109             draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
00110             break;
00111 
00112          case TGSI_SEMANTIC_GENERIC:
00113             /* this includes texcoords and varying vars */
00114             src = draw_find_vs_output(softpipe->draw, TGSI_SEMANTIC_GENERIC,
00115                                       spfs->info.input_semantic_index[i]);
00116             draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
00117             break;
00118 
00119          default:
00120             assert(0);
00121          }
00122       }
00123 
00124       softpipe->psize_slot = draw_find_vs_output(softpipe->draw,
00125                                                  TGSI_SEMANTIC_PSIZE, 0);
00126       if (softpipe->psize_slot > 0) {
00127          draw_emit_vertex_attr(vinfo, EMIT_4F, INTERP_CONSTANT,
00128                                softpipe->psize_slot);
00129       }
00130 
00131       draw_compute_vertex_size(vinfo);
00132    }
00133 
00134    return vinfo;
00135 }
00136 
00137 
00152 struct vertex_info *
00153 softpipe_get_vbuf_vertex_info(struct softpipe_context *softpipe)
00154 {
00155    (void) softpipe_get_vertex_info(softpipe);
00156    return &softpipe->vertex_info_vbuf;
00157 }
00158 
00159 
00163 static void
00164 compute_cliprect(struct softpipe_context *sp)
00165 {
00166    uint surfWidth = sp->framebuffer.width;
00167    uint surfHeight = sp->framebuffer.height;
00168 
00169    if (sp->rasterizer->scissor) {
00170       /* clip to scissor rect */
00171       sp->cliprect.minx = MAX2(sp->scissor.minx, 0);
00172       sp->cliprect.miny = MAX2(sp->scissor.miny, 0);
00173       sp->cliprect.maxx = MIN2(sp->scissor.maxx, surfWidth);
00174       sp->cliprect.maxy = MIN2(sp->scissor.maxy, surfHeight);
00175    }
00176    else {
00177       /* clip to surface bounds */
00178       sp->cliprect.minx = 0;
00179       sp->cliprect.miny = 0;
00180       sp->cliprect.maxx = surfWidth;
00181       sp->cliprect.maxy = surfHeight;
00182    }
00183 }
00184 
00185 
00186 /* Hopefully this will remain quite simple, otherwise need to pull in
00187  * something like the state tracker mechanism.
00188  */
00189 void softpipe_update_derived( struct softpipe_context *softpipe )
00190 {
00191    if (softpipe->dirty & (SP_NEW_RASTERIZER |
00192                           SP_NEW_FS |
00193                           SP_NEW_VS))
00194       invalidate_vertex_layout( softpipe );
00195 
00196    if (softpipe->dirty & (SP_NEW_SCISSOR |
00197                           SP_NEW_DEPTH_STENCIL_ALPHA |
00198                           SP_NEW_FRAMEBUFFER))
00199       compute_cliprect(softpipe);
00200 
00201    if (softpipe->dirty & (SP_NEW_BLEND |
00202                           SP_NEW_DEPTH_STENCIL_ALPHA |
00203                           SP_NEW_FRAMEBUFFER |
00204                           SP_NEW_RASTERIZER |
00205                           SP_NEW_FS | 
00206                           SP_NEW_QUERY))
00207       sp_build_quad_pipeline(softpipe);
00208 
00209    softpipe->dirty = 0;
00210 }

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