i965: Consolidate BRW_NEW_TESS_{CTRL,EVAL}_PROGRAM flags.
[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 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 <keithw@vmware.com>
30 */
31
32
33 #ifndef BRWCONTEXT_INC
34 #define BRWCONTEXT_INC
35
36 #include <stdbool.h>
37 #include "main/macros.h"
38 #include "main/mtypes.h"
39 #include "brw_structs.h"
40 #include "brw_compiler.h"
41 #include "intel_aub.h"
42
43 #ifdef __cplusplus
44 extern "C" {
45 /* Evil hack for using libdrm in a c++ compiler. */
46 #define virtual virt
47 #endif
48
49 #include <intel_bufmgr.h>
50 #ifdef __cplusplus
51 #undef virtual
52 }
53 #endif
54
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 #include "intel_debug.h"
59 #include "intel_screen.h"
60 #include "intel_tex_obj.h"
61 #include "intel_resolve_map.h"
62
63 /* Glossary:
64 *
65 * URB - uniform resource buffer. A mid-sized buffer which is
66 * partitioned between the fixed function units and used for passing
67 * values (vertices, primitives, constants) between them.
68 *
69 * CURBE - constant URB entry. An urb region (entry) used to hold
70 * constant values which the fixed function units can be instructed to
71 * preload into the GRF when spawning a thread.
72 *
73 * VUE - vertex URB entry. An urb entry holding a vertex and usually
74 * a vertex header. The header contains control information and
75 * things like primitive type, Begin/end flags and clip codes.
76 *
77 * PUE - primitive URB entry. An urb entry produced by the setup (SF)
78 * unit holding rasterization and interpolation parameters.
79 *
80 * GRF - general register file. One of several register files
81 * addressable by programmed threads. The inputs (r0, payload, curbe,
82 * urb) of the thread are preloaded to this area before the thread is
83 * spawned. The registers are individually 8 dwords wide and suitable
84 * for general usage. Registers holding thread input values are not
85 * special and may be overwritten.
86 *
87 * MRF - message register file. Threads communicate (and terminate)
88 * by sending messages. Message parameters are placed in contiguous
89 * MRF registers. All program output is via these messages. URB
90 * entries are populated by sending a message to the shared URB
91 * function containing the new data, together with a control word,
92 * often an unmodified copy of R0.
93 *
94 * R0 - GRF register 0. Typically holds control information used when
95 * sending messages to other threads.
96 *
97 * EU or GEN4 EU: The name of the programmable subsystem of the
98 * i965 hardware. Threads are executed by the EU, the registers
99 * described above are part of the EU architecture.
100 *
101 * Fixed function units:
102 *
103 * CS - Command streamer. Notional first unit, little software
104 * interaction. Holds the URB entries used for constant data, ie the
105 * CURBEs.
106 *
107 * VF/VS - Vertex Fetch / Vertex Shader. The fixed function part of
108 * this unit is responsible for pulling vertices out of vertex buffers
109 * in vram and injecting them into the processing pipe as VUEs. If
110 * enabled, it first passes them to a VS thread which is a good place
111 * for the driver to implement any active vertex shader.
112 *
113 * HS - Hull Shader (Tessellation Control Shader)
114 *
115 * TE - Tessellation Engine (Tessellation Primitive Generation)
116 *
117 * DS - Domain Shader (Tessellation Evaluation Shader)
118 *
119 * GS - Geometry Shader. This corresponds to a new DX10 concept. If
120 * enabled, incoming strips etc are passed to GS threads in individual
121 * line/triangle/point units. The GS thread may perform arbitary
122 * computation and emit whatever primtives with whatever vertices it
123 * chooses. This makes GS an excellent place to implement GL's
124 * unfilled polygon modes, though of course it is capable of much
125 * more. Additionally, GS is used to translate away primitives not
126 * handled by latter units, including Quads and Lineloops.
127 *
128 * CS - Clipper. Mesa's clipping algorithms are imported to run on
129 * this unit. The fixed function part performs cliptesting against
130 * the 6 fixed clipplanes and makes descisions on whether or not the
131 * incoming primitive needs to be passed to a thread for clipping.
132 * User clip planes are handled via cooperation with the VS thread.
133 *
134 * SF - Strips Fans or Setup: Triangles are prepared for
135 * rasterization. Interpolation coefficients are calculated.
136 * Flatshading and two-side lighting usually performed here.
137 *
138 * WM - Windower. Interpolation of vertex attributes performed here.
139 * Fragment shader implemented here. SIMD aspects of EU taken full
140 * advantage of, as pixels are processed in blocks of 16.
141 *
142 * CC - Color Calculator. No EU threads associated with this unit.
143 * Handles blending and (presumably) depth and stencil testing.
144 */
145
146 struct brw_context;
147 struct brw_inst;
148 struct brw_vs_prog_key;
149 struct brw_vue_prog_key;
150 struct brw_wm_prog_key;
151 struct brw_wm_prog_data;
152 struct brw_cs_prog_key;
153 struct brw_cs_prog_data;
154
155 enum brw_pipeline {
156 BRW_RENDER_PIPELINE,
157 BRW_COMPUTE_PIPELINE,
158
159 BRW_NUM_PIPELINES
160 };
161
162 enum brw_cache_id {
163 BRW_CACHE_FS_PROG,
164 BRW_CACHE_BLORP_BLIT_PROG,
165 BRW_CACHE_SF_PROG,
166 BRW_CACHE_VS_PROG,
167 BRW_CACHE_FF_GS_PROG,
168 BRW_CACHE_GS_PROG,
169 BRW_CACHE_TCS_PROG,
170 BRW_CACHE_TES_PROG,
171 BRW_CACHE_CLIP_PROG,
172 BRW_CACHE_CS_PROG,
173
174 BRW_MAX_CACHE
175 };
176
177 enum brw_state_id {
178 /* brw_cache_ids must come first - see brw_state_cache.c */
179 BRW_STATE_URB_FENCE = BRW_MAX_CACHE,
180 BRW_STATE_FRAGMENT_PROGRAM,
181 BRW_STATE_GEOMETRY_PROGRAM,
182 BRW_STATE_TESS_PROGRAMS,
183 BRW_STATE_VERTEX_PROGRAM,
184 BRW_STATE_CURBE_OFFSETS,
185 BRW_STATE_REDUCED_PRIMITIVE,
186 BRW_STATE_PATCH_PRIMITIVE,
187 BRW_STATE_PRIMITIVE,
188 BRW_STATE_CONTEXT,
189 BRW_STATE_PSP,
190 BRW_STATE_SURFACES,
191 BRW_STATE_BINDING_TABLE_POINTERS,
192 BRW_STATE_INDICES,
193 BRW_STATE_VERTICES,
194 BRW_STATE_BATCH,
195 BRW_STATE_INDEX_BUFFER,
196 BRW_STATE_VS_CONSTBUF,
197 BRW_STATE_TCS_CONSTBUF,
198 BRW_STATE_TES_CONSTBUF,
199 BRW_STATE_GS_CONSTBUF,
200 BRW_STATE_PROGRAM_CACHE,
201 BRW_STATE_STATE_BASE_ADDRESS,
202 BRW_STATE_VUE_MAP_GEOM_OUT,
203 BRW_STATE_TRANSFORM_FEEDBACK,
204 BRW_STATE_RASTERIZER_DISCARD,
205 BRW_STATE_STATS_WM,
206 BRW_STATE_UNIFORM_BUFFER,
207 BRW_STATE_ATOMIC_BUFFER,
208 BRW_STATE_IMAGE_UNITS,
209 BRW_STATE_META_IN_PROGRESS,
210 BRW_STATE_INTERPOLATION_MAP,
211 BRW_STATE_PUSH_CONSTANT_ALLOCATION,
212 BRW_STATE_NUM_SAMPLES,
213 BRW_STATE_TEXTURE_BUFFER,
214 BRW_STATE_GEN4_UNIT_STATE,
215 BRW_STATE_CC_VP,
216 BRW_STATE_SF_VP,
217 BRW_STATE_CLIP_VP,
218 BRW_STATE_SAMPLER_STATE_TABLE,
219 BRW_STATE_VS_ATTRIB_WORKAROUNDS,
220 BRW_STATE_COMPUTE_PROGRAM,
221 BRW_STATE_CS_WORK_GROUPS,
222 BRW_STATE_URB_SIZE,
223 BRW_NUM_STATE_BITS
224 };
225
226 /**
227 * BRW_NEW_*_PROG_DATA and BRW_NEW_*_PROGRAM are similar, but distinct.
228 *
229 * BRW_NEW_*_PROGRAM relates to the gl_shader_program/gl_program structures.
230 * When the currently bound shader program differs from the previous draw
231 * call, these will be flagged. They cover brw->{stage}_program and
232 * ctx->{Stage}Program->_Current.
233 *
234 * BRW_NEW_*_PROG_DATA is flagged when the effective shaders change, from a
235 * driver perspective. Even if the same shader is bound at the API level,
236 * we may need to switch between multiple versions of that shader to handle
237 * changes in non-orthagonal state.
238 *
239 * Additionally, multiple shader programs may have identical vertex shaders
240 * (for example), or compile down to the same code in the backend. We combine
241 * those into a single program cache entry.
242 *
243 * BRW_NEW_*_PROG_DATA occurs when switching program cache entries, which
244 * covers the brw_*_prog_data structures, and brw->*.prog_offset.
245 */
246 #define BRW_NEW_FS_PROG_DATA (1ull << BRW_CACHE_FS_PROG)
247 /* XXX: The BRW_NEW_BLORP_BLIT_PROG_DATA dirty bit is unused (as BLORP doesn't
248 * use the normal state upload paths), but the cache is still used. To avoid
249 * polluting the brw_state_cache code with special cases, we retain the dirty
250 * bit for now. It should eventually be removed.
251 */
252 #define BRW_NEW_BLORP_BLIT_PROG_DATA (1ull << BRW_CACHE_BLORP_BLIT_PROG)
253 #define BRW_NEW_SF_PROG_DATA (1ull << BRW_CACHE_SF_PROG)
254 #define BRW_NEW_VS_PROG_DATA (1ull << BRW_CACHE_VS_PROG)
255 #define BRW_NEW_FF_GS_PROG_DATA (1ull << BRW_CACHE_FF_GS_PROG)
256 #define BRW_NEW_GS_PROG_DATA (1ull << BRW_CACHE_GS_PROG)
257 #define BRW_NEW_TCS_PROG_DATA (1ull << BRW_CACHE_TCS_PROG)
258 #define BRW_NEW_TES_PROG_DATA (1ull << BRW_CACHE_TES_PROG)
259 #define BRW_NEW_CLIP_PROG_DATA (1ull << BRW_CACHE_CLIP_PROG)
260 #define BRW_NEW_CS_PROG_DATA (1ull << BRW_CACHE_CS_PROG)
261 #define BRW_NEW_URB_FENCE (1ull << BRW_STATE_URB_FENCE)
262 #define BRW_NEW_FRAGMENT_PROGRAM (1ull << BRW_STATE_FRAGMENT_PROGRAM)
263 #define BRW_NEW_GEOMETRY_PROGRAM (1ull << BRW_STATE_GEOMETRY_PROGRAM)
264 #define BRW_NEW_TESS_PROGRAMS (1ull << BRW_STATE_TESS_PROGRAMS)
265 #define BRW_NEW_VERTEX_PROGRAM (1ull << BRW_STATE_VERTEX_PROGRAM)
266 #define BRW_NEW_CURBE_OFFSETS (1ull << BRW_STATE_CURBE_OFFSETS)
267 #define BRW_NEW_REDUCED_PRIMITIVE (1ull << BRW_STATE_REDUCED_PRIMITIVE)
268 #define BRW_NEW_PATCH_PRIMITIVE (1ull << BRW_STATE_PATCH_PRIMITIVE)
269 #define BRW_NEW_PRIMITIVE (1ull << BRW_STATE_PRIMITIVE)
270 #define BRW_NEW_CONTEXT (1ull << BRW_STATE_CONTEXT)
271 #define BRW_NEW_PSP (1ull << BRW_STATE_PSP)
272 #define BRW_NEW_SURFACES (1ull << BRW_STATE_SURFACES)
273 #define BRW_NEW_BINDING_TABLE_POINTERS (1ull << BRW_STATE_BINDING_TABLE_POINTERS)
274 #define BRW_NEW_INDICES (1ull << BRW_STATE_INDICES)
275 #define BRW_NEW_VERTICES (1ull << BRW_STATE_VERTICES)
276 /**
277 * Used for any batch entry with a relocated pointer that will be used
278 * by any 3D rendering.
279 */
280 #define BRW_NEW_BATCH (1ull << BRW_STATE_BATCH)
281 /** \see brw.state.depth_region */
282 #define BRW_NEW_INDEX_BUFFER (1ull << BRW_STATE_INDEX_BUFFER)
283 #define BRW_NEW_VS_CONSTBUF (1ull << BRW_STATE_VS_CONSTBUF)
284 #define BRW_NEW_TCS_CONSTBUF (1ull << BRW_STATE_TCS_CONSTBUF)
285 #define BRW_NEW_TES_CONSTBUF (1ull << BRW_STATE_TES_CONSTBUF)
286 #define BRW_NEW_GS_CONSTBUF (1ull << BRW_STATE_GS_CONSTBUF)
287 #define BRW_NEW_PROGRAM_CACHE (1ull << BRW_STATE_PROGRAM_CACHE)
288 #define BRW_NEW_STATE_BASE_ADDRESS (1ull << BRW_STATE_STATE_BASE_ADDRESS)
289 #define BRW_NEW_VUE_MAP_GEOM_OUT (1ull << BRW_STATE_VUE_MAP_GEOM_OUT)
290 #define BRW_NEW_TRANSFORM_FEEDBACK (1ull << BRW_STATE_TRANSFORM_FEEDBACK)
291 #define BRW_NEW_RASTERIZER_DISCARD (1ull << BRW_STATE_RASTERIZER_DISCARD)
292 #define BRW_NEW_STATS_WM (1ull << BRW_STATE_STATS_WM)
293 #define BRW_NEW_UNIFORM_BUFFER (1ull << BRW_STATE_UNIFORM_BUFFER)
294 #define BRW_NEW_ATOMIC_BUFFER (1ull << BRW_STATE_ATOMIC_BUFFER)
295 #define BRW_NEW_IMAGE_UNITS (1ull << BRW_STATE_IMAGE_UNITS)
296 #define BRW_NEW_META_IN_PROGRESS (1ull << BRW_STATE_META_IN_PROGRESS)
297 #define BRW_NEW_INTERPOLATION_MAP (1ull << BRW_STATE_INTERPOLATION_MAP)
298 #define BRW_NEW_PUSH_CONSTANT_ALLOCATION (1ull << BRW_STATE_PUSH_CONSTANT_ALLOCATION)
299 #define BRW_NEW_NUM_SAMPLES (1ull << BRW_STATE_NUM_SAMPLES)
300 #define BRW_NEW_TEXTURE_BUFFER (1ull << BRW_STATE_TEXTURE_BUFFER)
301 #define BRW_NEW_GEN4_UNIT_STATE (1ull << BRW_STATE_GEN4_UNIT_STATE)
302 #define BRW_NEW_CC_VP (1ull << BRW_STATE_CC_VP)
303 #define BRW_NEW_SF_VP (1ull << BRW_STATE_SF_VP)
304 #define BRW_NEW_CLIP_VP (1ull << BRW_STATE_CLIP_VP)
305 #define BRW_NEW_SAMPLER_STATE_TABLE (1ull << BRW_STATE_SAMPLER_STATE_TABLE)
306 #define BRW_NEW_VS_ATTRIB_WORKAROUNDS (1ull << BRW_STATE_VS_ATTRIB_WORKAROUNDS)
307 #define BRW_NEW_COMPUTE_PROGRAM (1ull << BRW_STATE_COMPUTE_PROGRAM)
308 #define BRW_NEW_CS_WORK_GROUPS (1ull << BRW_STATE_CS_WORK_GROUPS)
309 #define BRW_NEW_URB_SIZE (1ull << BRW_STATE_URB_SIZE)
310
311 struct brw_state_flags {
312 /** State update flags signalled by mesa internals */
313 GLuint mesa;
314 /**
315 * State update flags signalled as the result of brw_tracked_state updates
316 */
317 uint64_t brw;
318 };
319
320 /** Subclass of Mesa vertex program */
321 struct brw_vertex_program {
322 struct gl_vertex_program program;
323 GLuint id;
324 };
325
326
327 /** Subclass of Mesa tessellation control program */
328 struct brw_tess_ctrl_program {
329 struct gl_tess_ctrl_program program;
330 unsigned id; /**< serial no. to identify tess ctrl progs, never re-used */
331 };
332
333
334 /** Subclass of Mesa tessellation evaluation program */
335 struct brw_tess_eval_program {
336 struct gl_tess_eval_program program;
337 unsigned id; /**< serial no. to identify tess eval progs, never re-used */
338 };
339
340
341 /** Subclass of Mesa geometry program */
342 struct brw_geometry_program {
343 struct gl_geometry_program program;
344 unsigned id; /**< serial no. to identify geom progs, never re-used */
345 };
346
347
348 /** Subclass of Mesa fragment program */
349 struct brw_fragment_program {
350 struct gl_fragment_program program;
351 GLuint id; /**< serial no. to identify frag progs, never re-used */
352 };
353
354
355 /** Subclass of Mesa compute program */
356 struct brw_compute_program {
357 struct gl_compute_program program;
358 unsigned id; /**< serial no. to identify compute progs, never re-used */
359 };
360
361
362 struct brw_shader {
363 struct gl_shader base;
364
365 bool compiled_once;
366 };
367
368 /**
369 * Bitmask indicating which fragment shader inputs represent varyings (and
370 * hence have to be delivered to the fragment shader by the SF/SBE stage).
371 */
372 #define BRW_FS_VARYING_INPUT_MASK \
373 (BITFIELD64_RANGE(0, VARYING_SLOT_MAX) & \
374 ~VARYING_BIT_POS & ~VARYING_BIT_FACE)
375
376
377 /*
378 * Mapping of VUE map slots to interpolation modes.
379 */
380 struct interpolation_mode_map {
381 unsigned char mode[BRW_VARYING_SLOT_COUNT];
382 };
383
384 static inline bool brw_any_flat_varyings(struct interpolation_mode_map *map)
385 {
386 for (int i = 0; i < BRW_VARYING_SLOT_COUNT; i++)
387 if (map->mode[i] == INTERP_QUALIFIER_FLAT)
388 return true;
389
390 return false;
391 }
392
393 static inline bool brw_any_noperspective_varyings(struct interpolation_mode_map *map)
394 {
395 for (int i = 0; i < BRW_VARYING_SLOT_COUNT; i++)
396 if (map->mode[i] == INTERP_QUALIFIER_NOPERSPECTIVE)
397 return true;
398
399 return false;
400 }
401
402
403 struct brw_sf_prog_data {
404 GLuint urb_read_length;
405 GLuint total_grf;
406
407 /* Each vertex may have upto 12 attributes, 4 components each,
408 * except WPOS which requires only 2. (11*4 + 2) == 44 ==> 11
409 * rows.
410 *
411 * Actually we use 4 for each, so call it 12 rows.
412 */
413 GLuint urb_entry_size;
414 };
415
416
417 /**
418 * We always program SF to start reading at an offset of 1 (2 varying slots)
419 * from the start of the vertex URB entry. This causes it to skip:
420 * - VARYING_SLOT_PSIZ and BRW_VARYING_SLOT_NDC on gen4-5
421 * - VARYING_SLOT_PSIZ and VARYING_SLOT_POS on gen6+
422 */
423 #define BRW_SF_URB_ENTRY_READ_OFFSET 1
424
425
426 struct brw_clip_prog_data {
427 GLuint curb_read_length; /* user planes? */
428 GLuint clip_mode;
429 GLuint urb_read_length;
430 GLuint total_grf;
431 };
432
433 struct brw_ff_gs_prog_data {
434 GLuint urb_read_length;
435 GLuint total_grf;
436
437 /**
438 * Gen6 transform feedback: Amount by which the streaming vertex buffer
439 * indices should be incremented each time the GS is invoked.
440 */
441 unsigned svbi_postincrement_value;
442 };
443
444 /** Number of texture sampler units */
445 #define BRW_MAX_TEX_UNIT 32
446
447 /** Max number of render targets in a shader */
448 #define BRW_MAX_DRAW_BUFFERS 8
449
450 /** Max number of UBOs in a shader */
451 #define BRW_MAX_UBO 14
452
453 /** Max number of SSBOs in a shader */
454 #define BRW_MAX_SSBO 12
455
456 /** Max number of atomic counter buffer objects in a shader */
457 #define BRW_MAX_ABO 16
458
459 /** Max number of image uniforms in a shader */
460 #define BRW_MAX_IMAGES 32
461
462 /**
463 * Max number of binding table entries used for stream output.
464 *
465 * From the OpenGL 3.0 spec, table 6.44 (Transform Feedback State), the
466 * minimum value of MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS is 64.
467 *
468 * On Gen6, the size of transform feedback data is limited not by the number
469 * of components but by the number of binding table entries we set aside. We
470 * use one binding table entry for a float, one entry for a vector, and one
471 * entry per matrix column. Since the only way we can communicate our
472 * transform feedback capabilities to the client is via
473 * MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, we need to plan for the
474 * worst case, in which all the varyings are floats, so we use up one binding
475 * table entry per component. Therefore we need to set aside at least 64
476 * binding table entries for use by transform feedback.
477 *
478 * Note: since we don't currently pack varyings, it is currently impossible
479 * for the client to actually use up all of these binding table entries--if
480 * all of their varyings were floats, they would run out of varying slots and
481 * fail to link. But that's a bug, so it seems prudent to go ahead and
482 * allocate the number of binding table entries we will need once the bug is
483 * fixed.
484 */
485 #define BRW_MAX_SOL_BINDINGS 64
486
487 /** Maximum number of actual buffers used for stream output */
488 #define BRW_MAX_SOL_BUFFERS 4
489
490 #define BRW_MAX_SURFACES (BRW_MAX_DRAW_BUFFERS + \
491 BRW_MAX_TEX_UNIT * 2 + /* normal, gather */ \
492 BRW_MAX_UBO + \
493 BRW_MAX_SSBO + \
494 BRW_MAX_ABO + \
495 BRW_MAX_IMAGES + \
496 2 + /* shader time, pull constants */ \
497 1 /* cs num work groups */)
498
499 #define SURF_INDEX_GEN6_SOL_BINDING(t) (t)
500
501 /**
502 * Stride in bytes between shader_time entries.
503 *
504 * We separate entries by a cacheline to reduce traffic between EUs writing to
505 * different entries.
506 */
507 #define SHADER_TIME_STRIDE 64
508
509 struct brw_cache_item {
510 /**
511 * Effectively part of the key, cache_id identifies what kind of state
512 * buffer is involved, and also which dirty flag should set.
513 */
514 enum brw_cache_id cache_id;
515 /** 32-bit hash of the key data */
516 GLuint hash;
517 GLuint key_size; /* for variable-sized keys */
518 GLuint aux_size;
519 const void *key;
520
521 uint32_t offset;
522 uint32_t size;
523
524 struct brw_cache_item *next;
525 };
526
527
528 struct brw_cache {
529 struct brw_context *brw;
530
531 struct brw_cache_item **items;
532 drm_intel_bo *bo;
533 GLuint size, n_items;
534
535 uint32_t next_offset;
536 bool bo_used_by_gpu;
537 };
538
539
540 /* Considered adding a member to this struct to document which flags
541 * an update might raise so that ordering of the state atoms can be
542 * checked or derived at runtime. Dropped the idea in favor of having
543 * a debug mode where the state is monitored for flags which are
544 * raised that have already been tested against.
545 */
546 struct brw_tracked_state {
547 struct brw_state_flags dirty;
548 void (*emit)( struct brw_context *brw );
549 };
550
551 enum shader_time_shader_type {
552 ST_NONE,
553 ST_VS,
554 ST_TCS,
555 ST_TES,
556 ST_GS,
557 ST_FS8,
558 ST_FS16,
559 ST_CS,
560 };
561
562 struct brw_vertex_buffer {
563 /** Buffer object containing the uploaded vertex data */
564 drm_intel_bo *bo;
565 uint32_t offset;
566 /** Byte stride between elements in the uploaded array */
567 GLuint stride;
568 GLuint step_rate;
569 };
570 struct brw_vertex_element {
571 const struct gl_client_array *glarray;
572
573 int buffer;
574
575 /** Offset of the first element within the buffer object */
576 unsigned int offset;
577 };
578
579 struct brw_query_object {
580 struct gl_query_object Base;
581
582 /** Last query BO associated with this query. */
583 drm_intel_bo *bo;
584
585 /** Last index in bo with query data for this object. */
586 int last_index;
587
588 /** True if we know the batch has been flushed since we ended the query. */
589 bool flushed;
590 };
591
592 enum brw_gpu_ring {
593 UNKNOWN_RING,
594 RENDER_RING,
595 BLT_RING,
596 };
597
598 struct intel_batchbuffer {
599 /** Current batchbuffer being queued up. */
600 drm_intel_bo *bo;
601 /** Last BO submitted to the hardware. Used for glFinish(). */
602 drm_intel_bo *last_bo;
603
604 #ifdef DEBUG
605 uint16_t emit, total;
606 #endif
607 uint16_t reserved_space;
608 uint32_t *map_next;
609 uint32_t *map;
610 uint32_t *cpu_map;
611 #define BATCH_SZ (8192*sizeof(uint32_t))
612
613 uint32_t state_batch_offset;
614 enum brw_gpu_ring ring;
615 bool needs_sol_reset;
616
617 struct {
618 uint32_t *map_next;
619 int reloc_count;
620 } saved;
621 };
622
623 #define MAX_GS_INPUT_VERTICES 6
624
625 #define BRW_MAX_XFB_STREAMS 4
626
627 struct brw_transform_feedback_object {
628 struct gl_transform_feedback_object base;
629
630 /** A buffer to hold SO_WRITE_OFFSET(n) values while paused. */
631 drm_intel_bo *offset_bo;
632
633 /** If true, SO_WRITE_OFFSET(n) should be reset to zero at next use. */
634 bool zero_offsets;
635
636 /** The most recent primitive mode (GL_TRIANGLES/GL_POINTS/GL_LINES). */
637 GLenum primitive_mode;
638
639 /**
640 * Count of primitives generated during this transform feedback operation.
641 * @{
642 */
643 uint64_t prims_generated[BRW_MAX_XFB_STREAMS];
644 drm_intel_bo *prim_count_bo;
645 unsigned prim_count_buffer_index; /**< in number of uint64_t units */
646 /** @} */
647
648 /**
649 * Number of vertices written between last Begin/EndTransformFeedback().
650 *
651 * Used to implement DrawTransformFeedback().
652 */
653 uint64_t vertices_written[BRW_MAX_XFB_STREAMS];
654 bool vertices_written_valid;
655 };
656
657 /**
658 * Data shared between each programmable stage in the pipeline (vs, gs, and
659 * wm).
660 */
661 struct brw_stage_state
662 {
663 gl_shader_stage stage;
664 struct brw_stage_prog_data *prog_data;
665
666 /**
667 * Optional scratch buffer used to store spilled register values and
668 * variably-indexed GRF arrays.
669 */
670 drm_intel_bo *scratch_bo;
671
672 /** Offset in the program cache to the program */
673 uint32_t prog_offset;
674
675 /** Offset in the batchbuffer to Gen4-5 pipelined state (VS/WM/GS_STATE). */
676 uint32_t state_offset;
677
678 uint32_t push_const_offset; /* Offset in the batchbuffer */
679 int push_const_size; /* in 256-bit register increments */
680
681 /* Binding table: pointers to SURFACE_STATE entries. */
682 uint32_t bind_bo_offset;
683 uint32_t surf_offset[BRW_MAX_SURFACES];
684
685 /** SAMPLER_STATE count and table offset */
686 uint32_t sampler_count;
687 uint32_t sampler_offset;
688 };
689
690 enum brw_predicate_state {
691 /* The first two states are used if we can determine whether to draw
692 * without having to look at the values in the query object buffer. This
693 * will happen if there is no conditional render in progress, if the query
694 * object is already completed or if something else has already added
695 * samples to the preliminary result such as via a BLT command.
696 */
697 BRW_PREDICATE_STATE_RENDER,
698 BRW_PREDICATE_STATE_DONT_RENDER,
699 /* In this case whether to draw or not depends on the result of an
700 * MI_PREDICATE command so the predicate enable bit needs to be checked.
701 */
702 BRW_PREDICATE_STATE_USE_BIT
703 };
704
705 struct shader_times;
706
707 struct brw_l3_config;
708
709 /**
710 * brw_context is derived from gl_context.
711 */
712 struct brw_context
713 {
714 struct gl_context ctx; /**< base class, must be first field */
715
716 struct
717 {
718 void (*update_texture_surface)(struct gl_context *ctx,
719 unsigned unit,
720 uint32_t *surf_offset,
721 bool for_gather);
722 uint32_t (*update_renderbuffer_surface)(struct brw_context *brw,
723 struct gl_renderbuffer *rb,
724 bool layered, unsigned unit,
725 uint32_t surf_index);
726
727 void (*emit_texture_surface_state)(struct brw_context *brw,
728 struct intel_mipmap_tree *mt,
729 GLenum target,
730 unsigned min_layer,
731 unsigned max_layer,
732 unsigned min_level,
733 unsigned max_level,
734 unsigned format,
735 unsigned swizzle,
736 uint32_t *surf_offset,
737 bool rw, bool for_gather);
738 void (*emit_buffer_surface_state)(struct brw_context *brw,
739 uint32_t *out_offset,
740 drm_intel_bo *bo,
741 unsigned buffer_offset,
742 unsigned surface_format,
743 unsigned buffer_size,
744 unsigned pitch,
745 bool rw);
746 void (*emit_null_surface_state)(struct brw_context *brw,
747 unsigned width,
748 unsigned height,
749 unsigned samples,
750 uint32_t *out_offset);
751
752 /**
753 * Send the appropriate state packets to configure depth, stencil, and
754 * HiZ buffers (i965+ only)
755 */
756 void (*emit_depth_stencil_hiz)(struct brw_context *brw,
757 struct intel_mipmap_tree *depth_mt,
758 uint32_t depth_offset,
759 uint32_t depthbuffer_format,
760 uint32_t depth_surface_type,
761 struct intel_mipmap_tree *stencil_mt,
762 bool hiz, bool separate_stencil,
763 uint32_t width, uint32_t height,
764 uint32_t tile_x, uint32_t tile_y);
765
766 } vtbl;
767
768 dri_bufmgr *bufmgr;
769
770 drm_intel_context *hw_ctx;
771
772 /** BO for post-sync nonzero writes for gen6 workaround. */
773 drm_intel_bo *workaround_bo;
774 uint8_t pipe_controls_since_last_cs_stall;
775
776 /**
777 * Set of drm_intel_bo * that have been rendered to within this batchbuffer
778 * and would need flushing before being used from another cache domain that
779 * isn't coherent with it (i.e. the sampler).
780 */
781 struct set *render_cache;
782
783 /**
784 * Number of resets observed in the system at context creation.
785 *
786 * This is tracked in the context so that we can determine that another
787 * reset has occurred.
788 */
789 uint32_t reset_count;
790
791 struct intel_batchbuffer batch;
792 bool no_batch_wrap;
793
794 struct {
795 drm_intel_bo *bo;
796 uint32_t next_offset;
797 } upload;
798
799 /**
800 * Set if rendering has occurred to the drawable's front buffer.
801 *
802 * This is used in the DRI2 case to detect that glFlush should also copy
803 * the contents of the fake front buffer to the real front buffer.
804 */
805 bool front_buffer_dirty;
806
807 /** Framerate throttling: @{ */
808 drm_intel_bo *throttle_batch[2];
809
810 /* Limit the number of outstanding SwapBuffers by waiting for an earlier
811 * frame of rendering to complete. This gives a very precise cap to the
812 * latency between input and output such that rendering never gets more
813 * than a frame behind the user. (With the caveat that we technically are
814 * not using the SwapBuffers itself as a barrier but the first batch
815 * submitted afterwards, which may be immediately prior to the next
816 * SwapBuffers.)
817 */
818 bool need_swap_throttle;
819
820 /** General throttling, not caught by throttling between SwapBuffers */
821 bool need_flush_throttle;
822 /** @} */
823
824 GLuint stats_wm;
825
826 /**
827 * drirc options:
828 * @{
829 */
830 bool no_rast;
831 bool always_flush_batch;
832 bool always_flush_cache;
833 bool disable_throttling;
834 bool precompile;
835
836 driOptionCache optionCache;
837 /** @} */
838
839 GLuint primitive; /**< Hardware primitive, such as _3DPRIM_TRILIST. */
840
841 GLenum reduced_primitive;
842
843 /**
844 * Set if we're either a debug context or the INTEL_DEBUG=perf environment
845 * variable is set, this is the flag indicating to do expensive work that
846 * might lead to a perf_debug() call.
847 */
848 bool perf_debug;
849
850 uint32_t max_gtt_map_object_size;
851
852 int gen;
853 int gt;
854
855 bool is_g4x;
856 bool is_baytrail;
857 bool is_haswell;
858 bool is_cherryview;
859 bool is_broxton;
860
861 bool has_hiz;
862 bool has_separate_stencil;
863 bool must_use_separate_stencil;
864 bool has_llc;
865 bool has_swizzling;
866 bool has_surface_tile_offset;
867 bool has_compr4;
868 bool has_negative_rhw_bug;
869 bool has_pln;
870 bool no_simd8;
871 bool use_rep_send;
872 bool use_resource_streamer;
873
874 /**
875 * Whether LRI can be used to write register values from the batch buffer.
876 */
877 bool can_do_pipelined_register_writes;
878
879 /**
880 * Some versions of Gen hardware don't do centroid interpolation correctly
881 * on unlit pixels, causing incorrect values for derivatives near triangle
882 * edges. Enabling this flag causes the fragment shader to use
883 * non-centroid interpolation for unlit pixels, at the expense of two extra
884 * fragment shader instructions.
885 */
886 bool needs_unlit_centroid_workaround;
887
888 GLuint NewGLState;
889 struct {
890 struct brw_state_flags pipelines[BRW_NUM_PIPELINES];
891 } state;
892
893 enum brw_pipeline last_pipeline;
894
895 struct brw_cache cache;
896
897 /** IDs for meta stencil blit shader programs. */
898 unsigned meta_stencil_blit_programs[2];
899
900 /* Whether a meta-operation is in progress. */
901 bool meta_in_progress;
902
903 /* Whether the last depth/stencil packets were both NULL. */
904 bool no_depth_or_stencil;
905
906 /* The last PMA stall bits programmed. */
907 uint32_t pma_stall_bits;
908
909 struct {
910 /** The value of gl_BaseVertex for the current _mesa_prim. */
911 int gl_basevertex;
912
913 /**
914 * Buffer and offset used for GL_ARB_shader_draw_parameters
915 * (for now, only gl_BaseVertex).
916 */
917 drm_intel_bo *draw_params_bo;
918 uint32_t draw_params_offset;
919 } draw;
920
921 struct {
922 /**
923 * For gl_NumWorkGroups: If num_work_groups_bo is non NULL, then it is
924 * an indirect call, and num_work_groups_offset is valid. Otherwise,
925 * num_work_groups is set based on glDispatchCompute.
926 */
927 drm_intel_bo *num_work_groups_bo;
928 GLintptr num_work_groups_offset;
929 const GLuint *num_work_groups;
930 } compute;
931
932 struct {
933 struct brw_vertex_element inputs[VERT_ATTRIB_MAX];
934 struct brw_vertex_buffer buffers[VERT_ATTRIB_MAX];
935
936 struct brw_vertex_element *enabled[VERT_ATTRIB_MAX];
937 GLuint nr_enabled;
938 GLuint nr_buffers;
939
940 /* Summary of size and varying of active arrays, so we can check
941 * for changes to this state:
942 */
943 unsigned int min_index, max_index;
944
945 /* Offset from start of vertex buffer so we can avoid redefining
946 * the same VB packed over and over again.
947 */
948 unsigned int start_vertex_bias;
949
950 /**
951 * Certain vertex attribute formats aren't natively handled by the
952 * hardware and require special VS code to fix up their values.
953 *
954 * These bitfields indicate which workarounds are needed.
955 */
956 uint8_t attrib_wa_flags[VERT_ATTRIB_MAX];
957 } vb;
958
959 struct {
960 /**
961 * Index buffer for this draw_prims call.
962 *
963 * Updates are signaled by BRW_NEW_INDICES.
964 */
965 const struct _mesa_index_buffer *ib;
966
967 /* Updates are signaled by BRW_NEW_INDEX_BUFFER. */
968 drm_intel_bo *bo;
969 GLuint type;
970
971 /* Offset to index buffer index to use in CMD_3D_PRIM so that we can
972 * avoid re-uploading the IB packet over and over if we're actually
973 * referencing the same index buffer.
974 */
975 unsigned int start_vertex_offset;
976 } ib;
977
978 /* Active vertex program:
979 */
980 const struct gl_vertex_program *vertex_program;
981 const struct gl_geometry_program *geometry_program;
982 const struct gl_tess_ctrl_program *tess_ctrl_program;
983 const struct gl_tess_eval_program *tess_eval_program;
984 const struct gl_fragment_program *fragment_program;
985 const struct gl_compute_program *compute_program;
986
987 /**
988 * Number of samples in ctx->DrawBuffer, updated by BRW_NEW_NUM_SAMPLES so
989 * that we don't have to reemit that state every time we change FBOs.
990 */
991 int num_samples;
992
993 /**
994 * Platform specific constants containing the maximum number of threads
995 * for each pipeline stage.
996 */
997 unsigned max_vs_threads;
998 unsigned max_hs_threads;
999 unsigned max_ds_threads;
1000 unsigned max_gs_threads;
1001 unsigned max_wm_threads;
1002 unsigned max_cs_threads;
1003
1004 /* BRW_NEW_URB_ALLOCATIONS:
1005 */
1006 struct {
1007 GLuint vsize; /* vertex size plus header in urb registers */
1008 GLuint gsize; /* GS output size in urb registers */
1009 GLuint hsize; /* Tessellation control output size in urb registers */
1010 GLuint dsize; /* Tessellation evaluation output size in urb registers */
1011 GLuint csize; /* constant buffer size in urb registers */
1012 GLuint sfsize; /* setup data size in urb registers */
1013
1014 bool constrained;
1015
1016 GLuint min_vs_entries; /* Minimum number of VS entries */
1017 GLuint max_vs_entries; /* Maximum number of VS entries */
1018 GLuint max_hs_entries; /* Maximum number of HS entries */
1019 GLuint max_ds_entries; /* Maximum number of DS entries */
1020 GLuint max_gs_entries; /* Maximum number of GS entries */
1021
1022 GLuint nr_vs_entries;
1023 GLuint nr_hs_entries;
1024 GLuint nr_ds_entries;
1025 GLuint nr_gs_entries;
1026 GLuint nr_clip_entries;
1027 GLuint nr_sf_entries;
1028 GLuint nr_cs_entries;
1029
1030 GLuint vs_start;
1031 GLuint hs_start;
1032 GLuint ds_start;
1033 GLuint gs_start;
1034 GLuint clip_start;
1035 GLuint sf_start;
1036 GLuint cs_start;
1037 /**
1038 * URB size in the current configuration. The units this is expressed
1039 * in are somewhat inconsistent, see brw_device_info::urb::size.
1040 *
1041 * FINISHME: Represent the URB size consistently in KB on all platforms.
1042 */
1043 GLuint size;
1044
1045 /* True if the most recently sent _3DSTATE_URB message allocated
1046 * URB space for the GS.
1047 */
1048 bool gs_present;
1049
1050 /* True if the most recently sent _3DSTATE_URB message allocated
1051 * URB space for the HS and DS.
1052 */
1053 bool tess_present;
1054 } urb;
1055
1056
1057 /* BRW_NEW_CURBE_OFFSETS:
1058 */
1059 struct {
1060 GLuint wm_start; /**< pos of first wm const in CURBE buffer */
1061 GLuint wm_size; /**< number of float[4] consts, multiple of 16 */
1062 GLuint clip_start;
1063 GLuint clip_size;
1064 GLuint vs_start;
1065 GLuint vs_size;
1066 GLuint total_size;
1067
1068 /**
1069 * Pointer to the (intel_upload.c-generated) BO containing the uniforms
1070 * for upload to the CURBE.
1071 */
1072 drm_intel_bo *curbe_bo;
1073 /** Offset within curbe_bo of space for current curbe entry */
1074 GLuint curbe_offset;
1075 } curbe;
1076
1077 /**
1078 * Layout of vertex data exiting the geometry portion of the pipleine.
1079 * This comes from the last enabled shader stage (GS, DS, or VS).
1080 *
1081 * BRW_NEW_VUE_MAP_GEOM_OUT is flagged when the VUE map changes.
1082 */
1083 struct brw_vue_map vue_map_geom_out;
1084
1085 struct {
1086 struct brw_stage_state base;
1087 struct brw_vs_prog_data *prog_data;
1088 } vs;
1089
1090 struct {
1091 struct brw_stage_state base;
1092 struct brw_tcs_prog_data *prog_data;
1093
1094 /**
1095 * True if the 3DSTATE_HS command most recently emitted to the 3D
1096 * pipeline enabled the HS; false otherwise.
1097 */
1098 bool enabled;
1099 } tcs;
1100
1101 struct {
1102 struct brw_stage_state base;
1103 struct brw_tes_prog_data *prog_data;
1104
1105 /**
1106 * True if the 3DSTATE_DS command most recently emitted to the 3D
1107 * pipeline enabled the DS; false otherwise.
1108 */
1109 bool enabled;
1110 } tes;
1111
1112 struct {
1113 struct brw_stage_state base;
1114 struct brw_gs_prog_data *prog_data;
1115
1116 /**
1117 * True if the 3DSTATE_GS command most recently emitted to the 3D
1118 * pipeline enabled the GS; false otherwise.
1119 */
1120 bool enabled;
1121 } gs;
1122
1123 struct {
1124 struct brw_ff_gs_prog_data *prog_data;
1125
1126 bool prog_active;
1127 /** Offset in the program cache to the CLIP program pre-gen6 */
1128 uint32_t prog_offset;
1129 uint32_t state_offset;
1130
1131 uint32_t bind_bo_offset;
1132 /**
1133 * Surface offsets for the binding table. We only need surfaces to
1134 * implement transform feedback so BRW_MAX_SOL_BINDINGS is all that we
1135 * need in this case.
1136 */
1137 uint32_t surf_offset[BRW_MAX_SOL_BINDINGS];
1138 } ff_gs;
1139
1140 struct {
1141 struct brw_clip_prog_data *prog_data;
1142
1143 /** Offset in the program cache to the CLIP program pre-gen6 */
1144 uint32_t prog_offset;
1145
1146 /* Offset in the batch to the CLIP state on pre-gen6. */
1147 uint32_t state_offset;
1148
1149 /* As of gen6, this is the offset in the batch to the CLIP VP,
1150 * instead of vp_bo.
1151 */
1152 uint32_t vp_offset;
1153 } clip;
1154
1155
1156 struct {
1157 struct brw_sf_prog_data *prog_data;
1158
1159 /** Offset in the program cache to the CLIP program pre-gen6 */
1160 uint32_t prog_offset;
1161 uint32_t state_offset;
1162 uint32_t vp_offset;
1163 bool viewport_transform_enable;
1164 } sf;
1165
1166 struct {
1167 struct brw_stage_state base;
1168 struct brw_wm_prog_data *prog_data;
1169
1170 GLuint render_surf;
1171
1172 /**
1173 * Buffer object used in place of multisampled null render targets on
1174 * Gen6. See brw_emit_null_surface_state().
1175 */
1176 drm_intel_bo *multisampled_null_render_target_bo;
1177 uint32_t fast_clear_op;
1178
1179 float offset_clamp;
1180 } wm;
1181
1182 struct {
1183 struct brw_stage_state base;
1184 struct brw_cs_prog_data *prog_data;
1185 } cs;
1186
1187 /* RS hardware binding table */
1188 struct {
1189 drm_intel_bo *bo;
1190 uint32_t next_offset;
1191 } hw_bt_pool;
1192
1193 struct {
1194 uint32_t state_offset;
1195 uint32_t blend_state_offset;
1196 uint32_t depth_stencil_state_offset;
1197 uint32_t vp_offset;
1198 } cc;
1199
1200 struct {
1201 struct brw_query_object *obj;
1202 bool begin_emitted;
1203 } query;
1204
1205 struct {
1206 enum brw_predicate_state state;
1207 bool supported;
1208 } predicate;
1209
1210 struct {
1211 /** A map from pipeline statistics counter IDs to MMIO addresses. */
1212 const int *statistics_registers;
1213
1214 /** The number of active monitors using OA counters. */
1215 unsigned oa_users;
1216
1217 /**
1218 * A buffer object storing OA counter snapshots taken at the start and
1219 * end of each batch (creating "bookends" around the batch).
1220 */
1221 drm_intel_bo *bookend_bo;
1222
1223 /** The number of snapshots written to bookend_bo. */
1224 int bookend_snapshots;
1225
1226 /**
1227 * An array of monitors whose results haven't yet been assembled based on
1228 * the data in buffer objects.
1229 *
1230 * These may be active, or have already ended. However, the results
1231 * have not been requested.
1232 */
1233 struct brw_perf_monitor_object **unresolved;
1234 int unresolved_elements;
1235 int unresolved_array_size;
1236
1237 /**
1238 * Mapping from a uint32_t offset within an OA snapshot to the ID of
1239 * the counter which MI_REPORT_PERF_COUNT stores there.
1240 */
1241 const int *oa_snapshot_layout;
1242
1243 /** Number of 32-bit entries in a hardware counter snapshot. */
1244 int entries_per_oa_snapshot;
1245 } perfmon;
1246
1247 int num_atoms[BRW_NUM_PIPELINES];
1248 const struct brw_tracked_state render_atoms[76];
1249 const struct brw_tracked_state compute_atoms[10];
1250
1251 /* If (INTEL_DEBUG & DEBUG_BATCH) */
1252 struct {
1253 uint32_t offset;
1254 uint32_t size;
1255 enum aub_state_struct_type type;
1256 int index;
1257 } *state_batch_list;
1258 int state_batch_count;
1259
1260 uint32_t render_target_format[MESA_FORMAT_COUNT];
1261 bool format_supported_as_render_target[MESA_FORMAT_COUNT];
1262
1263 /* Interpolation modes, one byte per vue slot.
1264 * Used Gen4/5 by the clip|sf|wm stages. Ignored on Gen6+.
1265 */
1266 struct interpolation_mode_map interpolation_mode;
1267
1268 /* PrimitiveRestart */
1269 struct {
1270 bool in_progress;
1271 bool enable_cut_index;
1272 } prim_restart;
1273
1274 /** Computed depth/stencil/hiz state from the current attached
1275 * renderbuffers, valid only during the drawing state upload loop after
1276 * brw_workaround_depthstencil_alignment().
1277 */
1278 struct {
1279 struct intel_mipmap_tree *depth_mt;
1280 struct intel_mipmap_tree *stencil_mt;
1281
1282 /* Inter-tile (page-aligned) byte offsets. */
1283 uint32_t depth_offset, hiz_offset, stencil_offset;
1284 /* Intra-tile x,y offsets for drawing to depth/stencil/hiz */
1285 uint32_t tile_x, tile_y;
1286 } depthstencil;
1287
1288 uint32_t num_instances;
1289 int basevertex;
1290
1291 struct {
1292 const struct brw_l3_config *config;
1293 } l3;
1294
1295 struct {
1296 drm_intel_bo *bo;
1297 const char **names;
1298 int *ids;
1299 enum shader_time_shader_type *types;
1300 struct shader_times *cumulative;
1301 int num_entries;
1302 int max_entries;
1303 double report_time;
1304 } shader_time;
1305
1306 struct brw_fast_clear_state *fast_clear_state;
1307
1308 __DRIcontext *driContext;
1309 struct intel_screen *intelScreen;
1310 };
1311
1312 /*======================================================================
1313 * brw_vtbl.c
1314 */
1315 void brwInitVtbl( struct brw_context *brw );
1316
1317 /* brw_clear.c */
1318 extern void intelInitClearFuncs(struct dd_function_table *functions);
1319
1320 /*======================================================================
1321 * brw_context.c
1322 */
1323 extern const char *const brw_vendor_string;
1324
1325 extern const char *brw_get_renderer_string(unsigned deviceID);
1326
1327 enum {
1328 DRI_CONF_BO_REUSE_DISABLED,
1329 DRI_CONF_BO_REUSE_ALL
1330 };
1331
1332 void intel_update_renderbuffers(__DRIcontext *context,
1333 __DRIdrawable *drawable);
1334 void intel_prepare_render(struct brw_context *brw);
1335
1336 void intel_resolve_for_dri2_flush(struct brw_context *brw,
1337 __DRIdrawable *drawable);
1338
1339 GLboolean brwCreateContext(gl_api api,
1340 const struct gl_config *mesaVis,
1341 __DRIcontext *driContextPriv,
1342 unsigned major_version,
1343 unsigned minor_version,
1344 uint32_t flags,
1345 bool notify_reset,
1346 unsigned *error,
1347 void *sharedContextPrivate);
1348
1349 /*======================================================================
1350 * brw_misc_state.c
1351 */
1352 GLuint brw_get_rb_for_slice(struct brw_context *brw,
1353 struct intel_mipmap_tree *mt,
1354 unsigned level, unsigned layer, bool flat);
1355
1356 void brw_meta_updownsample(struct brw_context *brw,
1357 struct intel_mipmap_tree *src,
1358 struct intel_mipmap_tree *dst);
1359
1360 void brw_meta_fbo_stencil_blit(struct brw_context *brw,
1361 struct gl_framebuffer *read_fb,
1362 struct gl_framebuffer *draw_fb,
1363 GLfloat srcX0, GLfloat srcY0,
1364 GLfloat srcX1, GLfloat srcY1,
1365 GLfloat dstX0, GLfloat dstY0,
1366 GLfloat dstX1, GLfloat dstY1);
1367
1368 void brw_meta_stencil_updownsample(struct brw_context *brw,
1369 struct intel_mipmap_tree *src,
1370 struct intel_mipmap_tree *dst);
1371
1372 bool brw_meta_fast_clear(struct brw_context *brw,
1373 struct gl_framebuffer *fb,
1374 GLbitfield mask,
1375 bool partial_clear);
1376
1377 void
1378 brw_meta_resolve_color(struct brw_context *brw,
1379 struct intel_mipmap_tree *mt);
1380 void
1381 brw_meta_fast_clear_free(struct brw_context *brw);
1382
1383
1384 /*======================================================================
1385 * brw_misc_state.c
1386 */
1387 void brw_get_depthstencil_tile_masks(struct intel_mipmap_tree *depth_mt,
1388 uint32_t depth_level,
1389 uint32_t depth_layer,
1390 struct intel_mipmap_tree *stencil_mt,
1391 uint32_t *out_tile_mask_x,
1392 uint32_t *out_tile_mask_y);
1393 void brw_workaround_depthstencil_alignment(struct brw_context *brw,
1394 GLbitfield clear_mask);
1395
1396 /* brw_object_purgeable.c */
1397 void brw_init_object_purgeable_functions(struct dd_function_table *functions);
1398
1399 /*======================================================================
1400 * brw_queryobj.c
1401 */
1402 void brw_init_common_queryobj_functions(struct dd_function_table *functions);
1403 void gen4_init_queryobj_functions(struct dd_function_table *functions);
1404 void brw_emit_query_begin(struct brw_context *brw);
1405 void brw_emit_query_end(struct brw_context *brw);
1406
1407 /** gen6_queryobj.c */
1408 void gen6_init_queryobj_functions(struct dd_function_table *functions);
1409 void brw_write_timestamp(struct brw_context *brw, drm_intel_bo *bo, int idx);
1410 void brw_write_depth_count(struct brw_context *brw, drm_intel_bo *bo, int idx);
1411 void brw_store_register_mem64(struct brw_context *brw,
1412 drm_intel_bo *bo, uint32_t reg, int idx);
1413
1414 /** brw_conditional_render.c */
1415 void brw_init_conditional_render_functions(struct dd_function_table *functions);
1416 bool brw_check_conditional_render(struct brw_context *brw);
1417
1418 /** intel_batchbuffer.c */
1419 void brw_load_register_mem(struct brw_context *brw,
1420 uint32_t reg,
1421 drm_intel_bo *bo,
1422 uint32_t read_domains, uint32_t write_domain,
1423 uint32_t offset);
1424 void brw_load_register_mem64(struct brw_context *brw,
1425 uint32_t reg,
1426 drm_intel_bo *bo,
1427 uint32_t read_domains, uint32_t write_domain,
1428 uint32_t offset);
1429
1430 /*======================================================================
1431 * brw_state_dump.c
1432 */
1433 void brw_debug_batch(struct brw_context *brw);
1434 void brw_annotate_aub(struct brw_context *brw);
1435
1436 /*======================================================================
1437 * brw_tex.c
1438 */
1439 void brw_validate_textures( struct brw_context *brw );
1440
1441
1442 /*======================================================================
1443 * brw_program.c
1444 */
1445 static inline bool
1446 key_debug(struct brw_context *brw, const char *name, int a, int b)
1447 {
1448 if (a != b) {
1449 perf_debug(" %s %d->%d\n", name, a, b);
1450 return true;
1451 }
1452 return false;
1453 }
1454
1455 void brwInitFragProgFuncs( struct dd_function_table *functions );
1456
1457 /* Per-thread scratch space is a power-of-two multiple of 1KB. */
1458 static inline int
1459 brw_get_scratch_size(int size)
1460 {
1461 return util_next_power_of_two(size | 1023);
1462 }
1463 void brw_get_scratch_bo(struct brw_context *brw,
1464 drm_intel_bo **scratch_bo, int size);
1465 void brw_init_shader_time(struct brw_context *brw);
1466 int brw_get_shader_time_index(struct brw_context *brw,
1467 struct gl_shader_program *shader_prog,
1468 struct gl_program *prog,
1469 enum shader_time_shader_type type);
1470 void brw_collect_and_report_shader_time(struct brw_context *brw);
1471 void brw_destroy_shader_time(struct brw_context *brw);
1472
1473 /* brw_urb.c
1474 */
1475 void brw_upload_urb_fence(struct brw_context *brw);
1476
1477 /* brw_curbe.c
1478 */
1479 void brw_upload_cs_urb_state(struct brw_context *brw);
1480
1481 /* brw_fs_reg_allocate.cpp
1482 */
1483 void brw_fs_alloc_reg_sets(struct brw_compiler *compiler);
1484
1485 /* brw_vec4_reg_allocate.cpp */
1486 void brw_vec4_alloc_reg_set(struct brw_compiler *compiler);
1487
1488 /* brw_disasm.c */
1489 int brw_disassemble_inst(FILE *file, const struct brw_device_info *devinfo,
1490 struct brw_inst *inst, bool is_compacted);
1491
1492 /* brw_vs.c */
1493 gl_clip_plane *brw_select_clip_planes(struct gl_context *ctx);
1494
1495 /* brw_draw_upload.c */
1496 unsigned brw_get_vertex_surface_type(struct brw_context *brw,
1497 const struct gl_client_array *glarray);
1498
1499 static inline unsigned
1500 brw_get_index_type(GLenum type)
1501 {
1502 assert((type == GL_UNSIGNED_BYTE)
1503 || (type == GL_UNSIGNED_SHORT)
1504 || (type == GL_UNSIGNED_INT));
1505
1506 /* The possible values for type are GL_UNSIGNED_BYTE (0x1401),
1507 * GL_UNSIGNED_SHORT (0x1403), and GL_UNSIGNED_INT (0x1405) which we want
1508 * to map to scale factors of 0, 1, and 2, respectively. These scale
1509 * factors are then left-shfited by 8 to be in the correct position in the
1510 * CMD_INDEX_BUFFER packet.
1511 *
1512 * Subtracting 0x1401 gives 0, 2, and 4. Shifting left by 7 afterwards
1513 * gives 0x00000000, 0x00000100, and 0x00000200. These just happen to be
1514 * the values the need to be written in the CMD_INDEX_BUFFER packet.
1515 */
1516 return (type - 0x1401) << 7;
1517 }
1518
1519 void brw_prepare_vertices(struct brw_context *brw);
1520
1521 /* brw_wm_surface_state.c */
1522 void brw_init_surface_formats(struct brw_context *brw);
1523 void brw_create_constant_surface(struct brw_context *brw,
1524 drm_intel_bo *bo,
1525 uint32_t offset,
1526 uint32_t size,
1527 uint32_t *out_offset);
1528 void brw_create_buffer_surface(struct brw_context *brw,
1529 drm_intel_bo *bo,
1530 uint32_t offset,
1531 uint32_t size,
1532 uint32_t *out_offset);
1533 void brw_update_buffer_texture_surface(struct gl_context *ctx,
1534 unsigned unit,
1535 uint32_t *surf_offset);
1536 void
1537 brw_update_sol_surface(struct brw_context *brw,
1538 struct gl_buffer_object *buffer_obj,
1539 uint32_t *out_offset, unsigned num_vector_components,
1540 unsigned stride_dwords, unsigned offset_dwords);
1541 void brw_upload_ubo_surfaces(struct brw_context *brw,
1542 struct gl_shader *shader,
1543 struct brw_stage_state *stage_state,
1544 struct brw_stage_prog_data *prog_data);
1545 void brw_upload_abo_surfaces(struct brw_context *brw,
1546 struct gl_shader *shader,
1547 struct brw_stage_state *stage_state,
1548 struct brw_stage_prog_data *prog_data);
1549 void brw_upload_image_surfaces(struct brw_context *brw,
1550 struct gl_shader *shader,
1551 struct brw_stage_state *stage_state,
1552 struct brw_stage_prog_data *prog_data);
1553
1554 /* brw_surface_formats.c */
1555 bool brw_render_target_supported(struct brw_context *brw,
1556 struct gl_renderbuffer *rb);
1557 bool brw_losslessly_compressible_format(struct brw_context *brw,
1558 uint32_t brw_format);
1559 uint32_t brw_depth_format(struct brw_context *brw, mesa_format format);
1560 mesa_format brw_lower_mesa_image_format(const struct brw_device_info *devinfo,
1561 mesa_format format);
1562
1563 /* brw_performance_monitor.c */
1564 void brw_init_performance_monitors(struct brw_context *brw);
1565 void brw_dump_perf_monitors(struct brw_context *brw);
1566 void brw_perf_monitor_new_batch(struct brw_context *brw);
1567 void brw_perf_monitor_finish_batch(struct brw_context *brw);
1568
1569 /* intel_buffer_objects.c */
1570 int brw_bo_map(struct brw_context *brw, drm_intel_bo *bo, int write_enable,
1571 const char *bo_name);
1572 int brw_bo_map_gtt(struct brw_context *brw, drm_intel_bo *bo,
1573 const char *bo_name);
1574
1575 /* intel_extensions.c */
1576 extern void intelInitExtensions(struct gl_context *ctx);
1577
1578 /* intel_state.c */
1579 extern int intel_translate_shadow_compare_func(GLenum func);
1580 extern int intel_translate_compare_func(GLenum func);
1581 extern int intel_translate_stencil_op(GLenum op);
1582 extern int intel_translate_logic_op(GLenum opcode);
1583
1584 /* intel_syncobj.c */
1585 void intel_init_syncobj_functions(struct dd_function_table *functions);
1586
1587 /* gen6_sol.c */
1588 struct gl_transform_feedback_object *
1589 brw_new_transform_feedback(struct gl_context *ctx, GLuint name);
1590 void
1591 brw_delete_transform_feedback(struct gl_context *ctx,
1592 struct gl_transform_feedback_object *obj);
1593 void
1594 brw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1595 struct gl_transform_feedback_object *obj);
1596 void
1597 brw_end_transform_feedback(struct gl_context *ctx,
1598 struct gl_transform_feedback_object *obj);
1599 GLsizei
1600 brw_get_transform_feedback_vertex_count(struct gl_context *ctx,
1601 struct gl_transform_feedback_object *obj,
1602 GLuint stream);
1603
1604 /* gen7_sol_state.c */
1605 void
1606 gen7_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1607 struct gl_transform_feedback_object *obj);
1608 void
1609 gen7_end_transform_feedback(struct gl_context *ctx,
1610 struct gl_transform_feedback_object *obj);
1611 void
1612 gen7_pause_transform_feedback(struct gl_context *ctx,
1613 struct gl_transform_feedback_object *obj);
1614 void
1615 gen7_resume_transform_feedback(struct gl_context *ctx,
1616 struct gl_transform_feedback_object *obj);
1617
1618 /* brw_blorp_blit.cpp */
1619 GLbitfield
1620 brw_blorp_framebuffer(struct brw_context *brw,
1621 struct gl_framebuffer *readFb,
1622 struct gl_framebuffer *drawFb,
1623 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1624 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
1625 GLbitfield mask, GLenum filter);
1626
1627 bool
1628 brw_blorp_copytexsubimage(struct brw_context *brw,
1629 struct gl_renderbuffer *src_rb,
1630 struct gl_texture_image *dst_image,
1631 int slice,
1632 int srcX0, int srcY0,
1633 int dstX0, int dstY0,
1634 int width, int height);
1635
1636 /* gen6_multisample_state.c */
1637 unsigned
1638 gen6_determine_sample_mask(struct brw_context *brw);
1639
1640 void
1641 gen6_emit_3dstate_multisample(struct brw_context *brw,
1642 unsigned num_samples);
1643 void
1644 gen6_emit_3dstate_sample_mask(struct brw_context *brw, unsigned mask);
1645 void
1646 gen6_get_sample_position(struct gl_context *ctx,
1647 struct gl_framebuffer *fb,
1648 GLuint index,
1649 GLfloat *result);
1650 void
1651 gen6_set_sample_maps(struct gl_context *ctx);
1652
1653 /* gen8_multisample_state.c */
1654 void gen8_emit_3dstate_multisample(struct brw_context *brw, unsigned num_samp);
1655 void gen8_emit_3dstate_sample_pattern(struct brw_context *brw);
1656
1657 /* gen7_urb.c */
1658 void
1659 gen7_emit_push_constant_state(struct brw_context *brw, unsigned vs_size,
1660 unsigned hs_size, unsigned ds_size,
1661 unsigned gs_size, unsigned fs_size);
1662
1663 void
1664 gen7_emit_urb_state(struct brw_context *brw,
1665 unsigned nr_vs_entries,
1666 unsigned vs_size, unsigned vs_start,
1667 unsigned nr_hs_entries,
1668 unsigned hs_size, unsigned hs_start,
1669 unsigned nr_ds_entries,
1670 unsigned ds_size, unsigned ds_start,
1671 unsigned nr_gs_entries,
1672 unsigned gs_size, unsigned gs_start);
1673
1674
1675 /* brw_reset.c */
1676 extern GLenum
1677 brw_get_graphics_reset_status(struct gl_context *ctx);
1678
1679 /* brw_compute.c */
1680 extern void
1681 brw_init_compute_functions(struct dd_function_table *functions);
1682
1683 /*======================================================================
1684 * Inline conversion functions. These are better-typed than the
1685 * macros used previously:
1686 */
1687 static inline struct brw_context *
1688 brw_context( struct gl_context *ctx )
1689 {
1690 return (struct brw_context *)ctx;
1691 }
1692
1693 static inline struct brw_vertex_program *
1694 brw_vertex_program(struct gl_vertex_program *p)
1695 {
1696 return (struct brw_vertex_program *) p;
1697 }
1698
1699 static inline const struct brw_vertex_program *
1700 brw_vertex_program_const(const struct gl_vertex_program *p)
1701 {
1702 return (const struct brw_vertex_program *) p;
1703 }
1704
1705 static inline struct brw_tess_ctrl_program *
1706 brw_tess_ctrl_program(struct gl_tess_ctrl_program *p)
1707 {
1708 return (struct brw_tess_ctrl_program *) p;
1709 }
1710
1711 static inline struct brw_tess_eval_program *
1712 brw_tess_eval_program(struct gl_tess_eval_program *p)
1713 {
1714 return (struct brw_tess_eval_program *) p;
1715 }
1716
1717 static inline struct brw_geometry_program *
1718 brw_geometry_program(struct gl_geometry_program *p)
1719 {
1720 return (struct brw_geometry_program *) p;
1721 }
1722
1723 static inline struct brw_fragment_program *
1724 brw_fragment_program(struct gl_fragment_program *p)
1725 {
1726 return (struct brw_fragment_program *) p;
1727 }
1728
1729 static inline const struct brw_fragment_program *
1730 brw_fragment_program_const(const struct gl_fragment_program *p)
1731 {
1732 return (const struct brw_fragment_program *) p;
1733 }
1734
1735 static inline struct brw_compute_program *
1736 brw_compute_program(struct gl_compute_program *p)
1737 {
1738 return (struct brw_compute_program *) p;
1739 }
1740
1741 /**
1742 * Pre-gen6, the register file of the EUs was shared between threads,
1743 * and each thread used some subset allocated on a 16-register block
1744 * granularity. The unit states wanted these block counts.
1745 */
1746 static inline int
1747 brw_register_blocks(int reg_count)
1748 {
1749 return ALIGN(reg_count, 16) / 16 - 1;
1750 }
1751
1752 static inline uint32_t
1753 brw_program_reloc(struct brw_context *brw, uint32_t state_offset,
1754 uint32_t prog_offset)
1755 {
1756 if (brw->gen >= 5) {
1757 /* Using state base address. */
1758 return prog_offset;
1759 }
1760
1761 drm_intel_bo_emit_reloc(brw->batch.bo,
1762 state_offset,
1763 brw->cache.bo,
1764 prog_offset,
1765 I915_GEM_DOMAIN_INSTRUCTION, 0);
1766
1767 return brw->cache.bo->offset64 + prog_offset;
1768 }
1769
1770 bool brw_do_cubemap_normalize(struct exec_list *instructions);
1771 bool brw_lower_texture_gradients(struct brw_context *brw,
1772 struct exec_list *instructions);
1773 bool brw_do_lower_unnormalized_offset(struct exec_list *instructions);
1774
1775 struct opcode_desc {
1776 char *name;
1777 int nsrc;
1778 int ndst;
1779 };
1780
1781 extern const struct opcode_desc opcode_descs[128];
1782 extern const char * const conditional_modifier[16];
1783 extern const char *const pred_ctrl_align16[16];
1784
1785 void
1786 brw_emit_depthbuffer(struct brw_context *brw);
1787
1788 void
1789 brw_emit_depth_stencil_hiz(struct brw_context *brw,
1790 struct intel_mipmap_tree *depth_mt,
1791 uint32_t depth_offset, uint32_t depthbuffer_format,
1792 uint32_t depth_surface_type,
1793 struct intel_mipmap_tree *stencil_mt,
1794 bool hiz, bool separate_stencil,
1795 uint32_t width, uint32_t height,
1796 uint32_t tile_x, uint32_t tile_y);
1797
1798 void
1799 gen6_emit_depth_stencil_hiz(struct brw_context *brw,
1800 struct intel_mipmap_tree *depth_mt,
1801 uint32_t depth_offset, uint32_t depthbuffer_format,
1802 uint32_t depth_surface_type,
1803 struct intel_mipmap_tree *stencil_mt,
1804 bool hiz, bool separate_stencil,
1805 uint32_t width, uint32_t height,
1806 uint32_t tile_x, uint32_t tile_y);
1807
1808 void
1809 gen7_emit_depth_stencil_hiz(struct brw_context *brw,
1810 struct intel_mipmap_tree *depth_mt,
1811 uint32_t depth_offset, uint32_t depthbuffer_format,
1812 uint32_t depth_surface_type,
1813 struct intel_mipmap_tree *stencil_mt,
1814 bool hiz, bool separate_stencil,
1815 uint32_t width, uint32_t height,
1816 uint32_t tile_x, uint32_t tile_y);
1817 void
1818 gen8_emit_depth_stencil_hiz(struct brw_context *brw,
1819 struct intel_mipmap_tree *depth_mt,
1820 uint32_t depth_offset, uint32_t depthbuffer_format,
1821 uint32_t depth_surface_type,
1822 struct intel_mipmap_tree *stencil_mt,
1823 bool hiz, bool separate_stencil,
1824 uint32_t width, uint32_t height,
1825 uint32_t tile_x, uint32_t tile_y);
1826
1827 void gen8_hiz_exec(struct brw_context *brw, struct intel_mipmap_tree *mt,
1828 unsigned int level, unsigned int layer, enum gen6_hiz_op op);
1829
1830 uint32_t get_hw_prim_for_gl_prim(int mode);
1831
1832 void
1833 gen6_upload_push_constants(struct brw_context *brw,
1834 const struct gl_program *prog,
1835 const struct brw_stage_prog_data *prog_data,
1836 struct brw_stage_state *stage_state,
1837 enum aub_state_struct_type type);
1838
1839 bool
1840 gen9_use_linear_1d_layout(const struct brw_context *brw,
1841 const struct intel_mipmap_tree *mt);
1842
1843 /* brw_pipe_control.c */
1844 int brw_init_pipe_control(struct brw_context *brw,
1845 const struct brw_device_info *info);
1846 void brw_fini_pipe_control(struct brw_context *brw);
1847
1848 void brw_emit_pipe_control_flush(struct brw_context *brw, uint32_t flags);
1849 void brw_emit_pipe_control_write(struct brw_context *brw, uint32_t flags,
1850 drm_intel_bo *bo, uint32_t offset,
1851 uint32_t imm_lower, uint32_t imm_upper);
1852 void brw_emit_mi_flush(struct brw_context *brw);
1853 void brw_emit_post_sync_nonzero_flush(struct brw_context *brw);
1854 void brw_emit_depth_stall_flushes(struct brw_context *brw);
1855 void gen7_emit_vs_workaround_flush(struct brw_context *brw);
1856 void gen7_emit_cs_stall_flush(struct brw_context *brw);
1857
1858 #ifdef __cplusplus
1859 }
1860 #endif
1861
1862 #endif