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 "util/u_math.h"
29 #include "util/u_memory.h"
30 #include "pipe/p_shader_tokens.h"
31 #include "draw/draw_context.h"
32 #include "draw/draw_vertex.h"
33 #include "draw/draw_private.h"
34 #include "lp_context.h"
35 #include "lp_screen.h"
40 * Mark the current vertex layout as "invalid".
41 * We'll validate the vertex layout later, when we start to actually
42 * render a point or line or tri.
45 invalidate_vertex_layout(struct llvmpipe_context
*llvmpipe
)
47 llvmpipe
->vertex_info
.num_attribs
= 0;
52 * The vertex info describes how to convert the post-transformed vertices
53 * (simple float[][4]) used by the 'draw' module into vertices for
56 * This function validates the vertex layout and returns a pointer to a
60 llvmpipe_get_vertex_info(struct llvmpipe_context
*llvmpipe
)
62 struct vertex_info
*vinfo
= &llvmpipe
->vertex_info
;
64 if (vinfo
->num_attribs
== 0) {
65 /* compute vertex layout now */
66 const struct lp_fragment_shader
*lpfs
= llvmpipe
->fs
;
67 struct vertex_info
*vinfo_vbuf
= &llvmpipe
->vertex_info_vbuf
;
68 const uint num
= draw_current_shader_outputs(llvmpipe
->draw
);
71 /* Tell draw_vbuf to simply emit the whole post-xform vertex
72 * as-is. No longer any need to try and emit draw vertex_header
75 vinfo_vbuf
->num_attribs
= 0;
76 for (i
= 0; i
< num
; i
++) {
77 draw_emit_vertex_attr(vinfo_vbuf
, EMIT_4F
, INTERP_PERSPECTIVE
, i
);
79 draw_compute_vertex_size(vinfo_vbuf
);
82 * Loop over fragment shader inputs, searching for the matching output
83 * from the vertex shader.
85 vinfo
->num_attribs
= 0;
86 for (i
= 0; i
< lpfs
->info
.num_inputs
; i
++) {
88 enum interp_mode interp
;
90 switch (lpfs
->info
.input_interpolate
[i
]) {
91 case TGSI_INTERPOLATE_CONSTANT
:
92 interp
= INTERP_CONSTANT
;
94 case TGSI_INTERPOLATE_LINEAR
:
95 interp
= INTERP_LINEAR
;
97 case TGSI_INTERPOLATE_PERSPECTIVE
:
98 interp
= INTERP_PERSPECTIVE
;
102 interp
= INTERP_LINEAR
;
105 switch (lpfs
->info
.input_semantic_name
[i
]) {
106 case TGSI_SEMANTIC_POSITION
:
110 case TGSI_SEMANTIC_COLOR
:
111 if (llvmpipe
->rasterizer
->flatshade
) {
112 interp
= INTERP_CONSTANT
;
117 /* this includes texcoords and varying vars */
118 src
= draw_find_shader_output(llvmpipe
->draw
,
119 lpfs
->info
.input_semantic_name
[i
],
120 lpfs
->info
.input_semantic_index
[i
]);
121 draw_emit_vertex_attr(vinfo
, EMIT_4F
, interp
, src
);
124 llvmpipe
->psize_slot
= draw_find_shader_output(llvmpipe
->draw
,
125 TGSI_SEMANTIC_PSIZE
, 0);
126 if (llvmpipe
->psize_slot
> 0) {
127 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
,
128 llvmpipe
->psize_slot
);
131 draw_compute_vertex_size(vinfo
);
139 * Called from vbuf module.
141 * Note that there's actually two different vertex layouts in llvmpipe.
143 * The normal one is computed in llvmpipe_get_vertex_info() above and is
144 * used by the point/line/tri "setup" code.
146 * The other one (this one) is only used by the vbuf module (which is
147 * not normally used by default but used in testing). For the vbuf module,
148 * we basically want to pass-through the draw module's vertex layout as-is.
149 * When the llvmpipe vbuf code begins drawing, the normal vertex layout
150 * will come into play again.
153 llvmpipe_get_vbuf_vertex_info(struct llvmpipe_context
*llvmpipe
)
155 (void) llvmpipe_get_vertex_info(llvmpipe
);
156 return &llvmpipe
->vertex_info_vbuf
;
161 * Recompute cliprect from scissor bounds, scissor enable and surface size.
164 compute_cliprect(struct llvmpipe_context
*lp
)
166 /* LP_NEW_FRAMEBUFFER
168 uint surfWidth
= lp
->framebuffer
.width
;
169 uint surfHeight
= lp
->framebuffer
.height
;
173 if (lp
->rasterizer
->scissor
) {
177 * clip to scissor rect:
179 lp
->cliprect
.minx
= MAX2(lp
->scissor
.minx
, 0);
180 lp
->cliprect
.miny
= MAX2(lp
->scissor
.miny
, 0);
181 lp
->cliprect
.maxx
= MIN2(lp
->scissor
.maxx
, surfWidth
);
182 lp
->cliprect
.maxy
= MIN2(lp
->scissor
.maxy
, surfHeight
);
185 /* clip to surface bounds */
186 lp
->cliprect
.minx
= 0;
187 lp
->cliprect
.miny
= 0;
188 lp
->cliprect
.maxx
= surfWidth
;
189 lp
->cliprect
.maxy
= surfHeight
;
194 /* Hopefully this will remain quite simple, otherwise need to pull in
195 * something like the state tracker mechanism.
197 void llvmpipe_update_derived( struct llvmpipe_context
*llvmpipe
)
199 struct llvmpipe_screen
*lp_screen
= llvmpipe_screen(llvmpipe
->pipe
.screen
);
201 /* Check for updated textures.
203 if (llvmpipe
->tex_timestamp
!= lp_screen
->timestamp
) {
204 llvmpipe
->tex_timestamp
= lp_screen
->timestamp
;
205 llvmpipe
->dirty
|= LP_NEW_TEXTURE
;
208 if (llvmpipe
->dirty
& (LP_NEW_SAMPLER
|
213 if (llvmpipe
->dirty
& (LP_NEW_RASTERIZER
|
216 invalidate_vertex_layout( llvmpipe
);
218 if (llvmpipe
->dirty
& (LP_NEW_SCISSOR
|
221 compute_cliprect(llvmpipe
);
223 if (llvmpipe
->dirty
& (LP_NEW_FS
|
225 LP_NEW_DEPTH_STENCIL_ALPHA
|
228 llvmpipe_update_fs( llvmpipe
);