i915_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 
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 "i915_context.h"
00034 #include "i915_state.h"
00035 #include "i915_reg.h"
00036 #include "i915_fpc.h"
00037 
00038 
00039 
00044 static void calculate_vertex_layout( struct i915_context *i915 )
00045 {
00046    const struct i915_fragment_shader *fs = i915->fs;
00047    const enum interp_mode colorInterp = i915->rasterizer->color_interp;
00048    struct vertex_info vinfo;
00049    boolean texCoords[8], colors[2], fog, needW;
00050    uint i;
00051    int src;
00052 
00053    memset(texCoords, 0, sizeof(texCoords));
00054    colors[0] = colors[1] = fog = needW = FALSE;
00055    memset(&vinfo, 0, sizeof(vinfo));
00056 
00057    /* Determine which fragment program inputs are needed.  Setup HW vertex
00058     * layout below, in the HW-specific attribute order.
00059     */
00060    for (i = 0; i < fs->info.num_inputs; i++) {
00061       switch (fs->info.input_semantic_name[i]) {
00062       case TGSI_SEMANTIC_POSITION:
00063          break;
00064       case TGSI_SEMANTIC_COLOR:
00065          assert(fs->info.input_semantic_index[i] < 2);
00066          colors[fs->info.input_semantic_index[i]] = TRUE;
00067          break;
00068       case TGSI_SEMANTIC_GENERIC:
00069          /* usually a texcoord */
00070          {
00071             const uint unit = fs->info.input_semantic_index[i];
00072             assert(unit < 8);
00073             texCoords[unit] = TRUE;
00074             needW = TRUE;
00075          }
00076          break;
00077       case TGSI_SEMANTIC_FOG:
00078          fog = TRUE;
00079          break;
00080       default:
00081          assert(0);
00082       }
00083    }
00084 
00085    
00086    /* pos */
00087    src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_POSITION, 0);
00088    if (needW) {
00089       draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_LINEAR, src);
00090       vinfo.hwfmt[0] |= S4_VFMT_XYZW;
00091       vinfo.attrib[0].emit = EMIT_4F;
00092    }
00093    else {
00094       draw_emit_vertex_attr(&vinfo, EMIT_3F, INTERP_LINEAR, src);
00095       vinfo.hwfmt[0] |= S4_VFMT_XYZ;
00096       vinfo.attrib[0].emit = EMIT_3F;
00097    }
00098 
00099    /* hardware point size */
00100    /* XXX todo */
00101 
00102    /* primary color */
00103    if (colors[0]) {
00104       src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_COLOR, 0);
00105       draw_emit_vertex_attr(&vinfo, EMIT_4UB, colorInterp, src);
00106       vinfo.hwfmt[0] |= S4_VFMT_COLOR;
00107    }
00108 
00109    /* secondary color */
00110    if (colors[1]) {
00111       src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_COLOR, 1);
00112       draw_emit_vertex_attr(&vinfo, EMIT_4UB, colorInterp, src);
00113       vinfo.hwfmt[0] |= S4_VFMT_SPEC_FOG;
00114    }
00115 
00116    /* fog coord, not fog blend factor */
00117    if (fog) {
00118       src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_FOG, 0);
00119       draw_emit_vertex_attr(&vinfo, EMIT_1F, INTERP_PERSPECTIVE, src);
00120       vinfo.hwfmt[0] |= S4_VFMT_FOG_PARAM;
00121    }
00122 
00123    /* texcoords */
00124    for (i = 0; i < 8; i++) {
00125       uint hwtc;
00126       if (texCoords[i]) {
00127          hwtc = TEXCOORDFMT_4D;
00128          src = draw_find_vs_output(i915->draw, TGSI_SEMANTIC_GENERIC, i);
00129          draw_emit_vertex_attr(&vinfo, EMIT_4F, INTERP_PERSPECTIVE, src);
00130       }
00131       else {
00132          hwtc = TEXCOORDFMT_NOT_PRESENT;
00133       }
00134       vinfo.hwfmt[1] |= hwtc << (i * 4);
00135    }
00136 
00137    draw_compute_vertex_size(&vinfo);
00138 
00139    if (memcmp(&i915->current.vertex_info, &vinfo, sizeof(vinfo))) {
00140       /* Need to set this flag so that the LIS2/4 registers get set.
00141        * It also means the i915_update_immediate() function must be called
00142        * after this one, in i915_update_derived().
00143        */
00144       i915->dirty |= I915_NEW_VERTEX_FORMAT;
00145 
00146       memcpy(&i915->current.vertex_info, &vinfo, sizeof(vinfo));
00147    }
00148 }
00149 
00150 
00151 
00152 
00153 /* Hopefully this will remain quite simple, otherwise need to pull in
00154  * something like the state tracker mechanism.
00155  */
00156 void i915_update_derived( struct i915_context *i915 )
00157 {
00158    if (i915->dirty & (I915_NEW_RASTERIZER | I915_NEW_FS | I915_NEW_VS))
00159       calculate_vertex_layout( i915 );
00160 
00161    if (i915->dirty & (I915_NEW_SAMPLER | I915_NEW_TEXTURE))
00162       i915_update_samplers(i915);
00163 
00164    if (i915->dirty & I915_NEW_TEXTURE)
00165       i915_update_textures(i915);
00166 
00167    if (i915->dirty)
00168       i915_update_immediate( i915 );
00169 
00170    if (i915->dirty)
00171       i915_update_dynamic( i915 );
00172 
00173    if (i915->dirty & I915_NEW_FS) {
00174       i915->hardware_dirty |= I915_HW_PROGRAM; /* XXX right? */
00175    }
00176 
00177    /* HW emit currently references framebuffer state directly:
00178     */
00179    if (i915->dirty & I915_NEW_FRAMEBUFFER)
00180       i915->hardware_dirty |= I915_HW_STATIC;
00181 
00182    i915->dirty = 0;
00183 }

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