| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Mesa 3-D graphics library |
| Brian | 4b3835d | 2007-04-16 10:58:30 -0600 | [diff] [blame] | 3 | * Version: 6.5.3 |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 4 | * |
| Brian | 4b3835d | 2007-04-16 10:58:30 -0600 | [diff] [blame] | 5 | * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. |
| 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 | * 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: |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 13 | * |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 14 | * The above copyright notice and this permission notice shall be included |
| 15 | * in all copies or substantial portions of the Software. |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 16 | * |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 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. |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 23 | * |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 24 | * Authors: |
| Brian Paul | 05a4b37 | 2002-10-29 20:28:36 +0000 | [diff] [blame] | 25 | * Keith Whitwell <keith@tungstengraphics.com> |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 26 | */ |
| 27 | |
| Brian | c223c6b | 2007-07-04 13:15:20 -0600 | [diff] [blame] | 28 | #include "main/glheader.h" |
| 29 | #include "main/context.h" |
| 30 | #include "main/imports.h" |
| Brian | c223c6b | 2007-07-04 13:15:20 -0600 | [diff] [blame] | 31 | #include "main/mtypes.h" |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 32 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 33 | #include "t_context.h" |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 34 | #include "t_pipeline.h" |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 35 | #include "t_vp_build.h" |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame] | 36 | #include "t_vertex.h" |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 37 | |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 38 | void _tnl_install_pipeline( GLcontext *ctx, |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 39 | const struct tnl_pipeline_stage **stages ) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 40 | { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 41 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 42 | GLuint i; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 43 | |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 44 | tnl->pipeline.new_state = ~0; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 45 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 46 | /* Create a writeable copy of each stage. |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 47 | */ |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 48 | for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) { |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 49 | struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; |
| Brian Paul | e197de5 | 2010-02-19 08:09:01 -0700 | [diff] [blame^] | 50 | memcpy(s, stages[i], sizeof(*s)); |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 51 | if (s->create) |
| 52 | s->create(ctx, s); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 53 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 54 | |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 55 | tnl->pipeline.nr_stages = i; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 56 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 57 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 58 | void _tnl_destroy_pipeline( GLcontext *ctx ) |
| 59 | { |
| 60 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 61 | GLuint i; |
| 62 | |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 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 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 68 | |
| 69 | tnl->pipeline.nr_stages = 0; |
| 70 | } |
| 71 | |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 72 | |
| 73 | |
| 74 | static GLuint check_input_changes( GLcontext *ctx ) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 75 | { |
| 76 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 77 | GLuint i; |
| 78 | |
| Brian Paul | 94b30dc | 2006-04-25 00:53:25 +0000 | [diff] [blame] | 79 | for (i = 0; i <= _TNL_LAST_MAT; i++) { |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 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; |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 85 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 86 | } |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 87 | |
| 88 | return tnl->pipeline.input_changes; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame] | 92 | static GLuint check_output_changes( GLcontext *ctx ) |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 93 | { |
| 94 | #if 0 |
| 95 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 96 | |
| 97 | for (i = 0; i < VERT_RESULT_MAX; i++) { |
| 98 | if (tnl->vb.ResultPtr[i]->size != tnl->last_result_size[i] || |
| 99 | tnl->vb.ResultPtr[i]->stride != tnl->last_result_stride[i]) { |
| 100 | tnl->last_result_size[i] = tnl->vb.ResultPtr[i]->size; |
| 101 | tnl->last_result_stride[i] = tnl->vb.ResultPtr[i]->stride; |
| 102 | tnl->pipeline.output_changes |= 1<<i; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | if (tnl->pipeline.output_changes) |
| 107 | tnl->Driver.NotifyOutputChanges( ctx, tnl->pipeline.output_changes ); |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame] | 108 | |
| 109 | return tnl->pipeline.output_changes; |
| 110 | #else |
| 111 | return ~0; |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 112 | #endif |
| 113 | } |
| 114 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 115 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 116 | void _tnl_run_pipeline( GLcontext *ctx ) |
| 117 | { |
| 118 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 119 | unsigned short __tmp; |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 120 | GLuint i; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 121 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 122 | if (!tnl->vb.Count) |
| 123 | return; |
| 124 | |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 125 | /* Check for changed input sizes or change in stride to/from zero |
| 126 | * (ie const or non-const). |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 127 | */ |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 128 | if (check_input_changes( ctx ) || tnl->pipeline.new_state) { |
| Brian | a328e46 | 2006-12-13 14:58:13 -0700 | [diff] [blame] | 129 | if (ctx->VertexProgram._MaintainTnlProgram) |
| Keith Whitwell | 8103203 | 2005-06-09 14:55:34 +0000 | [diff] [blame] | 130 | _tnl_UpdateFixedFunctionProgram( ctx ); |
| Keith Whitwell | a661654 | 2005-04-22 13:02:04 +0000 | [diff] [blame] | 131 | |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 132 | for (i = 0; i < tnl->pipeline.nr_stages ; i++) { |
| 133 | struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; |
| 134 | if (s->validate) |
| 135 | s->validate( ctx, s ); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 136 | } |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 137 | |
| 138 | tnl->pipeline.new_state = 0; |
| 139 | tnl->pipeline.input_changes = 0; |
| Keith Whitwell | 2b2bd08 | 2005-05-18 15:26:48 +0000 | [diff] [blame] | 140 | |
| 141 | /* Pipeline can only change its output in response to either a |
| 142 | * statechange or an input size/stride change. No other changes |
| 143 | * are allowed. |
| 144 | */ |
| 145 | if (check_output_changes( ctx )) |
| 146 | _tnl_notify_pipeline_output_change( ctx ); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 147 | } |
| Keith Whitwell | c6b2a92 | 2001-02-15 01:33:52 +0000 | [diff] [blame] | 148 | |
| Keith Whitwell | 6f973f3 | 2005-04-22 12:51:19 +0000 | [diff] [blame] | 149 | START_FAST_MATH(__tmp); |
| 150 | |
| 151 | for (i = 0; i < tnl->pipeline.nr_stages ; i++) { |
| 152 | struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i]; |
| 153 | if (!s->run( ctx, s )) |
| 154 | break; |
| 155 | } |
| 156 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 157 | END_FAST_MATH(__tmp); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | |
| 161 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 162 | /* The default pipeline. This is useful for software rasterizers, and |
| 163 | * simple hardware rasterizers. For customization, I don't recommend |
| 164 | * tampering with the internals of these stages in the way that |
| 165 | * drivers did in Mesa 3.4. These stages are basically black boxes, |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 166 | * and should be left intact. |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 167 | * |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 168 | * To customize the pipeline, consider: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 169 | * |
| 170 | * - removing redundant stages (making sure that the software rasterizer |
| 171 | * can cope with this on fallback paths). An example is fog |
| 172 | * coordinate generation, which is not required in the FX driver. |
| 173 | * |
| 174 | * - replacing general-purpose machine-independent stages with |
| 175 | * general-purpose machine-specific stages. There is no example of |
| 176 | * this to date, though it must be borne in mind that all subsequent |
| 177 | * stages that reference the output of the new stage must cope with |
| 178 | * any machine-specific data introduced. This may not be easy |
| 179 | * unless there are no such stages (ie the new stage is the last in |
| 180 | * the pipe). |
| 181 | * |
| 182 | * - inserting optimized (but specialized) stages ahead of the |
| 183 | * general-purpose fallback implementation. For example, the old |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 184 | * fastpath mechanism, which only works when the VB->Elts input is |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 185 | * available, can be duplicated by placing the fastpath stage at the |
| 186 | * head of this pipeline. Such specialized stages are currently |
| 187 | * constrained to have no outputs (ie. they must either finish the * |
| 188 | * pipeline by returning GL_FALSE from run(), or do nothing). |
| 189 | * |
| 190 | * 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] | 191 | * case, if it becomes necessary to do so. |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 192 | */ |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 193 | const struct tnl_pipeline_stage *_tnl_default_pipeline[] = { |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 194 | &_tnl_vertex_transform_stage, |
| 195 | &_tnl_normal_transform_stage, |
| 196 | &_tnl_lighting_stage, |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 197 | &_tnl_texgen_stage, |
| 198 | &_tnl_texture_transform_stage, |
| 199 | &_tnl_point_attenuation_stage, |
| Keith Whitwell | 8103203 | 2005-06-09 14:55:34 +0000 | [diff] [blame] | 200 | &_tnl_vertex_program_stage, |
| H. Verbeet | e9d1889 | 2008-06-16 10:40:32 -0600 | [diff] [blame] | 201 | &_tnl_fog_coordinate_stage, |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 202 | &_tnl_render_stage, |
| Keith Whitwell | b97e478 | 2005-02-10 10:57:22 +0000 | [diff] [blame] | 203 | NULL |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 204 | }; |
| Keith Whitwell | 8103203 | 2005-06-09 14:55:34 +0000 | [diff] [blame] | 205 | |
| 206 | const struct tnl_pipeline_stage *_tnl_vp_pipeline[] = { |
| Brian | 4b3835d | 2007-04-16 10:58:30 -0600 | [diff] [blame] | 207 | &_tnl_vertex_program_stage, |
| Keith Whitwell | 8103203 | 2005-06-09 14:55:34 +0000 | [diff] [blame] | 208 | &_tnl_render_stage, |
| 209 | NULL |
| 210 | }; |