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 "rtasm/rtasm_x86sse.h"
48 #include "tgsi/exec/tgsi_exec.h"
49 #include "tgsi/util/tgsi_scan.h"
54 struct gallivm_cpu_engine
;
56 struct draw_pt_middle_end
;
57 struct draw_pt_front_end
;
61 * Carry some useful information around with the vertices in the prim pipe.
63 struct vertex_header
{
67 unsigned vertex_id
:16;
71 float data
[][4]; /* Note variable size */
74 /* NOTE: It should match vertex_id size above */
75 #define UNDEFINED_VERTEX_ID 0xffff
77 /* XXX This is too large */
78 #define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float))
83 * Basic info for a point/line/triangle primitive.
86 float det
; /**< front/back face determinant */
87 unsigned reset_line_stipple
:1;
90 struct vertex_header
*v
[3]; /**< 1 to 3 vertex pointers */
98 * Base class for all primitive drawing stages.
102 struct draw_context
*draw
; /**< parent context */
104 struct draw_stage
*next
; /**< next stage in pipeline */
106 struct vertex_header
**tmp
; /**< temp vert storage, such as for clipping */
109 void (*point
)( struct draw_stage
*,
110 struct prim_header
* );
112 void (*line
)( struct draw_stage
*,
113 struct prim_header
* );
115 void (*tri
)( struct draw_stage
*,
116 struct prim_header
* );
118 void (*flush
)( struct draw_stage
*,
121 void (*reset_stipple_counter
)( struct draw_stage
* );
123 void (*destroy
)( struct draw_stage
* );
127 #define PRIM_QUEUE_LENGTH 32
128 #define VCACHE_SIZE 32
129 #define VCACHE_OVERFLOW 4
130 #define VS_QUEUE_LENGTH (VCACHE_SIZE + VCACHE_OVERFLOW + 1) /* can never fill up */
133 * Private version of the compiled vertex_shader
135 struct draw_vertex_shader
{
137 /* This member will disappear shortly:
139 struct pipe_shader_state state
;
141 struct tgsi_shader_info info
;
143 void (*prepare
)( struct draw_vertex_shader
*shader
,
144 struct draw_context
*draw
);
146 /* Run the shader - this interface will get cleaned up in the
149 void (*run
)( struct draw_vertex_shader
*shader
,
150 struct draw_context
*draw
,
151 const unsigned *elts
,
153 struct vertex_header
*vOut
[] );
156 void (*delete)( struct draw_vertex_shader
* );
160 /* Internal function for vertex fetch.
162 typedef void (*fetch_func
)(const void *ptr
, float *attrib
);
163 typedef void (*full_fetch_func
)( struct draw_context
*draw
,
164 struct tgsi_exec_machine
*machine
,
165 const unsigned *elts
,
168 typedef void (*pt_fetch_func
)( struct draw_context
*draw
,
177 * Private context for the drawing module.
181 /** Drawing/primitive pipeline stages */
183 struct draw_stage
*first
; /**< one of the following */
185 struct draw_stage
*validate
;
187 /* stages (in logical order) */
188 struct draw_stage
*flatshade
;
189 struct draw_stage
*clip
;
190 struct draw_stage
*cull
;
191 struct draw_stage
*twoside
;
192 struct draw_stage
*offset
;
193 struct draw_stage
*unfilled
;
194 struct draw_stage
*stipple
;
195 struct draw_stage
*aapoint
;
196 struct draw_stage
*aaline
;
197 struct draw_stage
*pstipple
;
198 struct draw_stage
*wide_line
;
199 struct draw_stage
*wide_point
;
200 struct draw_stage
*rasterize
;
204 struct vbuf_render
*render
;
206 /* Support prototype passthrough path:
209 unsigned prim
; /* XXX: to be removed */
210 unsigned hw_vertex_size
; /* XXX: to be removed */
213 struct draw_pt_middle_end
*fetch_emit
;
214 struct draw_pt_middle_end
*fetch_shade_emit
;
215 struct draw_pt_middle_end
*fetch_shade_cliptest_pipeline_or_emit
;
219 struct draw_pt_front_end
*noop
;
220 struct draw_pt_front_end
*split_arrays
;
221 struct draw_pt_front_end
*vcache
;
228 /* pipe state that we need: */
229 const struct pipe_rasterizer_state
*rasterizer
;
230 struct pipe_viewport_state viewport
;
231 struct pipe_vertex_buffer vertex_buffer
[PIPE_MAX_ATTRIBS
];
232 struct pipe_vertex_element vertex_element
[PIPE_MAX_ATTRIBS
];
233 struct draw_vertex_shader
*vertex_shader
;
235 boolean identity_viewport
;
237 uint num_vs_outputs
; /**< convenience, from vertex_shader */
239 /* user-space vertex data, buffers */
241 /** vertex element/index buffer (ex: glDrawElements) */
243 /** bytes per index (0, 1, 2 or 4) */
247 const void *vbuffer
[PIPE_MAX_ATTRIBS
];
249 /** constant buffer (for vertex shader) */
250 const void *constants
;
253 /* Clip derived state:
258 float wide_point_threshold
; /**< convert pnts to tris if larger than this */
259 float wide_line_threshold
; /**< convert lines to tris if wider than this */
260 boolean line_stipple
; /**< do line stipple? */
261 boolean point_sprite
; /**< convert points to quads for sprites? */
264 /* If a prim stage introduces new vertex attributes, they'll be stored here
272 unsigned reduced_prim
;
274 /** TGSI program interpreter runtime state */
275 struct tgsi_exec_machine machine
;
277 /* Vertex fetch internal state
280 const ubyte
*src_ptr
[PIPE_MAX_ATTRIBS
];
281 unsigned pitch
[PIPE_MAX_ATTRIBS
];
282 fetch_func fetch
[PIPE_MAX_ATTRIBS
];
284 full_fetch_func fetch_func
;
285 pt_fetch_func pt_fetch
;
288 /* Post-tnl vertex cache:
291 unsigned referenced
; /**< bitfield */
294 unsigned in
; /* client array element */
295 unsigned out
; /* index in vs queue/array */
296 } idx
[VCACHE_SIZE
+ VCACHE_OVERFLOW
];
300 /** To find space in the vertex cache: */
301 struct vertex_header
*(*get_vertex
)( struct draw_context
*draw
,
305 /* Vertex shader queue:
309 unsigned elt
; /**< index into the user's vertex arrays */
310 struct vertex_header
*vertex
;
311 } queue
[VS_QUEUE_LENGTH
];
317 * Run the vertex shader on all vertices in the vertex queue.
319 void (*shader_queue_flush
)(struct draw_context
*draw
);
321 /* Prim pipeline queue:
324 /* Need to queue up primitives until their vertices have been
325 * transformed by a vs queue flush.
327 struct prim_header queue
[PRIM_QUEUE_LENGTH
];
332 /* This (and the tgsi_exec_machine struct) probably need to be moved somewhere private.
334 struct gallivm_cpu_engine
*engine
;
335 void *driver_private
;
340 extern struct draw_stage
*draw_unfilled_stage( struct draw_context
*context
);
341 extern struct draw_stage
*draw_twoside_stage( struct draw_context
*context
);
342 extern struct draw_stage
*draw_offset_stage( struct draw_context
*context
);
343 extern struct draw_stage
*draw_clip_stage( struct draw_context
*context
);
344 extern struct draw_stage
*draw_flatshade_stage( struct draw_context
*context
);
345 extern struct draw_stage
*draw_cull_stage( struct draw_context
*context
);
346 extern struct draw_stage
*draw_stipple_stage( struct draw_context
*context
);
347 extern struct draw_stage
*draw_wide_line_stage( struct draw_context
*context
);
348 extern struct draw_stage
*draw_wide_point_stage( struct draw_context
*context
);
349 extern struct draw_stage
*draw_validate_stage( struct draw_context
*context
);
352 extern void draw_free_temp_verts( struct draw_stage
*stage
);
354 extern void draw_alloc_temp_verts( struct draw_stage
*stage
, unsigned nr
);
356 extern void draw_reset_vertex_ids( struct draw_context
*draw
);
359 extern int draw_vertex_cache_check_space( struct draw_context
*draw
,
362 extern void draw_vertex_cache_invalidate( struct draw_context
*draw
);
363 extern void draw_vertex_cache_unreference( struct draw_context
*draw
);
364 extern void draw_vertex_cache_reset_vertex_ids( struct draw_context
*draw
);
366 extern void draw_vertex_shader_queue_flush( struct draw_context
*draw
);
368 extern void draw_update_vertex_fetch( struct draw_context
*draw
);
370 extern boolean
draw_need_pipeline(const struct draw_context
*draw
,
374 /* Passthrough mode (second attempt):
376 boolean
draw_pt_init( struct draw_context
*draw
);
377 void draw_pt_destroy( struct draw_context
*draw
);
378 boolean
draw_pt_arrays( struct draw_context
*draw
,
385 /* Prototype/hack (DEPRECATED)
388 draw_passthrough_arrays(struct draw_context
*draw
,
394 #define DRAW_FLUSH_SHADER_QUEUE 0x1 /* sized not to overflow, never raised */
395 #define DRAW_FLUSH_PRIM_QUEUE 0x2
396 #define DRAW_FLUSH_VERTEX_CACHE 0x4
397 #define DRAW_FLUSH_STATE_CHANGE 0x8
398 #define DRAW_FLUSH_BACKEND 0x10
401 void draw_do_flush( struct draw_context
*draw
, unsigned flags
);
406 * Get a writeable copy of a vertex.
407 * \param stage drawing stage info
408 * \param vert the vertex to copy (source)
409 * \param idx index into stage's tmp[] array to put the copy (dest)
410 * \return pointer to the copied vertex
412 static INLINE
struct vertex_header
*
413 dup_vert( struct draw_stage
*stage
,
414 const struct vertex_header
*vert
,
417 struct vertex_header
*tmp
= stage
->tmp
[idx
];
418 const uint vsize
= sizeof(struct vertex_header
)
419 + stage
->draw
->num_vs_outputs
* 4 * sizeof(float);
420 memcpy(tmp
, vert
, vsize
);
421 tmp
->vertex_id
= UNDEFINED_VERTEX_ID
;
426 dot4(const float *a
, const float *b
)
428 float result
= (a
[0]*b
[0] +
436 #endif /* DRAW_PRIVATE_H */