t_pipeline.c revision 4a49301e
1/* 2 * Mesa 3-D graphics library 3 * Version: 6.5.3 4 * 5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the "Software"), 9 * to deal in the Software without restriction, including without limitation 10 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 11 * and/or sell copies of the Software, and to permit persons to whom the 12 * Software is furnished to do so, subject to the following conditions: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 23 * 24 * Authors: 25 * Keith Whitwell <keith@tungstengraphics.com> 26 */ 27 28#include "main/glheader.h" 29#include "main/context.h" 30#include "main/imports.h" 31#include "main/mtypes.h" 32 33#include "t_context.h" 34#include "t_pipeline.h" 35#include "t_vp_build.h" 36#include "t_vertex.h" 37 38void _tnl_install_pipeline( GLcontext *ctx, 39 const struct tnl_pipeline_stage **stages ) 40{ 41 TNLcontext *tnl = TNL_CONTEXT(ctx); 42 GLuint i; 43 44 tnl->pipeline.new_state = ~0; 45 46 /* Create a writeable copy of each stage. 47 */ 48 for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) { 49 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; 50 MEMCPY(s, stages[i], sizeof(*s)); 51 if (s->create) 52 s->create(ctx, s); 53 } 54 55 tnl->pipeline.nr_stages = i; 56} 57 58void _tnl_destroy_pipeline( GLcontext *ctx ) 59{ 60 TNLcontext *tnl = TNL_CONTEXT(ctx); 61 GLuint i; 62 63 for (i = 0 ; i < tnl->pipeline.nr_stages ; i++) { 64 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; 65 if (s->destroy) 66 s->destroy(s); 67 } 68 69 tnl->pipeline.nr_stages = 0; 70} 71 72 73 74static GLuint check_input_changes( GLcontext *ctx ) 75{ 76 TNLcontext *tnl = TNL_CONTEXT(ctx); 77 GLuint i; 78 79 for (i = 0; i <= _TNL_LAST_MAT; i++) { 80 if (tnl->vb.AttribPtr[i]->size != tnl->pipeline.last_attrib_size[i] || 81 tnl->vb.AttribPtr[i]->stride != tnl->pipeline.last_attrib_stride[i]) { 82 tnl->pipeline.last_attrib_size[i] = tnl->vb.AttribPtr[i]->size; 83 tnl->pipeline.last_attrib_stride[i] = tnl->vb.AttribPtr[i]->stride; 84 tnl->pipeline.input_changes |= 1<<i; 85 } 86 } 87 88 if (tnl->pipeline.input_changes && 89 tnl->Driver.NotifyInputChanges) 90 tnl->Driver.NotifyInputChanges( ctx, tnl->pipeline.input_changes ); 91 92 return tnl->pipeline.input_changes; 93} 94 95 96static GLuint check_output_changes( GLcontext *ctx ) 97{ 98#if 0 99 TNLcontext *tnl = TNL_CONTEXT(ctx); 100 101 for (i = 0; i < VERT_RESULT_MAX; i++) { 102 if (tnl->vb.ResultPtr[i]->size != tnl->last_result_size[i] || 103 tnl->vb.ResultPtr[i]->stride != tnl->last_result_stride[i]) { 104 tnl->last_result_size[i] = tnl->vb.ResultPtr[i]->size; 105 tnl->last_result_stride[i] = tnl->vb.ResultPtr[i]->stride; 106 tnl->pipeline.output_changes |= 1<<i; 107 } 108 } 109 110 if (tnl->pipeline.output_changes) 111 tnl->Driver.NotifyOutputChanges( ctx, tnl->pipeline.output_changes ); 112 113 return tnl->pipeline.output_changes; 114#else 115 return ~0; 116#endif 117} 118 119 120void _tnl_run_pipeline( GLcontext *ctx ) 121{ 122 TNLcontext *tnl = TNL_CONTEXT(ctx); 123 unsigned short __tmp; 124 GLuint i; 125 126 if (!tnl->vb.Count) 127 return; 128 129 /* Check for changed input sizes or change in stride to/from zero 130 * (ie const or non-const). 131 */ 132 if (check_input_changes( ctx ) || tnl->pipeline.new_state) { 133 if (ctx->VertexProgram._MaintainTnlProgram) 134 _tnl_UpdateFixedFunctionProgram( ctx ); 135 136 for (i = 0; i < tnl->pipeline.nr_stages ; i++) { 137 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; 138 if (s->validate) 139 s->validate( ctx, s ); 140 } 141 142 tnl->pipeline.new_state = 0; 143 tnl->pipeline.input_changes = 0; 144 145 /* Pipeline can only change its output in response to either a 146 * statechange or an input size/stride change. No other changes 147 * are allowed. 148 */ 149 if (check_output_changes( ctx )) 150 _tnl_notify_pipeline_output_change( ctx ); 151 } 152 153 START_FAST_MATH(__tmp); 154 155 for (i = 0; i < tnl->pipeline.nr_stages ; i++) { 156 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; 157 if (!s->run( ctx, s )) 158 break; 159 } 160 161 END_FAST_MATH(__tmp); 162} 163 164 165 166/* The default pipeline. This is useful for software rasterizers, and 167 * simple hardware rasterizers. For customization, I don't recommend 168 * tampering with the internals of these stages in the way that 169 * drivers did in Mesa 3.4. These stages are basically black boxes, 170 * and should be left intact. 171 * 172 * To customize the pipeline, consider: 173 * 174 * - removing redundant stages (making sure that the software rasterizer 175 * can cope with this on fallback paths). An example is fog 176 * coordinate generation, which is not required in the FX driver. 177 * 178 * - replacing general-purpose machine-independent stages with 179 * general-purpose machine-specific stages. There is no example of 180 * this to date, though it must be borne in mind that all subsequent 181 * stages that reference the output of the new stage must cope with 182 * any machine-specific data introduced. This may not be easy 183 * unless there are no such stages (ie the new stage is the last in 184 * the pipe). 185 * 186 * - inserting optimized (but specialized) stages ahead of the 187 * general-purpose fallback implementation. For example, the old 188 * fastpath mechanism, which only works when the VB->Elts input is 189 * available, can be duplicated by placing the fastpath stage at the 190 * head of this pipeline. Such specialized stages are currently 191 * constrained to have no outputs (ie. they must either finish the * 192 * pipeline by returning GL_FALSE from run(), or do nothing). 193 * 194 * Some work can be done to lift some of the restrictions in the final 195 * case, if it becomes necessary to do so. 196 */ 197const struct tnl_pipeline_stage *_tnl_default_pipeline[] = { 198 &_tnl_vertex_transform_stage, 199 &_tnl_normal_transform_stage, 200 &_tnl_lighting_stage, 201 &_tnl_texgen_stage, 202 &_tnl_texture_transform_stage, 203 &_tnl_point_attenuation_stage, 204 &_tnl_vertex_program_stage, 205 &_tnl_fog_coordinate_stage, 206 &_tnl_render_stage, 207 NULL 208}; 209 210const struct tnl_pipeline_stage *_tnl_vp_pipeline[] = { 211 &_tnl_vertex_program_stage, 212 &_tnl_render_stage, 213 NULL 214}; 215