Minor r200 vertex program cleanups. Remove disabled leftovers from r300 vertex progra...
[mesa.git] / src / mesa / drivers / dri / i965 / brw_context.h
1 /*
2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
5
6 Permission is hereby granted, free of charge, to any person obtaining
7 a 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, sublicense, 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
16 portions of the Software.
17
18 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
19 EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
21 IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE
22 LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
23 OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
24 WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25
26 **********************************************************************/
27 /*
28 * Authors:
29 * Keith Whitwell <keith@tungstengraphics.com>
30 */
31
32
33 #ifndef BRWCONTEXT_INC
34 #define BRWCONTEXT_INC
35
36 #include "intel_context.h"
37 #include "brw_structs.h"
38 #include "imports.h"
39 #include "brw_attrib.h"
40
41
42 /* Glossary:
43 *
44 * URB - uniform resource buffer. A mid-sized buffer which is
45 * partitioned between the fixed function units and used for passing
46 * values (vertices, primitives, constants) between them.
47 *
48 * CURBE - constant URB entry. An urb region (entry) used to hold
49 * constant values which the fixed function units can be instructed to
50 * preload into the GRF when spawining a thread.
51 *
52 * VUE - vertex URB entry. An urb entry holding a vertex and usually
53 * a vertex header. The header contains control information and
54 * things like primitive type, Begin/end flags and clip codes.
55 *
56 * PUE - primitive URB entry. An urb entry produced by the setup (SF)
57 * unit holding rasterization and interpolation parameters.
58 *
59 * GRF - general register file. One of several register files
60 * addressable by programmed threads. The inputs (r0, payload, curbe,
61 * urb) of the thread are preloaded to this area before the thread is
62 * spawned. The registers are individually 8 dwords wide and suitable
63 * for general usage. Registers holding thread input values are not
64 * special and may be overwritten.
65 *
66 * MRF - message register file. Threads communicate (and terminate)
67 * by sending messages. Message parameters are placed in contigous
68 * MRF registers. All program output is via these messages. URB
69 * entries are populated by sending a message to the shared URB
70 * function containing the new data, together with a control word,
71 * often an unmodified copy of R0.
72 *
73 * R0 - GRF register 0. Typically holds control information used when
74 * sending messages to other threads.
75 *
76 * EU or GEN4 EU: The name of the programmable subsystem of the
77 * i965 hardware. Threads are executed by the EU, the registers
78 * described above are part of the EU architecture.
79 *
80 * Fixed function units:
81 *
82 * CS - Command streamer. Notional first unit, little software
83 * interaction. Holds the URB entries used for constant data, ie the
84 * CURBEs.
85 *
86 * VF/VS - Vertex Fetch / Vertex Shader. The fixed function part of
87 * this unit is responsible for pulling vertices out of vertex buffers
88 * in vram and injecting them into the processing pipe as VUEs. If
89 * enabled, it first passes them to a VS thread which is a good place
90 * for the driver to implement any active vertex shader.
91 *
92 * GS - Geometry Shader. This corresponds to a new DX10 concept. If
93 * enabled, incoming strips etc are passed to GS threads in individual
94 * line/triangle/point units. The GS thread may perform arbitary
95 * computation and emit whatever primtives with whatever vertices it
96 * chooses. This makes GS an excellent place to implement GL's
97 * unfilled polygon modes, though of course it is capable of much
98 * more. Additionally, GS is used to translate away primitives not
99 * handled by latter units, including Quads and Lineloops.
100 *
101 * CS - Clipper. Mesa's clipping algorithms are imported to run on
102 * this unit. The fixed function part performs cliptesting against
103 * the 6 fixed clipplanes and makes descisions on whether or not the
104 * incoming primitive needs to be passed to a thread for clipping.
105 * User clip planes are handled via cooperation with the VS thread.
106 *
107 * SF - Strips Fans or Setup: Triangles are prepared for
108 * rasterization. Interpolation coefficients are calculated.
109 * Flatshading and two-side lighting usually performed here.
110 *
111 * WM - Windower. Interpolation of vertex attributes performed here.
112 * Fragment shader implemented here. SIMD aspects of EU taken full
113 * advantage of, as pixels are processed in blocks of 16.
114 *
115 * CC - Color Calculator. No EU threads associated with this unit.
116 * Handles blending and (presumably) depth and stencil testing.
117 */
118
119 #define BRW_FALLBACK_TEXTURE 0x1
120 #define BRW_MAX_CURBE (32*16)
121
122 struct brw_context;
123
124 #define BRW_NEW_URB_FENCE 0x1
125 #define BRW_NEW_FRAGMENT_PROGRAM 0x2
126 #define BRW_NEW_VERTEX_PROGRAM 0x4
127 #define BRW_NEW_INPUT_DIMENSIONS 0x8
128 #define BRW_NEW_CURBE_OFFSETS 0x10
129 #define BRW_NEW_REDUCED_PRIMITIVE 0x20
130 #define BRW_NEW_PRIMITIVE 0x40
131 #define BRW_NEW_CONTEXT 0x80
132 #define BRW_NEW_WM_INPUT_DIMENSIONS 0x100
133 #define BRW_NEW_INPUT_VARYING 0x200
134 #define BRW_NEW_TNL_PROGRAM 0x400
135 #define BRW_NEW_PSP 0x800
136 #define BRW_NEW_METAOPS 0x1000
137 #define BRW_NEW_FENCE 0x2000
138
139
140
141 struct brw_state_flags {
142 GLuint mesa;
143 GLuint cache;
144 GLuint brw;
145 };
146
147 struct brw_vertex_program {
148 struct gl_vertex_program program;
149 GLuint id;
150 GLuint param_state; /* flags indicating state tracked by params */
151 };
152
153
154
155 struct brw_fragment_program {
156 struct gl_fragment_program program;
157 GLuint id;
158 GLuint param_state; /* flags indicating state tracked by params */
159 };
160
161
162
163
164 /* Data about a particular attempt to compile a program. Note that
165 * there can be many of these, each in a different GL state
166 * corresponding to a different brw_wm_prog_key struct, with different
167 * compiled programs:
168 */
169 struct brw_wm_prog_data {
170 GLuint curb_read_length;
171 GLuint urb_read_length;
172
173 GLuint first_curbe_grf;
174 GLuint total_grf;
175 GLuint total_scratch;
176
177 GLuint nr_params;
178 GLboolean error;
179
180 /* Pointer to tracked values (only valid once
181 * _mesa_load_state_parameters has been called at runtime).
182 */
183 const GLfloat *param[BRW_MAX_CURBE];
184 };
185
186 struct brw_sf_prog_data {
187 GLuint urb_read_length;
188 GLuint total_grf;
189
190 /* Each vertex may have upto 12 attributes, 4 components each,
191 * except WPOS which requires only 2. (11*4 + 2) == 44 ==> 11
192 * rows.
193 *
194 * Actually we use 4 for each, so call it 12 rows.
195 */
196 GLuint urb_entry_size;
197 };
198
199 struct brw_clip_prog_data {
200 GLuint curb_read_length; /* user planes? */
201 GLuint clip_mode;
202 GLuint urb_read_length;
203 GLuint total_grf;
204 };
205
206 struct brw_gs_prog_data {
207 GLuint urb_read_length;
208 GLuint total_grf;
209 };
210
211 struct brw_vs_prog_data {
212 GLuint curb_read_length;
213 GLuint urb_read_length;
214 GLuint total_grf;
215 GLuint outputs_written;
216 GLuint inputs_read;
217
218 /* Used for calculating urb partitions:
219 */
220 GLuint urb_entry_size;
221 };
222
223
224 /* Size == 0 if output either not written, or always [0,0,0,1]
225 */
226 struct brw_vs_ouput_sizes {
227 GLubyte output_size[VERT_RESULT_MAX];
228 };
229
230
231 #define BRW_MAX_TEX_UNIT 8
232 #define BRW_WM_MAX_SURF BRW_MAX_TEX_UNIT + 1
233
234 /* Create a fixed sized struct for caching binding tables:
235 */
236 struct brw_surface_binding_table {
237 GLuint surf_ss_offset[BRW_WM_MAX_SURF];
238 };
239
240
241 struct brw_cache;
242
243 struct brw_mem_pool {
244 struct buffer *buffer;
245
246 GLuint size;
247 GLuint offset; /* offset of first free byte */
248
249 struct brw_context *brw;
250 };
251
252 struct brw_cache_item {
253 GLuint hash;
254 GLuint key_size; /* for variable-sized keys */
255 const void *key;
256
257 GLuint offset; /* offset within pool's buffer */
258 GLuint data_size;
259
260 struct brw_cache_item *next;
261 };
262
263
264
265 struct brw_cache {
266 GLuint id;
267
268 const char *name;
269
270 struct brw_context *brw;
271 struct brw_mem_pool *pool;
272
273 struct brw_cache_item **items;
274 GLuint size, n_items;
275
276 GLuint key_size; /* for fixed-size keys */
277 GLuint aux_size;
278
279 GLuint aub_type;
280 GLuint aub_sub_type;
281
282 GLuint last_addr; /* offset of active item */
283 };
284
285
286
287 struct brw_state_pointers {
288 struct gl_colorbuffer_attrib *Color;
289 struct gl_depthbuffer_attrib *Depth;
290 struct gl_fog_attrib *Fog;
291 struct gl_hint_attrib *Hint;
292 struct gl_light_attrib *Light;
293 struct gl_line_attrib *Line;
294 struct gl_point_attrib *Point;
295 struct gl_polygon_attrib *Polygon;
296 GLuint *PolygonStipple;
297 struct gl_scissor_attrib *Scissor;
298 struct gl_stencil_attrib *Stencil;
299 struct gl_texture_attrib *Texture;
300 struct gl_transform_attrib *Transform;
301 struct gl_viewport_attrib *Viewport;
302 struct gl_vertex_program_state *VertexProgram;
303 struct gl_fragment_program_state *FragmentProgram;
304 };
305
306 /* Considered adding a member to this struct to document which flags
307 * an update might raise so that ordering of the state atoms can be
308 * checked or derived at runtime. Dropped the idea in favor of having
309 * a debug mode where the state is monitored for flags which are
310 * raised that have already been tested against.
311 */
312 struct brw_tracked_state {
313 struct brw_state_flags dirty;
314 void (*update)( struct brw_context *brw );
315 };
316
317
318 enum brw_cache_id {
319 BRW_CC_VP,
320 BRW_CC_UNIT,
321 BRW_WM_PROG,
322 BRW_SAMPLER_DEFAULT_COLOR,
323 BRW_SAMPLER,
324 BRW_WM_UNIT,
325 BRW_SF_PROG,
326 BRW_SF_VP,
327 BRW_SF_UNIT,
328 BRW_VS_UNIT,
329 BRW_VS_PROG,
330 BRW_GS_UNIT,
331 BRW_GS_PROG,
332 BRW_CLIP_VP,
333 BRW_CLIP_UNIT,
334 BRW_CLIP_PROG,
335
336 /* These two are in the SS pool:
337 */
338 BRW_SS_SURFACE,
339 BRW_SS_SURF_BIND,
340
341 BRW_MAX_CACHE
342 };
343
344 /* Flags for brw->state.cache.
345 */
346 #define CACHE_NEW_CC_VP (1<<BRW_CC_VP)
347 #define CACHE_NEW_CC_UNIT (1<<BRW_CC_UNIT)
348 #define CACHE_NEW_WM_PROG (1<<BRW_WM_PROG)
349 #define CACHE_NEW_SAMPLER_DEFAULT_COLOR (1<<BRW_SAMPLER_DEFAULT_COLOR)
350 #define CACHE_NEW_SAMPLER (1<<BRW_SAMPLER)
351 #define CACHE_NEW_WM_UNIT (1<<BRW_WM_UNIT)
352 #define CACHE_NEW_SF_PROG (1<<BRW_SF_PROG)
353 #define CACHE_NEW_SF_VP (1<<BRW_SF_VP)
354 #define CACHE_NEW_SF_UNIT (1<<BRW_SF_UNIT)
355 #define CACHE_NEW_VS_UNIT (1<<BRW_VS_UNIT)
356 #define CACHE_NEW_VS_PROG (1<<BRW_VS_PROG)
357 #define CACHE_NEW_GS_UNIT (1<<BRW_GS_UNIT)
358 #define CACHE_NEW_GS_PROG (1<<BRW_GS_PROG)
359 #define CACHE_NEW_CLIP_VP (1<<BRW_CLIP_VP)
360 #define CACHE_NEW_CLIP_UNIT (1<<BRW_CLIP_UNIT)
361 #define CACHE_NEW_CLIP_PROG (1<<BRW_CLIP_PROG)
362 #define CACHE_NEW_SURFACE (1<<BRW_SS_SURFACE)
363 #define CACHE_NEW_SURF_BIND (1<<BRW_SS_SURF_BIND)
364
365
366
367
368 enum brw_mempool_id {
369 BRW_GS_POOL,
370 BRW_SS_POOL,
371 BRW_MAX_POOL
372 };
373
374
375 struct brw_cached_batch_item {
376 struct header *header;
377 GLuint sz;
378 struct brw_cached_batch_item *next;
379 };
380
381
382
383 /* Protect against a future where BRW_ATTRIB_MAX > 32. Wouldn't life
384 * be easier if C allowed arrays of packed elements?
385 */
386 #define ATTRIB_BIT_DWORDS ((BRW_ATTRIB_MAX+31)/32)
387
388 struct brw_vertex_element {
389 const struct gl_client_array *glarray;
390
391 struct brw_vertex_element_state *vep;
392
393 GLuint index;
394 GLuint element_size;
395 GLuint count;
396 GLuint vbo_rebase_offset;
397 };
398
399
400
401 struct brw_vertex_info {
402 GLuint varying[ATTRIB_BIT_DWORDS]; /* varying:1[BRW_ATTRIB_MAX] */
403 GLuint sizes[ATTRIB_BIT_DWORDS * 2]; /* sizes:2[BRW_ATTRIB_MAX] */
404 };
405
406
407
408
409 /* Cache for TNL programs.
410 */
411 struct brw_tnl_cache_item {
412 GLuint hash;
413 void *key;
414 void *data;
415 struct brw_tnl_cache_item *next;
416 };
417
418 struct brw_tnl_cache {
419 struct brw_tnl_cache_item **items;
420 GLuint size, n_items;
421 };
422
423
424
425 struct brw_context
426 {
427 struct intel_context intel;
428 GLuint primitive;
429
430 GLboolean emit_state_always;
431
432 GLboolean wrap;
433
434 struct {
435 struct brw_state_flags dirty;
436 struct brw_tracked_state **atoms;
437 GLuint nr_atoms;
438
439
440 struct intel_region *draw_region;
441 struct intel_region *depth_region;
442 } state;
443
444 struct brw_state_pointers attribs;
445
446 GLboolean tmp_fallback;
447
448 struct brw_mem_pool pool[BRW_MAX_POOL];
449 struct brw_cache cache[BRW_MAX_CACHE];
450 struct brw_cached_batch_item *cached_batch_items;
451
452 struct {
453 /* Fallback values for inputs not supplied:
454 */
455 struct gl_client_array current_values[BRW_ATTRIB_MAX];
456
457 /* Arrays with buffer objects to copy non-bufferobj arrays into
458 * for upload:
459 */
460 struct gl_client_array vbo_array[BRW_ATTRIB_MAX];
461
462 #define BRW_NR_UPLOAD_BUFS 17
463 #define BRW_UPLOAD_INIT_SIZE (128*1024)
464
465 struct {
466 struct gl_buffer_object *vbo[BRW_NR_UPLOAD_BUFS];
467 GLuint buf;
468 GLuint offset;
469 GLuint size;
470 GLuint wrap;
471 } upload;
472
473 /* Currenly bound arrays, including fallbacks to current_values
474 * above:
475 */
476 struct brw_vertex_element inputs[BRW_ATTRIB_MAX];
477
478 /* Summary of size and varying of active arrays, so we can check
479 * for changes to this state:
480 */
481 struct brw_vertex_info info;
482 } vb;
483
484 struct {
485 /* Will be allocated on demand if needed.
486 */
487 struct brw_state_pointers attribs;
488 struct gl_vertex_program *vp;
489 struct gl_fragment_program *fp;
490
491 struct gl_buffer_object *vbo;
492
493 struct intel_region *saved_draw_region;
494 struct intel_region *saved_depth_region;
495
496 GLuint restore_draw_mask;
497 GLboolean active;
498 } metaops;
499
500 /* Track fixed function t&l in a vertex program:
501 */
502 struct gl_vertex_program *tnl_program;
503 struct brw_tnl_cache tnl_program_cache;
504
505 /* Active vertex program:
506 */
507 struct gl_vertex_program *vertex_program;
508 struct gl_fragment_program *fragment_program;
509
510
511 /* For populating the gtt:
512 */
513 GLuint next_free_page;
514
515
516 /* BRW_NEW_URB_ALLOCATIONS:
517 */
518 struct {
519 GLuint vsize; /* vertex size plus header in urb registers */
520 GLuint csize; /* constant buffer size in urb registers */
521 GLuint sfsize; /* setup data size in urb registers */
522
523 GLboolean constrained;
524
525 GLuint nr_vs_entries;
526 GLuint nr_gs_entries;
527 GLuint nr_clip_entries;
528 GLuint nr_sf_entries;
529 GLuint nr_cs_entries;
530
531 /* GLuint vs_size; */
532 /* GLuint gs_size; */
533 /* GLuint clip_size; */
534 /* GLuint sf_size; */
535 /* GLuint cs_size; */
536
537 GLuint vs_start;
538 GLuint gs_start;
539 GLuint clip_start;
540 GLuint sf_start;
541 GLuint cs_start;
542 } urb;
543
544
545 /* BRW_NEW_CURBE_OFFSETS:
546 */
547 struct {
548 GLuint wm_start;
549 GLuint wm_size;
550 GLuint clip_start;
551 GLuint clip_size;
552 GLuint vs_start;
553 GLuint vs_size;
554 GLuint total_size;
555
556 /* Dynamic tracker which changes to reflect the state referenced
557 * by active fp and vp program parameters:
558 */
559 struct brw_tracked_state tracked_state;
560
561 GLuint gs_offset;
562
563 GLfloat *last_buf;
564 GLuint last_bufsz;
565 } curbe;
566
567 struct {
568 struct brw_vs_prog_data *prog_data;
569
570 GLuint prog_gs_offset;
571 GLuint state_gs_offset;
572 } vs;
573
574 struct {
575 struct brw_gs_prog_data *prog_data;
576
577 GLboolean prog_active;
578 GLuint prog_gs_offset;
579 GLuint state_gs_offset;
580 } gs;
581
582 struct {
583 struct brw_clip_prog_data *prog_data;
584
585 GLuint prog_gs_offset;
586 GLuint vp_gs_offset;
587 GLuint state_gs_offset;
588 } clip;
589
590
591 struct {
592 struct brw_sf_prog_data *prog_data;
593
594 GLuint prog_gs_offset;
595 GLuint vp_gs_offset;
596 GLuint state_gs_offset;
597 } sf;
598
599 struct {
600 struct brw_wm_prog_data *prog_data;
601
602 /* Input sizes, calculated from active vertex program:
603 */
604 GLuint input_size_masks[4];
605
606
607 /* State structs
608 */
609 struct brw_sampler_default_color sdc[BRW_MAX_TEX_UNIT];
610 struct brw_sampler_state sampler[BRW_MAX_TEX_UNIT];
611
612 GLuint render_surf;
613 GLuint nr_surfaces;
614
615 GLuint max_threads;
616 struct buffer *scratch_buffer;
617 GLuint scratch_buffer_size;
618
619 GLuint sampler_count;
620 GLuint sampler_gs_offset;
621
622 struct brw_surface_binding_table bind;
623 GLuint bind_ss_offset;
624
625 GLuint prog_gs_offset;
626 GLuint state_gs_offset;
627 } wm;
628
629
630 struct {
631 GLuint vp_gs_offset;
632 GLuint state_gs_offset;
633 } cc;
634
635
636 /* Used to give every program string a unique id
637 */
638 GLuint program_id;
639 };
640
641
642 #define BRW_PACKCOLOR8888(r,g,b,a) ((r<<24) | (g<<16) | (b<<8) | a)
643
644
645
646 /*======================================================================
647 * brw_vtbl.c
648 */
649 void brwInitVtbl( struct brw_context *brw );
650 void brw_do_flush( struct brw_context *brw,
651 GLuint flags );
652
653 /*======================================================================
654 * brw_context.c
655 */
656 GLboolean brwCreateContext( const __GLcontextModes *mesaVis,
657 __DRIcontextPrivate *driContextPriv,
658 void *sharedContextPrivate);
659
660
661
662 /*======================================================================
663 * brw_state.c
664 */
665 void brw_validate_state( struct brw_context *brw );
666 void brw_init_state( struct brw_context *brw );
667 void brw_destroy_state( struct brw_context *brw );
668
669
670
671 /*======================================================================
672 * brw_tex.c
673 */
674 void brwUpdateTextureState( struct intel_context *intel );
675 void brwInitTextureFuncs( struct dd_function_table *functions );
676
677 /*======================================================================
678 * brw_metaops.c
679 */
680
681 void brw_init_metaops( struct brw_context *brw );
682 void brw_destroy_metaops( struct brw_context *brw );
683
684
685 /*======================================================================
686 * brw_program.c
687 */
688 void brwInitFragProgFuncs( struct dd_function_table *functions );
689
690
691 /* brw_urb.c
692 */
693 void brw_upload_urb_fence(struct brw_context *brw);
694
695 void brw_upload_constant_buffer_state(struct brw_context *brw);
696
697
698 /*======================================================================
699 * Inline conversion functions. These are better-typed than the
700 * macros used previously:
701 */
702 static inline struct brw_context *
703 brw_context( GLcontext *ctx )
704 {
705 return (struct brw_context *)ctx;
706 }
707
708 #endif
709