1 /**************************************************************************
3 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
28 #include "pipe/p_util.h"
29 #include "pipe/p_shader_tokens.h"
30 #include "draw/draw_context.h"
31 #include "draw/draw_vertex.h"
32 #include "draw/draw_private.h"
33 #include "sp_context.h"
38 * Search vertex program's outputs to find a match for the given
39 * semantic name/index. Return the index of the output slot.
41 * Return 0 if not found. This will cause the fragment program to use
42 * vertex attrib 0 (position) in the cases where the fragment program
43 * attempts to use a missing vertex program output. This is an undefined
44 * condition that users shouldn't hit anyway.
47 find_vs_output(const struct pipe_shader_state
*vs
,
52 for (i
= 0; i
< vs
->num_outputs
; i
++) {
53 if (vs
->output_semantic_name
[i
] == semantic_name
&&
54 vs
->output_semantic_index
[i
] == semantic_index
)
62 * Mark the current vertex layout as "invalid".
63 * We'll validate the vertex layout later, when we start to actually
64 * render a point or line or tri.
67 invalidate_vertex_layout(struct softpipe_context
*softpipe
)
69 softpipe
->vertex_info
.num_attribs
= 0;
74 * The vertex info describes how to convert the post-transformed vertices
75 * (simple float[][4]) used by the 'draw' module into vertices for
78 * This function validates the vertex layout and returns a pointer to a
82 softpipe_get_vertex_info(struct softpipe_context
*softpipe
)
84 struct vertex_info
*vinfo
= &softpipe
->vertex_info
;
86 if (vinfo
->num_attribs
== 0) {
87 /* compute vertex layout now */
88 const struct pipe_shader_state
*vs
= &softpipe
->vs
->shader
;
89 const struct pipe_shader_state
*fs
= &softpipe
->fs
->shader
;
90 const enum interp_mode colorInterp
91 = softpipe
->rasterizer
->flatshade
? INTERP_CONSTANT
: INTERP_LINEAR
;
95 /* if using the post-transform vertex buffer, tell draw_vbuf to
96 * simply emit the whole post-xform vertex as-is:
98 struct vertex_info
*vinfo_vbuf
= &softpipe
->vertex_info_vbuf
;
99 vinfo_vbuf
->num_attribs
= 0;
100 draw_emit_vertex_attr(vinfo_vbuf
, EMIT_ALL
, INTERP_NONE
, 0);
101 vinfo_vbuf
->size
= 4 * vs
->num_outputs
102 + sizeof(struct vertex_header
) / 4;
106 * Loop over fragment shader inputs, searching for the matching output
107 * from the vertex shader.
109 vinfo
->num_attribs
= 0;
110 for (i
= 0; i
< fs
->num_inputs
; i
++) {
112 switch (fs
->input_semantic_name
[i
]) {
113 case TGSI_SEMANTIC_POSITION
:
114 src
= find_vs_output(vs
, TGSI_SEMANTIC_POSITION
, 0);
115 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_POS
, src
);
118 case TGSI_SEMANTIC_COLOR
:
119 src
= find_vs_output(vs
, TGSI_SEMANTIC_COLOR
,
120 fs
->input_semantic_index
[i
]);
121 draw_emit_vertex_attr(vinfo
, EMIT_4F
, colorInterp
, src
);
124 case TGSI_SEMANTIC_FOG
:
125 src
= find_vs_output(vs
, TGSI_SEMANTIC_FOG
, 0);
126 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, src
);
129 case TGSI_SEMANTIC_GENERIC
:
130 /* this includes texcoords and varying vars */
131 src
= find_vs_output(vs
, TGSI_SEMANTIC_GENERIC
,
132 fs
->input_semantic_index
[i
]);
133 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, src
);
141 softpipe
->psize_slot
= find_vs_output(vs
, TGSI_SEMANTIC_PSIZE
, 0);
142 if (softpipe
->psize_slot
> 0) {
143 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
,
144 softpipe
->psize_slot
);
147 draw_compute_vertex_size(vinfo
);
155 * Called from vbuf module.
157 * Note that there's actually two different vertex layouts in softpipe.
159 * The normal one is computed in softpipe_get_vertex_info() above and is
160 * used by the point/line/tri "setup" code.
162 * The other one (this one) is only used by the vbuf module (which is
163 * not normally used by default but used in testing). For the vbuf module,
164 * we basically want to pass-through the draw module's vertex layout as-is.
165 * When the softpipe vbuf code begins drawing, the normal vertex layout
166 * will come into play again.
169 softpipe_get_vbuf_vertex_info(struct softpipe_context
*softpipe
)
171 (void) softpipe_get_vertex_info(softpipe
);
172 return &softpipe
->vertex_info_vbuf
;
177 * Recompute cliprect from scissor bounds, scissor enable and surface size.
180 compute_cliprect(struct softpipe_context
*sp
)
182 unsigned surfWidth
, surfHeight
;
184 if (sp
->framebuffer
.num_cbufs
> 0) {
185 surfWidth
= sp
->framebuffer
.cbufs
[0]->width
;
186 surfHeight
= sp
->framebuffer
.cbufs
[0]->height
;
190 surfWidth
= sp
->scissor
.maxx
;
191 surfHeight
= sp
->scissor
.maxy
;
194 if (sp
->rasterizer
->scissor
) {
195 /* clip to scissor rect */
196 sp
->cliprect
.minx
= MAX2(sp
->scissor
.minx
, 0);
197 sp
->cliprect
.miny
= MAX2(sp
->scissor
.miny
, 0);
198 sp
->cliprect
.maxx
= MIN2(sp
->scissor
.maxx
, surfWidth
);
199 sp
->cliprect
.maxy
= MIN2(sp
->scissor
.maxy
, surfHeight
);
202 /* clip to surface bounds */
203 sp
->cliprect
.minx
= 0;
204 sp
->cliprect
.miny
= 0;
205 sp
->cliprect
.maxx
= surfWidth
;
206 sp
->cliprect
.maxy
= surfHeight
;
211 /* Hopefully this will remain quite simple, otherwise need to pull in
212 * something like the state tracker mechanism.
214 void softpipe_update_derived( struct softpipe_context
*softpipe
)
216 if (softpipe
->dirty
& (SP_NEW_RASTERIZER
|
219 invalidate_vertex_layout( softpipe
);
221 if (softpipe
->dirty
& (SP_NEW_SCISSOR
|
222 SP_NEW_DEPTH_STENCIL_ALPHA
|
224 compute_cliprect(softpipe
);
226 if (softpipe
->dirty
& (SP_NEW_BLEND
|
227 SP_NEW_DEPTH_STENCIL_ALPHA
|
232 sp_build_quad_pipeline(softpipe
);