1 /**************************************************************************
3 * Copyright 2007 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 "util/u_memory.h"
29 #include "pipe/p_shader_tokens.h"
30 #include "draw/draw_context.h"
31 #include "draw/draw_vertex.h"
32 #include "cell_context.h"
33 #include "cell_batch.h"
34 #include "cell_state.h"
35 #include "cell_state_emit.h"
39 * Determine how to map vertex program outputs to fragment program inputs.
40 * Basically, this will be used when computing the triangle interpolation
41 * coefficients from the post-transform vertex attributes.
44 calculate_vertex_layout( struct cell_context
*cell
)
46 const struct cell_fragment_shader_state
*fs
= cell
->fs
;
47 const enum interp_mode colorInterp
48 = cell
->rasterizer
->flatshade
? INTERP_CONSTANT
: INTERP_LINEAR
;
49 struct vertex_info
*vinfo
= &cell
->vertex_info
;
55 /* if using the post-transform vertex buffer, tell draw_vbuf to
56 * simply emit the whole post-xform vertex as-is:
58 struct vertex_info
*vinfo_vbuf
= &cell
->vertex_info_vbuf
;
59 vinfo_vbuf
->num_attribs
= 0;
60 draw_emit_vertex_attr(vinfo_vbuf
, EMIT_ALL
, INTERP_NONE
, 0);
61 vinfo_vbuf
->size
= 4 * vs
->num_outputs
+ sizeof(struct vertex_header
)/4;
66 vinfo
->num_attribs
= 0;
68 /* we always want to emit vertex pos */
69 src
= draw_find_shader_output(cell
->draw
, TGSI_SEMANTIC_POSITION
, 0);
71 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_POS
, src
);
75 * Loop over fragment shader inputs, searching for the matching output
76 * from the vertex shader.
78 for (i
= 0; i
< fs
->info
.num_inputs
; i
++) {
79 switch (fs
->info
.input_semantic_name
[i
]) {
80 case TGSI_SEMANTIC_POSITION
:
81 /* already done above */
84 case TGSI_SEMANTIC_COLOR
:
85 src
= draw_find_shader_output(cell
->draw
, TGSI_SEMANTIC_COLOR
,
86 fs
->info
.input_semantic_index
[i
]);
88 draw_emit_vertex_attr(vinfo
, EMIT_4F
, colorInterp
, src
);
91 case TGSI_SEMANTIC_FOG
:
92 src
= draw_find_shader_output(cell
->draw
, TGSI_SEMANTIC_FOG
, 0);
94 if (src
< 0) /* XXX temp hack, try demos/fogcoord.c with this */
98 draw_emit_vertex_attr(vinfo
, EMIT_1F
, INTERP_PERSPECTIVE
, src
);
101 case TGSI_SEMANTIC_GENERIC
:
102 /* this includes texcoords and varying vars */
103 src
= draw_find_shader_output(cell
->draw
, TGSI_SEMANTIC_GENERIC
,
104 fs
->info
.input_semantic_index
[i
]);
106 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, src
);
114 draw_compute_vertex_size(vinfo
);
116 /* XXX only signal this if format really changes */
117 cell
->dirty
|= CELL_NEW_VERTEX_INFO
;
123 * Recompute cliprect from scissor bounds, scissor enable and surface size.
126 compute_cliprect(struct cell_context
*sp
)
128 uint surfWidth
= sp
->framebuffer
.width
;
129 uint surfHeight
= sp
->framebuffer
.height
;
131 if (sp
->rasterizer
->scissor
) {
132 /* clip to scissor rect */
133 sp
->cliprect
.minx
= MAX2(sp
->scissor
.minx
, 0);
134 sp
->cliprect
.miny
= MAX2(sp
->scissor
.miny
, 0);
135 sp
->cliprect
.maxx
= MIN2(sp
->scissor
.maxx
, surfWidth
);
136 sp
->cliprect
.maxy
= MIN2(sp
->scissor
.maxy
, surfHeight
);
139 /* clip to surface bounds */
140 sp
->cliprect
.minx
= 0;
141 sp
->cliprect
.miny
= 0;
142 sp
->cliprect
.maxx
= surfWidth
;
143 sp
->cliprect
.maxy
= surfHeight
;
151 * Update derived state, send current state to SPUs prior to rendering.
153 void cell_update_derived( struct cell_context
*cell
)
155 if (cell
->dirty
& (CELL_NEW_RASTERIZER
|
158 calculate_vertex_layout( cell
);
161 if (cell
->dirty
& (CELL_NEW_SCISSOR
|
162 CELL_NEW_DEPTH_STENCIL_ALPHA
|
163 CELL_NEW_FRAMEBUFFER
))
164 compute_cliprect(cell
);
167 cell_emit_state(cell
);