2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
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 * 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.
25 /* Vertices are just an array of floats, with all the attributes
26 * packed. We currently assume a layout like:
28 * attr[0][0..3] - window position
29 * attr[1..n][0..3] - remaining attributes.
31 * Attributes are assumed to be 4 floats wide but are packed so that
32 * all the enabled attributes run contiguously.
37 #include "sp_context.h"
38 #include "sp_headers.h"
40 #include "core/tgsi_core.h"
43 const struct setup_coefficient
*coef
; /**< will point to quad->coef */
45 GLfloat attr
[FRAG_ATTRIB_MAX
][4][QUAD_SIZE
];
50 * Compute quad's attributes values, as constants (GL_FLAT shading).
52 static INLINE
void cinterp( struct exec_machine
*exec
,
58 for (j
= 0; j
< QUAD_SIZE
; j
++) {
59 exec
->attr
[attrib
][i
][j
] = exec
->coef
[attrib
].a0
[i
];
65 * Compute quad's attribute values by linear interpolation.
69 * INPUT[attr] = MAD COEF_A0[attr], COEF_DADX[attr], INPUT_WPOS.xxxx
70 * INPUT[attr] = MAD INPUT[attr], COEF_DADY[attr], INPUT_WPOS.yyyy
72 static INLINE
void linterp( struct exec_machine
*exec
,
78 for (j
= 0; j
< QUAD_SIZE
; j
++) {
79 const GLfloat x
= exec
->attr
[FRAG_ATTRIB_WPOS
][0][j
];
80 const GLfloat y
= exec
->attr
[FRAG_ATTRIB_WPOS
][1][j
];
81 exec
->attr
[attrib
][i
][j
] = (exec
->coef
[attrib
].a0
[i
] +
82 exec
->coef
[attrib
].dadx
[i
] * x
+
83 exec
->coef
[attrib
].dady
[i
] * y
);
89 * Compute quad's attribute values by linear interpolation with
90 * perspective correction.
94 * INPUT[attr] = MAD COEF_A0[attr], COEF_DADX[attr], INPUT_WPOS.xxxx
95 * INPUT[attr] = MAD INPUT[attr], COEF_DADY[attr], INPUT_WPOS.yyyy
96 * INPUT[attr] = MUL INPUT[attr], INPUT_WPOS.wwww
98 * (Or should that be 1/w ???)
100 static INLINE
void pinterp( struct exec_machine
*exec
,
106 for (j
= 0; j
< QUAD_SIZE
; j
++) {
107 const GLfloat x
= exec
->attr
[FRAG_ATTRIB_WPOS
][0][j
];
108 const GLfloat y
= exec
->attr
[FRAG_ATTRIB_WPOS
][1][j
];
109 const GLfloat invW
= exec
->attr
[FRAG_ATTRIB_WPOS
][3][j
];
110 exec
->attr
[attrib
][i
][j
] = ((exec
->coef
[attrib
].a0
[i
] +
111 exec
->coef
[attrib
].dadx
[i
] * x
+
112 exec
->coef
[attrib
].dady
[i
] * y
) * invW
);
118 /* This should be done by the fragment shader execution unit (code
119 * generated from the decl instructions). Do it here for now.
122 shade_quad( struct quad_stage
*qs
, struct quad_header
*quad
)
124 struct softpipe_context
*softpipe
= qs
->softpipe
;
125 struct exec_machine exec
;
126 GLfloat fx
= quad
->x0
;
127 GLfloat fy
= quad
->y0
;
129 GLboolean need_z
= softpipe
->depth_test
.enabled
; /* XXX hack */
131 exec
.coef
= quad
->coef
;
135 exec
.attr
[FRAG_ATTRIB_WPOS
][0][0] = fx
;
136 exec
.attr
[FRAG_ATTRIB_WPOS
][0][1] = fx
+ 1.0;
137 exec
.attr
[FRAG_ATTRIB_WPOS
][0][2] = fx
;
138 exec
.attr
[FRAG_ATTRIB_WPOS
][0][3] = fx
+ 1.0;
140 exec
.attr
[FRAG_ATTRIB_WPOS
][1][0] = fy
;
141 exec
.attr
[FRAG_ATTRIB_WPOS
][1][1] = fy
;
142 exec
.attr
[FRAG_ATTRIB_WPOS
][1][2] = fy
+ 1.0;
143 exec
.attr
[FRAG_ATTRIB_WPOS
][1][3] = fy
+ 1.0;
145 /* Z and W are done by linear interpolation:
146 * XXX we'll probably have to use integers for Z
148 if (/*softpipe->*/need_z
) {
149 linterp(&exec
, 0, 2); /* attr[0].z */
152 if (softpipe
->need_w
) {
153 linterp(&exec
, 0, 3); /* attr[0].w */
154 // invert(&exec, 0, 3);
157 /* Interpolate all the remaining attributes. This will get pushed
158 * into the fragment program's responsibilities at some point.
160 for (i
= 1; i
< quad
->nr_attrs
; i
++) {
162 for (j
= 0; j
< NUM_CHANNELS
; j
++)
163 linterp(&exec
, i
, j
);
165 switch (quad
->interp
[i
]) {
166 case INTERP_CONSTANT
:
167 for (j
= 0; j
< NUM_CHANNELS
; j
++)
168 cinterp(&exec
, i
, j
);
172 for (j
= 0; j
< NUM_CHANNELS
; j
++)
173 linterp(&exec
, i
, j
);
176 case INTERP_PERSPECTIVE
:
177 for (j
= 0; j
< NUM_CHANNELS
; j
++)
178 pinterp(&exec
, i
, j
);
185 /*softpipe->run_fs( tri->fp, quad, &tri->outputs );*/
188 struct tgsi_exec_machine machine
;
189 struct tgsi_exec_vector inputs
[FRAG_ATTRIB_MAX
+ 1];
190 struct tgsi_exec_vector outputs
[FRAG_ATTRIB_MAX
+ 1];
191 struct tgsi_exec_vector
*ainputs
;
192 struct tgsi_exec_vector
*aoutputs
;
195 ainputs
= (struct tgsi_exec_vector
*) tgsi_align_128bit( inputs
);
196 aoutputs
= (struct tgsi_exec_vector
*) tgsi_align_128bit( outputs
);
198 for( i
= total
= 0; i
< PIPE_ATTRIB_MAX
; i
++ ) {
201 attr
= softpipe
->fp_attr_to_slot
[i
];
203 assert( total
< FRAG_ATTRIB_MAX
);
204 assert( attr
< FRAG_ATTRIB_MAX
);
205 assert( sizeof( ainputs
[0] ) == sizeof( exec
.attr
[0] ) );
210 sizeof( ainputs
[0] ) );
215 tgsi_exec_machine_init(
217 softpipe
->fs
.tokens
);
219 machine
.Inputs
= ainputs
;
220 machine
.Outputs
= aoutputs
;
222 tgsi_exec_machine_run(
227 GLuint attr
= softpipe
->fp_attr_to_slot
[FRAG_ATTRIB_COL0
];
230 memcpy(quad
->outputs
.color
,
232 sizeof(quad
->outputs
.color
));
235 quad
->outputs
.depth
[0] = exec
.attr
[0][2][0];
236 quad
->outputs
.depth
[1] = exec
.attr
[0][2][1];
237 quad
->outputs
.depth
[2] = exec
.attr
[0][2][2];
238 quad
->outputs
.depth
[3] = exec
.attr
[0][2][3];
243 /* shader may cull fragments */
245 qs
->next
->run(qs
->next
, quad
);
250 struct quad_stage
*sp_quad_shade_stage( struct softpipe_context
*softpipe
)
252 struct quad_stage
*stage
= CALLOC_STRUCT(quad_stage
);
254 stage
->softpipe
= softpipe
;
255 stage
->run
= shade_quad
;