1 /* $Id: t_pipeline.c,v 1.20 2001/12/14 02:51:45 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2001 Brian Paul All Rights Reserved.
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:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
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.
27 * Keith Whitwell <keithw@valinux.com>
37 #include "math/m_translate.h"
38 #include "math/m_xform.h"
40 #include "t_context.h"
41 #include "t_pipeline.h"
44 void _tnl_install_pipeline( GLcontext
*ctx
,
45 const struct gl_pipeline_stage
**stages
)
47 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
48 struct gl_pipeline
*pipe
= &tnl
->pipeline
;
51 ASSERT(pipe
->nr_stages
== 0);
53 pipe
->run_state_changes
= ~0;
54 pipe
->run_input_changes
= ~0;
55 pipe
->build_state_changes
= ~0;
56 pipe
->build_state_trigger
= 0;
59 /* Create a writeable copy of each stage.
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
;
66 MEMSET( &pipe
->stages
[i
], 0, sizeof( **stages
));
71 void _tnl_destroy_pipeline( GLcontext
*ctx
)
73 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
76 for (i
= 0 ; i
< tnl
->pipeline
.nr_stages
; i
++)
77 tnl
->pipeline
.stages
[i
].destroy( &tnl
->pipeline
.stages
[i
] );
79 tnl
->pipeline
.nr_stages
= 0;
82 /* TODO: merge validate with run.
84 void _tnl_validate_pipeline( GLcontext
*ctx
)
86 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
87 struct gl_pipeline
*pipe
= &tnl
->pipeline
;
88 struct gl_pipeline_stage
*s
= pipe
->stages
;
89 GLuint newstate
= pipe
->build_state_changes
;
91 GLuint changed_inputs
= 0;
94 pipe
->build_state_changes
= 0;
96 for ( ; s
->check
; s
++) {
98 s
->changed_inputs
|= s
->inputs
& changed_inputs
;
100 if (s
->check_state
& newstate
) {
102 GLuint old_outputs
= s
->outputs
;
105 changed_inputs
|= old_outputs
;
112 pipe
->inputs
|= s
->inputs
& ~generated
;
113 generated
|= s
->outputs
;
120 void _tnl_run_pipeline( GLcontext
*ctx
)
122 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
123 struct vertex_buffer
*VB
= &tnl
->vb
;
124 struct gl_pipeline
*pipe
= &tnl
->pipeline
;
125 struct gl_pipeline_stage
*s
= pipe
->stages
;
126 GLuint changed_state
= pipe
->run_state_changes
;
127 GLuint changed_inputs
= pipe
->run_input_changes
;
128 GLboolean running
= GL_TRUE
;
129 unsigned short __tmp
;
131 pipe
->run_state_changes
= 0;
132 pipe
->run_input_changes
= 0;
134 printf("%s()\n", __FUNCTION__
);
138 ASSERT(pipe
->build_state_changes
== 0);
140 START_FAST_MATH(__tmp
);
142 /* If something changes in the pipeline, tag all subsequent stages
143 * using this value for recalculation. Inactive stages have their
144 * state and inputs examined to try to keep cached data alive over
147 for ( ; s
->run
; s
++) {
148 s
->changed_inputs
|= s
->inputs
& changed_inputs
;
150 if (s
->run_state
& changed_state
)
151 s
->changed_inputs
= s
->inputs
;
153 if (s
->active
&& running
) {
154 if (s
->changed_inputs
)
155 changed_inputs
|= s
->outputs
;
157 running
= s
->run( ctx
, s
);
159 s
->changed_inputs
= 0;
160 VB
->importable_data
&= ~s
->outputs
;
164 END_FAST_MATH(__tmp
);
169 /* 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,
173 * and should be left intact.
175 * To customize the pipeline, consider:
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.
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
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).
197 * Some work can be done to lift some of the restrictions in the final
198 * case, if it becomes necessary to do so.
200 const struct gl_pipeline_stage
*_tnl_default_pipeline
[] = {
201 &_tnl_vertex_transform_stage
,
202 &_tnl_normal_transform_stage
,
203 &_tnl_lighting_stage
,
204 &_tnl_fog_coordinate_stage
,
206 &_tnl_texture_transform_stage
,
207 &_tnl_point_attenuation_stage
,
208 &_tnl_vertex_program_stage
,