| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 1 | /* $Id: t_pipeline.c,v 1.7 2000/12/26 05:09:33 keithw 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 | * |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 7 | * Copyright (C) 1999-2000 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 | * |
| 26 | * Author: |
| 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 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 44 | void _tnl_install_pipeline( GLcontext *ctx, |
| 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 | 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 | |
| 74 | for (i = 0 ; i < tnl->pipeline.nr_stages ; i++) |
| 75 | tnl->pipeline.stages[i].destroy( &tnl->pipeline.stages[i] ); |
| 76 | |
| 77 | tnl->pipeline.nr_stages = 0; |
| 78 | } |
| 79 | |
| 80 | |
| 81 | |
| 82 | void _tnl_validate_pipeline( GLcontext *ctx ) |
| 83 | { |
| 84 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 85 | struct gl_pipeline *pipe = &tnl->pipeline; |
| 86 | struct gl_pipeline_stage *stage = pipe->stages; |
| 87 | GLuint newstate = pipe->build_state_changes; |
| 88 | GLuint generated = 0; |
| 89 | GLuint i; |
| 90 | |
| 91 | pipe->inputs = 0; |
| 92 | pipe->build_state_changes = 0; |
| 93 | |
| 94 | for (i = 0 ; i < pipe->nr_stages ; i++) { |
| 95 | if (stage[i].check_state & newstate) { |
| 96 | stage[i].check(ctx, &stage[i]); |
| 97 | } |
| 98 | |
| 99 | if (stage[i].active) { |
| 100 | pipe->inputs |= stage[i].inputs & ~generated; |
| 101 | generated |= stage[i].outputs; |
| 102 | } |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | |
| 107 | |
| 108 | |
| 109 | void _tnl_run_pipeline( GLcontext *ctx ) |
| 110 | { |
| 111 | TNLcontext *tnl = TNL_CONTEXT(ctx); |
| 112 | struct gl_pipeline *pipe = &tnl->pipeline; |
| 113 | struct gl_pipeline_stage *stage = pipe->stages; |
| 114 | GLuint changed_state = pipe->run_state_changes; |
| 115 | GLuint changed_inputs = pipe->run_input_changes; |
| 116 | GLboolean running = GL_TRUE; |
| 117 | GLuint i; |
| 118 | |
| 119 | unsigned short __tmp; |
| 120 | |
| 121 | /* Done elsewhere. |
| 122 | */ |
| 123 | ASSERT(pipe->build_state_changes == 0); |
| 124 | |
| 125 | START_FAST_MATH(__tmp); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 126 | |
| 127 | /* If something changes in the pipeline, tag all subsequent stages |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 128 | * using this value for recalculation. |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 129 | * |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 130 | * Even inactive stages have their state and inputs examined to try |
| 131 | * to keep cached data alive over state-changes. |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 132 | */ |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 133 | for (i = 0 ; i < pipe->nr_stages ; i++) { |
| 134 | |
| 135 | stage[i].changed_inputs |= stage[i].inputs & changed_inputs; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 136 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 137 | if (stage[i].run_state & changed_state) { |
| 138 | stage[i].changed_inputs = stage[i].inputs; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 139 | } |
| 140 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 141 | if (stage[i].active) { |
| 142 | if (stage[i].changed_inputs) |
| 143 | changed_inputs |= stage[i].outputs; |
| 144 | |
| 145 | if (running) { |
| 146 | running = stage[i].run( ctx, &stage[i] ); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 147 | } |
| 148 | } |
| 149 | } |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 150 | END_FAST_MATH(__tmp); |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 151 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 152 | pipe->run_state_changes = 0; |
| 153 | pipe->run_input_changes = 0; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | |
| 157 | |
| Keith Whitwell | cab974c | 2000-12-26 05:09:27 +0000 | [diff] [blame^] | 158 | /* The default pipeline. This is useful for software rasterizers, and |
| 159 | * simple hardware rasterizers. For customization, I don't recommend |
| 160 | * tampering with the internals of these stages in the way that |
| 161 | * drivers did in Mesa 3.4. These stages are basically black boxes, |
| 162 | * and should be left intact. |
| 163 | * |
| 164 | * To customize the pipeline, consider: |
| 165 | * |
| 166 | * - removing redundant stages (making sure that the software rasterizer |
| 167 | * can cope with this on fallback paths). An example is fog |
| 168 | * coordinate generation, which is not required in the FX driver. |
| 169 | * |
| 170 | * - replacing general-purpose machine-independent stages with |
| 171 | * general-purpose machine-specific stages. There is no example of |
| 172 | * this to date, though it must be borne in mind that all subsequent |
| 173 | * stages that reference the output of the new stage must cope with |
| 174 | * any machine-specific data introduced. This may not be easy |
| 175 | * unless there are no such stages (ie the new stage is the last in |
| 176 | * the pipe). |
| 177 | * |
| 178 | * - inserting optimized (but specialized) stages ahead of the |
| 179 | * general-purpose fallback implementation. For example, the old |
| 180 | * fastpath mechanism, which only works when the VERT_ELT input is |
| 181 | * available, can be duplicated by placing the fastpath stage at the |
| 182 | * head of this pipeline. Such specialized stages are currently |
| 183 | * constrained to have no outputs (ie. they must either finish the * |
| 184 | * pipeline by returning GL_FALSE from run(), or do nothing). |
| 185 | * |
| 186 | * Some work can be done to lift some of the restrictions in the final |
| 187 | * case, if it becomes necessary to do so. |
| 188 | */ |
| 189 | const struct gl_pipeline_stage *_tnl_default_pipeline[] = { |
| 190 | &_tnl_update_material_stage, |
| 191 | &_tnl_vertex_transform_stage, |
| 192 | &_tnl_normal_transform_stage, |
| 193 | &_tnl_lighting_stage, |
| 194 | &_tnl_fog_coordinate_stage, |
| 195 | &_tnl_texgen_stage, |
| 196 | &_tnl_texture_transform_stage, |
| 197 | &_tnl_point_attenuation_stage, |
| 198 | &_tnl_render_stage, |
| 199 | 0 |
| 200 | }; |
| Keith Whitwell | 23caf20 | 2000-11-16 21:05:34 +0000 | [diff] [blame] | 201 | |