blob: a50a3f0f2f294e2298ee87019e2ecf19f1b0eeaf [file] [log] [blame]
Keith Whitwell23caf202000-11-16 21:05:34 +00001
2/*
3 * Mesa 3-D graphics library
Michal Krola2ea6062006-02-13 11:23:36 +00004 * Version: 6.5
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00005 *
Michal Krola2ea6062006-02-13 11:23:36 +00006 * Copyright (C) 1999-2006 Brian Paul All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00007 *
Keith Whitwell23caf202000-11-16 21:05:34 +00008 * 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:
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000014 *
Keith Whitwell23caf202000-11-16 21:05:34 +000015 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000017 *
Keith Whitwell23caf202000-11-16 21:05:34 +000018 * 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.
Keith Whitwellcab974c2000-12-26 05:09:27 +000024 *
Gareth Hughes22144ab2001-03-12 00:48:37 +000025 * Authors:
Brian Paul05a4b372002-10-29 20:28:36 +000026 * Keith Whitwell <keith@tungstengraphics.com>
Keith Whitwell23caf202000-11-16 21:05:34 +000027 */
28
29#include "glheader.h"
30#include "context.h"
Brian Paul3c634522002-10-24 23:57:19 +000031#include "imports.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000032#include "state.h"
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000033#include "mtypes.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000034
Keith Whitwellcab974c2000-12-26 05:09:27 +000035#include "t_context.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000036#include "t_pipeline.h"
Keith Whitwell6f973f32005-04-22 12:51:19 +000037#include "t_vp_build.h"
Keith Whitwell2b2bd082005-05-18 15:26:48 +000038#include "t_vertex.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000039
Gareth Hughes22144ab2001-03-12 00:48:37 +000040void _tnl_install_pipeline( GLcontext *ctx,
Keith Whitwellae0eaf92003-11-24 15:23:18 +000041 const struct tnl_pipeline_stage **stages )
Keith Whitwell23caf202000-11-16 21:05:34 +000042{
Keith Whitwell23caf202000-11-16 21:05:34 +000043 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwell23caf202000-11-16 21:05:34 +000044 GLuint i;
Keith Whitwell23caf202000-11-16 21:05:34 +000045
Keith Whitwell6f973f32005-04-22 12:51:19 +000046 tnl->pipeline.new_state = ~0;
Keith Whitwell23caf202000-11-16 21:05:34 +000047
Keith Whitwellcab974c2000-12-26 05:09:27 +000048 /* Create a writeable copy of each stage.
Keith Whitwell23caf202000-11-16 21:05:34 +000049 */
Keith Whitwellcab974c2000-12-26 05:09:27 +000050 for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) {
Keith Whitwell6f973f32005-04-22 12:51:19 +000051 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
52 MEMCPY(s, stages[i], sizeof(*s));
53 if (s->create)
54 s->create(ctx, s);
Keith Whitwell23caf202000-11-16 21:05:34 +000055 }
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000056
Keith Whitwell6f973f32005-04-22 12:51:19 +000057 tnl->pipeline.nr_stages = i;
Keith Whitwellcab974c2000-12-26 05:09:27 +000058}
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000059
Keith Whitwellcab974c2000-12-26 05:09:27 +000060void _tnl_destroy_pipeline( GLcontext *ctx )
61{
62 TNLcontext *tnl = TNL_CONTEXT(ctx);
63 GLuint i;
64
Keith Whitwell6f973f32005-04-22 12:51:19 +000065 for (i = 0 ; i < tnl->pipeline.nr_stages ; i++) {
66 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
67 if (s->destroy)
68 s->destroy(s);
69 }
Keith Whitwellcab974c2000-12-26 05:09:27 +000070
71 tnl->pipeline.nr_stages = 0;
72}
73
Keith Whitwell6f973f32005-04-22 12:51:19 +000074
75
76static GLuint check_input_changes( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +000077{
78 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwell6f973f32005-04-22 12:51:19 +000079 GLuint i;
80
Brian Paul94b30dc2006-04-25 00:53:25 +000081 for (i = 0; i <= _TNL_LAST_MAT; i++) {
Keith Whitwell6f973f32005-04-22 12:51:19 +000082 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;
Gareth Hughes22144ab2001-03-12 00:48:37 +000087 }
Keith Whitwellcab974c2000-12-26 05:09:27 +000088 }
Keith Whitwell6f973f32005-04-22 12:51:19 +000089
Keith Whitwellf4fbda32005-11-01 17:29:46 +000090 if (tnl->pipeline.input_changes &&
91 tnl->Driver.NotifyInputChanges)
92 tnl->Driver.NotifyInputChanges( ctx, tnl->pipeline.input_changes );
93
Keith Whitwell6f973f32005-04-22 12:51:19 +000094 return tnl->pipeline.input_changes;
Keith Whitwellcab974c2000-12-26 05:09:27 +000095}
96
97
Keith Whitwell2b2bd082005-05-18 15:26:48 +000098static GLuint check_output_changes( GLcontext *ctx )
Keith Whitwell6f973f32005-04-22 12:51:19 +000099{
100#if 0
101 TNLcontext *tnl = TNL_CONTEXT(ctx);
102
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;
109 }
110 }
111
112 if (tnl->pipeline.output_changes)
113 tnl->Driver.NotifyOutputChanges( ctx, tnl->pipeline.output_changes );
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000114
115 return tnl->pipeline.output_changes;
116#else
117 return ~0;
Keith Whitwell6f973f32005-04-22 12:51:19 +0000118#endif
119}
120
Keith Whitwellcab974c2000-12-26 05:09:27 +0000121
Keith Whitwellcab974c2000-12-26 05:09:27 +0000122void _tnl_run_pipeline( GLcontext *ctx )
123{
124 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000125 unsigned short __tmp;
Keith Whitwell6f973f32005-04-22 12:51:19 +0000126 GLuint i;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000127
Keith Whitwell79073402004-01-05 09:43:42 +0000128 if (!tnl->vb.Count)
129 return;
130
Keith Whitwell6f973f32005-04-22 12:51:19 +0000131 /* Check for changed input sizes or change in stride to/from zero
132 * (ie const or non-const).
Keith Whitwellcab974c2000-12-26 05:09:27 +0000133 */
Keith Whitwell6f973f32005-04-22 12:51:19 +0000134 if (check_input_changes( ctx ) || tnl->pipeline.new_state) {
Briana328e462006-12-13 14:58:13 -0700135 if (ctx->VertexProgram._MaintainTnlProgram)
Keith Whitwell81032032005-06-09 14:55:34 +0000136 _tnl_UpdateFixedFunctionProgram( ctx );
Keith Whitwella6616542005-04-22 13:02:04 +0000137
Keith Whitwell6f973f32005-04-22 12:51:19 +0000138 for (i = 0; i < tnl->pipeline.nr_stages ; i++) {
139 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
140 if (s->validate)
141 s->validate( ctx, s );
Keith Whitwell23caf202000-11-16 21:05:34 +0000142 }
Keith Whitwell6f973f32005-04-22 12:51:19 +0000143
144 tnl->pipeline.new_state = 0;
145 tnl->pipeline.input_changes = 0;
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000146
147 /* Pipeline can only change its output in response to either a
148 * statechange or an input size/stride change. No other changes
149 * are allowed.
150 */
151 if (check_output_changes( ctx ))
152 _tnl_notify_pipeline_output_change( ctx );
Keith Whitwell23caf202000-11-16 21:05:34 +0000153 }
Keith Whitwellc6b2a922001-02-15 01:33:52 +0000154
Keith Whitwell6f973f32005-04-22 12:51:19 +0000155 START_FAST_MATH(__tmp);
156
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 ))
160 break;
161 }
162
Keith Whitwellcab974c2000-12-26 05:09:27 +0000163 END_FAST_MATH(__tmp);
Keith Whitwell23caf202000-11-16 21:05:34 +0000164}
165
166
167
Keith Whitwellcab974c2000-12-26 05:09:27 +0000168/* 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,
Gareth Hughes22144ab2001-03-12 00:48:37 +0000172 * and should be left intact.
Keith Whitwellcab974c2000-12-26 05:09:27 +0000173 *
Gareth Hughes22144ab2001-03-12 00:48:37 +0000174 * To customize the pipeline, consider:
Keith Whitwellcab974c2000-12-26 05:09:27 +0000175 *
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.
179 *
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
186 * the pipe).
187 *
188 * - inserting optimized (but specialized) stages ahead of the
189 * general-purpose fallback implementation. For example, the old
Keith Whitwellae0eaf92003-11-24 15:23:18 +0000190 * fastpath mechanism, which only works when the VB->Elts input is
Keith Whitwellcab974c2000-12-26 05:09:27 +0000191 * 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).
195 *
196 * Some work can be done to lift some of the restrictions in the final
Gareth Hughes22144ab2001-03-12 00:48:37 +0000197 * case, if it becomes necessary to do so.
Keith Whitwellcab974c2000-12-26 05:09:27 +0000198 */
Keith Whitwellae0eaf92003-11-24 15:23:18 +0000199const struct tnl_pipeline_stage *_tnl_default_pipeline[] = {
Gareth Hughes22144ab2001-03-12 00:48:37 +0000200 &_tnl_vertex_transform_stage,
201 &_tnl_normal_transform_stage,
202 &_tnl_lighting_stage,
203 &_tnl_fog_coordinate_stage,
204 &_tnl_texgen_stage,
205 &_tnl_texture_transform_stage,
206 &_tnl_point_attenuation_stage,
Brian Paul1e71d2a2004-01-31 19:49:10 +0000207#if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program)
Keith Whitwell81032032005-06-09 14:55:34 +0000208 &_tnl_arb_vertex_program_stage,
209 &_tnl_vertex_program_stage,
Keith Whitwell6f973f32005-04-22 12:51:19 +0000210#endif
Keith Whitwellcab974c2000-12-26 05:09:27 +0000211 &_tnl_render_stage,
Keith Whitwellb97e4782005-02-10 10:57:22 +0000212 NULL
Keith Whitwellcab974c2000-12-26 05:09:27 +0000213};
Keith Whitwell81032032005-06-09 14:55:34 +0000214
215const struct tnl_pipeline_stage *_tnl_vp_pipeline[] = {
216 &_tnl_arb_vertex_program_stage,
217 &_tnl_render_stage,
218 NULL
219};