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 "pipe/draw/draw_context.h"
31 #include "pipe/draw/draw_vertex.h"
32 #include "sp_context.h"
37 * Determine which post-transform / pre-rasterization vertex attributes
39 * Derived from: fs, setup states.
41 static void calculate_vertex_layout( struct softpipe_context
*softpipe
)
43 const struct pipe_shader_state
*vs
= softpipe
->vs
->state
;
44 const struct pipe_shader_state
*fs
= &softpipe
->fs
->shader
;
45 const enum interp_mode colorInterp
46 = softpipe
->rasterizer
->flatshade
? INTERP_CONSTANT
: INTERP_LINEAR
;
47 struct vertex_info
*vinfo
= &softpipe
->vertex_info
;
48 boolean emitBack0
= FALSE
, emitBack1
= FALSE
, emitPsize
= FALSE
;
49 uint front0
= 0, back0
= 0, front1
= 0, back1
= 0;
52 memset(vinfo
, 0, sizeof(*vinfo
));
55 if (fs
->input_semantic_name
[0] == TGSI_SEMANTIC_POSITION
) {
56 /* Need Z if depth test is enabled or the fragment program uses the
57 * fragment position (XYZW).
61 softpipe
->psize_slot
= -1;
63 /* always emit vertex pos */
64 draw_emit_vertex_attr(vinfo
, FORMAT_4F
, INTERP_LINEAR
);
67 * XXX I think we need to reconcile the vertex shader outputs with
68 * the fragment shader inputs here to make sure the slots line up.
69 * Might just be getting lucky so far.
70 * Or maybe do that in the state tracker?
73 for (i
= 0; i
< vs
->num_outputs
; i
++) {
74 switch (vs
->output_semantic_name
[i
]) {
76 case TGSI_SEMANTIC_POSITION
:
77 /* vertex programs always emit position, but might not be
78 * needed for fragment progs.
83 case TGSI_SEMANTIC_COLOR
:
84 if (vs
->output_semantic_index
[i
] == 0) {
85 front0
= draw_emit_vertex_attr(vinfo
, FORMAT_4F
, colorInterp
);
88 assert(vs
->output_semantic_index
[i
] == 1);
89 front1
= draw_emit_vertex_attr(vinfo
, FORMAT_4F
, colorInterp
);
93 case TGSI_SEMANTIC_BCOLOR
:
94 if (vs
->output_semantic_index
[i
] == 0) {
98 assert(vs
->output_semantic_index
[i
] == 1);
103 case TGSI_SEMANTIC_FOG
:
104 draw_emit_vertex_attr(vinfo
, FORMAT_1F
, INTERP_PERSPECTIVE
);
107 case TGSI_SEMANTIC_PSIZE
:
108 /* XXX only emit if drawing points or front/back polygon mode
114 case TGSI_SEMANTIC_GENERIC
:
115 /* this includes texcoords and varying vars */
116 draw_emit_vertex_attr(vinfo
, FORMAT_4F
, INTERP_PERSPECTIVE
);
124 softpipe
->nr_frag_attrs
= fs
->num_inputs
;
126 /* We want these after all other attribs since they won't get passed
127 * to the fragment shader. All prior vertex output attribs should match
128 * up 1:1 with the fragment shader inputs.
131 back0
= draw_emit_vertex_attr(vinfo
, FORMAT_4F
, colorInterp
);
134 back1
= draw_emit_vertex_attr(vinfo
, FORMAT_4F
, colorInterp
);
138 = draw_emit_vertex_attr(vinfo
, FORMAT_1F
, INTERP_CONSTANT
);
141 /* If the attributes have changed, tell the draw module about
142 * the new vertex layout.
144 /* XXX we also need to do this when the shading mode (interp modes) change: */
145 if (1/*vinfo->attr_mask != softpipe->attr_mask*/) {
146 /*softpipe->attr_mask = vinfo->attr_mask;*/
148 draw_set_vertex_info( softpipe
->draw
, vinfo
);
150 draw_set_twoside_attributes(softpipe
->draw
,
151 front0
, back0
, front1
, back1
);
157 * Recompute cliprect from scissor bounds, scissor enable and surface size.
160 compute_cliprect(struct softpipe_context
*sp
)
162 unsigned surfWidth
, surfHeight
;
164 if (sp
->framebuffer
.num_cbufs
> 0) {
165 surfWidth
= sp
->framebuffer
.cbufs
[0]->width
;
166 surfHeight
= sp
->framebuffer
.cbufs
[0]->height
;
170 surfWidth
= sp
->scissor
.maxx
;
171 surfHeight
= sp
->scissor
.maxy
;
174 if (sp
->rasterizer
->scissor
) {
175 /* clip to scissor rect */
176 sp
->cliprect
.minx
= MAX2(sp
->scissor
.minx
, 0);
177 sp
->cliprect
.miny
= MAX2(sp
->scissor
.miny
, 0);
178 sp
->cliprect
.maxx
= MIN2(sp
->scissor
.maxx
, surfWidth
);
179 sp
->cliprect
.maxy
= MIN2(sp
->scissor
.maxy
, surfHeight
);
182 /* clip to surface bounds */
183 sp
->cliprect
.minx
= 0;
184 sp
->cliprect
.miny
= 0;
185 sp
->cliprect
.maxx
= surfWidth
;
186 sp
->cliprect
.maxy
= surfHeight
;
191 /* Hopefully this will remain quite simple, otherwise need to pull in
192 * something like the state tracker mechanism.
194 void softpipe_update_derived( struct softpipe_context
*softpipe
)
196 if (softpipe
->dirty
& (SP_NEW_RASTERIZER
| SP_NEW_FS
))
197 calculate_vertex_layout( softpipe
);
199 if (softpipe
->dirty
& (SP_NEW_SCISSOR
|
200 SP_NEW_DEPTH_STENCIL_ALPHA
|
202 compute_cliprect(softpipe
);
204 if (softpipe
->dirty
& (SP_NEW_BLEND
|
205 SP_NEW_DEPTH_STENCIL_ALPHA
|
210 sp_build_quad_pipeline(softpipe
);