t_pipeline.c revision 16837e4219e03df36c34f08cee1967b946c44536
1/* $Id: t_pipeline.c,v 1.17 2001/04/30 09:04:00 keithw Exp $ */ 2 3/* 4 * Mesa 3-D graphics library 5 * Version: 3.5 6 * 7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved. 8 * 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: 15 * 16 * The above copyright notice and this permission notice shall be included 17 * in all copies or substantial portions of the Software. 18 * 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 * Authors: 27 * Keith Whitwell <keithw@valinux.com> 28 */ 29 30#include "glheader.h" 31#include "context.h" 32#include "mem.h" 33#include "mmath.h" 34#include "state.h" 35#include "mtypes.h" 36 37#include "math/m_translate.h" 38#include "math/m_xform.h" 39 40#include "t_context.h" 41#include "t_pipeline.h" 42 43 44void _tnl_install_pipeline( GLcontext *ctx, 45 const struct gl_pipeline_stage **stages ) 46{ 47 TNLcontext *tnl = TNL_CONTEXT(ctx); 48 struct gl_pipeline *pipe = &tnl->pipeline; 49 GLuint i; 50 51 ASSERT(pipe->nr_stages == 0); 52 53 pipe->run_state_changes = ~0; 54 pipe->run_input_changes = ~0; 55 pipe->build_state_changes = ~0; 56 pipe->build_state_trigger = 0; 57 pipe->inputs = 0; 58 59 /* Create a writeable copy of each stage. 60 */ 61 for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) { 62 MEMCPY( &pipe->stages[i], stages[i], sizeof( **stages )); 63 pipe->build_state_trigger |= pipe->stages[i].check_state; 64 } 65 66 pipe->nr_stages = i; 67} 68 69void _tnl_destroy_pipeline( GLcontext *ctx ) 70{ 71 TNLcontext *tnl = TNL_CONTEXT(ctx); 72 GLuint i; 73 74 for (i = 0 ; i < tnl->pipeline.nr_stages ; i++) 75 tnl->pipeline.stages[i].destroy( &tnl->pipeline.stages[i] ); 76 77 tnl->pipeline.nr_stages = 0; 78} 79 80/* TODO: merge validate with run. 81 */ 82void _tnl_validate_pipeline( GLcontext *ctx ) 83{ 84 TNLcontext *tnl = TNL_CONTEXT(ctx); 85 struct gl_pipeline *pipe = &tnl->pipeline; 86 struct gl_pipeline_stage *s = pipe->stages; 87 GLuint newstate = pipe->build_state_changes; 88 GLuint generated = 0; 89 GLuint i; 90 GLuint changed_inputs = 0; 91 92 pipe->inputs = 0; 93 pipe->build_state_changes = 0; 94 95 for (i = pipe->nr_stages+1 ; --i ; s++) { 96 97 s->changed_inputs |= s->inputs & changed_inputs; 98 99 if (s->check_state & newstate) { 100 if (s->active) { 101 GLuint old_outputs = s->outputs; 102 s->check(ctx, s); 103 if (!s->active) 104 changed_inputs |= old_outputs; 105 } 106 else 107 s->check(ctx, s); 108 } 109 110 if (s->active) { 111 pipe->inputs |= s->inputs & ~generated; 112 generated |= s->outputs; 113 } 114 } 115} 116 117 118 119void _tnl_run_pipeline( GLcontext *ctx ) 120{ 121 TNLcontext *tnl = TNL_CONTEXT(ctx); 122 struct vertex_buffer *VB = &tnl->vb; 123 struct gl_pipeline *pipe = &tnl->pipeline; 124 struct gl_pipeline_stage *s = pipe->stages; 125 GLuint changed_state = pipe->run_state_changes; 126 GLuint changed_inputs = pipe->run_input_changes; 127 GLboolean running = GL_TRUE; 128 GLuint i; 129 unsigned short __tmp; 130 131 /* Done elsewhere. 132 */ 133 ASSERT(pipe->build_state_changes == 0); 134 135/* _tnl_print_vert_flags( "run_pipeline, new inputs", changed_inputs ); */ 136/* _mesa_print_state( "run_pipeline, new state", changed_state ); */ 137 138 START_FAST_MATH(__tmp); 139 if (tnl->Driver.PipelineStart) 140 tnl->Driver.PipelineStart( ctx ); 141 142 /* If something changes in the pipeline, tag all subsequent stages 143 * using this value for recalculation. 144 * 145 * Even inactive stages have their state and inputs examined to try 146 * to keep cached data alive over state-changes. 147 */ 148 for (i = pipe->nr_stages+1 ; --i ; s++) { 149 s->changed_inputs |= s->inputs & changed_inputs; 150 151 if (s->run_state & changed_state) { 152 s->changed_inputs = s->inputs; 153 } 154 155 if (s->active) { 156 if (running) { 157 if (s->changed_inputs) 158 changed_inputs |= s->outputs; 159 160 if (0) 161 fprintf(stderr, "run %s inputs %x\n", 162 s->name, s->changed_inputs); 163 164 running = s->run( ctx, s ); 165 s->changed_inputs = 0; /* readded this apr 30 */ 166 VB->importable_data &= ~s->outputs; 167 } 168 } 169 } 170 171 if (tnl->Driver.PipelineFinish) 172 tnl->Driver.PipelineFinish( ctx ); 173 END_FAST_MATH(__tmp); 174 175 pipe->run_state_changes = 0; 176 pipe->run_input_changes = 0; 177} 178 179 180 181/* The default pipeline. This is useful for software rasterizers, and 182 * simple hardware rasterizers. For customization, I don't recommend 183 * tampering with the internals of these stages in the way that 184 * drivers did in Mesa 3.4. These stages are basically black boxes, 185 * and should be left intact. 186 * 187 * To customize the pipeline, consider: 188 * 189 * - removing redundant stages (making sure that the software rasterizer 190 * can cope with this on fallback paths). An example is fog 191 * coordinate generation, which is not required in the FX driver. 192 * 193 * - replacing general-purpose machine-independent stages with 194 * general-purpose machine-specific stages. There is no example of 195 * this to date, though it must be borne in mind that all subsequent 196 * stages that reference the output of the new stage must cope with 197 * any machine-specific data introduced. This may not be easy 198 * unless there are no such stages (ie the new stage is the last in 199 * the pipe). 200 * 201 * - inserting optimized (but specialized) stages ahead of the 202 * general-purpose fallback implementation. For example, the old 203 * fastpath mechanism, which only works when the VERT_ELT input is 204 * available, can be duplicated by placing the fastpath stage at the 205 * head of this pipeline. Such specialized stages are currently 206 * constrained to have no outputs (ie. they must either finish the * 207 * pipeline by returning GL_FALSE from run(), or do nothing). 208 * 209 * Some work can be done to lift some of the restrictions in the final 210 * case, if it becomes necessary to do so. 211 */ 212const struct gl_pipeline_stage *_tnl_default_pipeline[] = { 213 &_tnl_vertex_transform_stage, 214 &_tnl_normal_transform_stage, 215 &_tnl_lighting_stage, 216 &_tnl_fog_coordinate_stage, 217 &_tnl_texgen_stage, 218 &_tnl_texture_transform_stage, 219 &_tnl_point_attenuation_stage, 220 &_tnl_render_stage, 221 0 222}; 223