blob: 357ef1e24b5bf4914fe2b3e3b4e31d86eb314ae3 [file] [log] [blame]
Keith Whitwell23caf202000-11-16 21:05:34 +00001/*
2 * Mesa 3-D graphics library
Brian4b3835d2007-04-16 10:58:30 -06003 * Version: 6.5.3
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00004 *
Brian4b3835d2007-04-16 10:58:30 -06005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00006 *
Keith Whitwell23caf202000-11-16 21:05:34 +00007 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000013 *
Keith Whitwell23caf202000-11-16 21:05:34 +000014 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000016 *
Keith Whitwell23caf202000-11-16 21:05:34 +000017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Keith Whitwellcab974c2000-12-26 05:09:27 +000023 *
Gareth Hughes22144ab2001-03-12 00:48:37 +000024 * Authors:
Brian Paul05a4b372002-10-29 20:28:36 +000025 * Keith Whitwell <keith@tungstengraphics.com>
Keith Whitwell23caf202000-11-16 21:05:34 +000026 */
27
Brianc223c6b2007-07-04 13:15:20 -060028#include "main/glheader.h"
29#include "main/context.h"
30#include "main/imports.h"
31#include "main/state.h"
32#include "main/mtypes.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000033
Keith Whitwellcab974c2000-12-26 05:09:27 +000034#include "t_context.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000035#include "t_pipeline.h"
Keith Whitwell6f973f32005-04-22 12:51:19 +000036#include "t_vp_build.h"
Keith Whitwell2b2bd082005-05-18 15:26:48 +000037#include "t_vertex.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000038
Gareth Hughes22144ab2001-03-12 00:48:37 +000039void _tnl_install_pipeline( GLcontext *ctx,
Keith Whitwellae0eaf92003-11-24 15:23:18 +000040 const struct tnl_pipeline_stage **stages )
Keith Whitwell23caf202000-11-16 21:05:34 +000041{
Keith Whitwell23caf202000-11-16 21:05:34 +000042 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwell23caf202000-11-16 21:05:34 +000043 GLuint i;
Keith Whitwell23caf202000-11-16 21:05:34 +000044
Keith Whitwell6f973f32005-04-22 12:51:19 +000045 tnl->pipeline.new_state = ~0;
Keith Whitwell23caf202000-11-16 21:05:34 +000046
Keith Whitwellcab974c2000-12-26 05:09:27 +000047 /* Create a writeable copy of each stage.
Keith Whitwell23caf202000-11-16 21:05:34 +000048 */
Keith Whitwellcab974c2000-12-26 05:09:27 +000049 for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) {
Keith Whitwell6f973f32005-04-22 12:51:19 +000050 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
51 MEMCPY(s, stages[i], sizeof(*s));
52 if (s->create)
53 s->create(ctx, s);
Keith Whitwell23caf202000-11-16 21:05:34 +000054 }
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000055
Keith Whitwell6f973f32005-04-22 12:51:19 +000056 tnl->pipeline.nr_stages = i;
Keith Whitwellcab974c2000-12-26 05:09:27 +000057}
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000058
Keith Whitwellcab974c2000-12-26 05:09:27 +000059void _tnl_destroy_pipeline( GLcontext *ctx )
60{
61 TNLcontext *tnl = TNL_CONTEXT(ctx);
62 GLuint i;
63
Keith Whitwell6f973f32005-04-22 12:51:19 +000064 for (i = 0 ; i < tnl->pipeline.nr_stages ; i++) {
65 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
66 if (s->destroy)
67 s->destroy(s);
68 }
Keith Whitwellcab974c2000-12-26 05:09:27 +000069
70 tnl->pipeline.nr_stages = 0;
71}
72
Keith Whitwell6f973f32005-04-22 12:51:19 +000073
74
75static GLuint check_input_changes( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +000076{
77 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwell6f973f32005-04-22 12:51:19 +000078 GLuint i;
79
Brian Paul94b30dc2006-04-25 00:53:25 +000080 for (i = 0; i <= _TNL_LAST_MAT; i++) {
Keith Whitwell6f973f32005-04-22 12:51:19 +000081 if (tnl->vb.AttribPtr[i]->size != tnl->pipeline.last_attrib_size[i] ||
82 tnl->vb.AttribPtr[i]->stride != tnl->pipeline.last_attrib_stride[i]) {
83 tnl->pipeline.last_attrib_size[i] = tnl->vb.AttribPtr[i]->size;
84 tnl->pipeline.last_attrib_stride[i] = tnl->vb.AttribPtr[i]->stride;
85 tnl->pipeline.input_changes |= 1<<i;
Gareth Hughes22144ab2001-03-12 00:48:37 +000086 }
Keith Whitwellcab974c2000-12-26 05:09:27 +000087 }
Keith Whitwell6f973f32005-04-22 12:51:19 +000088
Keith Whitwellf4fbda32005-11-01 17:29:46 +000089 if (tnl->pipeline.input_changes &&
90 tnl->Driver.NotifyInputChanges)
91 tnl->Driver.NotifyInputChanges( ctx, tnl->pipeline.input_changes );
92
Keith Whitwell6f973f32005-04-22 12:51:19 +000093 return tnl->pipeline.input_changes;
Keith Whitwellcab974c2000-12-26 05:09:27 +000094}
95
96
Keith Whitwell2b2bd082005-05-18 15:26:48 +000097static GLuint check_output_changes( GLcontext *ctx )
Keith Whitwell6f973f32005-04-22 12:51:19 +000098{
99#if 0
100 TNLcontext *tnl = TNL_CONTEXT(ctx);
101
102 for (i = 0; i < VERT_RESULT_MAX; i++) {
103 if (tnl->vb.ResultPtr[i]->size != tnl->last_result_size[i] ||
104 tnl->vb.ResultPtr[i]->stride != tnl->last_result_stride[i]) {
105 tnl->last_result_size[i] = tnl->vb.ResultPtr[i]->size;
106 tnl->last_result_stride[i] = tnl->vb.ResultPtr[i]->stride;
107 tnl->pipeline.output_changes |= 1<<i;
108 }
109 }
110
111 if (tnl->pipeline.output_changes)
112 tnl->Driver.NotifyOutputChanges( ctx, tnl->pipeline.output_changes );
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000113
114 return tnl->pipeline.output_changes;
115#else
116 return ~0;
Keith Whitwell6f973f32005-04-22 12:51:19 +0000117#endif
118}
119
Keith Whitwellcab974c2000-12-26 05:09:27 +0000120
Keith Whitwellcab974c2000-12-26 05:09:27 +0000121void _tnl_run_pipeline( GLcontext *ctx )
122{
123 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwellcab974c2000-12-26 05:09:27 +0000124 unsigned short __tmp;
Keith Whitwell6f973f32005-04-22 12:51:19 +0000125 GLuint i;
Keith Whitwellcab974c2000-12-26 05:09:27 +0000126
Keith Whitwell79073402004-01-05 09:43:42 +0000127 if (!tnl->vb.Count)
128 return;
129
Keith Whitwell6f973f32005-04-22 12:51:19 +0000130 /* Check for changed input sizes or change in stride to/from zero
131 * (ie const or non-const).
Keith Whitwellcab974c2000-12-26 05:09:27 +0000132 */
Keith Whitwell6f973f32005-04-22 12:51:19 +0000133 if (check_input_changes( ctx ) || tnl->pipeline.new_state) {
Briana328e462006-12-13 14:58:13 -0700134 if (ctx->VertexProgram._MaintainTnlProgram)
Keith Whitwell81032032005-06-09 14:55:34 +0000135 _tnl_UpdateFixedFunctionProgram( ctx );
Keith Whitwella6616542005-04-22 13:02:04 +0000136
Keith Whitwell6f973f32005-04-22 12:51:19 +0000137 for (i = 0; i < tnl->pipeline.nr_stages ; i++) {
138 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
139 if (s->validate)
140 s->validate( ctx, s );
Keith Whitwell23caf202000-11-16 21:05:34 +0000141 }
Keith Whitwell6f973f32005-04-22 12:51:19 +0000142
143 tnl->pipeline.new_state = 0;
144 tnl->pipeline.input_changes = 0;
Keith Whitwell2b2bd082005-05-18 15:26:48 +0000145
146 /* Pipeline can only change its output in response to either a
147 * statechange or an input size/stride change. No other changes
148 * are allowed.
149 */
150 if (check_output_changes( ctx ))
151 _tnl_notify_pipeline_output_change( ctx );
Keith Whitwell23caf202000-11-16 21:05:34 +0000152 }
Keith Whitwellc6b2a922001-02-15 01:33:52 +0000153
Keith Whitwell6f973f32005-04-22 12:51:19 +0000154 START_FAST_MATH(__tmp);
155
156 for (i = 0; i < tnl->pipeline.nr_stages ; i++) {
157 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
158 if (!s->run( ctx, s ))
159 break;
160 }
161
Keith Whitwellcab974c2000-12-26 05:09:27 +0000162 END_FAST_MATH(__tmp);
Keith Whitwell23caf202000-11-16 21:05:34 +0000163}
164
165
166
Keith Whitwellcab974c2000-12-26 05:09:27 +0000167/* The default pipeline. This is useful for software rasterizers, and
168 * simple hardware rasterizers. For customization, I don't recommend
169 * tampering with the internals of these stages in the way that
170 * drivers did in Mesa 3.4. These stages are basically black boxes,
Gareth Hughes22144ab2001-03-12 00:48:37 +0000171 * and should be left intact.
Keith Whitwellcab974c2000-12-26 05:09:27 +0000172 *
Gareth Hughes22144ab2001-03-12 00:48:37 +0000173 * To customize the pipeline, consider:
Keith Whitwellcab974c2000-12-26 05:09:27 +0000174 *
175 * - removing redundant stages (making sure that the software rasterizer
176 * can cope with this on fallback paths). An example is fog
177 * coordinate generation, which is not required in the FX driver.
178 *
179 * - replacing general-purpose machine-independent stages with
180 * general-purpose machine-specific stages. There is no example of
181 * this to date, though it must be borne in mind that all subsequent
182 * stages that reference the output of the new stage must cope with
183 * any machine-specific data introduced. This may not be easy
184 * unless there are no such stages (ie the new stage is the last in
185 * the pipe).
186 *
187 * - inserting optimized (but specialized) stages ahead of the
188 * general-purpose fallback implementation. For example, the old
Keith Whitwellae0eaf92003-11-24 15:23:18 +0000189 * fastpath mechanism, which only works when the VB->Elts input is
Keith Whitwellcab974c2000-12-26 05:09:27 +0000190 * available, can be duplicated by placing the fastpath stage at the
191 * head of this pipeline. Such specialized stages are currently
192 * constrained to have no outputs (ie. they must either finish the *
193 * pipeline by returning GL_FALSE from run(), or do nothing).
194 *
195 * Some work can be done to lift some of the restrictions in the final
Gareth Hughes22144ab2001-03-12 00:48:37 +0000196 * case, if it becomes necessary to do so.
Keith Whitwellcab974c2000-12-26 05:09:27 +0000197 */
Keith Whitwellae0eaf92003-11-24 15:23:18 +0000198const struct tnl_pipeline_stage *_tnl_default_pipeline[] = {
Gareth Hughes22144ab2001-03-12 00:48:37 +0000199 &_tnl_vertex_transform_stage,
200 &_tnl_normal_transform_stage,
201 &_tnl_lighting_stage,
Gareth Hughes22144ab2001-03-12 00:48:37 +0000202 &_tnl_texgen_stage,
203 &_tnl_texture_transform_stage,
204 &_tnl_point_attenuation_stage,
Keith Whitwell81032032005-06-09 14:55:34 +0000205 &_tnl_vertex_program_stage,
H. Verbeete9d18892008-06-16 10:40:32 -0600206 &_tnl_fog_coordinate_stage,
Keith Whitwellcab974c2000-12-26 05:09:27 +0000207 &_tnl_render_stage,
Keith Whitwellb97e4782005-02-10 10:57:22 +0000208 NULL
Keith Whitwellcab974c2000-12-26 05:09:27 +0000209};
Keith Whitwell81032032005-06-09 14:55:34 +0000210
211const struct tnl_pipeline_stage *_tnl_vp_pipeline[] = {
Brian4b3835d2007-04-16 10:58:30 -0600212 &_tnl_vertex_program_stage,
Keith Whitwell81032032005-06-09 14:55:34 +0000213 &_tnl_render_stage,
214 NULL
215};