blob: 6e39788f9d6e8638047b75d458953ada2af8a946 [file] [log] [blame]
Brian Paul86b84272001-12-14 02:50:01 +00001/* $Id: t_pipeline.c,v 1.20 2001/12/14 02:51:45 brianp Exp $ */
Keith Whitwell23caf202000-11-16 21:05:34 +00002
3/*
4 * Mesa 3-D graphics library
5 * Version: 3.5
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
Gareth Hughes22144ab2001-03-12 00:48:37 +00007 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00008 *
Keith Whitwell23caf202000-11-16 21:05:34 +00009 * 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 Jansen5e3bc0c2000-11-22 07:32:16 +000015 *
Keith Whitwell23caf202000-11-16 21:05:34 +000016 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000018 *
Keith Whitwell23caf202000-11-16 21:05:34 +000019 * 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 Whitwellcab974c2000-12-26 05:09:27 +000025 *
Gareth Hughes22144ab2001-03-12 00:48:37 +000026 * Authors:
27 * Keith Whitwell <keithw@valinux.com>
Keith Whitwell23caf202000-11-16 21:05:34 +000028 */
29
30#include "glheader.h"
31#include "context.h"
32#include "mem.h"
33#include "mmath.h"
34#include "state.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000035#include "mtypes.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000036
37#include "math/m_translate.h"
38#include "math/m_xform.h"
39
Keith Whitwellcab974c2000-12-26 05:09:27 +000040#include "t_context.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000041#include "t_pipeline.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000042
43
Gareth Hughes22144ab2001-03-12 00:48:37 +000044void _tnl_install_pipeline( GLcontext *ctx,
Keith Whitwellcab974c2000-12-26 05:09:27 +000045 const struct gl_pipeline_stage **stages )
Keith Whitwell23caf202000-11-16 21:05:34 +000046{
Keith Whitwell23caf202000-11-16 21:05:34 +000047 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +000048 struct gl_pipeline *pipe = &tnl->pipeline;
Keith Whitwell23caf202000-11-16 21:05:34 +000049 GLuint i;
Keith Whitwell23caf202000-11-16 21:05:34 +000050
Keith Whitwellcab974c2000-12-26 05:09:27 +000051 ASSERT(pipe->nr_stages == 0);
Keith Whitwell23caf202000-11-16 21:05:34 +000052
Keith Whitwellcab974c2000-12-26 05:09:27 +000053 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 Whitwell23caf202000-11-16 21:05:34 +000058
Keith Whitwellcab974c2000-12-26 05:09:27 +000059 /* Create a writeable copy of each stage.
Keith Whitwell23caf202000-11-16 21:05:34 +000060 */
Keith Whitwellcab974c2000-12-26 05:09:27 +000061 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 Whitwell23caf202000-11-16 21:05:34 +000064 }
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000065
Keith Whitwell7954a0c2001-05-10 12:18:38 +000066 MEMSET( &pipe->stages[i], 0, sizeof( **stages ));
67
Keith Whitwellcab974c2000-12-26 05:09:27 +000068 pipe->nr_stages = i;
69}
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000070
Keith Whitwellcab974c2000-12-26 05:09:27 +000071void _tnl_destroy_pipeline( GLcontext *ctx )
72{
73 TNLcontext *tnl = TNL_CONTEXT(ctx);
74 GLuint i;
75
Gareth Hughes22144ab2001-03-12 00:48:37 +000076 for (i = 0 ; i < tnl->pipeline.nr_stages ; i++)
Keith Whitwellcab974c2000-12-26 05:09:27 +000077 tnl->pipeline.stages[i].destroy( &tnl->pipeline.stages[i] );
78
79 tnl->pipeline.nr_stages = 0;
80}
81
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +000082/* TODO: merge validate with run.
83 */
Keith Whitwellcab974c2000-12-26 05:09:27 +000084void _tnl_validate_pipeline( GLcontext *ctx )
85{
86 TNLcontext *tnl = TNL_CONTEXT(ctx);
87 struct gl_pipeline *pipe = &tnl->pipeline;
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +000088 struct gl_pipeline_stage *s = pipe->stages;
Keith Whitwellcab974c2000-12-26 05:09:27 +000089 GLuint newstate = pipe->build_state_changes;
90 GLuint generated = 0;
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +000091 GLuint changed_inputs = 0;
Keith Whitwellcab974c2000-12-26 05:09:27 +000092
93 pipe->inputs = 0;
94 pipe->build_state_changes = 0;
95
Keith Whitwell7954a0c2001-05-10 12:18:38 +000096 for ( ; s->check ; s++) {
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +000097
98 s->changed_inputs |= s->inputs & changed_inputs;
Gareth Hughes22144ab2001-03-12 00:48:37 +000099
100 if (s->check_state & newstate) {
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000101 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 Hughes22144ab2001-03-12 00:48:37 +0000107 else
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000108 s->check(ctx, s);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000109 }
110
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000111 if (s->active) {
112 pipe->inputs |= s->inputs & ~generated;
113 generated |= s->outputs;
Gareth Hughes22144ab2001-03-12 00:48:37 +0000114 }
Keith Whitwellcab974c2000-12-26 05:09:27 +0000115 }
116}
117
118
119
Keith Whitwellcab974c2000-12-26 05:09:27 +0000120void _tnl_run_pipeline( GLcontext *ctx )
121{
122 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwell3004bf82001-04-19 12:23:07 +0000123 struct vertex_buffer *VB = &tnl->vb;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000124 struct gl_pipeline *pipe = &tnl->pipeline;
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000125 struct gl_pipeline_stage *s = pipe->stages;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000126 GLuint changed_state = pipe->run_state_changes;
127 GLuint changed_inputs = pipe->run_input_changes;
128 GLboolean running = GL_TRUE;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000129 unsigned short __tmp;
130
Keith Whitwell7954a0c2001-05-10 12:18:38 +0000131 pipe->run_state_changes = 0;
132 pipe->run_input_changes = 0;
133
Brian Paul86b84272001-12-14 02:50:01 +0000134 printf("%s()\n", __FUNCTION__);
135
Keith Whitwellcab974c2000-12-26 05:09:27 +0000136 /* Done elsewhere.
137 */
138 ASSERT(pipe->build_state_changes == 0);
Gareth Hughese7e38a42001-05-21 16:33:41 +0000139
Keith Whitwellcab974c2000-12-26 05:09:27 +0000140 START_FAST_MATH(__tmp);
Keith Whitwell23caf202000-11-16 21:05:34 +0000141
142 /* If something changes in the pipeline, tag all subsequent stages
Keith Whitwell7954a0c2001-05-10 12:18:38 +0000143 * using this value for recalculation. Inactive stages have their
144 * state and inputs examined to try to keep cached data alive over
Gareth Hughese7e38a42001-05-21 16:33:41 +0000145 * state-changes.
Keith Whitwell23caf202000-11-16 21:05:34 +0000146 */
Keith Whitwell7954a0c2001-05-10 12:18:38 +0000147 for ( ; s->run ; s++) {
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000148 s->changed_inputs |= s->inputs & changed_inputs;
Keith Whitwell23caf202000-11-16 21:05:34 +0000149
Gareth Hughese7e38a42001-05-21 16:33:41 +0000150 if (s->run_state & changed_state)
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000151 s->changed_inputs = s->inputs;
Keith Whitwell23caf202000-11-16 21:05:34 +0000152
Keith Whitwell7954a0c2001-05-10 12:18:38 +0000153 if (s->active && running) {
154 if (s->changed_inputs)
155 changed_inputs |= s->outputs;
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000156
Keith Whitwell7954a0c2001-05-10 12:18:38 +0000157 running = s->run( ctx, s );
Keith Whitwell16837e42001-04-30 09:04:00 +0000158
Keith Whitwell7954a0c2001-05-10 12:18:38 +0000159 s->changed_inputs = 0;
160 VB->importable_data &= ~s->outputs;
Keith Whitwell23caf202000-11-16 21:05:34 +0000161 }
162 }
Keith Whitwellc6b2a922001-02-15 01:33:52 +0000163
Keith Whitwellcab974c2000-12-26 05:09:27 +0000164 END_FAST_MATH(__tmp);
Keith Whitwell23caf202000-11-16 21:05:34 +0000165}
166
167
168
Keith Whitwellcab974c2000-12-26 05:09:27 +0000169/* The default pipeline. This is useful for software rasterizers, and
170 * simple hardware rasterizers. For customization, I don't recommend
171 * tampering with the internals of these stages in the way that
172 * drivers did in Mesa 3.4. These stages are basically black boxes,
Gareth Hughes22144ab2001-03-12 00:48:37 +0000173 * and should be left intact.
Keith Whitwellcab974c2000-12-26 05:09:27 +0000174 *
Gareth Hughes22144ab2001-03-12 00:48:37 +0000175 * To customize the pipeline, consider:
Keith Whitwellcab974c2000-12-26 05:09:27 +0000176 *
177 * - removing redundant stages (making sure that the software rasterizer
178 * can cope with this on fallback paths). An example is fog
179 * coordinate generation, which is not required in the FX driver.
180 *
181 * - replacing general-purpose machine-independent stages with
182 * general-purpose machine-specific stages. There is no example of
183 * this to date, though it must be borne in mind that all subsequent
184 * stages that reference the output of the new stage must cope with
185 * any machine-specific data introduced. This may not be easy
186 * unless there are no such stages (ie the new stage is the last in
187 * the pipe).
188 *
189 * - inserting optimized (but specialized) stages ahead of the
190 * general-purpose fallback implementation. For example, the old
191 * fastpath mechanism, which only works when the VERT_ELT input is
192 * available, can be duplicated by placing the fastpath stage at the
193 * head of this pipeline. Such specialized stages are currently
194 * constrained to have no outputs (ie. they must either finish the *
195 * pipeline by returning GL_FALSE from run(), or do nothing).
196 *
197 * Some work can be done to lift some of the restrictions in the final
Gareth Hughes22144ab2001-03-12 00:48:37 +0000198 * case, if it becomes necessary to do so.
Keith Whitwellcab974c2000-12-26 05:09:27 +0000199 */
200const struct gl_pipeline_stage *_tnl_default_pipeline[] = {
Gareth Hughes22144ab2001-03-12 00:48:37 +0000201 &_tnl_vertex_transform_stage,
202 &_tnl_normal_transform_stage,
203 &_tnl_lighting_stage,
204 &_tnl_fog_coordinate_stage,
205 &_tnl_texgen_stage,
206 &_tnl_texture_transform_stage,
207 &_tnl_point_attenuation_stage,
Brian Paul86b84272001-12-14 02:50:01 +0000208 &_tnl_vertex_program_stage,
Keith Whitwellcab974c2000-12-26 05:09:27 +0000209 &_tnl_render_stage,
210 0
211};