7e5efbfde39899712bb9c6c60ab9f6e8e27b5d0d
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"
30 #include "pipe/draw/draw_context.h"
31 #include "pipe/draw/draw_vertex.h"
33 #include "sp_context.h"
36 #include "pipe/tgsi/exec/tgsi_token.h"
40 * Determine which post-transform / pre-rasterization vertex attributes
42 * Derived from: fs, setup states.
44 static void calculate_vertex_layout( struct softpipe_context
*softpipe
)
46 const struct pipe_shader_state
*vs
= softpipe
->vs
->state
;
47 const struct pipe_shader_state
*fs
= &softpipe
->fs
->shader
;
48 const enum interp_mode colorInterp
49 = softpipe
->rasterizer
->flatshade
? INTERP_CONSTANT
: INTERP_LINEAR
;
50 struct vertex_info
*vinfo
= &softpipe
->vertex_info
;
51 boolean emitBack0
= FALSE
, emitBack1
= FALSE
, emitPsize
= FALSE
;
52 uint front0
= 0, back0
= 0, front1
= 0, back1
= 0;
55 memset(vinfo
, 0, sizeof(*vinfo
));
57 if (softpipe
->depth_stencil
->depth
.enabled
)
58 softpipe
->need_z
= TRUE
;
60 softpipe
->need_z
= FALSE
;
61 softpipe
->need_w
= FALSE
;
63 if (fs
->input_semantic_name
[0] == TGSI_SEMANTIC_POSITION
) {
64 /* Need Z if depth test is enabled or the fragment program uses the
65 * fragment position (XYZW).
67 softpipe
->need_z
= TRUE
;
68 softpipe
->need_w
= TRUE
;
71 softpipe
->psize_slot
= -1;
73 /* always emit vertex pos */
74 draw_emit_vertex_attr(vinfo
, FORMAT_4F
, INTERP_LINEAR
);
77 * XXX I think we need to reconcile the vertex shader outputs with
78 * the fragment shader inputs here to make sure the slots line up.
79 * Might just be getting lucky so far.
80 * Or maybe do that in the state tracker?
83 for (i
= 0; i
< vs
->num_outputs
; i
++) {
84 switch (vs
->output_semantic_name
[i
]) {
86 case TGSI_SEMANTIC_POSITION
:
87 /* vertex programs always emit position, but might not be
88 * needed for fragment progs.
93 case TGSI_SEMANTIC_COLOR
:
94 if (fs
->input_semantic_index
[i
] == 0) {
95 front0
= draw_emit_vertex_attr(vinfo
, FORMAT_4F
, colorInterp
);
98 assert(fs
->input_semantic_index
[i
] == 1);
99 front1
= draw_emit_vertex_attr(vinfo
, FORMAT_4F
, colorInterp
);
103 case TGSI_SEMANTIC_BCOLOR
:
104 if (fs
->input_semantic_index
[i
] == 0) {
108 assert(fs
->input_semantic_index
[i
] == 1);
113 case TGSI_SEMANTIC_FOG
:
114 draw_emit_vertex_attr(vinfo
, FORMAT_1F
, INTERP_PERSPECTIVE
);
117 case TGSI_SEMANTIC_PSIZE
:
118 /* XXX only emit if drawing points or front/back polygon mode
124 case TGSI_SEMANTIC_GENERIC
:
125 /* this includes texcoords and varying vars */
126 draw_emit_vertex_attr(vinfo
, FORMAT_4F
, INTERP_PERSPECTIVE
);
127 softpipe
->need_w
= TRUE
;
135 softpipe
->nr_frag_attrs
= vinfo
->num_attribs
;
137 /* We want these after all other attribs since they won't get passed
138 * to the fragment shader. All prior vertex output attribs should match
139 * up 1:1 with the fragment shader inputs.
142 back0
= draw_emit_vertex_attr(vinfo
, FORMAT_4F
, colorInterp
);
145 back1
= draw_emit_vertex_attr(vinfo
, FORMAT_4F
, colorInterp
);
149 = draw_emit_vertex_attr(vinfo
, FORMAT_1F
, INTERP_CONSTANT
);
152 /* If the attributes have changed, tell the draw module about
153 * the new vertex layout.
155 /* XXX we also need to do this when the shading mode (interp modes) change: */
156 if (1/*vinfo->attr_mask != softpipe->attr_mask*/) {
157 /*softpipe->attr_mask = vinfo->attr_mask;*/
159 draw_set_vertex_info( softpipe
->draw
, vinfo
);
161 draw_set_twoside_attributes(softpipe
->draw
,
162 front0
, back0
, front1
, back1
);
168 * Recompute cliprect from scissor bounds, scissor enable and surface size.
171 compute_cliprect(struct softpipe_context
*sp
)
173 unsigned surfWidth
, surfHeight
;
175 if (sp
->framebuffer
.num_cbufs
> 0) {
176 surfWidth
= sp
->framebuffer
.cbufs
[0]->width
;
177 surfHeight
= sp
->framebuffer
.cbufs
[0]->height
;
181 surfWidth
= sp
->scissor
.maxx
;
182 surfHeight
= sp
->scissor
.maxy
;
185 if (sp
->rasterizer
->scissor
) {
186 /* clip to scissor rect */
187 sp
->cliprect
.minx
= MAX2(sp
->scissor
.minx
, 0);
188 sp
->cliprect
.miny
= MAX2(sp
->scissor
.miny
, 0);
189 sp
->cliprect
.maxx
= MIN2(sp
->scissor
.maxx
, surfWidth
);
190 sp
->cliprect
.maxy
= MIN2(sp
->scissor
.maxy
, surfHeight
);
193 /* clip to surface bounds */
194 sp
->cliprect
.minx
= 0;
195 sp
->cliprect
.miny
= 0;
196 sp
->cliprect
.maxx
= surfWidth
;
197 sp
->cliprect
.maxy
= surfHeight
;
202 /* Hopefully this will remain quite simple, otherwise need to pull in
203 * something like the state tracker mechanism.
205 void softpipe_update_derived( struct softpipe_context
*softpipe
)
207 if (softpipe
->dirty
& (SP_NEW_RASTERIZER
| SP_NEW_FS
))
208 calculate_vertex_layout( softpipe
);
210 if (softpipe
->dirty
& (SP_NEW_SCISSOR
|
211 SP_NEW_DEPTH_STENCIL
|
213 compute_cliprect(softpipe
);
215 if (softpipe
->dirty
& (SP_NEW_BLEND
|
216 SP_NEW_DEPTH_STENCIL
|
221 sp_build_quad_pipeline(softpipe
);