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