3 * Mesa 3-D graphics library
6 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 * Keith Whitwell <keith@tungstengraphics.com>
35 #include "t_context.h"
36 #include "t_pipeline.h"
37 #include "t_vp_build.h"
40 void _tnl_install_pipeline( GLcontext
*ctx
,
41 const struct tnl_pipeline_stage
**stages
)
43 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
46 tnl
->pipeline
.new_state
= ~0;
48 /* Create a writeable copy of each stage.
50 for (i
= 0 ; i
< MAX_PIPELINE_STAGES
&& stages
[i
] ; i
++) {
51 struct tnl_pipeline_stage
*s
= &tnl
->pipeline
.stages
[i
];
52 MEMCPY(s
, stages
[i
], sizeof(*s
));
57 tnl
->pipeline
.nr_stages
= i
;
60 void _tnl_destroy_pipeline( GLcontext
*ctx
)
62 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
65 for (i
= 0 ; i
< tnl
->pipeline
.nr_stages
; i
++) {
66 struct tnl_pipeline_stage
*s
= &tnl
->pipeline
.stages
[i
];
71 tnl
->pipeline
.nr_stages
= 0;
76 static GLuint
check_input_changes( GLcontext
*ctx
)
78 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
81 for (i
= 0; i
<= _TNL_LAST_MAT
; i
++) {
82 if (tnl
->vb
.AttribPtr
[i
]->size
!= tnl
->pipeline
.last_attrib_size
[i
] ||
83 tnl
->vb
.AttribPtr
[i
]->stride
!= tnl
->pipeline
.last_attrib_stride
[i
]) {
84 tnl
->pipeline
.last_attrib_size
[i
] = tnl
->vb
.AttribPtr
[i
]->size
;
85 tnl
->pipeline
.last_attrib_stride
[i
] = tnl
->vb
.AttribPtr
[i
]->stride
;
86 tnl
->pipeline
.input_changes
|= 1<<i
;
90 if (tnl
->pipeline
.input_changes
&&
91 tnl
->Driver
.NotifyInputChanges
)
92 tnl
->Driver
.NotifyInputChanges( ctx
, tnl
->pipeline
.input_changes
);
94 return tnl
->pipeline
.input_changes
;
98 static GLuint
check_output_changes( GLcontext
*ctx
)
101 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
103 for (i
= 0; i
< VERT_RESULT_MAX
; i
++) {
104 if (tnl
->vb
.ResultPtr
[i
]->size
!= tnl
->last_result_size
[i
] ||
105 tnl
->vb
.ResultPtr
[i
]->stride
!= tnl
->last_result_stride
[i
]) {
106 tnl
->last_result_size
[i
] = tnl
->vb
.ResultPtr
[i
]->size
;
107 tnl
->last_result_stride
[i
] = tnl
->vb
.ResultPtr
[i
]->stride
;
108 tnl
->pipeline
.output_changes
|= 1<<i
;
112 if (tnl
->pipeline
.output_changes
)
113 tnl
->Driver
.NotifyOutputChanges( ctx
, tnl
->pipeline
.output_changes
);
115 return tnl
->pipeline
.output_changes
;
122 void _tnl_run_pipeline( GLcontext
*ctx
)
124 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
125 unsigned short __tmp
;
131 /* Check for changed input sizes or change in stride to/from zero
132 * (ie const or non-const).
134 if (check_input_changes( ctx
) || tnl
->pipeline
.new_state
) {
135 if (ctx
->VertexProgram
._MaintainTnlProgram
)
136 _tnl_UpdateFixedFunctionProgram( ctx
);
138 for (i
= 0; i
< tnl
->pipeline
.nr_stages
; i
++) {
139 struct tnl_pipeline_stage
*s
= &tnl
->pipeline
.stages
[i
];
141 s
->validate( ctx
, s
);
144 tnl
->pipeline
.new_state
= 0;
145 tnl
->pipeline
.input_changes
= 0;
147 /* Pipeline can only change its output in response to either a
148 * statechange or an input size/stride change. No other changes
151 if (check_output_changes( ctx
))
152 _tnl_notify_pipeline_output_change( ctx
);
155 START_FAST_MATH(__tmp
);
157 for (i
= 0; i
< tnl
->pipeline
.nr_stages
; i
++) {
158 struct tnl_pipeline_stage
*s
= &tnl
->pipeline
.stages
[i
];
159 if (!s
->run( ctx
, s
))
163 END_FAST_MATH(__tmp
);
168 /* The default pipeline. This is useful for software rasterizers, and
169 * simple hardware rasterizers. For customization, I don't recommend
170 * tampering with the internals of these stages in the way that
171 * drivers did in Mesa 3.4. These stages are basically black boxes,
172 * and should be left intact.
174 * To customize the pipeline, consider:
176 * - removing redundant stages (making sure that the software rasterizer
177 * can cope with this on fallback paths). An example is fog
178 * coordinate generation, which is not required in the FX driver.
180 * - replacing general-purpose machine-independent stages with
181 * general-purpose machine-specific stages. There is no example of
182 * this to date, though it must be borne in mind that all subsequent
183 * stages that reference the output of the new stage must cope with
184 * any machine-specific data introduced. This may not be easy
185 * unless there are no such stages (ie the new stage is the last in
188 * - inserting optimized (but specialized) stages ahead of the
189 * general-purpose fallback implementation. For example, the old
190 * fastpath mechanism, which only works when the VB->Elts input is
191 * available, can be duplicated by placing the fastpath stage at the
192 * head of this pipeline. Such specialized stages are currently
193 * constrained to have no outputs (ie. they must either finish the *
194 * pipeline by returning GL_FALSE from run(), or do nothing).
196 * Some work can be done to lift some of the restrictions in the final
197 * case, if it becomes necessary to do so.
199 const struct tnl_pipeline_stage
*_tnl_default_pipeline
[] = {
200 &_tnl_vertex_transform_stage
,
201 &_tnl_normal_transform_stage
,
202 &_tnl_lighting_stage
,
203 &_tnl_fog_coordinate_stage
,
205 &_tnl_texture_transform_stage
,
206 &_tnl_point_attenuation_stage
,
207 #if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program)
208 &_tnl_arb_vertex_program_stage
,
209 &_tnl_vertex_program_stage
,
215 const struct tnl_pipeline_stage
*_tnl_vp_pipeline
[] = {
216 &_tnl_arb_vertex_program_stage
,