2000-11-16 21:05:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mesa 3-D graphics library
|
2003-03-01 01:50:20 +00:00
|
|
|
* Version: 5.1
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
2003-03-01 01:50:20 +00:00
|
|
|
* Copyright (C) 1999-2003 Brian Paul All Rights Reserved.
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
2000-11-16 21:05:34 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
2000-11-16 21:05:34 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
2000-11-16 21:05:34 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
|
|
|
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
* BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
|
|
|
|
* AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2000-12-26 05:09:27 +00:00
|
|
|
*
|
2001-03-12 00:48:37 +00:00
|
|
|
* Authors:
|
2002-10-29 20:28:36 +00:00
|
|
|
* Keith Whitwell <keith@tungstengraphics.com>
|
2000-11-16 21:05:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "glheader.h"
|
|
|
|
#include "context.h"
|
2002-10-24 23:57:19 +00:00
|
|
|
#include "imports.h"
|
2000-11-16 21:05:34 +00:00
|
|
|
#include "state.h"
|
2000-11-22 07:32:16 +00:00
|
|
|
#include "mtypes.h"
|
2000-11-16 21:05:34 +00:00
|
|
|
|
|
|
|
#include "math/m_translate.h"
|
|
|
|
#include "math/m_xform.h"
|
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
#include "t_context.h"
|
2000-11-16 21:05:34 +00:00
|
|
|
#include "t_pipeline.h"
|
|
|
|
|
|
|
|
|
2001-03-12 00:48:37 +00:00
|
|
|
void _tnl_install_pipeline( GLcontext *ctx,
|
2000-12-26 05:09:27 +00:00
|
|
|
const struct gl_pipeline_stage **stages )
|
2000-11-16 21:05:34 +00:00
|
|
|
{
|
|
|
|
TNLcontext *tnl = TNL_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
struct gl_pipeline *pipe = &tnl->pipeline;
|
2000-11-16 21:05:34 +00:00
|
|
|
GLuint i;
|
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
ASSERT(pipe->nr_stages == 0);
|
2000-11-16 21:05:34 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
pipe->run_state_changes = ~0;
|
|
|
|
pipe->run_input_changes = ~0;
|
|
|
|
pipe->build_state_changes = ~0;
|
|
|
|
pipe->build_state_trigger = 0;
|
|
|
|
pipe->inputs = 0;
|
2000-11-16 21:05:34 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
/* Create a writeable copy of each stage.
|
2000-11-16 21:05:34 +00:00
|
|
|
*/
|
2000-12-26 05:09:27 +00:00
|
|
|
for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) {
|
|
|
|
MEMCPY( &pipe->stages[i], stages[i], sizeof( **stages ));
|
|
|
|
pipe->build_state_trigger |= pipe->stages[i].check_state;
|
2000-11-16 21:05:34 +00:00
|
|
|
}
|
2000-11-22 07:32:16 +00:00
|
|
|
|
2001-05-10 12:18:38 +00:00
|
|
|
MEMSET( &pipe->stages[i], 0, sizeof( **stages ));
|
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
pipe->nr_stages = i;
|
2000-11-16 21:05:34 +00:00
|
|
|
}
|
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
void _tnl_destroy_pipeline( GLcontext *ctx )
|
2000-11-16 21:05:34 +00:00
|
|
|
{
|
|
|
|
TNLcontext *tnl = TNL_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
GLuint i;
|
2000-11-22 07:32:16 +00:00
|
|
|
|
2001-03-12 00:48:37 +00:00
|
|
|
for (i = 0 ; i < tnl->pipeline.nr_stages ; i++)
|
2000-12-26 05:09:27 +00:00
|
|
|
tnl->pipeline.stages[i].destroy( &tnl->pipeline.stages[i] );
|
2000-11-22 07:32:16 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
tnl->pipeline.nr_stages = 0;
|
2000-11-16 21:05:34 +00:00
|
|
|
}
|
|
|
|
|
2001-01-29 20:47:39 +00:00
|
|
|
/* TODO: merge validate with run.
|
|
|
|
*/
|
2000-12-26 05:09:27 +00:00
|
|
|
void _tnl_validate_pipeline( GLcontext *ctx )
|
2000-11-16 21:05:34 +00:00
|
|
|
{
|
|
|
|
TNLcontext *tnl = TNL_CONTEXT(ctx);
|
2000-12-26 05:09:27 +00:00
|
|
|
struct gl_pipeline *pipe = &tnl->pipeline;
|
2001-01-29 20:47:39 +00:00
|
|
|
struct gl_pipeline_stage *s = pipe->stages;
|
2000-12-26 05:09:27 +00:00
|
|
|
GLuint newstate = pipe->build_state_changes;
|
2000-11-16 21:05:34 +00:00
|
|
|
GLuint generated = 0;
|
2001-01-29 20:47:39 +00:00
|
|
|
GLuint changed_inputs = 0;
|
2000-11-16 21:05:34 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
pipe->inputs = 0;
|
|
|
|
pipe->build_state_changes = 0;
|
2000-11-16 21:05:34 +00:00
|
|
|
|
2001-05-10 12:18:38 +00:00
|
|
|
for ( ; s->check ; s++) {
|
2001-01-29 20:47:39 +00:00
|
|
|
|
|
|
|
s->changed_inputs |= s->inputs & changed_inputs;
|
2001-03-12 00:48:37 +00:00
|
|
|
|
|
|
|
if (s->check_state & newstate) {
|
2001-01-29 20:47:39 +00:00
|
|
|
if (s->active) {
|
|
|
|
GLuint old_outputs = s->outputs;
|
|
|
|
s->check(ctx, s);
|
|
|
|
if (!s->active)
|
|
|
|
changed_inputs |= old_outputs;
|
|
|
|
}
|
2001-03-12 00:48:37 +00:00
|
|
|
else
|
2001-01-29 20:47:39 +00:00
|
|
|
s->check(ctx, s);
|
2000-11-16 21:05:34 +00:00
|
|
|
}
|
|
|
|
|
2001-01-29 20:47:39 +00:00
|
|
|
if (s->active) {
|
|
|
|
pipe->inputs |= s->inputs & ~generated;
|
|
|
|
generated |= s->outputs;
|
2001-03-12 00:48:37 +00:00
|
|
|
}
|
2000-11-16 21:05:34 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
void _tnl_run_pipeline( GLcontext *ctx )
|
2000-11-16 21:05:34 +00:00
|
|
|
{
|
|
|
|
TNLcontext *tnl = TNL_CONTEXT(ctx);
|
2001-04-19 12:23:07 +00:00
|
|
|
struct vertex_buffer *VB = &tnl->vb;
|
2000-12-26 05:09:27 +00:00
|
|
|
struct gl_pipeline *pipe = &tnl->pipeline;
|
2001-01-29 20:47:39 +00:00
|
|
|
struct gl_pipeline_stage *s = pipe->stages;
|
2000-12-26 05:09:27 +00:00
|
|
|
GLuint changed_state = pipe->run_state_changes;
|
|
|
|
GLuint changed_inputs = pipe->run_input_changes;
|
|
|
|
GLboolean running = GL_TRUE;
|
|
|
|
unsigned short __tmp;
|
2000-11-16 21:05:34 +00:00
|
|
|
|
2001-05-10 12:18:38 +00:00
|
|
|
pipe->run_state_changes = 0;
|
|
|
|
pipe->run_input_changes = 0;
|
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
/* Done elsewhere.
|
|
|
|
*/
|
|
|
|
ASSERT(pipe->build_state_changes == 0);
|
2001-05-21 16:33:41 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
START_FAST_MATH(__tmp);
|
2000-11-22 07:32:16 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
/* If something changes in the pipeline, tag all subsequent stages
|
2001-05-10 12:18:38 +00:00
|
|
|
* using this value for recalculation. Inactive stages have their
|
|
|
|
* state and inputs examined to try to keep cached data alive over
|
2001-05-21 16:33:41 +00:00
|
|
|
* state-changes.
|
2000-12-26 05:09:27 +00:00
|
|
|
*/
|
2001-05-10 12:18:38 +00:00
|
|
|
for ( ; s->run ; s++) {
|
2001-01-29 20:47:39 +00:00
|
|
|
s->changed_inputs |= s->inputs & changed_inputs;
|
2000-11-16 21:05:34 +00:00
|
|
|
|
2001-05-21 16:33:41 +00:00
|
|
|
if (s->run_state & changed_state)
|
2001-01-29 20:47:39 +00:00
|
|
|
s->changed_inputs = s->inputs;
|
2000-11-22 07:32:16 +00:00
|
|
|
|
2001-05-10 12:18:38 +00:00
|
|
|
if (s->active && running) {
|
|
|
|
if (s->changed_inputs)
|
|
|
|
changed_inputs |= s->outputs;
|
2001-01-29 20:47:39 +00:00
|
|
|
|
2001-05-10 12:18:38 +00:00
|
|
|
running = s->run( ctx, s );
|
2001-04-30 09:04:00 +00:00
|
|
|
|
2001-05-10 12:18:38 +00:00
|
|
|
s->changed_inputs = 0;
|
|
|
|
VB->importable_data &= ~s->outputs;
|
2000-11-16 21:05:34 +00:00
|
|
|
}
|
|
|
|
}
|
2001-02-15 01:33:52 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
END_FAST_MATH(__tmp);
|
2000-11-16 21:05:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2000-11-22 07:32:16 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
/* The default pipeline. This is useful for software rasterizers, and
|
|
|
|
* simple hardware rasterizers. For customization, I don't recommend
|
|
|
|
* tampering with the internals of these stages in the way that
|
|
|
|
* drivers did in Mesa 3.4. These stages are basically black boxes,
|
2001-03-12 00:48:37 +00:00
|
|
|
* and should be left intact.
|
2000-12-26 05:09:27 +00:00
|
|
|
*
|
2001-03-12 00:48:37 +00:00
|
|
|
* To customize the pipeline, consider:
|
2000-12-26 05:09:27 +00:00
|
|
|
*
|
|
|
|
* - removing redundant stages (making sure that the software rasterizer
|
|
|
|
* can cope with this on fallback paths). An example is fog
|
|
|
|
* coordinate generation, which is not required in the FX driver.
|
|
|
|
*
|
|
|
|
* - replacing general-purpose machine-independent stages with
|
|
|
|
* general-purpose machine-specific stages. There is no example of
|
|
|
|
* this to date, though it must be borne in mind that all subsequent
|
|
|
|
* stages that reference the output of the new stage must cope with
|
|
|
|
* any machine-specific data introduced. This may not be easy
|
|
|
|
* unless there are no such stages (ie the new stage is the last in
|
|
|
|
* the pipe).
|
|
|
|
*
|
|
|
|
* - inserting optimized (but specialized) stages ahead of the
|
|
|
|
* general-purpose fallback implementation. For example, the old
|
2002-01-22 14:35:16 +00:00
|
|
|
* fastpath mechanism, which only works when the VERT_BIT_ELT input is
|
2000-12-26 05:09:27 +00:00
|
|
|
* available, can be duplicated by placing the fastpath stage at the
|
|
|
|
* head of this pipeline. Such specialized stages are currently
|
|
|
|
* constrained to have no outputs (ie. they must either finish the *
|
|
|
|
* pipeline by returning GL_FALSE from run(), or do nothing).
|
|
|
|
*
|
|
|
|
* Some work can be done to lift some of the restrictions in the final
|
2001-03-12 00:48:37 +00:00
|
|
|
* case, if it becomes necessary to do so.
|
2000-12-26 05:09:27 +00:00
|
|
|
*/
|
|
|
|
const struct gl_pipeline_stage *_tnl_default_pipeline[] = {
|
2001-03-12 00:48:37 +00:00
|
|
|
&_tnl_vertex_transform_stage,
|
|
|
|
&_tnl_normal_transform_stage,
|
|
|
|
&_tnl_lighting_stage,
|
|
|
|
&_tnl_fog_coordinate_stage,
|
|
|
|
&_tnl_texgen_stage,
|
|
|
|
&_tnl_texture_transform_stage,
|
|
|
|
&_tnl_point_attenuation_stage,
|
2002-10-16 17:57:51 +00:00
|
|
|
#if FEATURE_NV_vertex_program
|
2001-12-14 02:50:01 +00:00
|
|
|
&_tnl_vertex_program_stage,
|
2002-10-16 17:57:51 +00:00
|
|
|
#endif
|
2000-12-26 05:09:27 +00:00
|
|
|
&_tnl_render_stage,
|
|
|
|
0
|
|
|
|
};
|