| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 1 | /* $Id: t_pipeline.c,v 1.3 2000/11/22 07:32:18 joukj Exp $ */ |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 2 | |
| 3 | /* |
| 4 | * Mesa 3-D graphics library |
| 5 | * Version: 3.5 |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 6 | * |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2000 Brian Paul All Rights Reserved. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 8 | * |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 9 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 10 | * copy of this software and associated documentation files (the "Software"), |
| 11 | * to deal in the Software without restriction, including without limitation |
| 12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 13 | * and/or sell copies of the Software, and to permit persons to whom the |
| 14 | * Software is furnished to do so, subject to the following conditions: |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 15 | * |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 16 | * The above copyright notice and this permission notice shall be included |
| 17 | * in all copies or substantial portions of the Software. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 18 | * |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
| 23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
| 24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 25 | */ |
| 26 | |
| 27 | /* Dynamic pipelines, support for CVA. |
| 28 | * Copyright (C) 1999 Keith Whitwell. |
| 29 | */ |
| 30 | |
| 31 | #include "glheader.h" |
| 32 | #include "context.h" |
| 33 | #include "mem.h" |
| 34 | #include "mmath.h" |
| 35 | #include "state.h" |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 36 | #include "mtypes.h" |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 37 | |
| 38 | #include "math/m_translate.h" |
| 39 | #include "math/m_xform.h" |
| 40 | |
| 41 | #include "t_bbox.h" |
| 42 | #include "t_clip.h" |
| 43 | #include "t_cva.h" |
| 44 | #include "t_fog.h" |
| 45 | #include "t_light.h" |
| 46 | #include "t_pipeline.h" |
| 47 | #include "t_shade.h" |
| 48 | #include "t_stages.h" |
| 49 | #include "t_vbcull.h" |
| 50 | #include "t_vbindirect.h" |
| 51 | #include "t_vbrender.h" |
| 52 | #include "t_vbxform.h" |
| 53 | |
| 54 | |
| 55 | |
| 56 | |
| 57 | |
| 58 | void gl_print_pipe_ops( const char *msg, GLuint flags ) |
| 59 | { |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 60 | fprintf(stderr, |
| Brian Paul | 189476f | 2000-11-20 18:06:11 +0000 | [diff] [blame] | 61 | "%s: (0x%x) %s%s%s%s%s%s%s%s%s%s%s%s\n", |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 62 | msg, |
| 63 | flags, |
| 64 | (flags & PIPE_OP_CVA_PREPARE) ? "cva-prepare, " : "", |
| 65 | (flags & PIPE_OP_VERT_XFORM) ? "vert-xform, " : "", |
| 66 | (flags & PIPE_OP_NORM_XFORM) ? "norm-xform, " : "", |
| 67 | (flags & PIPE_OP_LIGHT) ? "light, " : "", |
| 68 | (flags & PIPE_OP_FOG) ? "fog, " : "", |
| 69 | (flags & PIPE_OP_TEX0) ? "tex-0, " : "", |
| 70 | (flags & PIPE_OP_TEX1) ? "tex-1, " : "", |
| Brian Paul | 189476f | 2000-11-20 18:06:11 +0000 | [diff] [blame] | 71 | (flags & PIPE_OP_TEX2) ? "tex-2, " : "", |
| 72 | (flags & PIPE_OP_TEX3) ? "tex-3, " : "", |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 73 | (flags & PIPE_OP_RAST_SETUP_0) ? "rast-0, " : "", |
| 74 | (flags & PIPE_OP_RAST_SETUP_1) ? "rast-1, " : "", |
| 75 | (flags & PIPE_OP_RENDER) ? "render, " : ""); |
| 76 | |
| 77 | } |
| 78 | |
| 79 | |
| 80 | |
| 81 | /* Have to reset only those parts of the vb which are being recalculated. |
| 82 | */ |
| 83 | void gl_reset_cva_vb( struct vertex_buffer *VB, GLuint stages ) |
| 84 | { |
| 85 | GLcontext *ctx = VB->ctx; |
| 86 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 87 | |
| 88 | if (MESA_VERBOSE&VERBOSE_PIPELINE) |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 89 | gl_print_pipe_ops( "reset cva vb", stages ); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 90 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 91 | if (stages & PIPE_OP_VERT_XFORM) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 92 | { |
| 93 | if (VB->ClipOrMask & CLIP_USER_BIT) |
| 94 | MEMSET(VB->UserClipMask, 0, VB->Count); |
| 95 | |
| 96 | VB->ClipOrMask = 0; |
| 97 | VB->ClipAndMask = CLIP_ALL_BITS; |
| 98 | VB->CullMode = 0; |
| 99 | VB->CullFlag[0] = VB->CullFlag[1] = 0; |
| 100 | VB->Culled = 0; |
| 101 | } |
| 102 | |
| 103 | if (stages & PIPE_OP_NORM_XFORM) { |
| 104 | VB->NormalPtr = &tnl->CVA.v.Normal; |
| 105 | } |
| 106 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 107 | if (stages & PIPE_OP_LIGHT) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 108 | { |
| 109 | VB->ColorPtr = VB->Color[0] = VB->Color[1] = &tnl->CVA.v.Color; |
| 110 | VB->IndexPtr = VB->Index[0] = VB->Index[1] = &tnl->CVA.v.Index; |
| 111 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 112 | else if (stages & PIPE_OP_FOG) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 113 | { |
| 114 | if (ctx->Light.Enabled) { |
| 115 | VB->Color[0] = VB->LitColor[0]; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 116 | VB->Color[1] = VB->LitColor[1]; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 117 | VB->Index[0] = VB->LitIndex[0]; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 118 | VB->Index[1] = VB->LitIndex[1]; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 119 | } else { |
| 120 | VB->Color[0] = VB->Color[1] = &tnl->CVA.v.Color; |
| 121 | VB->Index[0] = VB->Index[1] = &tnl->CVA.v.Index; |
| 122 | } |
| 123 | VB->ColorPtr = VB->Color[0]; |
| 124 | VB->IndexPtr = VB->Index[0]; |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | |
| 129 | |
| 130 | |
| 131 | |
| 132 | |
| 133 | static void pipeline_ctr( struct gl_pipeline *p, GLcontext *ctx, GLuint type ) |
| 134 | { |
| 135 | GLuint i; |
| 136 | (void) ctx; |
| 137 | |
| 138 | p->state_change = 0; |
| 139 | p->cva_state_change = 0; |
| 140 | p->inputs = 0; |
| 141 | p->outputs = 0; |
| 142 | p->type = type; |
| 143 | p->ops = 0; |
| 144 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 145 | for (i = 0 ; i < gl_default_nr_stages ; i++) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 146 | p->state_change |= gl_default_pipeline[i].state_change; |
| 147 | } |
| 148 | |
| 149 | |
| 150 | void _tnl_pipeline_init( GLcontext *ctx ) |
| 151 | { |
| 152 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 153 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 154 | MEMCPY( tnl->PipelineStage, |
| 155 | gl_default_pipeline, |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 156 | sizeof(*gl_default_pipeline) * gl_default_nr_stages ); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 157 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 158 | tnl->NrPipelineStages = gl_default_nr_stages; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 159 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 160 | pipeline_ctr( &tnl->CVA.elt, ctx, PIPE_IMMEDIATE); |
| 161 | pipeline_ctr( &tnl->CVA.pre, ctx, PIPE_PRECALC ); |
| 162 | } |
| 163 | |
| 164 | |
| 165 | |
| 166 | #define MINIMAL_VERT_DATA (VERT_DATA & ~(VERT_TEX0_4 | \ |
| 167 | VERT_TEX1_4 | \ |
| 168 | VERT_TEX2_4 | \ |
| 169 | VERT_TEX3_4 | \ |
| 170 | VERT_EVAL_ANY)) |
| 171 | |
| 172 | #define VERT_CURRENT_DATA (VERT_TEX0_1234 | \ |
| 173 | VERT_TEX1_1234 | \ |
| 174 | VERT_TEX2_1234 | \ |
| 175 | VERT_TEX3_1234 | \ |
| 176 | VERT_RGBA | \ |
| 177 | VERT_SPEC_RGB | \ |
| 178 | VERT_FOG_COORD | \ |
| 179 | VERT_INDEX | \ |
| 180 | VERT_EDGE | \ |
| 181 | VERT_NORM | \ |
| 182 | VERT_MATERIAL) |
| 183 | |
| 184 | /* Called prior to every recomputation of the CVA precalc data, except where |
| 185 | * the driver is able to calculate the pipeline unassisted. |
| 186 | */ |
| 187 | static void build_full_precalc_pipeline( GLcontext *ctx ) |
| 188 | { |
| 189 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 190 | struct gl_pipeline_stage *pipeline = tnl->PipelineStage; |
| 191 | struct gl_cva *cva = &tnl->CVA; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 192 | struct gl_pipeline *pre = &cva->pre; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 193 | struct gl_pipeline_stage **stages = pre->stages; |
| 194 | GLuint i; |
| 195 | GLuint newstate = pre->new_state; |
| 196 | GLuint changed_ops = 0; |
| 197 | GLuint oldoutputs = pre->outputs; |
| 198 | GLuint oldinputs = pre->inputs; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 199 | GLuint fallback = (VERT_CURRENT_DATA & tnl->_CurrentFlag & |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 200 | ~tnl->_ArraySummary); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 201 | GLuint changed_outputs = (tnl->_ArrayNewState | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 202 | (fallback & cva->orflag)); |
| 203 | GLuint available = fallback | tnl->_ArrayFlags; |
| 204 | |
| 205 | pre->cva_state_change = 0; |
| 206 | pre->ops = 0; |
| 207 | pre->outputs = 0; |
| 208 | pre->inputs = 0; |
| 209 | pre->forbidden_inputs = 0; |
| 210 | pre->fallback = 0; |
| 211 | |
| 212 | /* KW: Disable data reuse during Mesa reorg. Make this more readable... |
| 213 | */ |
| 214 | newstate = ~0; |
| 215 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 216 | if (tnl->_ArraySummary & VERT_ELT) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 217 | cva->orflag &= VERT_MATERIAL; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 218 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 219 | cva->orflag &= ~(tnl->_ArraySummary & ~VERT_OBJ_ANY); |
| 220 | available &= ~cva->orflag; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 221 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 222 | pre->outputs = available; |
| 223 | pre->inputs = available; |
| 224 | |
| 225 | if (MESA_VERBOSE & VERBOSE_PIPELINE) { |
| 226 | fprintf(stderr, ": Rebuild pipeline\n"); |
| 227 | gl_print_vert_flags("orflag", cva->orflag); |
| 228 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 229 | |
| 230 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 231 | |
| 232 | /* If something changes in the pipeline, tag all subsequent stages |
| 233 | * using this value for recalcuation. Also used to build the full |
| 234 | * pipeline by setting newstate and newinputs to ~0. |
| 235 | * |
| 236 | * Because all intermediate values are buffered, the new inputs |
| 237 | * are enough to fully specify what needs to be calculated, and a |
| 238 | * single pass identifies all stages requiring recalculation. |
| 239 | */ |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 240 | for (i = 0 ; i < tnl->NrPipelineStages ; i++) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 241 | { |
| 242 | pipeline[i].check(ctx, &pipeline[i]); |
| 243 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 244 | if (pipeline[i].type & PIPE_PRECALC) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 245 | { |
| 246 | if ((newstate & pipeline[i].cva_state_change) || |
| 247 | (changed_outputs & pipeline[i].inputs) || |
| 248 | !pipeline[i].inputs) |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 249 | { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 250 | changed_ops |= pipeline[i].ops; |
| 251 | changed_outputs |= pipeline[i].outputs; |
| 252 | pipeline[i].active &= ~PIPE_PRECALC; |
| 253 | |
| 254 | if ((pipeline[i].inputs & ~available) == 0 && |
| 255 | (pipeline[i].ops & pre->ops) == 0) |
| 256 | { |
| 257 | pipeline[i].active |= PIPE_PRECALC; |
| 258 | *stages++ = &pipeline[i]; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 259 | } |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 260 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 261 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 262 | /* Incompatible with multiple stages structs implementing |
| 263 | * the same stage. |
| 264 | */ |
| 265 | available &= ~pipeline[i].outputs; |
| 266 | pre->outputs &= ~pipeline[i].outputs; |
| 267 | |
| 268 | if (pipeline[i].active & PIPE_PRECALC) { |
| 269 | pre->ops |= pipeline[i].ops; |
| 270 | pre->outputs |= pipeline[i].outputs; |
| 271 | available |= pipeline[i].outputs; |
| 272 | pre->forbidden_inputs |= pipeline[i].pre_forbidden_inputs; |
| 273 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 274 | } |
| 275 | else if (pipeline[i].active & PIPE_PRECALC) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 276 | { |
| 277 | pipeline[i].active &= ~PIPE_PRECALC; |
| 278 | changed_outputs |= pipeline[i].outputs; |
| 279 | changed_ops |= pipeline[i].ops; |
| 280 | } |
| 281 | } |
| 282 | |
| 283 | *stages = 0; |
| 284 | |
| 285 | pre->new_outputs = pre->outputs & (changed_outputs | ~oldoutputs); |
| 286 | pre->new_inputs = pre->inputs & ~oldinputs; |
| 287 | pre->fallback = pre->inputs & fallback; |
| 288 | pre->forbidden_inputs |= pre->inputs & fallback; |
| 289 | |
| 290 | pre->changed_ops = changed_ops; |
| 291 | } |
| 292 | |
| 293 | void gl_build_precalc_pipeline( GLcontext *ctx ) |
| 294 | { |
| 295 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 296 | struct gl_pipeline *pre = &tnl->CVA.pre; |
| 297 | struct gl_pipeline *elt = &tnl->CVA.elt; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 298 | |
| 299 | if (!ctx->Driver.BuildPrecalcPipeline || |
| 300 | !ctx->Driver.BuildPrecalcPipeline( ctx )) |
| 301 | build_full_precalc_pipeline( ctx ); |
| 302 | |
| 303 | pre->data_valid = 0; |
| 304 | pre->pipeline_valid = 1; |
| 305 | elt->pipeline_valid = 0; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 306 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 307 | tnl->CVA.orflag = 0; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 308 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 309 | if (MESA_VERBOSE&VERBOSE_PIPELINE) |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 310 | gl_print_pipeline( ctx, pre ); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 311 | } |
| 312 | |
| 313 | |
| 314 | static void build_full_immediate_pipeline( GLcontext *ctx ) |
| 315 | { |
| 316 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 317 | struct gl_pipeline_stage *pipeline = tnl->PipelineStage; |
| 318 | struct gl_cva *cva = &tnl->CVA; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 319 | struct gl_pipeline *pre = &cva->pre; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 320 | struct gl_pipeline *elt = &cva->elt; |
| 321 | struct gl_pipeline_stage **stages = elt->stages; |
| 322 | GLuint i; |
| 323 | GLuint newstate = elt->new_state; |
| 324 | GLuint active_ops = 0; |
| 325 | GLuint available = cva->orflag | MINIMAL_VERT_DATA; |
| 326 | GLuint generated = 0; |
| 327 | GLuint is_elt = 0; |
| 328 | |
| 329 | if (pre->data_valid && tnl->CompileCVAFlag) { |
| 330 | is_elt = 1; |
| 331 | active_ops = cva->pre.ops; |
| 332 | available |= pre->outputs | VERT_PRECALC_DATA; |
| 333 | } |
| 334 | |
| 335 | |
| 336 | elt->outputs = 0; /* not used */ |
| 337 | elt->inputs = 0; |
| 338 | |
| 339 | for (i = 0 ; i < tnl->NrPipelineStages ; i++) { |
| 340 | pipeline[i].active &= ~PIPE_IMMEDIATE; |
| 341 | |
| 342 | if ((pipeline[i].state_change & newstate) || |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 343 | (pipeline[i].elt_forbidden_inputs & available)) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 344 | { |
| 345 | pipeline[i].check(ctx, &pipeline[i]); |
| 346 | } |
| 347 | |
| 348 | if ((pipeline[i].type & PIPE_IMMEDIATE) && |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 349 | (pipeline[i].ops & active_ops) == 0 && |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 350 | (pipeline[i].elt_forbidden_inputs & available) == 0 |
| 351 | ) |
| 352 | { |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 353 | if (pipeline[i].inputs & ~available) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 354 | elt->forbidden_inputs |= pipeline[i].inputs & ~available; |
| 355 | else |
| 356 | { |
| 357 | elt->inputs |= pipeline[i].inputs & ~generated; |
| 358 | elt->forbidden_inputs |= pipeline[i].elt_forbidden_inputs; |
| 359 | pipeline[i].active |= PIPE_IMMEDIATE; |
| 360 | *stages++ = &pipeline[i]; |
| 361 | generated |= pipeline[i].outputs; |
| 362 | available |= pipeline[i].outputs; |
| 363 | active_ops |= pipeline[i].ops; |
| 364 | } |
| 365 | } |
| 366 | } |
| 367 | |
| 368 | *stages = 0; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 369 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 370 | elt->copy_transformed_data = 1; |
| 371 | elt->replay_copied_vertices = 0; |
| 372 | |
| 373 | if (is_elt) { |
| 374 | cva->merge = elt->inputs & pre->outputs; |
| 375 | elt->ops = active_ops & ~pre->ops; |
| 376 | } |
| 377 | } |
| 378 | |
| 379 | |
| 380 | |
| 381 | void gl_build_immediate_pipeline( GLcontext *ctx ) |
| 382 | { |
| 383 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 384 | struct gl_pipeline *elt = &tnl->CVA.elt; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 385 | |
| 386 | if (!ctx->Driver.BuildEltPipeline || |
| 387 | !ctx->Driver.BuildEltPipeline( ctx )) { |
| 388 | build_full_immediate_pipeline( ctx ); |
| 389 | } |
| 390 | |
| 391 | elt->pipeline_valid = 1; |
| 392 | tnl->CVA.orflag = 0; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 393 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 394 | if (MESA_VERBOSE&VERBOSE_PIPELINE) |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 395 | gl_print_pipeline( ctx, elt ); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 396 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 397 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 398 | #define INTERESTED ~0 |
| 399 | |
| 400 | void gl_update_pipelines( GLcontext *ctx ) |
| 401 | { |
| 402 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 403 | GLuint newstate = ctx->NewState; |
| 404 | struct gl_cva *cva = &tnl->CVA; |
| 405 | |
| 406 | newstate &= INTERESTED; |
| 407 | |
| 408 | if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_STATE)) |
| 409 | gl_print_enable_flags("enabled", ctx->_Enabled); |
| 410 | |
| 411 | if (newstate || |
| 412 | cva->lock_changed || |
| 413 | cva->orflag != cva->last_orflag || |
| 414 | tnl->_ArrayFlags != cva->last_array_flags) |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 415 | { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 416 | GLuint flags = VERT_WIN; |
| 417 | |
| 418 | if (ctx->Visual.RGBAflag) { |
| 419 | flags |= VERT_RGBA; |
| 420 | if (ctx->_TriangleCaps && DD_SEPERATE_SPECULAR) |
| 421 | flags |= VERT_SPEC_RGB; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 422 | } else |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 423 | flags |= VERT_INDEX; |
| 424 | |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 425 | if (ctx->Texture._ReallyEnabled & TEXTURE0_ANY) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 426 | flags |= VERT_TEX0_ANY; |
| 427 | |
| 428 | if (ctx->Texture._ReallyEnabled & TEXTURE1_ANY) |
| 429 | flags |= VERT_TEX1_ANY; |
| 430 | |
| 431 | #if MAX_TEXTURE_UNITS > 2 |
| 432 | if (ctx->Texture._ReallyEnabled & TEXTURE2_ANY) |
| 433 | flags |= VERT_TEX2_ANY; |
| 434 | #endif |
| 435 | #if MAX_TEXTURE_UNITS > 3 |
| 436 | if (ctx->Texture._ReallyEnabled & TEXTURE3_ANY) |
| 437 | flags |= VERT_TEX3_ANY; |
| 438 | #endif |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 439 | |
| 440 | if (ctx->Polygon._Unfilled) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 441 | flags |= VERT_EDGE; |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 442 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 443 | if (ctx->Fog.FogCoordinateSource == GL_FOG_COORDINATE_EXT) |
| 444 | flags |= VERT_FOG_COORD; |
| 445 | |
| 446 | if (ctx->RenderMode==GL_FEEDBACK) { |
| 447 | flags = (VERT_WIN | VERT_RGBA | VERT_INDEX | VERT_NORM | VERT_EDGE |
| 448 | | VERT_TEX0_ANY |
| 449 | | VERT_TEX1_ANY |
| 450 | #if MAX_TEXTURE_UNITS > 2 |
| 451 | | VERT_TEX2_ANY |
| 452 | #endif |
| 453 | #if MAX_TEXTURE_UNITS > 3 |
| 454 | | VERT_TEX3_ANY |
| 455 | #endif |
| 456 | ); |
| 457 | } |
| 458 | |
| 459 | tnl->_RenderFlags = flags; |
| 460 | |
| 461 | cva->elt.new_state |= newstate; |
| 462 | cva->elt.pipeline_valid = 0; |
| 463 | |
| 464 | cva->pre.new_state |= newstate; |
| 465 | cva->pre.forbidden_inputs = 0; |
| 466 | cva->pre.pipeline_valid = 0; |
| 467 | cva->lock_changed = 0; |
| 468 | } |
| 469 | |
| 470 | if (tnl->_ArrayNewState != cva->last_array_new_state) |
| 471 | cva->pre.pipeline_valid = 0; |
| 472 | |
| 473 | cva->pre.data_valid = 0; |
| 474 | cva->last_array_new_state = tnl->_ArrayNewState; |
| 475 | cva->last_orflag = cva->orflag; |
| 476 | cva->last_array_flags = tnl->_ArrayFlags; |
| 477 | } |
| 478 | |
| 479 | void gl_run_pipeline( struct vertex_buffer *VB ) |
| 480 | { |
| 481 | struct gl_pipeline *pipe = VB->pipeline; |
| 482 | struct gl_pipeline_stage **stages = pipe->stages; |
| 483 | unsigned short x; |
| 484 | |
| 485 | pipe->data_valid = 1; /* optimized stages might want to reset this. */ |
| 486 | |
| 487 | if (0) gl_print_pipeline( VB->ctx, pipe ); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 488 | |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 489 | START_FAST_MATH(x); |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame^] | 490 | |
| 491 | for ( VB->Culled = 0; *stages && !VB->Culled ; stages++ ) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 492 | (*stages)->run( VB ); |
| 493 | |
| 494 | END_FAST_MATH(x); |
| 495 | |
| 496 | pipe->new_state = 0; |
| 497 | } |
| 498 | |