2001-01-17 02:49:38 +00:00
|
|
|
/* $Id: t_pipeline.c,v 1.10 2001/01/17 02:49:39 keithw Exp $ */
|
2000-11-16 21:05:34 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Mesa 3-D graphics library
|
|
|
|
* Version: 3.5
|
2000-11-22 07:32:16 +00:00
|
|
|
*
|
2000-11-16 21:05:34 +00:00
|
|
|
* Copyright (C) 1999-2000 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
|
|
|
*
|
|
|
|
* Author:
|
|
|
|
* Keith Whitwell <keithw@valinux.com>
|
2000-11-16 21:05:34 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "glheader.h"
|
|
|
|
#include "context.h"
|
|
|
|
#include "mem.h"
|
|
|
|
#include "mmath.h"
|
|
|
|
#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"
|
|
|
|
|
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
void _tnl_install_pipeline( GLcontext *ctx,
|
|
|
|
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
|
|
|
|
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
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
for (i = 0 ; i < tnl->pipeline.nr_stages ; i++)
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
struct gl_pipeline_stage *stage = pipe->stages;
|
|
|
|
GLuint newstate = pipe->build_state_changes;
|
2000-11-16 21:05:34 +00:00
|
|
|
GLuint generated = 0;
|
2000-12-26 05:09:27 +00:00
|
|
|
GLuint i;
|
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
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
for (i = 0 ; i < pipe->nr_stages ; i++) {
|
|
|
|
if (stage[i].check_state & newstate) {
|
|
|
|
stage[i].check(ctx, &stage[i]);
|
2000-11-16 21:05:34 +00:00
|
|
|
}
|
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
if (stage[i].active) {
|
|
|
|
pipe->inputs |= stage[i].inputs & ~generated;
|
|
|
|
generated |= stage[i].outputs;
|
|
|
|
}
|
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);
|
2000-12-26 05:09:27 +00:00
|
|
|
struct gl_pipeline *pipe = &tnl->pipeline;
|
|
|
|
struct gl_pipeline_stage *stage = pipe->stages;
|
|
|
|
GLuint changed_state = pipe->run_state_changes;
|
|
|
|
GLuint changed_inputs = pipe->run_input_changes;
|
|
|
|
GLboolean running = GL_TRUE;
|
|
|
|
GLuint i;
|
|
|
|
unsigned short __tmp;
|
2000-11-16 21:05:34 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
/* Done elsewhere.
|
|
|
|
*/
|
|
|
|
ASSERT(pipe->build_state_changes == 0);
|
2000-11-22 07:32:16 +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
|
|
|
|
* using this value for recalculation.
|
|
|
|
*
|
|
|
|
* Even inactive stages have their state and inputs examined to try
|
|
|
|
* to keep cached data alive over state-changes.
|
|
|
|
*/
|
|
|
|
for (i = 0 ; i < pipe->nr_stages ; i++) {
|
|
|
|
|
|
|
|
stage[i].changed_inputs |= stage[i].inputs & changed_inputs;
|
2000-11-16 21:05:34 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
if (stage[i].run_state & changed_state) {
|
|
|
|
stage[i].changed_inputs = stage[i].inputs;
|
2000-11-24 15:21:59 +00:00
|
|
|
}
|
2000-11-22 07:32:16 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
if (stage[i].active) {
|
2001-01-17 02:49:38 +00:00
|
|
|
if (stage[i].changed_inputs)
|
2000-12-26 05:09:27 +00:00
|
|
|
changed_inputs |= stage[i].outputs;
|
2000-11-16 21:05:34 +00:00
|
|
|
|
2000-12-26 05:09:27 +00:00
|
|
|
if (running) {
|
|
|
|
running = stage[i].run( ctx, &stage[i] );
|
2001-01-17 02:49:38 +00:00
|
|
|
stage[i].changed_inputs = 0;
|
2000-12-26 05:09:27 +00:00
|
|
|
}
|
2000-11-16 21:05:34 +00:00
|
|
|
}
|
|
|
|
}
|
2000-12-26 05:09:27 +00:00
|
|
|
END_FAST_MATH(__tmp);
|
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;
|
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,
|
|
|
|
* and should be left intact.
|
|
|
|
*
|
|
|
|
* To customize the pipeline, consider:
|
|
|
|
*
|
|
|
|
* - 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
|
|
|
|
* fastpath mechanism, which only works when the VERT_ELT input is
|
|
|
|
* 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
|
|
|
|
* case, if it becomes necessary to do so.
|
|
|
|
*/
|
|
|
|
const struct gl_pipeline_stage *_tnl_default_pipeline[] = {
|
|
|
|
&_tnl_update_material_stage,
|
|
|
|
&_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,
|
|
|
|
&_tnl_render_stage,
|
|
|
|
0
|
|
|
|
};
|
2000-11-16 21:05:34 +00:00
|
|
|
|