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 find_vs_output(const struct cell_vertex_shader_state
*vs
,
44 for (i
= 0; i
< vs
->info
.num_outputs
; i
++) {
45 if (vs
->info
.output_semantic_name
[i
] == semantic_name
&&
46 vs
->info
.output_semantic_index
[i
] == semantic_index
)
54 * Determine how to map vertex program outputs to fragment program inputs.
55 * Basically, this will be used when computing the triangle interpolation
56 * coefficients from the post-transform vertex attributes.
59 calculate_vertex_layout( struct cell_context
*cell
)
61 const struct cell_vertex_shader_state
*vs
= cell
->vs
;
62 const struct cell_fragment_shader_state
*fs
= cell
->fs
;
63 const enum interp_mode colorInterp
64 = cell
->rasterizer
->flatshade
? INTERP_CONSTANT
: INTERP_LINEAR
;
65 struct vertex_info
*vinfo
= &cell
->vertex_info
;
71 /* if using the post-transform vertex buffer, tell draw_vbuf to
72 * simply emit the whole post-xform vertex as-is:
74 struct vertex_info
*vinfo_vbuf
= &cell
->vertex_info_vbuf
;
75 vinfo_vbuf
->num_attribs
= 0;
76 draw_emit_vertex_attr(vinfo_vbuf
, EMIT_ALL
, INTERP_NONE
, 0);
77 vinfo_vbuf
->size
= 4 * vs
->num_outputs
+ sizeof(struct vertex_header
)/4;
82 vinfo
->num_attribs
= 0;
84 /* we always want to emit vertex pos */
85 src
= find_vs_output(vs
, TGSI_SEMANTIC_POSITION
, 0);
87 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_POS
, src
);
91 * Loop over fragment shader inputs, searching for the matching output
92 * from the vertex shader.
94 for (i
= 0; i
< fs
->info
.num_inputs
; i
++) {
95 switch (fs
->info
.input_semantic_name
[i
]) {
96 case TGSI_SEMANTIC_POSITION
:
97 /* already done above */
100 case TGSI_SEMANTIC_COLOR
:
101 src
= find_vs_output(vs
, TGSI_SEMANTIC_COLOR
,
102 fs
->info
.input_semantic_index
[i
]);
104 draw_emit_vertex_attr(vinfo
, EMIT_4F
, colorInterp
, src
);
107 case TGSI_SEMANTIC_FOG
:
108 src
= find_vs_output(vs
, TGSI_SEMANTIC_FOG
, 0);
110 if (src
< 0) /* XXX temp hack, try demos/fogcoord.c with this */
114 draw_emit_vertex_attr(vinfo
, EMIT_1F
, INTERP_PERSPECTIVE
, src
);
117 case TGSI_SEMANTIC_GENERIC
:
118 /* this includes texcoords and varying vars */
119 src
= find_vs_output(vs
, TGSI_SEMANTIC_GENERIC
,
120 fs
->info
.input_semantic_index
[i
]);
122 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_PERSPECTIVE
, src
);
130 draw_compute_vertex_size(vinfo
);
132 /* XXX only signal this if format really changes */
133 cell
->dirty
|= CELL_NEW_VERTEX_INFO
;
139 * Recompute cliprect from scissor bounds, scissor enable and surface size.
142 compute_cliprect(struct cell_context
*sp
)
144 uint surfWidth
= sp
->framebuffer
.width
;
145 uint surfHeight
= sp
->framebuffer
.height
;
147 if (sp
->rasterizer
->scissor
) {
148 /* clip to scissor rect */
149 sp
->cliprect
.minx
= MAX2(sp
->scissor
.minx
, 0);
150 sp
->cliprect
.miny
= MAX2(sp
->scissor
.miny
, 0);
151 sp
->cliprect
.maxx
= MIN2(sp
->scissor
.maxx
, surfWidth
);
152 sp
->cliprect
.maxy
= MIN2(sp
->scissor
.maxy
, surfHeight
);
155 /* clip to surface bounds */
156 sp
->cliprect
.minx
= 0;
157 sp
->cliprect
.miny
= 0;
158 sp
->cliprect
.maxx
= surfWidth
;
159 sp
->cliprect
.maxy
= surfHeight
;
166 void cell_update_derived( struct cell_context
*cell
)
168 if (cell
->dirty
& (CELL_NEW_RASTERIZER
|
171 calculate_vertex_layout( cell
);
174 if (cell
->dirty
& (CELL_NEW_SCISSOR
|
175 CELL_NEW_DEPTH_STENCIL_ALPHA
|
176 CELL_NEW_FRAMEBUFFER
))
177 compute_cliprect(cell
);
180 cell_emit_state(cell
);