| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 1 | |
| 2 | /* |
| 3 | * Mesa 3-D graphics library |
| Brian Paul | 27558a1 | 2003-03-01 01:50:20 +0000 | [diff] [blame] | 4 | * Version: 5.1 |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 5 | * |
| Brian Paul | 27558a1 | 2003-03-01 01:50:20 +0000 | [diff] [blame] | 6 | * Copyright (C) 1999-2003 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 | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 40 | |
| 41 | |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 42 | void _tnl_install_pipeline( GLcontext *ctx, |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 43 | const struct tnl_pipeline_stage **stages ) |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 44 | { |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 45 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 46 | struct tnl_pipeline *pipe = &tnl->pipeline; |
| 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 | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 49 | ASSERT(pipe->nr_stages == 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 | pipe->run_state_changes = ~0; |
| 52 | pipe->run_input_changes = ~0; |
| 53 | pipe->build_state_changes = ~0; |
| 54 | pipe->build_state_trigger = 0; |
| 55 | pipe->inputs = 0; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 56 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 57 | /* Create a writeable copy of each stage. |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 58 | */ |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 59 | for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) { |
| 60 | MEMCPY( &pipe->stages[i], stages[i], sizeof( **stages )); |
| 61 | pipe->build_state_trigger |= pipe->stages[i].check_state; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 62 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 63 | |
| Keith Whitwell | 7954a0c | 2001-05-10 12:18:38 +0000 | [diff] [blame] | 64 | MEMSET( &pipe->stages[i], 0, sizeof( **stages )); |
| 65 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 66 | pipe->nr_stages = i; |
| 67 | } |
| Jouk Jansen | 5e3bc0c | 2000-11-22 07:32:16 +0000 | [diff] [blame] | 68 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 69 | void _tnl_destroy_pipeline( GLcontext *ctx ) |
| 70 | { |
| 71 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 72 | GLuint i; |
| 73 | |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 74 | for (i = 0 ; i < tnl->pipeline.nr_stages ; i++) |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 75 | tnl->pipeline.stages[i].destroy( &tnl->pipeline.stages[i] ); |
| 76 | |
| 77 | tnl->pipeline.nr_stages = 0; |
| 78 | } |
| 79 | |
| Keith Whitwell | 5c1e7fa | 2001-01-29 20:47:39 +0000 | [diff] [blame] | 80 | /* TODO: merge validate with run. |
| 81 | */ |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 82 | void _tnl_validate_pipeline( GLcontext *ctx ) |
| 83 | { |
| 84 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 85 | struct tnl_pipeline *pipe = &tnl->pipeline; |
| 86 | struct tnl_pipeline_stage *s = pipe->stages; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 87 | GLuint newstate = pipe->build_state_changes; |
| 88 | GLuint generated = 0; |
| Keith Whitwell | 5c1e7fa | 2001-01-29 20:47:39 +0000 | [diff] [blame] | 89 | GLuint changed_inputs = 0; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 90 | |
| 91 | pipe->inputs = 0; |
| 92 | pipe->build_state_changes = 0; |
| 93 | |
| Keith Whitwell | 7954a0c | 2001-05-10 12:18:38 +0000 | [diff] [blame] | 94 | for ( ; s->check ; s++) { |
| Keith Whitwell | 5c1e7fa | 2001-01-29 20:47:39 +0000 | [diff] [blame] | 95 | |
| 96 | s->changed_inputs |= s->inputs & changed_inputs; |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 97 | |
| 98 | if (s->check_state & newstate) { |
| Keith Whitwell | 5c1e7fa | 2001-01-29 20:47:39 +0000 | [diff] [blame] | 99 | if (s->active) { |
| 100 | GLuint old_outputs = s->outputs; |
| 101 | s->check(ctx, s); |
| 102 | if (!s->active) |
| 103 | changed_inputs |= old_outputs; |
| 104 | } |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 105 | else |
| Keith Whitwell | 5c1e7fa | 2001-01-29 20:47:39 +0000 | [diff] [blame] | 106 | s->check(ctx, s); |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 107 | } |
| 108 | |
| Keith Whitwell | 5c1e7fa | 2001-01-29 20:47:39 +0000 | [diff] [blame] | 109 | if (s->active) { |
| 110 | pipe->inputs |= s->inputs & ~generated; |
| 111 | generated |= s->outputs; |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 112 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 113 | } |
| 114 | } |
| 115 | |
| 116 | |
| 117 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 118 | void _tnl_run_pipeline( GLcontext *ctx ) |
| 119 | { |
| 120 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 121 | struct tnl_pipeline *pipe = &tnl->pipeline; |
| 122 | struct tnl_pipeline_stage *s = pipe->stages; |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 123 | GLuint changed_state = pipe->run_state_changes; |
| 124 | GLuint changed_inputs = pipe->run_input_changes; |
| 125 | GLboolean running = GL_TRUE; |
| Brian Paul | b305028 | 2003-12-04 03:19:46 +0000 | [diff] [blame] | 126 | #ifdef HAVE_FAST_MATH |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 127 | unsigned short __tmp; |
| Brian Paul | b305028 | 2003-12-04 03:19:46 +0000 | [diff] [blame] | 128 | #endif |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 129 | |
| Keith Whitwell | 7907340 | 2004-01-05 09:43:42 +0000 | [diff] [blame] | 130 | if (!tnl->vb.Count) |
| 131 | return; |
| 132 | |
| Keith Whitwell | 7954a0c | 2001-05-10 12:18:38 +0000 | [diff] [blame] | 133 | pipe->run_state_changes = 0; |
| 134 | pipe->run_input_changes = 0; |
| 135 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 136 | /* Done elsewhere. |
| 137 | */ |
| 138 | ASSERT(pipe->build_state_changes == 0); |
| Gareth Hughes | e7e38a4 | 2001-05-21 16:33:41 +0000 | [diff] [blame] | 139 | |
| Brian Paul | b305028 | 2003-12-04 03:19:46 +0000 | [diff] [blame] | 140 | #ifdef HAVE_FAST_MATH |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 141 | START_FAST_MATH(__tmp); |
| Brian Paul | b305028 | 2003-12-04 03:19:46 +0000 | [diff] [blame] | 142 | #endif |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 143 | |
| 144 | /* If something changes in the pipeline, tag all subsequent stages |
| Keith Whitwell | 7954a0c | 2001-05-10 12:18:38 +0000 | [diff] [blame] | 145 | * using this value for recalculation. Inactive stages have their |
| 146 | * state and inputs examined to try to keep cached data alive over |
| Gareth Hughes | e7e38a4 | 2001-05-21 16:33:41 +0000 | [diff] [blame] | 147 | * state-changes. |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 148 | */ |
| Keith Whitwell | 7954a0c | 2001-05-10 12:18:38 +0000 | [diff] [blame] | 149 | for ( ; s->run ; s++) { |
| Keith Whitwell | 5c1e7fa | 2001-01-29 20:47:39 +0000 | [diff] [blame] | 150 | s->changed_inputs |= s->inputs & changed_inputs; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 151 | |
| Gareth Hughes | e7e38a4 | 2001-05-21 16:33:41 +0000 | [diff] [blame] | 152 | if (s->run_state & changed_state) |
| Keith Whitwell | 5c1e7fa | 2001-01-29 20:47:39 +0000 | [diff] [blame] | 153 | s->changed_inputs = s->inputs; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 154 | |
| Keith Whitwell | 7954a0c | 2001-05-10 12:18:38 +0000 | [diff] [blame] | 155 | if (s->active && running) { |
| 156 | if (s->changed_inputs) |
| 157 | changed_inputs |= s->outputs; |
| Keith Whitwell | 5c1e7fa | 2001-01-29 20:47:39 +0000 | [diff] [blame] | 158 | |
| Keith Whitwell | 7954a0c | 2001-05-10 12:18:38 +0000 | [diff] [blame] | 159 | running = s->run( ctx, s ); |
| Keith Whitwell | 16837e4 | 2001-04-30 09:04:00 +0000 | [diff] [blame] | 160 | |
| Keith Whitwell | 7954a0c | 2001-05-10 12:18:38 +0000 | [diff] [blame] | 161 | s->changed_inputs = 0; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 162 | } |
| 163 | } |
| Keith Whitwell | c6b2a92 | 2001-02-15 01:33:52 +0000 | [diff] [blame] | 164 | |
| Brian Paul | b305028 | 2003-12-04 03:19:46 +0000 | [diff] [blame] | 165 | #ifdef HAVE_FAST_MATH |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 166 | END_FAST_MATH(__tmp); |
| Brian Paul | b305028 | 2003-12-04 03:19:46 +0000 | [diff] [blame] | 167 | #endif |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | |
| 171 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 172 | /* The default pipeline. This is useful for software rasterizers, and |
| 173 | * simple hardware rasterizers. For customization, I don't recommend |
| 174 | * tampering with the internals of these stages in the way that |
| 175 | * drivers did in Mesa 3.4. These stages are basically black boxes, |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 176 | * and should be left intact. |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 177 | * |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 178 | * To customize the pipeline, consider: |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 179 | * |
| 180 | * - removing redundant stages (making sure that the software rasterizer |
| 181 | * can cope with this on fallback paths). An example is fog |
| 182 | * coordinate generation, which is not required in the FX driver. |
| 183 | * |
| 184 | * - replacing general-purpose machine-independent stages with |
| 185 | * general-purpose machine-specific stages. There is no example of |
| 186 | * this to date, though it must be borne in mind that all subsequent |
| 187 | * stages that reference the output of the new stage must cope with |
| 188 | * any machine-specific data introduced. This may not be easy |
| 189 | * unless there are no such stages (ie the new stage is the last in |
| 190 | * the pipe). |
| 191 | * |
| 192 | * - inserting optimized (but specialized) stages ahead of the |
| 193 | * general-purpose fallback implementation. For example, the old |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 194 | * fastpath mechanism, which only works when the VB->Elts input is |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 195 | * available, can be duplicated by placing the fastpath stage at the |
| 196 | * head of this pipeline. Such specialized stages are currently |
| 197 | * constrained to have no outputs (ie. they must either finish the * |
| 198 | * pipeline by returning GL_FALSE from run(), or do nothing). |
| 199 | * |
| 200 | * 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] | 201 | * case, if it becomes necessary to do so. |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 202 | */ |
| Keith Whitwell | ae0eaf9 | 2003-11-24 15:23:18 +0000 | [diff] [blame] | 203 | const struct tnl_pipeline_stage *_tnl_default_pipeline[] = { |
| Gareth Hughes | 22144ab | 2001-03-12 00:48:37 +0000 | [diff] [blame] | 204 | &_tnl_vertex_transform_stage, |
| 205 | &_tnl_normal_transform_stage, |
| 206 | &_tnl_lighting_stage, |
| 207 | &_tnl_fog_coordinate_stage, |
| 208 | &_tnl_texgen_stage, |
| 209 | &_tnl_texture_transform_stage, |
| 210 | &_tnl_point_attenuation_stage, |
| Brian Paul | 1e71d2a | 2004-01-31 19:49:10 +0000 | [diff] [blame] | 211 | #if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program) |
| Brian Paul | 86b8427 | 2001-12-14 02:50:01 +0000 | [diff] [blame] | 212 | &_tnl_vertex_program_stage, |
| Brian Paul | 8dfc5b9 | 2002-10-16 17:57:51 +0000 | [diff] [blame] | 213 | #endif |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 214 | &_tnl_render_stage, |
| Keith Whitwell | b97e478 | 2005-02-10 10:57:22 +0000 | [diff] [blame^] | 215 | NULL |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame] | 216 | }; |