Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 1 | /************************************************************************** |
| 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 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 28 | /** |
| 29 | * Private data structures, etc for the draw module. |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 30 | */ |
| 31 | |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 32 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 33 | /** |
| 34 | * Authors: |
| 35 | * Keith Whitwell <keith@tungstengraphics.com> |
| 36 | * Brian Paul |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 37 | */ |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 38 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 39 | |
| 40 | #ifndef DRAW_PRIVATE_H |
| 41 | #define DRAW_PRIVATE_H |
| 42 | |
| 43 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 44 | #include "pipe/p_state.h" |
| 45 | #include "pipe/p_defines.h" |
Brian | 766fa51 | 2007-08-20 17:02:07 -0600 | [diff] [blame] | 46 | |
José Fonseca | f430d95 | 2008-02-19 12:52:28 +0900 | [diff] [blame] | 47 | #include "rtasm/rtasm_x86sse.h" |
José Fonseca | 6acd63a | 2008-02-15 17:50:12 +0900 | [diff] [blame] | 48 | #include "tgsi/exec/tgsi_exec.h" |
Brian | cddeca5 | 2008-02-27 16:02:58 -0700 | [diff] [blame] | 49 | #include "tgsi/util/tgsi_scan.h" |
Brian | 0d13ade | 2007-10-02 11:46:11 -0600 | [diff] [blame] | 50 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 51 | |
Brian | aceeb80 | 2008-02-18 16:19:05 -0700 | [diff] [blame] | 52 | struct pipe_context; |
Zack Rusin | 25b17b2 | 2007-10-29 08:27:32 -0400 | [diff] [blame] | 53 | struct gallivm_prog; |
| 54 | struct gallivm_cpu_engine; |
José Fonseca | c28fdf3 | 2007-11-07 12:08:19 +0000 | [diff] [blame] | 55 | |
Keith Whitwell | f40357e | 2008-03-23 16:44:59 +0000 | [diff] [blame] | 56 | struct draw_pt_middle_end; |
| 57 | struct draw_pt_front_end; |
| 58 | |
Zack Rusin | aadbb1d | 2008-04-12 15:45:28 -0400 | [diff] [blame] | 59 | #define MAX_SHADER_VERTICES 128 |
| 60 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 61 | /** |
| 62 | * Basic vertex info. |
| 63 | * Carry some useful information around with the vertices in the prim pipe. |
| 64 | */ |
| 65 | struct vertex_header { |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 66 | unsigned clipmask:12; |
| 67 | unsigned edgeflag:1; |
Keith Whitwell | a37e0da | 2007-09-25 13:20:53 +0100 | [diff] [blame] | 68 | unsigned pad:3; |
| 69 | unsigned vertex_id:16; |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 70 | |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 71 | float clip[4]; |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 72 | |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 73 | float data[][4]; /* Note variable size */ |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 74 | }; |
| 75 | |
José Fonseca | c28fdf3 | 2007-11-07 12:08:19 +0000 | [diff] [blame] | 76 | /* NOTE: It should match vertex_id size above */ |
| 77 | #define UNDEFINED_VERTEX_ID 0xffff |
| 78 | |
Brian | d8b16d4 | 2007-08-23 17:00:47 -0600 | [diff] [blame] | 79 | /* XXX This is too large */ |
Brian | 0867345 | 2007-09-20 13:42:37 -0600 | [diff] [blame] | 80 | #define MAX_VERTEX_SIZE ((2 + PIPE_MAX_SHADER_OUTPUTS) * 4 * sizeof(float)) |
Zack Rusin | e330919 | 2008-04-14 12:27:24 -0400 | [diff] [blame] | 81 | #define MAX_VERTEX_ALLOCATION ((MAX_VERTEX_SIZE + 0x0f) & ~0x0f) |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 82 | |
| 83 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 84 | |
| 85 | /** |
| 86 | * Basic info for a point/line/triangle primitive. |
| 87 | */ |
| 88 | struct prim_header { |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 89 | float det; /**< front/back face determinant */ |
| 90 | unsigned reset_line_stipple:1; |
| 91 | unsigned edgeflags:3; |
| 92 | unsigned pad:28; |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 93 | struct vertex_header *v[3]; /**< 1 to 3 vertex pointers */ |
| 94 | }; |
| 95 | |
| 96 | |
| 97 | |
| 98 | struct draw_context; |
| 99 | |
| 100 | /** |
| 101 | * Base class for all primitive drawing stages. |
| 102 | */ |
Brian | ea470ee | 2007-07-12 13:32:31 -0600 | [diff] [blame] | 103 | struct draw_stage |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 104 | { |
| 105 | struct draw_context *draw; /**< parent context */ |
| 106 | |
Brian | ea470ee | 2007-07-12 13:32:31 -0600 | [diff] [blame] | 107 | struct draw_stage *next; /**< next stage in pipeline */ |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 108 | |
Brian | 193c85e | 2007-11-09 07:54:46 -0700 | [diff] [blame] | 109 | struct vertex_header **tmp; /**< temp vert storage, such as for clipping */ |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 110 | unsigned nr_tmps; |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 111 | |
Brian | ea470ee | 2007-07-12 13:32:31 -0600 | [diff] [blame] | 112 | void (*point)( struct draw_stage *, |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 113 | struct prim_header * ); |
| 114 | |
Brian | ea470ee | 2007-07-12 13:32:31 -0600 | [diff] [blame] | 115 | void (*line)( struct draw_stage *, |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 116 | struct prim_header * ); |
| 117 | |
Brian | ea470ee | 2007-07-12 13:32:31 -0600 | [diff] [blame] | 118 | void (*tri)( struct draw_stage *, |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 119 | struct prim_header * ); |
Zack Rusin | a1a989f | 2007-09-28 04:33:55 -0400 | [diff] [blame] | 120 | |
Brian | 0bfd085 | 2008-01-25 15:59:27 -0700 | [diff] [blame] | 121 | void (*flush)( struct draw_stage *, |
Brian | 1603a33 | 2008-01-25 17:21:05 -0700 | [diff] [blame] | 122 | unsigned flags ); |
Brian | 0360b49 | 2007-07-25 15:48:09 -0600 | [diff] [blame] | 123 | |
| 124 | void (*reset_stipple_counter)( struct draw_stage * ); |
Michal | d754548 | 2007-11-23 11:30:51 +0000 | [diff] [blame] | 125 | |
| 126 | void (*destroy)( struct draw_stage * ); |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 127 | }; |
| 128 | |
| 129 | |
Keith Whitwell | 30479ef | 2008-02-15 18:56:41 +0000 | [diff] [blame] | 130 | #define PRIM_QUEUE_LENGTH 32 |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 131 | #define VCACHE_SIZE 32 |
| 132 | #define VCACHE_OVERFLOW 4 |
| 133 | #define VS_QUEUE_LENGTH (VCACHE_SIZE + VCACHE_OVERFLOW + 1) /* can never fill up */ |
| 134 | |
Zack Rusin | a1a989f | 2007-09-28 04:33:55 -0400 | [diff] [blame] | 135 | /** |
| 136 | * Private version of the compiled vertex_shader |
| 137 | */ |
| 138 | struct draw_vertex_shader { |
Keith Whitwell | b29d8d2 | 2008-02-15 13:37:01 +0000 | [diff] [blame] | 139 | |
| 140 | /* This member will disappear shortly: |
| 141 | */ |
Brian | 12ab5f9 | 2008-03-12 13:20:29 -0600 | [diff] [blame] | 142 | struct pipe_shader_state state; |
Keith Whitwell | b29d8d2 | 2008-02-15 13:37:01 +0000 | [diff] [blame] | 143 | |
Brian | cddeca5 | 2008-02-27 16:02:58 -0700 | [diff] [blame] | 144 | struct tgsi_shader_info info; |
| 145 | |
Keith Whitwell | b29d8d2 | 2008-02-15 13:37:01 +0000 | [diff] [blame] | 146 | void (*prepare)( struct draw_vertex_shader *shader, |
| 147 | struct draw_context *draw ); |
| 148 | |
| 149 | /* Run the shader - this interface will get cleaned up in the |
| 150 | * future: |
| 151 | */ |
Zack Rusin | 808f968 | 2008-04-11 19:58:22 -0400 | [diff] [blame] | 152 | boolean (*run)( struct draw_vertex_shader *shader, |
| 153 | struct draw_context *draw, |
| 154 | const unsigned *elts, |
| 155 | unsigned count, |
Zack Rusin | e330919 | 2008-04-14 12:27:24 -0400 | [diff] [blame] | 156 | void *out, |
| 157 | unsigned vertex_size); |
Zack Rusin | 808f968 | 2008-04-11 19:58:22 -0400 | [diff] [blame] | 158 | |
Keith Whitwell | b29d8d2 | 2008-02-15 13:37:01 +0000 | [diff] [blame] | 159 | |
| 160 | void (*delete)( struct draw_vertex_shader * ); |
Zack Rusin | a1a989f | 2007-09-28 04:33:55 -0400 | [diff] [blame] | 161 | }; |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 162 | |
Keith Whitwell | 027983f | 2008-01-24 11:19:06 +0000 | [diff] [blame] | 163 | |
| 164 | /* Internal function for vertex fetch. |
| 165 | */ |
| 166 | typedef void (*fetch_func)(const void *ptr, float *attrib); |
Keith Whitwell | d2cb4ba | 2008-04-03 12:21:30 +0100 | [diff] [blame] | 167 | |
| 168 | fetch_func draw_get_fetch_func( enum pipe_format format ); |
| 169 | |
| 170 | |
| 171 | |
Keith Whitwell | 88858e0 | 2008-01-28 12:40:29 +0000 | [diff] [blame] | 172 | typedef void (*full_fetch_func)( struct draw_context *draw, |
| 173 | struct tgsi_exec_machine *machine, |
| 174 | const unsigned *elts, |
| 175 | unsigned count ); |
Keith Whitwell | 027983f | 2008-01-24 11:19:06 +0000 | [diff] [blame] | 176 | |
Keith Whitwell | 297b3be | 2008-03-10 19:49:15 +0000 | [diff] [blame] | 177 | typedef void (*pt_fetch_func)( struct draw_context *draw, |
| 178 | float *out, |
| 179 | unsigned start, |
| 180 | unsigned count ); |
Keith Whitwell | 027983f | 2008-01-24 11:19:06 +0000 | [diff] [blame] | 181 | |
| 182 | |
Keith Whitwell | 297b3be | 2008-03-10 19:49:15 +0000 | [diff] [blame] | 183 | struct vbuf_render; |
| 184 | |
Keith Whitwell | a8582ef | 2008-04-16 10:03:18 +0100 | [diff] [blame] | 185 | |
| 186 | #define PT_SHADE 0x1 |
| 187 | #define PT_CLIPTEST 0x2 |
| 188 | #define PT_PIPELINE 0x4 |
| 189 | #define PT_MAX_MIDDLE 0x8 |
| 190 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 191 | /** |
| 192 | * Private context for the drawing module. |
| 193 | */ |
| 194 | struct draw_context |
| 195 | { |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 196 | /** Drawing/primitive pipeline stages */ |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 197 | struct { |
Brian | ea470ee | 2007-07-12 13:32:31 -0600 | [diff] [blame] | 198 | struct draw_stage *first; /**< one of the following */ |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 199 | |
Keith Whitwell | 08589f7 | 2007-09-26 11:56:17 +0100 | [diff] [blame] | 200 | struct draw_stage *validate; |
| 201 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 202 | /* stages (in logical order) */ |
Brian | ea470ee | 2007-07-12 13:32:31 -0600 | [diff] [blame] | 203 | struct draw_stage *flatshade; |
| 204 | struct draw_stage *clip; |
| 205 | struct draw_stage *cull; |
| 206 | struct draw_stage *twoside; |
| 207 | struct draw_stage *offset; |
| 208 | struct draw_stage *unfilled; |
Brian | 329a847 | 2008-01-21 14:08:20 -0700 | [diff] [blame] | 209 | struct draw_stage *stipple; |
Brian | eb4dc2d | 2008-02-21 16:18:05 -0700 | [diff] [blame] | 210 | struct draw_stage *aapoint; |
Brian | aceeb80 | 2008-02-18 16:19:05 -0700 | [diff] [blame] | 211 | struct draw_stage *aaline; |
Brian | 446bfc3 | 2008-02-21 16:56:32 -0700 | [diff] [blame] | 212 | struct draw_stage *pstipple; |
Brian Paul | a1a1395 | 2008-02-28 17:49:22 -0700 | [diff] [blame] | 213 | struct draw_stage *wide_line; |
| 214 | struct draw_stage *wide_point; |
Zack Rusin | de69fc1 | 2007-09-18 10:02:16 -0400 | [diff] [blame] | 215 | struct draw_stage *rasterize; |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 216 | } pipeline; |
| 217 | |
Keith Whitwell | 297b3be | 2008-03-10 19:49:15 +0000 | [diff] [blame] | 218 | |
| 219 | struct vbuf_render *render; |
| 220 | |
| 221 | /* Support prototype passthrough path: |
| 222 | */ |
| 223 | struct { |
Keith Whitwell | f40357e | 2008-03-23 16:44:59 +0000 | [diff] [blame] | 224 | unsigned prim; /* XXX: to be removed */ |
| 225 | unsigned hw_vertex_size; /* XXX: to be removed */ |
| 226 | |
| 227 | struct { |
Keith Whitwell | a8582ef | 2008-04-16 10:03:18 +0100 | [diff] [blame] | 228 | struct draw_pt_middle_end *opt[PT_MAX_MIDDLE]; |
Keith Whitwell | f40357e | 2008-03-23 16:44:59 +0000 | [diff] [blame] | 229 | } middle; |
| 230 | |
| 231 | struct { |
Keith Whitwell | f40357e | 2008-03-23 16:44:59 +0000 | [diff] [blame] | 232 | struct draw_pt_front_end *vcache; |
| 233 | } front; |
| 234 | |
Keith Whitwell | 0b20d1b | 2008-04-04 13:18:09 +0100 | [diff] [blame] | 235 | struct { |
| 236 | char *verts; |
| 237 | unsigned vertex_stride; |
| 238 | unsigned vertex_count; |
| 239 | } pipeline; |
| 240 | |
Keith Whitwell | 297b3be | 2008-03-10 19:49:15 +0000 | [diff] [blame] | 241 | } pt; |
| 242 | |
Brian | df1744c | 2008-03-27 15:33:47 -0600 | [diff] [blame] | 243 | boolean flushing; |
Keith Whitwell | 297b3be | 2008-03-10 19:49:15 +0000 | [diff] [blame] | 244 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 245 | /* pipe state that we need: */ |
Zack Rusin | 2944018 | 2007-09-17 12:59:50 -0400 | [diff] [blame] | 246 | const struct pipe_rasterizer_state *rasterizer; |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 247 | struct pipe_viewport_state viewport; |
Keith Whitwell | c96d565 | 2008-04-17 13:14:22 +0100 | [diff] [blame^] | 248 | |
Brian | 39038c1 | 2008-03-27 17:41:55 -0600 | [diff] [blame] | 249 | struct pipe_vertex_buffer vertex_buffer[PIPE_MAX_ATTRIBS]; |
Keith Whitwell | c96d565 | 2008-04-17 13:14:22 +0100 | [diff] [blame^] | 250 | unsigned nr_vertex_buffers; |
| 251 | |
Brian | 39038c1 | 2008-03-27 17:41:55 -0600 | [diff] [blame] | 252 | struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS]; |
Keith Whitwell | b29d8d2 | 2008-02-15 13:37:01 +0000 | [diff] [blame] | 253 | struct draw_vertex_shader *vertex_shader; |
Brian | 3e2be1c | 2007-08-15 18:54:05 -0600 | [diff] [blame] | 254 | |
Brian | 594dab4 | 2008-03-31 14:14:30 -0600 | [diff] [blame] | 255 | boolean identity_viewport; |
| 256 | |
Brian | cd36436 | 2008-01-23 12:48:41 -0700 | [diff] [blame] | 257 | uint num_vs_outputs; /**< convenience, from vertex_shader */ |
| 258 | |
Brian | 6446986 | 2007-11-08 17:07:12 -0700 | [diff] [blame] | 259 | /* user-space vertex data, buffers */ |
| 260 | struct { |
Keith Whitwell | 84501e6 | 2008-04-04 17:02:20 +0100 | [diff] [blame] | 261 | const unsigned *edgeflag; |
| 262 | |
Brian | 6446986 | 2007-11-08 17:07:12 -0700 | [diff] [blame] | 263 | /** vertex element/index buffer (ex: glDrawElements) */ |
| 264 | const void *elts; |
| 265 | /** bytes per index (0, 1, 2 or 4) */ |
| 266 | unsigned eltSize; |
Brian | 3e2be1c | 2007-08-15 18:54:05 -0600 | [diff] [blame] | 267 | |
Brian | 6446986 | 2007-11-08 17:07:12 -0700 | [diff] [blame] | 268 | /** vertex arrays */ |
Brian | 39038c1 | 2008-03-27 17:41:55 -0600 | [diff] [blame] | 269 | const void *vbuffer[PIPE_MAX_ATTRIBS]; |
Brian | 6446986 | 2007-11-08 17:07:12 -0700 | [diff] [blame] | 270 | |
| 271 | /** constant buffer (for vertex shader) */ |
| 272 | const void *constants; |
Brian | 6446986 | 2007-11-08 17:07:12 -0700 | [diff] [blame] | 273 | } user; |
Brian | 63a51ae | 2007-09-06 17:07:09 -0600 | [diff] [blame] | 274 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 275 | /* Clip derived state: |
| 276 | */ |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 277 | float plane[12][4]; |
| 278 | unsigned nr_planes; |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 279 | |
Brian | 5e29aab | 2008-02-26 14:29:35 -0700 | [diff] [blame] | 280 | float wide_point_threshold; /**< convert pnts to tris if larger than this */ |
Brian Paul | a1a1395 | 2008-02-28 17:49:22 -0700 | [diff] [blame] | 281 | float wide_line_threshold; /**< convert lines to tris if wider than this */ |
Brian | 8b8c9ac | 2008-03-13 14:33:57 -0600 | [diff] [blame] | 282 | boolean line_stipple; /**< do line stipple? */ |
Brian | 5a09ad8 | 2008-03-14 16:13:35 -0600 | [diff] [blame] | 283 | boolean point_sprite; /**< convert points to quads for sprites? */ |
Keith Whitwell | b29d8d2 | 2008-02-15 13:37:01 +0000 | [diff] [blame] | 284 | boolean use_sse; |
Keith Whitwell | caf2933 | 2008-04-14 12:08:46 +0100 | [diff] [blame] | 285 | boolean use_pt_shaders; /* temporary flag to switch on pt shader paths */ |
Brian | f1fb69a | 2008-01-22 10:16:30 -0700 | [diff] [blame] | 286 | |
Brian | aceeb80 | 2008-02-18 16:19:05 -0700 | [diff] [blame] | 287 | /* If a prim stage introduces new vertex attributes, they'll be stored here |
| 288 | */ |
| 289 | struct { |
| 290 | uint semantic_name; |
| 291 | uint semantic_index; |
| 292 | int slot; |
| 293 | } extra_vp_outputs; |
| 294 | |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 295 | unsigned reduced_prim; |
| 296 | |
Brian | 0d13ade | 2007-10-02 11:46:11 -0600 | [diff] [blame] | 297 | /** TGSI program interpreter runtime state */ |
| 298 | struct tgsi_exec_machine machine; |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 299 | |
Keith Whitwell | 027983f | 2008-01-24 11:19:06 +0000 | [diff] [blame] | 300 | /* Vertex fetch internal state |
| 301 | */ |
| 302 | struct { |
Brian | 39038c1 | 2008-03-27 17:41:55 -0600 | [diff] [blame] | 303 | const ubyte *src_ptr[PIPE_MAX_ATTRIBS]; |
| 304 | unsigned pitch[PIPE_MAX_ATTRIBS]; |
| 305 | fetch_func fetch[PIPE_MAX_ATTRIBS]; |
Keith Whitwell | 027983f | 2008-01-24 11:19:06 +0000 | [diff] [blame] | 306 | unsigned nr_attrs; |
Keith Whitwell | 88858e0 | 2008-01-28 12:40:29 +0000 | [diff] [blame] | 307 | full_fetch_func fetch_func; |
Keith Whitwell | 297b3be | 2008-03-10 19:49:15 +0000 | [diff] [blame] | 308 | pt_fetch_func pt_fetch; |
Keith Whitwell | 027983f | 2008-01-24 11:19:06 +0000 | [diff] [blame] | 309 | } vertex_fetch; |
| 310 | |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 311 | /* Post-tnl vertex cache: |
| 312 | */ |
| 313 | struct { |
Brian | 3df65af | 2007-10-23 15:02:02 -0600 | [diff] [blame] | 314 | unsigned referenced; /**< bitfield */ |
Keith Whitwell | 30479ef | 2008-02-15 18:56:41 +0000 | [diff] [blame] | 315 | |
| 316 | struct { |
| 317 | unsigned in; /* client array element */ |
| 318 | unsigned out; /* index in vs queue/array */ |
| 319 | } idx[VCACHE_SIZE + VCACHE_OVERFLOW]; |
| 320 | |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 321 | unsigned overflow; |
Keith Whitwell | 08589f7 | 2007-09-26 11:56:17 +0100 | [diff] [blame] | 322 | |
Brian | 6446986 | 2007-11-08 17:07:12 -0700 | [diff] [blame] | 323 | /** To find space in the vertex cache: */ |
Keith Whitwell | 08589f7 | 2007-09-26 11:56:17 +0100 | [diff] [blame] | 324 | struct vertex_header *(*get_vertex)( struct draw_context *draw, |
| 325 | unsigned i ); |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 326 | } vcache; |
| 327 | |
| 328 | /* Vertex shader queue: |
| 329 | */ |
| 330 | struct { |
Zack Rusin | 3f7a3dd | 2008-04-12 21:52:46 -0400 | [diff] [blame] | 331 | unsigned elts[VS_QUEUE_LENGTH]; /**< index into the user's vertex arrays */ |
| 332 | char *vertex_cache; |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 333 | unsigned queue_nr; |
Keith Whitwell | 30479ef | 2008-02-15 18:56:41 +0000 | [diff] [blame] | 334 | unsigned post_nr; |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 335 | } vs; |
| 336 | |
Ian Romanick | 3d13605 | 2008-01-29 11:43:04 -0800 | [diff] [blame] | 337 | /** |
| 338 | * Run the vertex shader on all vertices in the vertex queue. |
| 339 | */ |
| 340 | void (*shader_queue_flush)(struct draw_context *draw); |
| 341 | |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 342 | /* Prim pipeline queue: |
| 343 | */ |
| 344 | struct { |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 345 | /* Need to queue up primitives until their vertices have been |
| 346 | * transformed by a vs queue flush. |
| 347 | */ |
| 348 | struct prim_header queue[PRIM_QUEUE_LENGTH]; |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 349 | unsigned queue_nr; |
Keith Whitwell | 4bb2134 | 2007-08-14 15:44:41 +0100 | [diff] [blame] | 350 | } pq; |
Zack Rusin | 8731e39 | 2007-09-28 07:33:54 -0400 | [diff] [blame] | 351 | |
Keith Whitwell | b29d8d2 | 2008-02-15 13:37:01 +0000 | [diff] [blame] | 352 | |
| 353 | /* This (and the tgsi_exec_machine struct) probably need to be moved somewhere private. |
| 354 | */ |
| 355 | struct gallivm_cpu_engine *engine; |
Ian Romanick | a89ee8a | 2008-01-30 20:10:45 -0800 | [diff] [blame] | 356 | void *driver_private; |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 357 | }; |
| 358 | |
| 359 | |
| 360 | |
Brian | ea470ee | 2007-07-12 13:32:31 -0600 | [diff] [blame] | 361 | extern struct draw_stage *draw_unfilled_stage( struct draw_context *context ); |
| 362 | extern struct draw_stage *draw_twoside_stage( struct draw_context *context ); |
| 363 | extern struct draw_stage *draw_offset_stage( struct draw_context *context ); |
| 364 | extern struct draw_stage *draw_clip_stage( struct draw_context *context ); |
| 365 | extern struct draw_stage *draw_flatshade_stage( struct draw_context *context ); |
| 366 | extern struct draw_stage *draw_cull_stage( struct draw_context *context ); |
Brian | 329a847 | 2008-01-21 14:08:20 -0700 | [diff] [blame] | 367 | extern struct draw_stage *draw_stipple_stage( struct draw_context *context ); |
Brian Paul | a1a1395 | 2008-02-28 17:49:22 -0700 | [diff] [blame] | 368 | extern struct draw_stage *draw_wide_line_stage( struct draw_context *context ); |
| 369 | extern struct draw_stage *draw_wide_point_stage( struct draw_context *context ); |
Keith Whitwell | 08589f7 | 2007-09-26 11:56:17 +0100 | [diff] [blame] | 370 | extern struct draw_stage *draw_validate_stage( struct draw_context *context ); |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 371 | |
| 372 | |
Brian | b08102a | 2008-02-13 10:25:38 -0700 | [diff] [blame] | 373 | extern void draw_free_temp_verts( struct draw_stage *stage ); |
| 374 | |
| 375 | extern void draw_alloc_temp_verts( struct draw_stage *stage, unsigned nr ); |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 376 | |
José Fonseca | 3e22180 | 2007-11-07 13:07:20 +0000 | [diff] [blame] | 377 | extern void draw_reset_vertex_ids( struct draw_context *draw ); |
| 378 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 379 | |
Brian | 9a11a4a | 2007-08-31 11:28:31 -0600 | [diff] [blame] | 380 | extern int draw_vertex_cache_check_space( struct draw_context *draw, |
| 381 | unsigned nr_verts ); |
| 382 | |
Brian | 9a11a4a | 2007-08-31 11:28:31 -0600 | [diff] [blame] | 383 | extern void draw_vertex_cache_invalidate( struct draw_context *draw ); |
| 384 | extern void draw_vertex_cache_unreference( struct draw_context *draw ); |
Keith Whitwell | a37e0da | 2007-09-25 13:20:53 +0100 | [diff] [blame] | 385 | extern void draw_vertex_cache_reset_vertex_ids( struct draw_context *draw ); |
| 386 | |
Brian | 9a11a4a | 2007-08-31 11:28:31 -0600 | [diff] [blame] | 387 | extern void draw_vertex_shader_queue_flush( struct draw_context *draw ); |
| 388 | |
Keith Whitwell | 027983f | 2008-01-24 11:19:06 +0000 | [diff] [blame] | 389 | extern void draw_update_vertex_fetch( struct draw_context *draw ); |
Brian | 9a11a4a | 2007-08-31 11:28:31 -0600 | [diff] [blame] | 390 | |
Keith Whitwell | 4505acf | 2008-03-25 15:17:53 +0000 | [diff] [blame] | 391 | extern boolean draw_need_pipeline(const struct draw_context *draw, |
| 392 | unsigned prim ); |
Brian | 8b8c9ac | 2008-03-13 14:33:57 -0600 | [diff] [blame] | 393 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 394 | |
Keith Whitwell | f40357e | 2008-03-23 16:44:59 +0000 | [diff] [blame] | 395 | /* Passthrough mode (second attempt): |
| 396 | */ |
| 397 | boolean draw_pt_init( struct draw_context *draw ); |
| 398 | void draw_pt_destroy( struct draw_context *draw ); |
| 399 | boolean draw_pt_arrays( struct draw_context *draw, |
| 400 | unsigned prim, |
| 401 | unsigned start, |
| 402 | unsigned count ); |
| 403 | |
Keith Whitwell | 0b20d1b | 2008-04-04 13:18:09 +0100 | [diff] [blame] | 404 | void draw_pt_reset_vertex_ids( struct draw_context *draw ); |
| 405 | void draw_pt_run_pipeline( struct draw_context *draw, |
| 406 | unsigned prim, |
| 407 | char *verts, |
| 408 | unsigned vertex_stride, |
| 409 | unsigned vertex_count, |
| 410 | const ushort *elts, |
| 411 | unsigned count ); |
Keith Whitwell | f40357e | 2008-03-23 16:44:59 +0000 | [diff] [blame] | 412 | |
| 413 | |
Brian | 1603a33 | 2008-01-25 17:21:05 -0700 | [diff] [blame] | 414 | #define DRAW_FLUSH_SHADER_QUEUE 0x1 /* sized not to overflow, never raised */ |
| 415 | #define DRAW_FLUSH_PRIM_QUEUE 0x2 |
| 416 | #define DRAW_FLUSH_VERTEX_CACHE 0x4 |
| 417 | #define DRAW_FLUSH_STATE_CHANGE 0x8 |
| 418 | #define DRAW_FLUSH_BACKEND 0x10 |
Keith Whitwell | 08589f7 | 2007-09-26 11:56:17 +0100 | [diff] [blame] | 419 | |
| 420 | |
Brian | 1603a33 | 2008-01-25 17:21:05 -0700 | [diff] [blame] | 421 | void draw_do_flush( struct draw_context *draw, unsigned flags ); |
Keith Whitwell | 08589f7 | 2007-09-26 11:56:17 +0100 | [diff] [blame] | 422 | |
Keith Whitwell | 84501e6 | 2008-04-04 17:02:20 +0100 | [diff] [blame] | 423 | boolean draw_get_edgeflag( struct draw_context *draw, |
| 424 | unsigned idx ); |
Keith Whitwell | 08589f7 | 2007-09-26 11:56:17 +0100 | [diff] [blame] | 425 | |
| 426 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 427 | /** |
| 428 | * Get a writeable copy of a vertex. |
| 429 | * \param stage drawing stage info |
| 430 | * \param vert the vertex to copy (source) |
| 431 | * \param idx index into stage's tmp[] array to put the copy (dest) |
| 432 | * \return pointer to the copied vertex |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 433 | */ |
| 434 | static INLINE struct vertex_header * |
Brian | ea470ee | 2007-07-12 13:32:31 -0600 | [diff] [blame] | 435 | dup_vert( struct draw_stage *stage, |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 436 | const struct vertex_header *vert, |
Brian | fd0a6d6 | 2007-08-16 12:52:20 -0600 | [diff] [blame] | 437 | unsigned idx ) |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 438 | { |
| 439 | struct vertex_header *tmp = stage->tmp[idx]; |
Brian | cd36436 | 2008-01-23 12:48:41 -0700 | [diff] [blame] | 440 | const uint vsize = sizeof(struct vertex_header) |
| 441 | + stage->draw->num_vs_outputs * 4 * sizeof(float); |
| 442 | memcpy(tmp, vert, vsize); |
José Fonseca | c28fdf3 | 2007-11-07 12:08:19 +0000 | [diff] [blame] | 443 | tmp->vertex_id = UNDEFINED_VERTEX_ID; |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 444 | return tmp; |
| 445 | } |
| 446 | |
Zack Rusin | b46926c | 2007-10-03 10:31:42 -0400 | [diff] [blame] | 447 | static INLINE float |
| 448 | dot4(const float *a, const float *b) |
| 449 | { |
| 450 | float result = (a[0]*b[0] + |
| 451 | a[1]*b[1] + |
| 452 | a[2]*b[2] + |
| 453 | a[3]*b[3]); |
| 454 | |
| 455 | return result; |
| 456 | } |
Keith Whitwell | 8e4a95a | 2007-05-24 10:41:34 +0100 | [diff] [blame] | 457 | |
Zack Rusin | 3f7a3dd | 2008-04-12 21:52:46 -0400 | [diff] [blame] | 458 | static INLINE struct vertex_header * |
Zack Rusin | e330919 | 2008-04-14 12:27:24 -0400 | [diff] [blame] | 459 | draw_header_from_block(char *block, int size, int num) |
Zack Rusin | 3f7a3dd | 2008-04-12 21:52:46 -0400 | [diff] [blame] | 460 | { |
Zack Rusin | 3f7a3dd | 2008-04-12 21:52:46 -0400 | [diff] [blame] | 461 | return (struct vertex_header*)(block + num * size); |
| 462 | } |
| 463 | |
Brian | 279ffe3 | 2007-07-09 16:14:26 -0600 | [diff] [blame] | 464 | #endif /* DRAW_PRIVATE_H */ |