blob: b7811e891e7f262b581a088cbb175f3113bdb77b [file] [log] [blame]
Keith Whitwell8e4a95a2007-05-24 10:41:34 +01001/**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
Brian279ffe32007-07-09 16:14:26 -060028/**
29 * Private data structures, etc for the draw module.
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010030 */
31
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010032
Brian279ffe32007-07-09 16:14:26 -060033/**
34 * Authors:
35 * Keith Whitwell <keith@tungstengraphics.com>
36 * Brian Paul
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010037 */
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010038
Brian279ffe32007-07-09 16:14:26 -060039
40#ifndef DRAW_PRIVATE_H
41#define DRAW_PRIVATE_H
42
43
Brian279ffe32007-07-09 16:14:26 -060044#include "pipe/p_state.h"
45#include "pipe/p_defines.h"
Brian766fa512007-08-20 17:02:07 -060046
Briand3eb25c2007-08-23 13:27:18 -060047#include "draw_vertex.h"
Brian279ffe32007-07-09 16:14:26 -060048
Zack Rusina1a989f2007-09-28 04:33:55 -040049#include "x86/rtasm/x86sse.h"
Brian0d13ade2007-10-02 11:46:11 -060050#include "pipe/tgsi/exec/tgsi_core.h"
51
Brian279ffe32007-07-09 16:14:26 -060052
53/**
54 * Basic vertex info.
55 * Carry some useful information around with the vertices in the prim pipe.
56 */
57struct vertex_header {
Brianfd0a6d62007-08-16 12:52:20 -060058 unsigned clipmask:12;
59 unsigned edgeflag:1;
Keith Whitwella37e0da2007-09-25 13:20:53 +010060 unsigned pad:3;
61 unsigned vertex_id:16;
Brian279ffe32007-07-09 16:14:26 -060062
Brianfd0a6d62007-08-16 12:52:20 -060063 float clip[4];
Brian279ffe32007-07-09 16:14:26 -060064
Brianfd0a6d62007-08-16 12:52:20 -060065 float data[][4]; /* Note variable size */
Brian279ffe32007-07-09 16:14:26 -060066};
67
Briand8b16d42007-08-23 17:00:47 -060068/* XXX This is too large */
Brian08673452007-09-20 13:42:37 -060069#define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float))
Keith Whitwell4bb21342007-08-14 15:44:41 +010070
71
Brian279ffe32007-07-09 16:14:26 -060072
73/**
74 * Basic info for a point/line/triangle primitive.
75 */
76struct prim_header {
Brianfd0a6d62007-08-16 12:52:20 -060077 float det; /**< front/back face determinant */
78 unsigned reset_line_stipple:1;
79 unsigned edgeflags:3;
80 unsigned pad:28;
Brian279ffe32007-07-09 16:14:26 -060081 struct vertex_header *v[3]; /**< 1 to 3 vertex pointers */
82};
83
84
85
86struct draw_context;
87
88/**
89 * Base class for all primitive drawing stages.
90 */
Brianea470ee2007-07-12 13:32:31 -060091struct draw_stage
Brian279ffe32007-07-09 16:14:26 -060092{
93 struct draw_context *draw; /**< parent context */
94
Brianea470ee2007-07-12 13:32:31 -060095 struct draw_stage *next; /**< next stage in pipeline */
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010096
97 struct vertex_header **tmp;
Brianfd0a6d62007-08-16 12:52:20 -060098 unsigned nr_tmps;
Keith Whitwell8e4a95a2007-05-24 10:41:34 +010099
Brianea470ee2007-07-12 13:32:31 -0600100 void (*begin)( struct draw_stage * );
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100101
Brianea470ee2007-07-12 13:32:31 -0600102 void (*point)( struct draw_stage *,
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100103 struct prim_header * );
104
Brianea470ee2007-07-12 13:32:31 -0600105 void (*line)( struct draw_stage *,
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100106 struct prim_header * );
107
Brianea470ee2007-07-12 13:32:31 -0600108 void (*tri)( struct draw_stage *,
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100109 struct prim_header * );
Zack Rusina1a989f2007-09-28 04:33:55 -0400110
Brianea470ee2007-07-12 13:32:31 -0600111 void (*end)( struct draw_stage * );
Brian0360b492007-07-25 15:48:09 -0600112
113 void (*reset_stipple_counter)( struct draw_stage * );
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100114};
115
116
Keith Whitwell4bb21342007-08-14 15:44:41 +0100117#define PRIM_QUEUE_LENGTH 16
118#define VCACHE_SIZE 32
119#define VCACHE_OVERFLOW 4
120#define VS_QUEUE_LENGTH (VCACHE_SIZE + VCACHE_OVERFLOW + 1) /* can never fill up */
121
Zack Rusina1a989f2007-09-28 04:33:55 -0400122/**
123 * Private version of the compiled vertex_shader
124 */
125struct draw_vertex_shader {
126 const struct pipe_shader_state *state;
Zack Rusina1a989f2007-09-28 04:33:55 -0400127};
Keith Whitwell4bb21342007-08-14 15:44:41 +0100128
Brian279ffe32007-07-09 16:14:26 -0600129/**
130 * Private context for the drawing module.
131 */
132struct draw_context
133{
Brianfd0a6d62007-08-16 12:52:20 -0600134 /** Drawing/primitive pipeline stages */
Brian279ffe32007-07-09 16:14:26 -0600135 struct {
Brianea470ee2007-07-12 13:32:31 -0600136 struct draw_stage *first; /**< one of the following */
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100137
Keith Whitwell08589f72007-09-26 11:56:17 +0100138 struct draw_stage *validate;
139
Brian279ffe32007-07-09 16:14:26 -0600140 /* stages (in logical order) */
Brian63a51ae2007-09-06 17:07:09 -0600141 struct draw_stage *feedback;
Brianea470ee2007-07-12 13:32:31 -0600142 struct draw_stage *flatshade;
143 struct draw_stage *clip;
144 struct draw_stage *cull;
145 struct draw_stage *twoside;
146 struct draw_stage *offset;
147 struct draw_stage *unfilled;
Briane3444de2007-10-22 11:01:34 -0600148 struct draw_stage *wide;
Zack Rusinde69fc12007-09-18 10:02:16 -0400149 struct draw_stage *rasterize;
Brian279ffe32007-07-09 16:14:26 -0600150 } pipeline;
151
152 /* pipe state that we need: */
Zack Rusin29440182007-09-17 12:59:50 -0400153 const struct pipe_rasterizer_state *rasterizer;
Brian63a51ae2007-09-06 17:07:09 -0600154 struct pipe_feedback_state feedback;
Brian279ffe32007-07-09 16:14:26 -0600155 struct pipe_viewport_state viewport;
Brian0a262992007-08-20 15:11:11 -0600156 struct pipe_vertex_buffer vertex_buffer[PIPE_ATTRIB_MAX];
157 struct pipe_vertex_element vertex_element[PIPE_ATTRIB_MAX];
Zack Rusina1a989f2007-09-28 04:33:55 -0400158 const struct draw_vertex_shader *vertex_shader;
Brian63a51ae2007-09-06 17:07:09 -0600159 struct pipe_vertex_buffer feedback_buffer[PIPE_ATTRIB_MAX];
160 struct pipe_vertex_element feedback_element[PIPE_ATTRIB_MAX];
Brian3e2be1c2007-08-15 18:54:05 -0600161
Brian766fa512007-08-20 17:02:07 -0600162 /** The mapped vertex element/index buffer */
163 const void *mapped_elts;
164 unsigned eltSize; /**< bytes per index (0, 1, 2 or 4) */
165 /** The mapped vertex arrays */
Brian0a262992007-08-20 15:11:11 -0600166 const void *mapped_vbuffer[PIPE_ATTRIB_MAX];
Brianc0bb4ba2007-08-22 12:24:51 -0600167 /** The mapped constant buffers (for vertex shader) */
168 const void *mapped_constants;
Brian3e2be1c2007-08-15 18:54:05 -0600169
Brian63a51ae2007-09-06 17:07:09 -0600170 /** The mapped vertex element/index buffer */
171 void *mapped_feedback_buffer[PIPE_MAX_FEEDBACK_ATTRIBS];
172 uint mapped_feedback_buffer_size[PIPE_MAX_FEEDBACK_ATTRIBS]; /* in bytes */
173
Brian279ffe32007-07-09 16:14:26 -0600174 /* Clip derived state:
175 */
Brianfd0a6d62007-08-16 12:52:20 -0600176 float plane[12][4];
177 unsigned nr_planes;
Brian279ffe32007-07-09 16:14:26 -0600178
Briand3eb25c2007-08-23 13:27:18 -0600179 /** Describes the layout of post-transformation vertices */
180 struct vertex_info vertex_info;
Brian963b8a72007-08-30 16:37:56 -0600181 /** Two-sided attributes: */
182 uint attrib_front0, attrib_back0;
183 uint attrib_front1, attrib_back1;
Brian279ffe32007-07-09 16:14:26 -0600184
Brian3eeef8a2007-10-15 10:30:38 -0600185 boolean drawing; /**< do we presently have something queued for drawing? */
Brianfd0a6d62007-08-16 12:52:20 -0600186 unsigned prim; /**< current prim type: PIPE_PRIM_x */
187 unsigned reduced_prim;
188
Brian0d13ade2007-10-02 11:46:11 -0600189 /** TGSI program interpreter runtime state */
190 struct tgsi_exec_machine machine;
Keith Whitwell4bb21342007-08-14 15:44:41 +0100191
192 /* Post-tnl vertex cache:
193 */
194 struct {
Brian3df65af2007-10-23 15:02:02 -0600195 unsigned referenced; /**< bitfield */
Brianfd0a6d62007-08-16 12:52:20 -0600196 unsigned idx[VCACHE_SIZE + VCACHE_OVERFLOW];
Keith Whitwell4bb21342007-08-14 15:44:41 +0100197 struct vertex_header *vertex[VCACHE_SIZE + VCACHE_OVERFLOW];
Brianfd0a6d62007-08-16 12:52:20 -0600198 unsigned overflow;
Keith Whitwell08589f72007-09-26 11:56:17 +0100199
200 struct vertex_header *(*get_vertex)( struct draw_context *draw,
201 unsigned i );
Keith Whitwell4bb21342007-08-14 15:44:41 +0100202 } vcache;
203
204 /* Vertex shader queue:
205 */
206 struct {
207 struct {
Brianfd0a6d62007-08-16 12:52:20 -0600208 unsigned elt;
Keith Whitwell4bb21342007-08-14 15:44:41 +0100209 struct vertex_header *dest;
210 } queue[VS_QUEUE_LENGTH];
Brianfd0a6d62007-08-16 12:52:20 -0600211 unsigned queue_nr;
Keith Whitwell4bb21342007-08-14 15:44:41 +0100212 } vs;
213
214 /* Prim pipeline queue:
215 */
216 struct {
217
218 /* Need to queue up primitives until their vertices have been
219 * transformed by a vs queue flush.
220 */
221 struct prim_header queue[PRIM_QUEUE_LENGTH];
Brianfd0a6d62007-08-16 12:52:20 -0600222 unsigned queue_nr;
Keith Whitwell4bb21342007-08-14 15:44:41 +0100223 } pq;
Zack Rusin8731e392007-09-28 07:33:54 -0400224
225 int use_sse : 1;
Brian279ffe32007-07-09 16:14:26 -0600226};
227
228
229
Brian63a51ae2007-09-06 17:07:09 -0600230extern struct draw_stage *draw_feedback_stage( struct draw_context *context );
Brianea470ee2007-07-12 13:32:31 -0600231extern struct draw_stage *draw_unfilled_stage( struct draw_context *context );
232extern struct draw_stage *draw_twoside_stage( struct draw_context *context );
233extern struct draw_stage *draw_offset_stage( struct draw_context *context );
234extern struct draw_stage *draw_clip_stage( struct draw_context *context );
235extern struct draw_stage *draw_flatshade_stage( struct draw_context *context );
236extern struct draw_stage *draw_cull_stage( struct draw_context *context );
Briane3444de2007-10-22 11:01:34 -0600237extern struct draw_stage *draw_wide_stage( struct draw_context *context );
Keith Whitwell08589f72007-09-26 11:56:17 +0100238extern struct draw_stage *draw_validate_stage( struct draw_context *context );
Brian279ffe32007-07-09 16:14:26 -0600239
240
Brianea470ee2007-07-12 13:32:31 -0600241extern void draw_free_tmps( struct draw_stage *stage );
Brianfd0a6d62007-08-16 12:52:20 -0600242extern void draw_alloc_tmps( struct draw_stage *stage, unsigned nr );
Brian279ffe32007-07-09 16:14:26 -0600243
244
Brian9a11a4a2007-08-31 11:28:31 -0600245extern int draw_vertex_cache_check_space( struct draw_context *draw,
246 unsigned nr_verts );
247
Brian9a11a4a2007-08-31 11:28:31 -0600248extern void draw_vertex_cache_invalidate( struct draw_context *draw );
249extern void draw_vertex_cache_unreference( struct draw_context *draw );
Keith Whitwella37e0da2007-09-25 13:20:53 +0100250extern void draw_vertex_cache_reset_vertex_ids( struct draw_context *draw );
251
Brian9a11a4a2007-08-31 11:28:31 -0600252
253extern void draw_vertex_shader_queue_flush( struct draw_context *draw );
254
255struct tgsi_exec_machine;
256
257extern void draw_vertex_fetch( struct draw_context *draw,
258 struct tgsi_exec_machine *machine,
259 const unsigned *elts,
260 unsigned count );
261
Brian279ffe32007-07-09 16:14:26 -0600262
Keith Whitwell08589f72007-09-26 11:56:17 +0100263#define DRAW_FLUSH_PRIM_QUEUE 0x1
264#define DRAW_FLUSH_VERTEX_CACHE_INVALIDATE 0x2
265#define DRAW_FLUSH_DRAW 0x4
266
267
268void draw_do_flush( struct draw_context *draw,
269 unsigned flags );
270
271
272
273
Brian279ffe32007-07-09 16:14:26 -0600274/**
275 * Get a writeable copy of a vertex.
276 * \param stage drawing stage info
277 * \param vert the vertex to copy (source)
278 * \param idx index into stage's tmp[] array to put the copy (dest)
279 * \return pointer to the copied vertex
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100280 */
281static INLINE struct vertex_header *
Brianea470ee2007-07-12 13:32:31 -0600282dup_vert( struct draw_stage *stage,
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100283 const struct vertex_header *vert,
Brianfd0a6d62007-08-16 12:52:20 -0600284 unsigned idx )
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100285{
286 struct vertex_header *tmp = stage->tmp[idx];
Briand3eb25c2007-08-23 13:27:18 -0600287 memcpy(tmp, vert, stage->draw->vertex_info.size * sizeof(float) );
Keith Whitwella37e0da2007-09-25 13:20:53 +0100288 tmp->vertex_id = ~0;
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100289 return tmp;
290}
291
Zack Rusinb46926c2007-10-03 10:31:42 -0400292static INLINE float
293dot4(const float *a, const float *b)
294{
295 float result = (a[0]*b[0] +
296 a[1]*b[1] +
297 a[2]*b[2] +
298 a[3]*b[3]);
299
300 return result;
301}
Keith Whitwell8e4a95a2007-05-24 10:41:34 +0100302
Brian279ffe32007-07-09 16:14:26 -0600303#endif /* DRAW_PRIVATE_H */