blob: 6b0ea815e2bde3cd7a0514d7f76d57b6a58d30ed [file] [log] [blame]
Keith Whitwell23caf202000-11-16 21:05:34 +00001
2/*
3 * Mesa 3-D graphics library
Brian Paul27558a12003-03-01 01:50:20 +00004 * Version: 5.1
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +00005 *
Brian Paul27558a12003-03-01 01:50:20 +00006 * Copyright (C) 1999-2003 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
35#include "math/m_translate.h"
36#include "math/m_xform.h"
37
Keith Whitwellcab974c2000-12-26 05:09:27 +000038#include "t_context.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000039#include "t_pipeline.h"
Keith Whitwell6f973f32005-04-22 12:51:19 +000040#include "t_vp_build.h"
Keith Whitwell2b2bd082005-05-18 15:26:48 +000041#include "t_vertex.h"
Keith Whitwell23caf202000-11-16 21:05:34 +000042
Gareth Hughes22144ab2001-03-12 00:48:37 +000043void _tnl_install_pipeline( GLcontext *ctx,
Keith Whitwellae0eaf92003-11-24 15:23:18 +000044 const struct tnl_pipeline_stage **stages )
Keith Whitwell23caf202000-11-16 21:05:34 +000045{
Keith Whitwell23caf202000-11-16 21:05:34 +000046 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwell23caf202000-11-16 21:05:34 +000047 GLuint i;
Keith Whitwell23caf202000-11-16 21:05:34 +000048
Keith Whitwell6f973f32005-04-22 12:51:19 +000049 tnl->pipeline.new_state = ~0;
Keith Whitwell23caf202000-11-16 21:05:34 +000050
Keith Whitwellcab974c2000-12-26 05:09:27 +000051 /* Create a writeable copy of each stage.
Keith Whitwell23caf202000-11-16 21:05:34 +000052 */
Keith Whitwellcab974c2000-12-26 05:09:27 +000053 for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) {
Keith Whitwell6f973f32005-04-22 12:51:19 +000054 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
55 MEMCPY(s, stages[i], sizeof(*s));
56 if (s->create)
57 s->create(ctx, s);
Keith Whitwell23caf202000-11-16 21:05:34 +000058 }
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000059
Keith Whitwell6f973f32005-04-22 12:51:19 +000060 tnl->pipeline.nr_stages = i;
Keith Whitwellcab974c2000-12-26 05:09:27 +000061}
Jouk Jansen5e3bc0c2000-11-22 07:32:16 +000062
Keith Whitwellcab974c2000-12-26 05:09:27 +000063void _tnl_destroy_pipeline( GLcontext *ctx )
64{
65 TNLcontext *tnl = TNL_CONTEXT(ctx);
66 GLuint i;
67
Keith Whitwell6f973f32005-04-22 12:51:19 +000068 for (i = 0 ; i < tnl->pipeline.nr_stages ; i++) {
69 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
70 if (s->destroy)
71 s->destroy(s);
72 }
Keith Whitwellcab974c2000-12-26 05:09:27 +000073
74 tnl->pipeline.nr_stages = 0;
75}
76
Keith Whitwell6f973f32005-04-22 12:51:19 +000077
78
79static GLuint check_input_changes( GLcontext *ctx )
Keith Whitwellcab974c2000-12-26 05:09:27 +000080{
81 TNLcontext *tnl = TNL_CONTEXT(ctx);
Keith Whitwell6f973f32005-04-22 12:51:19 +000082 GLuint i;
83
84 for (i = 0; i < _TNL_ATTRIB_EDGEFLAG; i++) {
85 if (tnl->vb.AttribPtr[i]->size != tnl->pipeline.last_attrib_size[i] ||
86 tnl->vb.AttribPtr[i]->stride != tnl->pipeline.last_attrib_stride[i]) {
87 tnl->pipeline.last_attrib_size[i] = tnl->vb.AttribPtr[i]->size;
88 tnl->pipeline.last_attrib_stride[i] = tnl->vb.AttribPtr[i]->stride;
89 tnl->pipeline.input_changes |= 1<<i;
Gareth Hughes22144ab2001-03-12 00:48:37 +000090 }
Keith Whitwellcab974c2000-12-26 05:09:27 +000091 }
Keith Whitwell6f973f32005-04-22 12:51:19 +000092
93 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) {
Keith Whitwella6616542005-04-22 13:02:04 +0000134#if TNL_FIXED_FUNCTION_PROGRAM
135 _tnl_UpdateFixedFunctionProgram( ctx );
136#endif
137
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[] = {
Keith Whitwell6f973f32005-04-22 12:51:19 +0000200#if TNL_FIXED_FUNCTION_PROGRAM
201 &_tnl_arb_vertex_program_stage,
202#else
Gareth Hughes22144ab2001-03-12 00:48:37 +0000203 &_tnl_vertex_transform_stage,
204 &_tnl_normal_transform_stage,
205 &_tnl_lighting_stage,
206 &_tnl_fog_coordinate_stage,
207 &_tnl_texgen_stage,
208 &_tnl_texture_transform_stage,
209 &_tnl_point_attenuation_stage,
Brian Paul1e71d2a2004-01-31 19:49:10 +0000210#if defined(FEATURE_NV_vertex_program) || defined(FEATURE_ARB_vertex_program)
Brian Paul86b84272001-12-14 02:50:01 +0000211 &_tnl_vertex_program_stage,
Brian Paul8dfc5b92002-10-16 17:57:51 +0000212#endif
Keith Whitwell6f973f32005-04-22 12:51:19 +0000213#endif
Keith Whitwellcab974c2000-12-26 05:09:27 +0000214 &_tnl_render_stage,
Keith Whitwellb97e4782005-02-10 10:57:22 +0000215 NULL
Keith Whitwellcab974c2000-12-26 05:09:27 +0000216};