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"
36 #include "lp_tex_cache.h"
41 * Mark the current vertex layout as "invalid".
42 * We'll validate the vertex layout later, when we start to actually
43 * render a point or line or tri.
46 invalidate_vertex_layout(struct llvmpipe_context
*llvmpipe
)
48 llvmpipe
->vertex_info
.num_attribs
= 0;
53 * The vertex info describes how to convert the post-transformed vertices
54 * (simple float[][4]) used by the 'draw' module into vertices for
57 * This function validates the vertex layout and returns a pointer to a
61 llvmpipe_get_vertex_info(struct llvmpipe_context
*llvmpipe
)
63 struct vertex_info
*vinfo
= &llvmpipe
->vertex_info
;
65 if (vinfo
->num_attribs
== 0) {
66 /* compute vertex layout now */
67 const struct lp_fragment_shader
*lpfs
= llvmpipe
->fs
;
68 const enum interp_mode colorInterp
69 = llvmpipe
->rasterizer
->flatshade
? INTERP_CONSTANT
: INTERP_LINEAR
;
73 /* if using the post-transform vertex buffer, tell draw_vbuf to
74 * simply emit the whole post-xform vertex as-is:
76 struct vertex_info
*vinfo_vbuf
= &llvmpipe
->vertex_info_vbuf
;
77 const uint num
= draw_num_vs_outputs(llvmpipe
->draw
);
80 /* No longer any need to try and emit draw vertex_header info.
82 vinfo_vbuf
->num_attribs
= 0;
83 for (i
= 0; i
< num
; i
++) {
84 draw_emit_vertex_attr(vinfo_vbuf
, EMIT_4F
, INTERP_PERSPECTIVE
, i
);
86 draw_compute_vertex_size(vinfo_vbuf
);
90 * Loop over fragment shader inputs, searching for the matching output
91 * from the vertex shader.
93 vinfo
->num_attribs
= 0;
94 for (i
= 0; i
< lpfs
->info
.num_inputs
; i
++) {
96 enum interp_mode interp
;
98 switch (lpfs
->info
.input_interpolate
[i
]) {
99 case TGSI_INTERPOLATE_CONSTANT
:
100 interp
= INTERP_CONSTANT
;
102 case TGSI_INTERPOLATE_LINEAR
:
103 interp
= INTERP_LINEAR
;
105 case TGSI_INTERPOLATE_PERSPECTIVE
:
106 interp
= INTERP_PERSPECTIVE
;
110 interp
= INTERP_LINEAR
;
113 switch (lpfs
->info
.input_semantic_name
[i
]) {
114 case TGSI_SEMANTIC_POSITION
:
115 src
= draw_find_vs_output(llvmpipe
->draw
,
116 TGSI_SEMANTIC_POSITION
, 0);
117 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_POS
, src
);
120 case TGSI_SEMANTIC_COLOR
:
121 src
= draw_find_vs_output(llvmpipe
->draw
, TGSI_SEMANTIC_COLOR
,
122 lpfs
->info
.input_semantic_index
[i
]);
123 draw_emit_vertex_attr(vinfo
, EMIT_4F
, colorInterp
, src
);
126 case TGSI_SEMANTIC_FOG
:
127 src
= draw_find_vs_output(llvmpipe
->draw
, TGSI_SEMANTIC_FOG
, 0);
128 draw_emit_vertex_attr(vinfo
, EMIT_4F
, interp
, src
);
131 case TGSI_SEMANTIC_GENERIC
:
132 case TGSI_SEMANTIC_FACE
:
133 /* this includes texcoords and varying vars */
134 src
= draw_find_vs_output(llvmpipe
->draw
, TGSI_SEMANTIC_GENERIC
,
135 lpfs
->info
.input_semantic_index
[i
]);
136 draw_emit_vertex_attr(vinfo
, EMIT_4F
, interp
, src
);
144 llvmpipe
->psize_slot
= draw_find_vs_output(llvmpipe
->draw
,
145 TGSI_SEMANTIC_PSIZE
, 0);
146 if (llvmpipe
->psize_slot
> 0) {
147 draw_emit_vertex_attr(vinfo
, EMIT_4F
, INTERP_CONSTANT
,
148 llvmpipe
->psize_slot
);
151 draw_compute_vertex_size(vinfo
);
159 * Called from vbuf module.
161 * Note that there's actually two different vertex layouts in llvmpipe.
163 * The normal one is computed in llvmpipe_get_vertex_info() above and is
164 * used by the point/line/tri "setup" code.
166 * The other one (this one) is only used by the vbuf module (which is
167 * not normally used by default but used in testing). For the vbuf module,
168 * we basically want to pass-through the draw module's vertex layout as-is.
169 * When the llvmpipe vbuf code begins drawing, the normal vertex layout
170 * will come into play again.
173 llvmpipe_get_vbuf_vertex_info(struct llvmpipe_context
*llvmpipe
)
175 (void) llvmpipe_get_vertex_info(llvmpipe
);
176 return &llvmpipe
->vertex_info_vbuf
;
181 * Recompute cliprect from scissor bounds, scissor enable and surface size.
184 compute_cliprect(struct llvmpipe_context
*lp
)
186 /* LP_NEW_FRAMEBUFFER
188 uint surfWidth
= lp
->framebuffer
.width
;
189 uint surfHeight
= lp
->framebuffer
.height
;
193 if (lp
->rasterizer
->scissor
) {
197 * clip to scissor rect:
199 lp
->cliprect
.minx
= MAX2(lp
->scissor
.minx
, 0);
200 lp
->cliprect
.miny
= MAX2(lp
->scissor
.miny
, 0);
201 lp
->cliprect
.maxx
= MIN2(lp
->scissor
.maxx
, surfWidth
);
202 lp
->cliprect
.maxy
= MIN2(lp
->scissor
.maxy
, surfHeight
);
205 /* clip to surface bounds */
206 lp
->cliprect
.minx
= 0;
207 lp
->cliprect
.miny
= 0;
208 lp
->cliprect
.maxx
= surfWidth
;
209 lp
->cliprect
.maxy
= surfHeight
;
215 update_tgsi_samplers( struct llvmpipe_context
*llvmpipe
)
219 /* vertex shader samplers */
220 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
221 llvmpipe
->tgsi
.vert_samplers
[i
].sampler
= llvmpipe
->sampler
[i
];
222 llvmpipe
->tgsi
.vert_samplers
[i
].texture
= llvmpipe
->texture
[i
];
223 llvmpipe
->tgsi
.frag_samplers
[i
].base
.get_samples
= lp_get_samples
;
226 /* fragment shader samplers */
227 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
228 llvmpipe
->tgsi
.frag_samplers
[i
].sampler
= llvmpipe
->sampler
[i
];
229 llvmpipe
->tgsi
.frag_samplers
[i
].texture
= llvmpipe
->texture
[i
];
230 llvmpipe
->tgsi
.frag_samplers
[i
].base
.get_samples
= lp_get_samples
;
233 for (i
= 0; i
< PIPE_MAX_SAMPLERS
; i
++) {
234 lp_tex_tile_cache_validate_texture( llvmpipe
->tex_cache
[i
] );
237 llvmpipe
->jit_context
.samplers
= (struct tgsi_sampler
**)llvmpipe
->tgsi
.frag_samplers_list
;
240 /* Hopefully this will remain quite simple, otherwise need to pull in
241 * something like the state tracker mechanism.
243 void llvmpipe_update_derived( struct llvmpipe_context
*llvmpipe
)
245 struct llvmpipe_screen
*lp_screen
= llvmpipe_screen(llvmpipe
->pipe
.screen
);
247 /* Check for updated textures.
249 if (llvmpipe
->tex_timestamp
!= lp_screen
->timestamp
) {
250 llvmpipe
->tex_timestamp
= lp_screen
->timestamp
;
251 llvmpipe
->dirty
|= LP_NEW_TEXTURE
;
254 if (llvmpipe
->dirty
& (LP_NEW_SAMPLER
|
256 update_tgsi_samplers( llvmpipe
);
258 if (llvmpipe
->dirty
& (LP_NEW_RASTERIZER
|
261 invalidate_vertex_layout( llvmpipe
);
263 if (llvmpipe
->dirty
& (LP_NEW_SCISSOR
|
266 compute_cliprect(llvmpipe
);
268 if (llvmpipe
->dirty
& (LP_NEW_FS
|
270 LP_NEW_DEPTH_STENCIL_ALPHA
|
273 llvmpipe_update_fs( llvmpipe
);