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