2 Copyright (C) Intel Corp. 2006. All Rights Reserved.
3 Intel funded Tungsten Graphics (http://www.tungstengraphics.com) to
4 develop this 3D driver.
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:
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.
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.
26 **********************************************************************/
29 * Keith Whitwell <keith@tungstengraphics.com>
33 #ifndef BRWCONTEXT_INC
34 #define BRWCONTEXT_INC
36 #include "intel_context.h"
37 #include "brw_structs.h"
39 #include "brw_attrib.h"
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.
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.
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.
56 * PUE - primitive URB entry. An urb entry produced by the setup (SF)
57 * unit holding rasterization and interpolation parameters.
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.
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.
73 * R0 - GRF register 0. Typically holds control information used when
74 * sending messages to other threads.
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.
80 * Fixed function units:
82 * CS - Command streamer. Notional first unit, little software
83 * interaction. Holds the URB entries used for constant data, ie the
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.
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.
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.
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.
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.
115 * CC - Color Calculator. No EU threads associated with this unit.
116 * Handles blending and (presumably) depth and stencil testing.
119 #define BRW_FALLBACK_TEXTURE 0x1
120 #define BRW_MAX_CURBE (32*16)
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
141 struct brw_state_flags
{
147 struct brw_vertex_program
{
148 struct gl_vertex_program program
;
150 GLuint param_state
; /* flags indicating state tracked by params */
155 struct brw_fragment_program
{
156 struct gl_fragment_program program
;
158 GLuint param_state
; /* flags indicating state tracked by params */
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
169 struct brw_wm_prog_data
{
170 GLuint curb_read_length
;
171 GLuint urb_read_length
;
173 GLuint first_curbe_grf
;
175 GLuint total_scratch
;
180 /* Pointer to tracked values (only valid once
181 * _mesa_load_state_parameters has been called at runtime).
183 const GLfloat
*param
[BRW_MAX_CURBE
];
186 struct brw_sf_prog_data
{
187 GLuint urb_read_length
;
190 /* Each vertex may have upto 12 attributes, 4 components each,
191 * except WPOS which requires only 2. (11*4 + 2) == 44 ==> 11
194 * Actually we use 4 for each, so call it 12 rows.
196 GLuint urb_entry_size
;
199 struct brw_clip_prog_data
{
200 GLuint curb_read_length
; /* user planes? */
202 GLuint urb_read_length
;
206 struct brw_gs_prog_data
{
207 GLuint urb_read_length
;
211 struct brw_vs_prog_data
{
212 GLuint curb_read_length
;
213 GLuint urb_read_length
;
215 GLuint outputs_written
;
218 /* Used for calculating urb partitions:
220 GLuint urb_entry_size
;
224 /* Size == 0 if output either not written, or always [0,0,0,1]
226 struct brw_vs_ouput_sizes
{
227 GLubyte output_size
[VERT_RESULT_MAX
];
231 #define BRW_MAX_TEX_UNIT 8
232 #define BRW_WM_MAX_SURF BRW_MAX_TEX_UNIT + 1
234 /* Create a fixed sized struct for caching binding tables:
236 struct brw_surface_binding_table
{
237 GLuint surf_ss_offset
[BRW_WM_MAX_SURF
];
243 struct brw_mem_pool
{
244 struct buffer
*buffer
;
247 GLuint offset
; /* offset of first free byte */
249 struct brw_context
*brw
;
252 struct brw_cache_item
{
254 GLuint key_size
; /* for variable-sized keys */
257 GLuint offset
; /* offset within pool's buffer */
260 struct brw_cache_item
*next
;
270 struct brw_context
*brw
;
271 struct brw_mem_pool
*pool
;
273 struct brw_cache_item
**items
;
274 GLuint size
, n_items
;
276 GLuint key_size
; /* for fixed-size keys */
282 GLuint last_addr
; /* offset of active item */
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
;
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.
312 struct brw_tracked_state
{
313 struct brw_state_flags dirty
;
314 void (*update
)( struct brw_context
*brw
);
322 BRW_SAMPLER_DEFAULT_COLOR
,
336 /* These two are in the SS pool:
344 /* Flags for brw->state.cache.
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)
368 enum brw_mempool_id
{
375 struct brw_cached_batch_item
{
376 struct header
*header
;
378 struct brw_cached_batch_item
*next
;
383 /* Protect against a future where BRW_ATTRIB_MAX > 32. Wouldn't life
384 * be easier if C allowed arrays of packed elements?
386 #define ATTRIB_BIT_DWORDS ((BRW_ATTRIB_MAX+31)/32)
388 struct brw_vertex_element
{
389 const struct gl_client_array
*glarray
;
391 struct brw_vertex_element_state
*vep
;
396 GLuint vbo_rebase_offset
;
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] */
409 /* Cache for TNL programs.
411 struct brw_tnl_cache_item
{
415 struct brw_tnl_cache_item
*next
;
418 struct brw_tnl_cache
{
419 struct brw_tnl_cache_item
**items
;
420 GLuint size
, n_items
;
427 struct intel_context intel
;
430 GLboolean emit_state_always
;
435 struct brw_state_flags dirty
;
436 struct brw_tracked_state
**atoms
;
440 struct intel_region
*draw_region
;
441 struct intel_region
*depth_region
;
444 struct brw_state_pointers attribs
;
446 GLboolean tmp_fallback
;
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
;
453 /* Fallback values for inputs not supplied:
455 struct gl_client_array current_values
[BRW_ATTRIB_MAX
];
457 /* Arrays with buffer objects to copy non-bufferobj arrays into
460 struct gl_client_array vbo_array
[BRW_ATTRIB_MAX
];
462 #define BRW_NR_UPLOAD_BUFS 17
463 #define BRW_UPLOAD_INIT_SIZE (128*1024)
466 struct gl_buffer_object
*vbo
[BRW_NR_UPLOAD_BUFS
];
473 /* Currenly bound arrays, including fallbacks to current_values
476 struct brw_vertex_element inputs
[BRW_ATTRIB_MAX
];
478 /* Summary of size and varying of active arrays, so we can check
479 * for changes to this state:
481 struct brw_vertex_info info
;
485 /* Will be allocated on demand if needed.
487 struct brw_state_pointers attribs
;
488 struct gl_vertex_program
*vp
;
489 struct gl_fragment_program
*fp
;
491 struct gl_buffer_object
*vbo
;
493 struct intel_region
*saved_draw_region
;
494 struct intel_region
*saved_depth_region
;
496 GLuint restore_draw_mask
;
500 /* Track fixed function t&l in a vertex program:
502 struct gl_vertex_program
*tnl_program
;
503 struct brw_tnl_cache tnl_program_cache
;
505 /* Active vertex program:
507 struct gl_vertex_program
*vertex_program
;
508 struct gl_fragment_program
*fragment_program
;
511 /* For populating the gtt:
513 GLuint next_free_page
;
516 /* BRW_NEW_URB_ALLOCATIONS:
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 */
523 GLboolean constrained
;
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
;
531 /* GLuint vs_size; */
532 /* GLuint gs_size; */
533 /* GLuint clip_size; */
534 /* GLuint sf_size; */
535 /* GLuint cs_size; */
545 /* BRW_NEW_CURBE_OFFSETS:
556 /* Dynamic tracker which changes to reflect the state referenced
557 * by active fp and vp program parameters:
559 struct brw_tracked_state tracked_state
;
568 struct brw_vs_prog_data
*prog_data
;
570 GLuint prog_gs_offset
;
571 GLuint state_gs_offset
;
575 struct brw_gs_prog_data
*prog_data
;
577 GLboolean prog_active
;
578 GLuint prog_gs_offset
;
579 GLuint state_gs_offset
;
583 struct brw_clip_prog_data
*prog_data
;
585 GLuint prog_gs_offset
;
587 GLuint state_gs_offset
;
592 struct brw_sf_prog_data
*prog_data
;
594 GLuint prog_gs_offset
;
596 GLuint state_gs_offset
;
600 struct brw_wm_prog_data
*prog_data
;
602 /* Input sizes, calculated from active vertex program:
604 GLuint input_size_masks
[4];
609 struct brw_sampler_default_color sdc
[BRW_MAX_TEX_UNIT
];
610 struct brw_sampler_state sampler
[BRW_MAX_TEX_UNIT
];
616 struct buffer
*scratch_buffer
;
617 GLuint scratch_buffer_size
;
619 GLuint sampler_count
;
620 GLuint sampler_gs_offset
;
622 struct brw_surface_binding_table bind
;
623 GLuint bind_ss_offset
;
625 GLuint prog_gs_offset
;
626 GLuint state_gs_offset
;
632 GLuint state_gs_offset
;
636 /* Used to give every program string a unique id
642 #define BRW_PACKCOLOR8888(r,g,b,a) ((r<<24) | (g<<16) | (b<<8) | a)
646 /*======================================================================
649 void brwInitVtbl( struct brw_context
*brw
);
650 void brw_do_flush( struct brw_context
*brw
,
653 /*======================================================================
656 GLboolean
brwCreateContext( const __GLcontextModes
*mesaVis
,
657 __DRIcontextPrivate
*driContextPriv
,
658 void *sharedContextPrivate
);
662 /*======================================================================
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
);
671 /*======================================================================
674 void brwUpdateTextureState( struct intel_context
*intel
);
675 void brwInitTextureFuncs( struct dd_function_table
*functions
);
677 /*======================================================================
681 void brw_init_metaops( struct brw_context
*brw
);
682 void brw_destroy_metaops( struct brw_context
*brw
);
685 /*======================================================================
688 void brwInitFragProgFuncs( struct dd_function_table
*functions
);
693 void brw_upload_urb_fence(struct brw_context
*brw
);
695 void brw_upload_constant_buffer_state(struct brw_context
*brw
);
698 /*======================================================================
699 * Inline conversion functions. These are better-typed than the
700 * macros used previously:
702 static inline struct brw_context
*
703 brw_context( GLcontext
*ctx
)
705 return (struct brw_context
*)ctx
;