00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
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
00058
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
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
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
00100
00101
00102
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
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
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
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
00141
00142
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
00154
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;
00175 }
00176
00177
00178
00179 if (i915->dirty & I915_NEW_FRAMEBUFFER)
00180 i915->hardware_dirty |= I915_HW_STATIC;
00181
00182 i915->dirty = 0;
00183 }