mesa: Restore 78-column wrapping of license text in C-style comments.
[mesa.git] / src / mesa / tnl / t_pipeline.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
4 *
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
6 *
7 * 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:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * 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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 *
25 * Authors:
26 * Keith Whitwell <keith@tungstengraphics.com>
27 */
28
29 #include "main/glheader.h"
30 #include "main/context.h"
31 #include "main/imports.h"
32 #include "main/mtypes.h"
33
34 #include "t_context.h"
35 #include "t_pipeline.h"
36 #include "t_vp_build.h"
37 #include "t_vertex.h"
38
39 void _tnl_install_pipeline( struct gl_context *ctx,
40 const struct tnl_pipeline_stage **stages )
41 {
42 TNLcontext *tnl = TNL_CONTEXT(ctx);
43 GLuint i;
44
45 tnl->pipeline.new_state = ~0;
46
47 /* Create a writeable copy of each stage.
48 */
49 for (i = 0 ; i < MAX_PIPELINE_STAGES && stages[i] ; i++) {
50 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);
54 }
55
56 tnl->pipeline.nr_stages = i;
57 }
58
59 void _tnl_destroy_pipeline( struct gl_context *ctx )
60 {
61 TNLcontext *tnl = TNL_CONTEXT(ctx);
62 GLuint i;
63
64 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 }
69
70 tnl->pipeline.nr_stages = 0;
71 }
72
73
74
75 static GLuint check_input_changes( struct gl_context *ctx )
76 {
77 TNLcontext *tnl = TNL_CONTEXT(ctx);
78 GLuint i;
79
80 for (i = 0; i <= _TNL_LAST_MAT; i++) {
81 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;
86 }
87 }
88
89 return tnl->pipeline.input_changes;
90 }
91
92
93 static GLuint check_output_changes( struct gl_context *ctx )
94 {
95 #if 0
96 TNLcontext *tnl = TNL_CONTEXT(ctx);
97
98 for (i = 0; i < VARYING_SLOT_MAX; i++) {
99 if (tnl->vb.ResultPtr[i]->size != tnl->last_result_size[i] ||
100 tnl->vb.ResultPtr[i]->stride != tnl->last_result_stride[i]) {
101 tnl->last_result_size[i] = tnl->vb.ResultPtr[i]->size;
102 tnl->last_result_stride[i] = tnl->vb.ResultPtr[i]->stride;
103 tnl->pipeline.output_changes |= 1<<i;
104 }
105 }
106
107 if (tnl->pipeline.output_changes)
108 tnl->Driver.NotifyOutputChanges( ctx, tnl->pipeline.output_changes );
109
110 return tnl->pipeline.output_changes;
111 #else
112 return ~0;
113 #endif
114 }
115
116
117 void _tnl_run_pipeline( struct gl_context *ctx )
118 {
119 TNLcontext *tnl = TNL_CONTEXT(ctx);
120 unsigned short __tmp;
121 GLuint i;
122
123 if (!tnl->vb.Count)
124 return;
125
126 /* Check for changed input sizes or change in stride to/from zero
127 * (ie const or non-const).
128 */
129 if (check_input_changes( ctx ) || tnl->pipeline.new_state) {
130 if (ctx->VertexProgram._MaintainTnlProgram)
131 _tnl_UpdateFixedFunctionProgram( ctx );
132
133 for (i = 0; i < tnl->pipeline.nr_stages ; i++) {
134 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
135 if (s->validate)
136 s->validate( ctx, s );
137 }
138
139 tnl->pipeline.new_state = 0;
140 tnl->pipeline.input_changes = 0;
141
142 /* Pipeline can only change its output in response to either a
143 * statechange or an input size/stride change. No other changes
144 * are allowed.
145 */
146 if (check_output_changes( ctx ))
147 _tnl_notify_pipeline_output_change( ctx );
148 }
149
150 #ifndef _OPENMP
151 /* Don't adjust FPU precision mode in case multiple threads are to be used.
152 * This would require that the additional threads also changed the FPU mode
153 * which is quite a mess as this had to be done in all parallelized sections;
154 * otherwise the master thread and all other threads are running in different
155 * modes, producing inconsistent results.
156 * Note that all x64 implementations don't define/use START_FAST_MATH, so
157 * this is "hack" is only used in i386 mode
158 */
159 START_FAST_MATH(__tmp);
160 #endif
161
162 for (i = 0; i < tnl->pipeline.nr_stages ; i++) {
163 struct tnl_pipeline_stage *s = &tnl->pipeline.stages[i];
164 if (!s->run( ctx, s ))
165 break;
166 }
167
168 #ifndef _OPENMP
169 END_FAST_MATH(__tmp);
170 #endif
171 }
172
173
174
175 /* The default pipeline. This is useful for software rasterizers, and
176 * simple hardware rasterizers. For customization, I don't recommend
177 * tampering with the internals of these stages in the way that
178 * drivers did in Mesa 3.4. These stages are basically black boxes,
179 * and should be left intact.
180 *
181 * To customize the pipeline, consider:
182 *
183 * - removing redundant stages (making sure that the software rasterizer
184 * can cope with this on fallback paths). An example is fog
185 * coordinate generation, which is not required in the FX driver.
186 *
187 * - replacing general-purpose machine-independent stages with
188 * general-purpose machine-specific stages. There is no example of
189 * this to date, though it must be borne in mind that all subsequent
190 * stages that reference the output of the new stage must cope with
191 * any machine-specific data introduced. This may not be easy
192 * unless there are no such stages (ie the new stage is the last in
193 * the pipe).
194 *
195 * - inserting optimized (but specialized) stages ahead of the
196 * general-purpose fallback implementation. For example, the old
197 * fastpath mechanism, which only works when the VB->Elts input is
198 * available, can be duplicated by placing the fastpath stage at the
199 * head of this pipeline. Such specialized stages are currently
200 * constrained to have no outputs (ie. they must either finish the *
201 * pipeline by returning GL_FALSE from run(), or do nothing).
202 *
203 * Some work can be done to lift some of the restrictions in the final
204 * case, if it becomes necessary to do so.
205 */
206 const struct tnl_pipeline_stage *_tnl_default_pipeline[] = {
207 &_tnl_vertex_transform_stage,
208 &_tnl_normal_transform_stage,
209 &_tnl_lighting_stage,
210 &_tnl_texgen_stage,
211 &_tnl_texture_transform_stage,
212 &_tnl_point_attenuation_stage,
213 &_tnl_vertex_program_stage,
214 &_tnl_fog_coordinate_stage,
215 &_tnl_render_stage,
216 NULL
217 };
218
219 const struct tnl_pipeline_stage *_tnl_vp_pipeline[] = {
220 &_tnl_vertex_program_stage,
221 &_tnl_render_stage,
222 NULL
223 };