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 **************************************************************************/
29 * Private data structures, etc for the draw module.
35 * Keith Whitwell <keith@tungstengraphics.com>
40 #ifndef DRAW_PRIVATE_H
41 #define DRAW_PRIVATE_H
44 #include "pipe/p_state.h"
45 #include "pipe/p_defines.h"
47 #include "draw_vertex.h"
49 #include "x86/rtasm/x86sse.h"
50 #include "pipe/tgsi/exec/tgsi_exec.h"
54 struct gallivm_cpu_engine
;
58 * Carry some useful information around with the vertices in the prim pipe.
60 struct vertex_header
{
64 unsigned vertex_id
:16;
68 float data
[][4]; /* Note variable size */
71 /* NOTE: It should match vertex_id size above */
72 #define UNDEFINED_VERTEX_ID 0xffff
74 /* XXX This is too large */
75 #define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float))
80 * Basic info for a point/line/triangle primitive.
83 float det
; /**< front/back face determinant */
84 unsigned reset_line_stipple
:1;
87 struct vertex_header
*v
[3]; /**< 1 to 3 vertex pointers */
95 * Base class for all primitive drawing stages.
99 struct draw_context
*draw
; /**< parent context */
101 struct draw_stage
*next
; /**< next stage in pipeline */
103 struct vertex_header
**tmp
; /**< temp vert storage, such as for clipping */
106 void (*begin
)( struct draw_stage
* );
108 void (*point
)( struct draw_stage
*,
109 struct prim_header
* );
111 void (*line
)( struct draw_stage
*,
112 struct prim_header
* );
114 void (*tri
)( struct draw_stage
*,
115 struct prim_header
* );
117 void (*end
)( struct draw_stage
* );
120 * Reset temporary vertex ids in this stage
122 * draw_free_tmps will be called instead if null.
124 void (*reset_tmps
)( struct draw_stage
* );
126 void (*reset_stipple_counter
)( struct draw_stage
* );
130 #define PRIM_QUEUE_LENGTH 16
131 #define VCACHE_SIZE 32
132 #define VCACHE_OVERFLOW 4
133 #define VS_QUEUE_LENGTH (VCACHE_SIZE + VCACHE_OVERFLOW + 1) /* can never fill up */
136 * Private version of the compiled vertex_shader
138 struct draw_vertex_shader
{
139 const struct pipe_shader_state
*state
;
140 #if defined(__i386__) || defined(__386__)
141 struct x86_function sse2_program
;
144 struct gallivm_prog
*llvm_prog
;
149 * Private context for the drawing module.
153 /** Drawing/primitive pipeline stages */
155 struct draw_stage
*first
; /**< one of the following */
157 struct draw_stage
*validate
;
159 /* stages (in logical order) */
160 struct draw_stage
*feedback
;
161 struct draw_stage
*flatshade
;
162 struct draw_stage
*clip
;
163 struct draw_stage
*cull
;
164 struct draw_stage
*twoside
;
165 struct draw_stage
*offset
;
166 struct draw_stage
*unfilled
;
167 struct draw_stage
*wide
;
168 struct draw_stage
*rasterize
;
171 /* pipe state that we need: */
172 const struct pipe_rasterizer_state
*rasterizer
;
173 struct pipe_feedback_state feedback
;
174 struct pipe_viewport_state viewport
;
175 struct pipe_vertex_buffer vertex_buffer
[PIPE_ATTRIB_MAX
];
176 struct pipe_vertex_element vertex_element
[PIPE_ATTRIB_MAX
];
177 const struct draw_vertex_shader
*vertex_shader
;
178 struct pipe_vertex_buffer feedback_buffer
[PIPE_ATTRIB_MAX
];
179 struct pipe_vertex_element feedback_element
[PIPE_ATTRIB_MAX
];
181 /* user-space vertex data, buffers */
183 /** vertex element/index buffer (ex: glDrawElements) */
185 /** bytes per index (0, 1, 2 or 4) */
189 const void *vbuffer
[PIPE_ATTRIB_MAX
];
191 /** constant buffer (for vertex shader) */
192 const void *constants
;
194 /** The vertex feedback buffer */
195 void *feedback_buffer
[PIPE_MAX_FEEDBACK_ATTRIBS
];
196 uint feedback_buffer_size
[PIPE_MAX_FEEDBACK_ATTRIBS
]; /* in bytes */
199 /* Clip derived state:
204 /** Describes the layout of post-transformation vertices */
205 struct vertex_info vertex_info
;
206 /** Two-sided attributes: */
207 uint attrib_front0
, attrib_back0
;
208 uint attrib_front1
, attrib_back1
;
210 boolean drawing
; /**< do we presently have something queued for drawing? */
211 unsigned prim
; /**< current prim type: PIPE_PRIM_x */
212 unsigned reduced_prim
;
214 /** TGSI program interpreter runtime state */
215 struct tgsi_exec_machine machine
;
217 /* Post-tnl vertex cache:
220 unsigned referenced
; /**< bitfield */
221 unsigned idx
[VCACHE_SIZE
+ VCACHE_OVERFLOW
];
222 struct vertex_header
*vertex
[VCACHE_SIZE
+ VCACHE_OVERFLOW
];
225 /** To find space in the vertex cache: */
226 struct vertex_header
*(*get_vertex
)( struct draw_context
*draw
,
230 /* Vertex shader queue:
234 unsigned elt
; /**< index into the user's vertex arrays */
235 struct vertex_header
*dest
; /**< points into vcache.vertex[] array */
236 } queue
[VS_QUEUE_LENGTH
];
240 /* Prim pipeline queue:
243 /* Need to queue up primitives until their vertices have been
244 * transformed by a vs queue flush.
246 struct prim_header queue
[PRIM_QUEUE_LENGTH
];
252 struct gallivm_cpu_engine
*engine
;
258 extern struct draw_stage
*draw_feedback_stage( struct draw_context
*context
);
259 extern struct draw_stage
*draw_unfilled_stage( struct draw_context
*context
);
260 extern struct draw_stage
*draw_twoside_stage( struct draw_context
*context
);
261 extern struct draw_stage
*draw_offset_stage( struct draw_context
*context
);
262 extern struct draw_stage
*draw_clip_stage( struct draw_context
*context
);
263 extern struct draw_stage
*draw_flatshade_stage( struct draw_context
*context
);
264 extern struct draw_stage
*draw_cull_stage( struct draw_context
*context
);
265 extern struct draw_stage
*draw_wide_stage( struct draw_context
*context
);
266 extern struct draw_stage
*draw_validate_stage( struct draw_context
*context
);
269 extern void draw_free_tmps( struct draw_stage
*stage
);
270 extern void draw_reset_tmps( struct draw_stage
*stage
);
271 extern void draw_alloc_tmps( struct draw_stage
*stage
, unsigned nr
);
273 extern void draw_reset_vertex_ids( struct draw_context
*draw
);
276 extern int draw_vertex_cache_check_space( struct draw_context
*draw
,
279 extern void draw_vertex_cache_invalidate( struct draw_context
*draw
);
280 extern void draw_vertex_cache_unreference( struct draw_context
*draw
);
281 extern void draw_vertex_cache_reset_vertex_ids( struct draw_context
*draw
);
284 extern void draw_vertex_shader_queue_flush( struct draw_context
*draw
);
286 extern void draw_vertex_shader_queue_flush_llvm( struct draw_context
*draw
);
289 struct tgsi_exec_machine
;
291 extern void draw_vertex_fetch( struct draw_context
*draw
,
292 struct tgsi_exec_machine
*machine
,
293 const unsigned *elts
,
297 #define DRAW_FLUSH_PRIM_QUEUE 0x1
298 #define DRAW_FLUSH_VERTEX_CACHE_INVALIDATE 0x2
299 #define DRAW_FLUSH_DRAW 0x4
302 void draw_do_flush( struct draw_context
*draw
,
309 * Get a writeable copy of a vertex.
310 * \param stage drawing stage info
311 * \param vert the vertex to copy (source)
312 * \param idx index into stage's tmp[] array to put the copy (dest)
313 * \return pointer to the copied vertex
315 static INLINE
struct vertex_header
*
316 dup_vert( struct draw_stage
*stage
,
317 const struct vertex_header
*vert
,
320 struct vertex_header
*tmp
= stage
->tmp
[idx
];
321 memcpy(tmp
, vert
, stage
->draw
->vertex_info
.size
* sizeof(float) );
322 tmp
->vertex_id
= UNDEFINED_VERTEX_ID
;
327 dot4(const float *a
, const float *b
)
329 float result
= (a
[0]*b
[0] +
337 #endif /* DRAW_PRIVATE_H */