blob: 467074abaa30710dcef1deba91940fae3987e778 [file] [log] [blame]
Keith Whitwellc6b2a922001-02-15 01:33:52 +00001/* $Id: t_pipeline.c,v 1.12 2001/02/15 01:33:52 keithw 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 *
Keith Whitwell23caf202000-11-16 21:05:34 +00007 * Copyright (C) 1999-2000 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 *
26 * Author:
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
Keith Whitwellcab974c2000-12-26 05:09:27 +000044void _tnl_install_pipeline( GLcontext *ctx,
45 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 Whitwellcab974c2000-12-26 05:09:27 +000066 pipe->nr_stages = i;
67}
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000068
Keith Whitwellcab974c2000-12-26 05:09:27 +000069void _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
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +000080/* TODO: merge validate with run.
81 */
Keith Whitwellcab974c2000-12-26 05:09:27 +000082void _tnl_validate_pipeline( GLcontext *ctx )
83{
84 TNLcontext *tnl = TNL_CONTEXT(ctx);
85 struct gl_pipeline *pipe = &tnl->pipeline;
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +000086 struct gl_pipeline_stage *s = pipe->stages;
Keith Whitwellcab974c2000-12-26 05:09:27 +000087 GLuint newstate = pipe->build_state_changes;
88 GLuint generated = 0;
89 GLuint i;
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +000090 GLuint changed_inputs = 0;
Keith Whitwellcab974c2000-12-26 05:09:27 +000091
92 pipe->inputs = 0;
93 pipe->build_state_changes = 0;
94
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +000095 for (i = pipe->nr_stages+1 ; --i ; s++) {
96
97 s->changed_inputs |= s->inputs & changed_inputs;
98
99 if (s->check_state & newstate) {
100 if (s->active) {
101 GLuint old_outputs = s->outputs;
102 s->check(ctx, s);
103 if (!s->active)
104 changed_inputs |= old_outputs;
105 }
106 else
107 s->check(ctx, s);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000108 }
109
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000110 if (s->active) {
111 pipe->inputs |= s->inputs & ~generated;
112 generated |= s->outputs;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000113 }
114 }
115}
116
117
118
Keith Whitwellcab974c2000-12-26 05:09:27 +0000119void _tnl_run_pipeline( GLcontext *ctx )
120{
121 TNLcontext *tnl = TNL_CONTEXT(ctx);
122 struct gl_pipeline *pipe = &tnl->pipeline;
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000123 struct gl_pipeline_stage *s = pipe->stages;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000124 GLuint changed_state = pipe->run_state_changes;
125 GLuint changed_inputs = pipe->run_input_changes;
126 GLboolean running = GL_TRUE;
127 GLuint i;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000128 unsigned short __tmp;
129
130 /* Done elsewhere.
131 */
132 ASSERT(pipe->build_state_changes == 0);
133
134 START_FAST_MATH(__tmp);
Keith Whitwellc6b2a922001-02-15 01:33:52 +0000135 if (ctx->Driver.PipelineStart)
136 ctx->Driver.PipelineStart( ctx );
Keith Whitwell23caf202000-11-16 21:05:34 +0000137
138 /* If something changes in the pipeline, tag all subsequent stages
Keith Whitwellcab974c2000-12-26 05:09:27 +0000139 * using this value for recalculation.
Keith Whitwell23caf202000-11-16 21:05:34 +0000140 *
Keith Whitwellcab974c2000-12-26 05:09:27 +0000141 * Even inactive stages have their state and inputs examined to try
142 * to keep cached data alive over state-changes.
Keith Whitwell23caf202000-11-16 21:05:34 +0000143 */
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000144 for (i = pipe->nr_stages+1 ; --i ; s++) {
145 s->changed_inputs |= s->inputs & changed_inputs;
Keith Whitwell23caf202000-11-16 21:05:34 +0000146
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000147 if (s->run_state & changed_state) {
148/* changed_inputs |= s->check(ctx, s); */
149 s->changed_inputs = s->inputs;
Keith Whitwell23caf202000-11-16 21:05:34 +0000150 }
151
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000152 if (s->active) {
Keith Whitwellcab974c2000-12-26 05:09:27 +0000153 if (running) {
Keith Whitwell5c1e7fa2001-01-29 20:47:39 +0000154 if (s->changed_inputs)
155 changed_inputs |= s->outputs;
156
157/* fprintf(stderr, "run %s\n", s->name); */
158 running = s->run( ctx, s );
Keith Whitwell23caf202000-11-16 21:05:34 +0000159 }
160 }
161 }
Keith Whitwellc6b2a922001-02-15 01:33:52 +0000162
163 if (ctx->Driver.PipelineFinish)
164 ctx->Driver.PipelineFinish( ctx );
Keith Whitwellcab974c2000-12-26 05:09:27 +0000165 END_FAST_MATH(__tmp);
Keith Whitwell23caf202000-11-16 21:05:34 +0000166
Keith Whitwellcab974c2000-12-26 05:09:27 +0000167 pipe->run_state_changes = 0;
168 pipe->run_input_changes = 0;
Keith Whitwell23caf202000-11-16 21:05:34 +0000169}
170
171
172
Keith Whitwellcab974c2000-12-26 05:09:27 +0000173/* The default pipeline. This is useful for software rasterizers, and
174 * simple hardware rasterizers. For customization, I don't recommend
175 * tampering with the internals of these stages in the way that
176 * drivers did in Mesa 3.4. These stages are basically black boxes,
177 * and should be left intact.
178 *
179 * To customize the pipeline, consider:
180 *
181 * - removing redundant stages (making sure that the software rasterizer
182 * can cope with this on fallback paths). An example is fog
183 * coordinate generation, which is not required in the FX driver.
184 *
185 * - replacing general-purpose machine-independent stages with
186 * general-purpose machine-specific stages. There is no example of
187 * this to date, though it must be borne in mind that all subsequent
188 * stages that reference the output of the new stage must cope with
189 * any machine-specific data introduced. This may not be easy
190 * unless there are no such stages (ie the new stage is the last in
191 * the pipe).
192 *
193 * - inserting optimized (but specialized) stages ahead of the
194 * general-purpose fallback implementation. For example, the old
195 * fastpath mechanism, which only works when the VERT_ELT input is
196 * available, can be duplicated by placing the fastpath stage at the
197 * head of this pipeline. Such specialized stages are currently
198 * constrained to have no outputs (ie. they must either finish the *
199 * pipeline by returning GL_FALSE from run(), or do nothing).
200 *
201 * Some work can be done to lift some of the restrictions in the final
202 * case, if it becomes necessary to do so.
203 */
204const struct gl_pipeline_stage *_tnl_default_pipeline[] = {
205 &_tnl_update_material_stage,
206 &_tnl_vertex_transform_stage,
207 &_tnl_normal_transform_stage,
208 &_tnl_lighting_stage,
209 &_tnl_fog_coordinate_stage,
210 &_tnl_texgen_stage,
211 &_tnl_texture_transform_stage,
212 &_tnl_point_attenuation_stage,
213 &_tnl_render_stage,
214 0
215};
Keith Whitwell23caf202000-11-16 21:05:34 +0000216