6cf3769c9a30ce6823406d0a42f4af9797dbde09
[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 "main/errors.h"
40 #include "brw_structs.h"
41 #include "brw_pipe_control.h"
42 #include "compiler/brw_compiler.h"
43
44 #include "isl/isl.h"
45 #include "blorp/blorp.h"
46
47 #include <brw_bufmgr.h>
48
49 #include "dev/gen_debug.h"
50 #include "common/gen_decoder.h"
51 #include "intel_screen.h"
52 #include "intel_tex_obj.h"
53 #include "perf/gen_perf.h"
54 #include "perf/gen_perf_query.h"
55
56 #ifdef __cplusplus
57 extern "C" {
58 #endif
59 /* Glossary:
60 *
61 * URB - uniform resource buffer. A mid-sized buffer which is
62 * partitioned between the fixed function units and used for passing
63 * values (vertices, primitives, constants) between them.
64 *
65 * CURBE - constant URB entry. An urb region (entry) used to hold
66 * constant values which the fixed function units can be instructed to
67 * preload into the GRF when spawning a thread.
68 *
69 * VUE - vertex URB entry. An urb entry holding a vertex and usually
70 * a vertex header. The header contains control information and
71 * things like primitive type, Begin/end flags and clip codes.
72 *
73 * PUE - primitive URB entry. An urb entry produced by the setup (SF)
74 * unit holding rasterization and interpolation parameters.
75 *
76 * GRF - general register file. One of several register files
77 * addressable by programmed threads. The inputs (r0, payload, curbe,
78 * urb) of the thread are preloaded to this area before the thread is
79 * spawned. The registers are individually 8 dwords wide and suitable
80 * for general usage. Registers holding thread input values are not
81 * special and may be overwritten.
82 *
83 * MRF - message register file. Threads communicate (and terminate)
84 * by sending messages. Message parameters are placed in contiguous
85 * MRF registers. All program output is via these messages. URB
86 * entries are populated by sending a message to the shared URB
87 * function containing the new data, together with a control word,
88 * often an unmodified copy of R0.
89 *
90 * R0 - GRF register 0. Typically holds control information used when
91 * sending messages to other threads.
92 *
93 * EU or GEN4 EU: The name of the programmable subsystem of the
94 * i965 hardware. Threads are executed by the EU, the registers
95 * described above are part of the EU architecture.
96 *
97 * Fixed function units:
98 *
99 * CS - Command streamer. Notional first unit, little software
100 * interaction. Holds the URB entries used for constant data, ie the
101 * CURBEs.
102 *
103 * VF/VS - Vertex Fetch / Vertex Shader. The fixed function part of
104 * this unit is responsible for pulling vertices out of vertex buffers
105 * in vram and injecting them into the processing pipe as VUEs. If
106 * enabled, it first passes them to a VS thread which is a good place
107 * for the driver to implement any active vertex shader.
108 *
109 * HS - Hull Shader (Tessellation Control Shader)
110 *
111 * TE - Tessellation Engine (Tessellation Primitive Generation)
112 *
113 * DS - Domain Shader (Tessellation Evaluation Shader)
114 *
115 * GS - Geometry Shader. This corresponds to a new DX10 concept. If
116 * enabled, incoming strips etc are passed to GS threads in individual
117 * line/triangle/point units. The GS thread may perform arbitary
118 * computation and emit whatever primtives with whatever vertices it
119 * chooses. This makes GS an excellent place to implement GL's
120 * unfilled polygon modes, though of course it is capable of much
121 * more. Additionally, GS is used to translate away primitives not
122 * handled by latter units, including Quads and Lineloops.
123 *
124 * CS - Clipper. Mesa's clipping algorithms are imported to run on
125 * this unit. The fixed function part performs cliptesting against
126 * the 6 fixed clipplanes and makes descisions on whether or not the
127 * incoming primitive needs to be passed to a thread for clipping.
128 * User clip planes are handled via cooperation with the VS thread.
129 *
130 * SF - Strips Fans or Setup: Triangles are prepared for
131 * rasterization. Interpolation coefficients are calculated.
132 * Flatshading and two-side lighting usually performed here.
133 *
134 * WM - Windower. Interpolation of vertex attributes performed here.
135 * Fragment shader implemented here. SIMD aspects of EU taken full
136 * advantage of, as pixels are processed in blocks of 16.
137 *
138 * CC - Color Calculator. No EU threads associated with this unit.
139 * Handles blending and (presumably) depth and stencil testing.
140 */
141
142 struct brw_context;
143 struct brw_inst;
144 struct brw_vs_prog_key;
145 struct brw_vue_prog_key;
146 struct brw_wm_prog_key;
147 struct brw_wm_prog_data;
148 struct brw_cs_prog_key;
149 struct brw_cs_prog_data;
150
151 enum brw_pipeline {
152 BRW_RENDER_PIPELINE,
153 BRW_COMPUTE_PIPELINE,
154
155 BRW_NUM_PIPELINES
156 };
157
158 enum brw_cache_id {
159 BRW_CACHE_FS_PROG,
160 BRW_CACHE_BLORP_PROG,
161 BRW_CACHE_SF_PROG,
162 BRW_CACHE_VS_PROG,
163 BRW_CACHE_FF_GS_PROG,
164 BRW_CACHE_GS_PROG,
165 BRW_CACHE_TCS_PROG,
166 BRW_CACHE_TES_PROG,
167 BRW_CACHE_CLIP_PROG,
168 BRW_CACHE_CS_PROG,
169
170 BRW_MAX_CACHE
171 };
172
173 enum gen9_astc5x5_wa_tex_type {
174 GEN9_ASTC5X5_WA_TEX_TYPE_ASTC5x5 = 1 << 0,
175 GEN9_ASTC5X5_WA_TEX_TYPE_AUX = 1 << 1,
176 };
177
178 enum brw_state_id {
179 /* brw_cache_ids must come first - see brw_program_cache.c */
180 BRW_STATE_URB_FENCE = BRW_MAX_CACHE,
181 BRW_STATE_FRAGMENT_PROGRAM,
182 BRW_STATE_GEOMETRY_PROGRAM,
183 BRW_STATE_TESS_PROGRAMS,
184 BRW_STATE_VERTEX_PROGRAM,
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_DEFAULT_TESS_LEVELS,
195 BRW_STATE_BATCH,
196 BRW_STATE_INDEX_BUFFER,
197 BRW_STATE_VS_CONSTBUF,
198 BRW_STATE_TCS_CONSTBUF,
199 BRW_STATE_TES_CONSTBUF,
200 BRW_STATE_GS_CONSTBUF,
201 BRW_STATE_PROGRAM_CACHE,
202 BRW_STATE_STATE_BASE_ADDRESS,
203 BRW_STATE_VUE_MAP_GEOM_OUT,
204 BRW_STATE_TRANSFORM_FEEDBACK,
205 BRW_STATE_RASTERIZER_DISCARD,
206 BRW_STATE_STATS_WM,
207 BRW_STATE_UNIFORM_BUFFER,
208 BRW_STATE_IMAGE_UNITS,
209 BRW_STATE_META_IN_PROGRESS,
210 BRW_STATE_PUSH_CONSTANT_ALLOCATION,
211 BRW_STATE_NUM_SAMPLES,
212 BRW_STATE_TEXTURE_BUFFER,
213 BRW_STATE_GEN4_UNIT_STATE,
214 BRW_STATE_CC_VP,
215 BRW_STATE_SF_VP,
216 BRW_STATE_CLIP_VP,
217 BRW_STATE_SAMPLER_STATE_TABLE,
218 BRW_STATE_VS_ATTRIB_WORKAROUNDS,
219 BRW_STATE_COMPUTE_PROGRAM,
220 BRW_STATE_CS_WORK_GROUPS,
221 BRW_STATE_URB_SIZE,
222 BRW_STATE_CC_STATE,
223 BRW_STATE_BLORP,
224 BRW_STATE_VIEWPORT_COUNT,
225 BRW_STATE_CONSERVATIVE_RASTERIZATION,
226 BRW_STATE_DRAW_CALL,
227 BRW_STATE_AUX,
228 BRW_NUM_STATE_BITS
229 };
230
231 /**
232 * BRW_NEW_*_PROG_DATA and BRW_NEW_*_PROGRAM are similar, but distinct.
233 *
234 * BRW_NEW_*_PROGRAM relates to the gl_shader_program/gl_program structures.
235 * When the currently bound shader program differs from the previous draw
236 * call, these will be flagged. They cover brw->{stage}_program and
237 * ctx->{Stage}Program->_Current.
238 *
239 * BRW_NEW_*_PROG_DATA is flagged when the effective shaders change, from a
240 * driver perspective. Even if the same shader is bound at the API level,
241 * we may need to switch between multiple versions of that shader to handle
242 * changes in non-orthagonal state.
243 *
244 * Additionally, multiple shader programs may have identical vertex shaders
245 * (for example), or compile down to the same code in the backend. We combine
246 * those into a single program cache entry.
247 *
248 * BRW_NEW_*_PROG_DATA occurs when switching program cache entries, which
249 * covers the brw_*_prog_data structures, and brw->*.prog_offset.
250 */
251 #define BRW_NEW_FS_PROG_DATA (1ull << BRW_CACHE_FS_PROG)
252 /* XXX: The BRW_NEW_BLORP_BLIT_PROG_DATA dirty bit is unused (as BLORP doesn't
253 * use the normal state upload paths), but the cache is still used. To avoid
254 * polluting the brw_program_cache code with special cases, we retain the
255 * dirty bit for now. It should eventually be removed.
256 */
257 #define BRW_NEW_BLORP_BLIT_PROG_DATA (1ull << BRW_CACHE_BLORP_PROG)
258 #define BRW_NEW_SF_PROG_DATA (1ull << BRW_CACHE_SF_PROG)
259 #define BRW_NEW_VS_PROG_DATA (1ull << BRW_CACHE_VS_PROG)
260 #define BRW_NEW_FF_GS_PROG_DATA (1ull << BRW_CACHE_FF_GS_PROG)
261 #define BRW_NEW_GS_PROG_DATA (1ull << BRW_CACHE_GS_PROG)
262 #define BRW_NEW_TCS_PROG_DATA (1ull << BRW_CACHE_TCS_PROG)
263 #define BRW_NEW_TES_PROG_DATA (1ull << BRW_CACHE_TES_PROG)
264 #define BRW_NEW_CLIP_PROG_DATA (1ull << BRW_CACHE_CLIP_PROG)
265 #define BRW_NEW_CS_PROG_DATA (1ull << BRW_CACHE_CS_PROG)
266 #define BRW_NEW_URB_FENCE (1ull << BRW_STATE_URB_FENCE)
267 #define BRW_NEW_FRAGMENT_PROGRAM (1ull << BRW_STATE_FRAGMENT_PROGRAM)
268 #define BRW_NEW_GEOMETRY_PROGRAM (1ull << BRW_STATE_GEOMETRY_PROGRAM)
269 #define BRW_NEW_TESS_PROGRAMS (1ull << BRW_STATE_TESS_PROGRAMS)
270 #define BRW_NEW_VERTEX_PROGRAM (1ull << BRW_STATE_VERTEX_PROGRAM)
271 #define BRW_NEW_REDUCED_PRIMITIVE (1ull << BRW_STATE_REDUCED_PRIMITIVE)
272 #define BRW_NEW_PATCH_PRIMITIVE (1ull << BRW_STATE_PATCH_PRIMITIVE)
273 #define BRW_NEW_PRIMITIVE (1ull << BRW_STATE_PRIMITIVE)
274 #define BRW_NEW_CONTEXT (1ull << BRW_STATE_CONTEXT)
275 #define BRW_NEW_PSP (1ull << BRW_STATE_PSP)
276 #define BRW_NEW_SURFACES (1ull << BRW_STATE_SURFACES)
277 #define BRW_NEW_BINDING_TABLE_POINTERS (1ull << BRW_STATE_BINDING_TABLE_POINTERS)
278 #define BRW_NEW_INDICES (1ull << BRW_STATE_INDICES)
279 #define BRW_NEW_VERTICES (1ull << BRW_STATE_VERTICES)
280 #define BRW_NEW_DEFAULT_TESS_LEVELS (1ull << BRW_STATE_DEFAULT_TESS_LEVELS)
281 /**
282 * Used for any batch entry with a relocated pointer that will be used
283 * by any 3D rendering.
284 */
285 #define BRW_NEW_BATCH (1ull << BRW_STATE_BATCH)
286 /** \see brw.state.depth_region */
287 #define BRW_NEW_INDEX_BUFFER (1ull << BRW_STATE_INDEX_BUFFER)
288 #define BRW_NEW_VS_CONSTBUF (1ull << BRW_STATE_VS_CONSTBUF)
289 #define BRW_NEW_TCS_CONSTBUF (1ull << BRW_STATE_TCS_CONSTBUF)
290 #define BRW_NEW_TES_CONSTBUF (1ull << BRW_STATE_TES_CONSTBUF)
291 #define BRW_NEW_GS_CONSTBUF (1ull << BRW_STATE_GS_CONSTBUF)
292 #define BRW_NEW_PROGRAM_CACHE (1ull << BRW_STATE_PROGRAM_CACHE)
293 #define BRW_NEW_STATE_BASE_ADDRESS (1ull << BRW_STATE_STATE_BASE_ADDRESS)
294 #define BRW_NEW_VUE_MAP_GEOM_OUT (1ull << BRW_STATE_VUE_MAP_GEOM_OUT)
295 #define BRW_NEW_VIEWPORT_COUNT (1ull << BRW_STATE_VIEWPORT_COUNT)
296 #define BRW_NEW_TRANSFORM_FEEDBACK (1ull << BRW_STATE_TRANSFORM_FEEDBACK)
297 #define BRW_NEW_RASTERIZER_DISCARD (1ull << BRW_STATE_RASTERIZER_DISCARD)
298 #define BRW_NEW_STATS_WM (1ull << BRW_STATE_STATS_WM)
299 #define BRW_NEW_UNIFORM_BUFFER (1ull << BRW_STATE_UNIFORM_BUFFER)
300 #define BRW_NEW_IMAGE_UNITS (1ull << BRW_STATE_IMAGE_UNITS)
301 #define BRW_NEW_META_IN_PROGRESS (1ull << BRW_STATE_META_IN_PROGRESS)
302 #define BRW_NEW_PUSH_CONSTANT_ALLOCATION (1ull << BRW_STATE_PUSH_CONSTANT_ALLOCATION)
303 #define BRW_NEW_NUM_SAMPLES (1ull << BRW_STATE_NUM_SAMPLES)
304 #define BRW_NEW_TEXTURE_BUFFER (1ull << BRW_STATE_TEXTURE_BUFFER)
305 #define BRW_NEW_GEN4_UNIT_STATE (1ull << BRW_STATE_GEN4_UNIT_STATE)
306 #define BRW_NEW_CC_VP (1ull << BRW_STATE_CC_VP)
307 #define BRW_NEW_SF_VP (1ull << BRW_STATE_SF_VP)
308 #define BRW_NEW_CLIP_VP (1ull << BRW_STATE_CLIP_VP)
309 #define BRW_NEW_SAMPLER_STATE_TABLE (1ull << BRW_STATE_SAMPLER_STATE_TABLE)
310 #define BRW_NEW_VS_ATTRIB_WORKAROUNDS (1ull << BRW_STATE_VS_ATTRIB_WORKAROUNDS)
311 #define BRW_NEW_COMPUTE_PROGRAM (1ull << BRW_STATE_COMPUTE_PROGRAM)
312 #define BRW_NEW_CS_WORK_GROUPS (1ull << BRW_STATE_CS_WORK_GROUPS)
313 #define BRW_NEW_URB_SIZE (1ull << BRW_STATE_URB_SIZE)
314 #define BRW_NEW_CC_STATE (1ull << BRW_STATE_CC_STATE)
315 #define BRW_NEW_BLORP (1ull << BRW_STATE_BLORP)
316 #define BRW_NEW_CONSERVATIVE_RASTERIZATION (1ull << BRW_STATE_CONSERVATIVE_RASTERIZATION)
317 #define BRW_NEW_DRAW_CALL (1ull << BRW_STATE_DRAW_CALL)
318 #define BRW_NEW_AUX_STATE (1ull << BRW_STATE_AUX)
319
320 struct brw_state_flags {
321 /** State update flags signalled by mesa internals */
322 GLuint mesa;
323 /**
324 * State update flags signalled as the result of brw_tracked_state updates
325 */
326 uint64_t brw;
327 };
328
329
330 /** Subclass of Mesa program */
331 struct brw_program {
332 struct gl_program program;
333 GLuint id;
334
335 bool compiled_once;
336 };
337
338
339 struct brw_ff_gs_prog_data {
340 GLuint urb_read_length;
341 GLuint total_grf;
342
343 /**
344 * Gen6 transform feedback: Amount by which the streaming vertex buffer
345 * indices should be incremented each time the GS is invoked.
346 */
347 unsigned svbi_postincrement_value;
348 };
349
350 /** Number of texture sampler units */
351 #define BRW_MAX_TEX_UNIT 32
352
353 /** Max number of UBOs in a shader */
354 #define BRW_MAX_UBO 14
355
356 /** Max number of SSBOs in a shader */
357 #define BRW_MAX_SSBO 12
358
359 /** Max number of atomic counter buffer objects in a shader */
360 #define BRW_MAX_ABO 16
361
362 /** Max number of image uniforms in a shader */
363 #define BRW_MAX_IMAGES 32
364
365 /** Maximum number of actual buffers used for stream output */
366 #define BRW_MAX_SOL_BUFFERS 4
367
368 #define BRW_MAX_SURFACES (BRW_MAX_DRAW_BUFFERS + \
369 BRW_MAX_TEX_UNIT * 2 + /* normal, gather */ \
370 BRW_MAX_UBO + \
371 BRW_MAX_SSBO + \
372 BRW_MAX_ABO + \
373 BRW_MAX_IMAGES + \
374 2 + /* shader time, pull constants */ \
375 1 /* cs num work groups */)
376
377 struct brw_cache {
378 struct brw_context *brw;
379
380 struct brw_cache_item **items;
381 struct brw_bo *bo;
382 void *map;
383 GLuint size, n_items;
384
385 uint32_t next_offset;
386 };
387
388 #define perf_debug(...) do { \
389 static GLuint msg_id = 0; \
390 if (unlikely(INTEL_DEBUG & DEBUG_PERF)) \
391 dbg_printf(__VA_ARGS__); \
392 if (brw->perf_debug) \
393 _mesa_gl_debugf(&brw->ctx, &msg_id, \
394 MESA_DEBUG_SOURCE_API, \
395 MESA_DEBUG_TYPE_PERFORMANCE, \
396 MESA_DEBUG_SEVERITY_MEDIUM, \
397 __VA_ARGS__); \
398 } while(0)
399
400 #define WARN_ONCE(cond, fmt...) do { \
401 if (unlikely(cond)) { \
402 static bool _warned = false; \
403 static GLuint msg_id = 0; \
404 if (!_warned) { \
405 fprintf(stderr, "WARNING: "); \
406 fprintf(stderr, fmt); \
407 _warned = true; \
408 \
409 _mesa_gl_debugf(ctx, &msg_id, \
410 MESA_DEBUG_SOURCE_API, \
411 MESA_DEBUG_TYPE_OTHER, \
412 MESA_DEBUG_SEVERITY_HIGH, fmt); \
413 } \
414 } \
415 } while (0)
416
417 /* Considered adding a member to this struct to document which flags
418 * an update might raise so that ordering of the state atoms can be
419 * checked or derived at runtime. Dropped the idea in favor of having
420 * a debug mode where the state is monitored for flags which are
421 * raised that have already been tested against.
422 */
423 struct brw_tracked_state {
424 struct brw_state_flags dirty;
425 void (*emit)( struct brw_context *brw );
426 };
427
428 enum shader_time_shader_type {
429 ST_NONE,
430 ST_VS,
431 ST_TCS,
432 ST_TES,
433 ST_GS,
434 ST_FS8,
435 ST_FS16,
436 ST_FS32,
437 ST_CS,
438 };
439
440 struct brw_vertex_buffer {
441 /** Buffer object containing the uploaded vertex data */
442 struct brw_bo *bo;
443 uint32_t offset;
444 uint32_t size;
445 /** Byte stride between elements in the uploaded array */
446 GLuint stride;
447 GLuint step_rate;
448 };
449 struct brw_vertex_element {
450 const struct gl_vertex_format *glformat;
451
452 int buffer;
453 bool is_dual_slot;
454 /** Offset of the first element within the buffer object */
455 unsigned int offset;
456 };
457
458 struct brw_query_object {
459 struct gl_query_object Base;
460
461 /** Last query BO associated with this query. */
462 struct brw_bo *bo;
463
464 /** Last index in bo with query data for this object. */
465 int last_index;
466
467 /** True if we know the batch has been flushed since we ended the query. */
468 bool flushed;
469 };
470
471 struct brw_reloc_list {
472 struct drm_i915_gem_relocation_entry *relocs;
473 int reloc_count;
474 int reloc_array_size;
475 };
476
477 struct brw_growing_bo {
478 struct brw_bo *bo;
479 uint32_t *map;
480 struct brw_bo *partial_bo;
481 uint32_t *partial_bo_map;
482 unsigned partial_bytes;
483 enum brw_memory_zone memzone;
484 };
485
486 struct intel_batchbuffer {
487 /** Current batchbuffer being queued up. */
488 struct brw_growing_bo batch;
489 /** Current statebuffer being queued up. */
490 struct brw_growing_bo state;
491
492 /** Last batchbuffer submitted to the hardware. Used for glFinish(). */
493 struct brw_bo *last_bo;
494
495 #ifdef DEBUG
496 uint16_t emit, total;
497 #endif
498 uint32_t *map_next;
499 uint32_t state_used;
500
501 bool use_shadow_copy;
502 bool use_batch_first;
503 bool needs_sol_reset;
504 bool state_base_address_emitted;
505 bool no_wrap;
506
507 struct brw_reloc_list batch_relocs;
508 struct brw_reloc_list state_relocs;
509 unsigned int valid_reloc_flags;
510
511 /** The validation list */
512 struct drm_i915_gem_exec_object2 *validation_list;
513 struct brw_bo **exec_bos;
514 int exec_count;
515 int exec_array_size;
516
517 /** The amount of aperture space (in bytes) used by all exec_bos */
518 uint64_t aperture_space;
519
520 struct {
521 uint32_t *map_next;
522 int batch_reloc_count;
523 int state_reloc_count;
524 int exec_count;
525 } saved;
526
527 /** Map from batch offset to brw_state_batch data (with DEBUG_BATCH) */
528 struct hash_table_u64 *state_batch_sizes;
529
530 struct gen_batch_decode_ctx decoder;
531 };
532
533 #define BRW_MAX_XFB_STREAMS 4
534
535 struct brw_transform_feedback_counter {
536 /**
537 * Index of the first entry of this counter within the primitive count BO.
538 * An entry is considered to be an N-tuple of 64bit values, where N is the
539 * number of vertex streams supported by the platform.
540 */
541 unsigned bo_start;
542
543 /**
544 * Index one past the last entry of this counter within the primitive
545 * count BO.
546 */
547 unsigned bo_end;
548
549 /**
550 * Primitive count values accumulated while this counter was active,
551 * excluding any entries buffered between \c bo_start and \c bo_end, which
552 * haven't been accounted for yet.
553 */
554 uint64_t accum[BRW_MAX_XFB_STREAMS];
555 };
556
557 static inline void
558 brw_reset_transform_feedback_counter(
559 struct brw_transform_feedback_counter *counter)
560 {
561 counter->bo_start = counter->bo_end;
562 memset(&counter->accum, 0, sizeof(counter->accum));
563 }
564
565 struct brw_transform_feedback_object {
566 struct gl_transform_feedback_object base;
567
568 /** A buffer to hold SO_WRITE_OFFSET(n) values while paused. */
569 struct brw_bo *offset_bo;
570
571 /** If true, SO_WRITE_OFFSET(n) should be reset to zero at next use. */
572 bool zero_offsets;
573
574 /** The most recent primitive mode (GL_TRIANGLES/GL_POINTS/GL_LINES). */
575 GLenum primitive_mode;
576
577 /**
578 * The maximum number of vertices that we can write without overflowing
579 * any of the buffers currently being used for transform feedback.
580 */
581 unsigned max_index;
582
583 struct brw_bo *prim_count_bo;
584
585 /**
586 * Count of primitives generated during this transform feedback operation.
587 */
588 struct brw_transform_feedback_counter counter;
589
590 /**
591 * Count of primitives generated during the previous transform feedback
592 * operation. Used to implement DrawTransformFeedback().
593 */
594 struct brw_transform_feedback_counter previous_counter;
595
596 /**
597 * Number of vertices written between last Begin/EndTransformFeedback().
598 *
599 * Used to implement DrawTransformFeedback().
600 */
601 uint64_t vertices_written[BRW_MAX_XFB_STREAMS];
602 bool vertices_written_valid;
603 };
604
605 /**
606 * Data shared between each programmable stage in the pipeline (vs, gs, and
607 * wm).
608 */
609 struct brw_stage_state
610 {
611 gl_shader_stage stage;
612 struct brw_stage_prog_data *prog_data;
613
614 /**
615 * Optional scratch buffer used to store spilled register values and
616 * variably-indexed GRF arrays.
617 *
618 * The contents of this buffer are short-lived so the same memory can be
619 * re-used at will for multiple shader programs (executed by the same fixed
620 * function). However reusing a scratch BO for which shader invocations
621 * are still in flight with a per-thread scratch slot size other than the
622 * original can cause threads with different scratch slot size and FFTID
623 * (which may be executed in parallel depending on the shader stage and
624 * hardware generation) to map to an overlapping region of the scratch
625 * space, which can potentially lead to mutual scratch space corruption.
626 * For that reason if you borrow this scratch buffer you should only be
627 * using the slot size given by the \c per_thread_scratch member below,
628 * unless you're taking additional measures to synchronize thread execution
629 * across slot size changes.
630 */
631 struct brw_bo *scratch_bo;
632
633 /**
634 * Scratch slot size allocated for each thread in the buffer object given
635 * by \c scratch_bo.
636 */
637 uint32_t per_thread_scratch;
638
639 /** Offset in the program cache to the program */
640 uint32_t prog_offset;
641
642 /** Offset in the batchbuffer to Gen4-5 pipelined state (VS/WM/GS_STATE). */
643 uint32_t state_offset;
644
645 struct brw_bo *push_const_bo; /* NULL if using the batchbuffer */
646 uint32_t push_const_offset; /* Offset in the push constant BO or batch */
647 int push_const_size; /* in 256-bit register increments */
648
649 /* Binding table: pointers to SURFACE_STATE entries. */
650 uint32_t bind_bo_offset;
651 uint32_t surf_offset[BRW_MAX_SURFACES];
652
653 /** SAMPLER_STATE count and table offset */
654 uint32_t sampler_count;
655 uint32_t sampler_offset;
656
657 struct brw_image_param image_param[BRW_MAX_IMAGES];
658
659 /** Need to re-emit 3DSTATE_CONSTANT_XS? */
660 bool push_constants_dirty;
661 };
662
663 enum brw_predicate_state {
664 /* The first two states are used if we can determine whether to draw
665 * without having to look at the values in the query object buffer. This
666 * will happen if there is no conditional render in progress, if the query
667 * object is already completed or if something else has already added
668 * samples to the preliminary result such as via a BLT command.
669 */
670 BRW_PREDICATE_STATE_RENDER,
671 BRW_PREDICATE_STATE_DONT_RENDER,
672 /* In this case whether to draw or not depends on the result of an
673 * MI_PREDICATE command so the predicate enable bit needs to be checked.
674 */
675 BRW_PREDICATE_STATE_USE_BIT,
676 /* In this case, either MI_PREDICATE doesn't exist or we lack the
677 * necessary kernel features to use it. Stall for the query result.
678 */
679 BRW_PREDICATE_STATE_STALL_FOR_QUERY,
680 };
681
682 struct shader_times;
683
684 struct gen_l3_config;
685 struct gen_perf;
686
687 struct brw_uploader {
688 struct brw_bufmgr *bufmgr;
689 struct brw_bo *bo;
690 void *map;
691 uint32_t next_offset;
692 unsigned default_size;
693 };
694
695 /**
696 * brw_context is derived from gl_context.
697 */
698 struct brw_context
699 {
700 struct gl_context ctx; /**< base class, must be first field */
701
702 struct
703 {
704 /**
705 * Emit an MI_REPORT_PERF_COUNT command packet.
706 *
707 * This asks the GPU to write a report of the current OA counter values
708 * into @bo at the given offset and containing the given @report_id
709 * which we can cross-reference when parsing the report (gen7+ only).
710 */
711 void (*emit_mi_report_perf_count)(struct brw_context *brw,
712 struct brw_bo *bo,
713 uint32_t offset_in_bytes,
714 uint32_t report_id);
715
716 void (*emit_compute_walker)(struct brw_context *brw);
717 void (*emit_raw_pipe_control)(struct brw_context *brw, uint32_t flags,
718 struct brw_bo *bo, uint32_t offset,
719 uint64_t imm);
720 } vtbl;
721
722 struct brw_bufmgr *bufmgr;
723
724 uint32_t hw_ctx;
725
726 /**
727 * BO for post-sync nonzero writes for gen6 workaround.
728 *
729 * This buffer also contains a marker + description of the driver. This
730 * buffer is added to all execbufs syscalls so that we can identify the
731 * driver that generated a hang by looking at the content of the buffer in
732 * the error state.
733 *
734 * Read/write should go at workaround_bo_offset in that buffer to avoid
735 * overriding the debug data.
736 */
737 struct brw_bo *workaround_bo;
738 uint32_t workaround_bo_offset;
739 uint8_t pipe_controls_since_last_cs_stall;
740
741 /**
742 * Set of struct brw_bo * that have been rendered to within this batchbuffer
743 * and would need flushing before being used from another cache domain that
744 * isn't coherent with it (i.e. the sampler).
745 */
746 struct hash_table *render_cache;
747
748 /**
749 * Set of struct brw_bo * that have been used as a depth buffer within this
750 * batchbuffer and would need flushing before being used from another cache
751 * domain that isn't coherent with it (i.e. the sampler).
752 */
753 struct set *depth_cache;
754
755 /**
756 * Number of resets observed in the system at context creation.
757 *
758 * This is tracked in the context so that we can determine that another
759 * reset has occurred.
760 */
761 uint32_t reset_count;
762
763 struct intel_batchbuffer batch;
764
765 struct brw_uploader upload;
766
767 /**
768 * Set if rendering has occurred to the drawable's front buffer.
769 *
770 * This is used in the DRI2 case to detect that glFlush should also copy
771 * the contents of the fake front buffer to the real front buffer.
772 */
773 bool front_buffer_dirty;
774
775 /**
776 * True if the __DRIdrawable's current __DRIimageBufferMask is
777 * __DRI_IMAGE_BUFFER_SHARED.
778 */
779 bool is_shared_buffer_bound;
780
781 /**
782 * True if a shared buffer is bound and it has received any rendering since
783 * the previous __DRImutableRenderBufferLoaderExtension::displaySharedBuffer().
784 */
785 bool is_shared_buffer_dirty;
786
787 /** Framerate throttling: @{ */
788 struct brw_bo *throttle_batch[2];
789
790 /* Limit the number of outstanding SwapBuffers by waiting for an earlier
791 * frame of rendering to complete. This gives a very precise cap to the
792 * latency between input and output such that rendering never gets more
793 * than a frame behind the user. (With the caveat that we technically are
794 * not using the SwapBuffers itself as a barrier but the first batch
795 * submitted afterwards, which may be immediately prior to the next
796 * SwapBuffers.)
797 */
798 bool need_swap_throttle;
799
800 /** General throttling, not caught by throttling between SwapBuffers */
801 bool need_flush_throttle;
802 /** @} */
803
804 GLuint stats_wm;
805
806 /**
807 * drirc options:
808 * @{
809 */
810 bool always_flush_batch;
811 bool always_flush_cache;
812 bool disable_throttling;
813 bool precompile;
814 bool dual_color_blend_by_location;
815
816 driOptionCache optionCache;
817 /** @} */
818
819 GLuint primitive; /**< Hardware primitive, such as _3DPRIM_TRILIST. */
820
821 bool object_preemption; /**< Object level preemption enabled. */
822
823 GLenum reduced_primitive;
824
825 /**
826 * Set if we're either a debug context or the INTEL_DEBUG=perf environment
827 * variable is set, this is the flag indicating to do expensive work that
828 * might lead to a perf_debug() call.
829 */
830 bool perf_debug;
831
832 uint64_t max_gtt_map_object_size;
833
834 bool has_hiz;
835 bool has_separate_stencil;
836 bool has_swizzling;
837
838 /** Derived stencil states. */
839 bool stencil_enabled;
840 bool stencil_two_sided;
841 bool stencil_write_enabled;
842 /** Derived polygon state. */
843 bool polygon_front_bit; /**< 0=GL_CCW, 1=GL_CW */
844
845 struct isl_device isl_dev;
846
847 struct blorp_context blorp;
848
849 GLuint NewGLState;
850 struct {
851 struct brw_state_flags pipelines[BRW_NUM_PIPELINES];
852 } state;
853
854 enum brw_pipeline last_pipeline;
855
856 struct brw_cache cache;
857
858 /* Whether a meta-operation is in progress. */
859 bool meta_in_progress;
860
861 /* Whether the last depth/stencil packets were both NULL. */
862 bool no_depth_or_stencil;
863
864 /* The last PMA stall bits programmed. */
865 uint32_t pma_stall_bits;
866
867 /* Whether INTEL_black_render is active. */
868 bool frontend_noop;
869
870 struct {
871 struct {
872 /**
873 * Either the value of gl_BaseVertex for indexed draw calls or the
874 * value of the argument <first> for non-indexed draw calls for the
875 * current _mesa_prim.
876 */
877 int firstvertex;
878
879 /** The value of gl_BaseInstance for the current _mesa_prim. */
880 int gl_baseinstance;
881 } params;
882
883 /**
884 * Buffer and offset used for GL_ARB_shader_draw_parameters which will
885 * point to the indirect buffer for indirect draw calls.
886 */
887 struct brw_bo *draw_params_bo;
888 uint32_t draw_params_offset;
889
890 struct {
891 /**
892 * The value of gl_DrawID for the current _mesa_prim. This always comes
893 * in from it's own vertex buffer since it's not part of the indirect
894 * draw parameters.
895 */
896 int gl_drawid;
897
898 /**
899 * Stores if the current _mesa_prim is an indexed or non-indexed draw
900 * (~0/0). Useful to calculate gl_BaseVertex as an AND of firstvertex
901 * and is_indexed_draw.
902 */
903 int is_indexed_draw;
904 } derived_params;
905
906 /**
907 * Buffer and offset used for GL_ARB_shader_draw_parameters which contains
908 * parameters that are not present in the indirect buffer. They will go in
909 * their own vertex element.
910 */
911 struct brw_bo *derived_draw_params_bo;
912 uint32_t derived_draw_params_offset;
913
914 /**
915 * Pointer to the the buffer storing the indirect draw parameters. It
916 * currently only stores the number of requested draw calls but more
917 * parameters could potentially be added.
918 */
919 struct brw_bo *draw_params_count_bo;
920 uint32_t draw_params_count_offset;
921
922 /**
923 * Draw indirect buffer.
924 */
925 unsigned draw_indirect_stride;
926 GLsizeiptr draw_indirect_offset;
927 struct gl_buffer_object *draw_indirect_data;
928 } draw;
929
930 struct {
931 /**
932 * For gl_NumWorkGroups: If num_work_groups_bo is non NULL, then it is
933 * an indirect call, and num_work_groups_offset is valid. Otherwise,
934 * num_work_groups is set based on glDispatchCompute.
935 */
936 struct brw_bo *num_work_groups_bo;
937 GLintptr num_work_groups_offset;
938 const GLuint *num_work_groups;
939 /**
940 * This is only used alongside ARB_compute_variable_group_size when the
941 * local work group size is variable, otherwise it's NULL.
942 */
943 const GLuint *group_size;
944 } compute;
945
946 struct {
947 struct brw_vertex_element inputs[VERT_ATTRIB_MAX];
948 struct brw_vertex_buffer buffers[VERT_ATTRIB_MAX];
949
950 struct brw_vertex_element *enabled[VERT_ATTRIB_MAX];
951 GLuint nr_enabled;
952 GLuint nr_buffers;
953
954 /* Summary of size and varying of active arrays, so we can check
955 * for changes to this state:
956 */
957 bool index_bounds_valid;
958 unsigned int min_index, max_index;
959
960 /* Offset from start of vertex buffer so we can avoid redefining
961 * the same VB packed over and over again.
962 */
963 unsigned int start_vertex_bias;
964
965 /**
966 * Certain vertex attribute formats aren't natively handled by the
967 * hardware and require special VS code to fix up their values.
968 *
969 * These bitfields indicate which workarounds are needed.
970 */
971 uint8_t attrib_wa_flags[VERT_ATTRIB_MAX];
972
973 /* High bits of the last seen vertex buffer address (for workarounds). */
974 uint16_t last_bo_high_bits[33];
975 } vb;
976
977 struct {
978 /**
979 * Index buffer for this draw_prims call.
980 *
981 * Updates are signaled by BRW_NEW_INDICES.
982 */
983 const struct _mesa_index_buffer *ib;
984
985 /* Updates are signaled by BRW_NEW_INDEX_BUFFER. */
986 struct brw_bo *bo;
987 uint32_t size;
988 unsigned index_size;
989
990 /* Offset to index buffer index to use in CMD_3D_PRIM so that we can
991 * avoid re-uploading the IB packet over and over if we're actually
992 * referencing the same index buffer.
993 */
994 unsigned int start_vertex_offset;
995
996 /* High bits of the last seen index buffer address (for workarounds). */
997 uint16_t last_bo_high_bits;
998
999 /* Used to understand is GPU state of primitive restart is up to date */
1000 bool enable_cut_index;
1001 } ib;
1002
1003 /* Active vertex program:
1004 */
1005 struct gl_program *programs[MESA_SHADER_STAGES];
1006
1007 /**
1008 * Number of samples in ctx->DrawBuffer, updated by BRW_NEW_NUM_SAMPLES so
1009 * that we don't have to reemit that state every time we change FBOs.
1010 */
1011 unsigned int num_samples;
1012
1013 /* BRW_NEW_URB_ALLOCATIONS:
1014 */
1015 struct {
1016 GLuint vsize; /* vertex size plus header in urb registers */
1017 GLuint gsize; /* GS output size in urb registers */
1018 GLuint hsize; /* Tessellation control output size in urb registers */
1019 GLuint dsize; /* Tessellation evaluation output size in urb registers */
1020 GLuint csize; /* constant buffer size in urb registers */
1021 GLuint sfsize; /* setup data size in urb registers */
1022
1023 bool constrained;
1024
1025 GLuint nr_vs_entries;
1026 GLuint nr_hs_entries;
1027 GLuint nr_ds_entries;
1028 GLuint nr_gs_entries;
1029 GLuint nr_clip_entries;
1030 GLuint nr_sf_entries;
1031 GLuint nr_cs_entries;
1032
1033 GLuint vs_start;
1034 GLuint hs_start;
1035 GLuint ds_start;
1036 GLuint gs_start;
1037 GLuint clip_start;
1038 GLuint sf_start;
1039 GLuint cs_start;
1040 /**
1041 * URB size in the current configuration. The units this is expressed
1042 * in are somewhat inconsistent, see gen_device_info::urb::size.
1043 *
1044 * FINISHME: Represent the URB size consistently in KB on all platforms.
1045 */
1046 GLuint size;
1047
1048 /* True if the most recently sent _3DSTATE_URB message allocated
1049 * URB space for the GS.
1050 */
1051 bool gs_present;
1052
1053 /* True if the most recently sent _3DSTATE_URB message allocated
1054 * URB space for the HS and DS.
1055 */
1056 bool tess_present;
1057 } urb;
1058
1059
1060 /* BRW_NEW_PUSH_CONSTANT_ALLOCATION */
1061 struct {
1062 GLuint wm_start; /**< pos of first wm const in CURBE buffer */
1063 GLuint wm_size; /**< number of float[4] consts, multiple of 16 */
1064 GLuint clip_start;
1065 GLuint clip_size;
1066 GLuint vs_start;
1067 GLuint vs_size;
1068 GLuint total_size;
1069
1070 /**
1071 * Pointer to the (intel_upload.c-generated) BO containing the uniforms
1072 * for upload to the CURBE.
1073 */
1074 struct brw_bo *curbe_bo;
1075 /** Offset within curbe_bo of space for current curbe entry */
1076 GLuint curbe_offset;
1077 } curbe;
1078
1079 /**
1080 * Layout of vertex data exiting the geometry portion of the pipleine.
1081 * This comes from the last enabled shader stage (GS, DS, or VS).
1082 *
1083 * BRW_NEW_VUE_MAP_GEOM_OUT is flagged when the VUE map changes.
1084 */
1085 struct brw_vue_map vue_map_geom_out;
1086
1087 struct {
1088 struct brw_stage_state base;
1089 } vs;
1090
1091 struct {
1092 struct brw_stage_state base;
1093 } tcs;
1094
1095 struct {
1096 struct brw_stage_state base;
1097 } tes;
1098
1099 struct {
1100 struct brw_stage_state base;
1101
1102 /**
1103 * True if the 3DSTATE_GS command most recently emitted to the 3D
1104 * pipeline enabled the GS; false otherwise.
1105 */
1106 bool enabled;
1107 } gs;
1108
1109 struct {
1110 struct brw_ff_gs_prog_data *prog_data;
1111
1112 bool prog_active;
1113 /** Offset in the program cache to the CLIP program pre-gen6 */
1114 uint32_t prog_offset;
1115 uint32_t state_offset;
1116
1117 uint32_t bind_bo_offset;
1118 /**
1119 * Surface offsets for the binding table. We only need surfaces to
1120 * implement transform feedback so BRW_MAX_SOL_BINDINGS is all that we
1121 * need in this case.
1122 */
1123 uint32_t surf_offset[BRW_MAX_SOL_BINDINGS];
1124 } ff_gs;
1125
1126 struct {
1127 struct brw_clip_prog_data *prog_data;
1128
1129 /** Offset in the program cache to the CLIP program pre-gen6 */
1130 uint32_t prog_offset;
1131
1132 /* Offset in the batch to the CLIP state on pre-gen6. */
1133 uint32_t state_offset;
1134
1135 /* As of gen6, this is the offset in the batch to the CLIP VP,
1136 * instead of vp_bo.
1137 */
1138 uint32_t vp_offset;
1139
1140 /**
1141 * The number of viewports to use. If gl_ViewportIndex is written,
1142 * we can have up to ctx->Const.MaxViewports viewports. If not,
1143 * the viewport index is always 0, so we can only emit one.
1144 */
1145 uint8_t viewport_count;
1146 } clip;
1147
1148
1149 struct {
1150 struct brw_sf_prog_data *prog_data;
1151
1152 /** Offset in the program cache to the CLIP program pre-gen6 */
1153 uint32_t prog_offset;
1154 uint32_t state_offset;
1155 uint32_t vp_offset;
1156 } sf;
1157
1158 struct {
1159 struct brw_stage_state base;
1160
1161 /**
1162 * Buffer object used in place of multisampled null render targets on
1163 * Gen6. See brw_emit_null_surface_state().
1164 */
1165 struct brw_bo *multisampled_null_render_target_bo;
1166
1167 float offset_clamp;
1168 } wm;
1169
1170 struct {
1171 struct brw_stage_state base;
1172 } cs;
1173
1174 struct {
1175 uint32_t state_offset;
1176 uint32_t blend_state_offset;
1177 uint32_t depth_stencil_state_offset;
1178 uint32_t vp_offset;
1179 } cc;
1180
1181 struct {
1182 struct brw_query_object *obj;
1183 bool begin_emitted;
1184 } query;
1185
1186 struct {
1187 enum brw_predicate_state state;
1188 bool supported;
1189 } predicate;
1190
1191 struct gen_perf_context *perf_ctx;
1192
1193 int num_atoms[BRW_NUM_PIPELINES];
1194 const struct brw_tracked_state render_atoms[76];
1195 const struct brw_tracked_state compute_atoms[11];
1196
1197 const enum isl_format *mesa_to_isl_render_format;
1198 const bool *mesa_format_supports_render;
1199
1200 /* PrimitiveRestart */
1201 struct {
1202 bool in_progress;
1203 bool enable_cut_index;
1204 } prim_restart;
1205
1206 /** Computed depth/stencil/hiz state from the current attached
1207 * renderbuffers, valid only during the drawing state upload loop after
1208 * brw_workaround_depthstencil_alignment().
1209 */
1210 struct {
1211 /* Inter-tile (page-aligned) byte offsets. */
1212 uint32_t depth_offset;
1213 /* Intra-tile x,y offsets for drawing to combined depth-stencil. Only
1214 * used for Gen < 6.
1215 */
1216 uint32_t tile_x, tile_y;
1217 } depthstencil;
1218
1219 uint32_t num_instances;
1220 int basevertex;
1221 int baseinstance;
1222
1223 struct {
1224 const struct gen_l3_config *config;
1225 } l3;
1226
1227 struct {
1228 struct brw_bo *bo;
1229 const char **names;
1230 int *ids;
1231 enum shader_time_shader_type *types;
1232 struct shader_times *cumulative;
1233 int num_entries;
1234 int max_entries;
1235 double report_time;
1236 } shader_time;
1237
1238 struct brw_fast_clear_state *fast_clear_state;
1239
1240 /* Array of aux usages to use for drawing. Aux usage for render targets is
1241 * a bit more complex than simply calling a single function so we need some
1242 * way of passing it form brw_draw.c to surface state setup.
1243 */
1244 enum isl_aux_usage draw_aux_usage[MAX_DRAW_BUFFERS];
1245
1246 enum gen9_astc5x5_wa_tex_type gen9_astc5x5_wa_tex_mask;
1247
1248 /** Last rendering scale argument provided to brw_emit_hashing_mode(). */
1249 unsigned current_hash_scale;
1250
1251 __DRIcontext *driContext;
1252 struct intel_screen *screen;
1253 };
1254
1255 /* brw_clear.c */
1256 extern void intelInitClearFuncs(struct dd_function_table *functions);
1257
1258 /*======================================================================
1259 * brw_context.c
1260 */
1261 extern const char *const brw_vendor_string;
1262
1263 extern const char *
1264 brw_get_renderer_string(const struct intel_screen *screen);
1265
1266 enum {
1267 DRI_CONF_BO_REUSE_DISABLED,
1268 DRI_CONF_BO_REUSE_ALL
1269 };
1270
1271 void intel_update_renderbuffers(__DRIcontext *context,
1272 __DRIdrawable *drawable);
1273 void intel_prepare_render(struct brw_context *brw);
1274
1275 void gen9_apply_single_tex_astc5x5_wa(struct brw_context *brw,
1276 mesa_format format,
1277 enum isl_aux_usage aux_usage);
1278
1279 void brw_predraw_resolve_inputs(struct brw_context *brw, bool rendering,
1280 bool *draw_aux_buffer_disabled);
1281
1282 void intel_resolve_for_dri2_flush(struct brw_context *brw,
1283 __DRIdrawable *drawable);
1284
1285 GLboolean brwCreateContext(gl_api api,
1286 const struct gl_config *mesaVis,
1287 __DRIcontext *driContextPriv,
1288 const struct __DriverContextConfig *ctx_config,
1289 unsigned *error,
1290 void *sharedContextPrivate);
1291
1292 /*======================================================================
1293 * brw_misc_state.c
1294 */
1295 void brw_workaround_depthstencil_alignment(struct brw_context *brw,
1296 GLbitfield clear_mask);
1297 void brw_emit_hashing_mode(struct brw_context *brw, unsigned width,
1298 unsigned height, unsigned scale);
1299
1300 /* brw_object_purgeable.c */
1301 void brw_init_object_purgeable_functions(struct dd_function_table *functions);
1302
1303 /*======================================================================
1304 * brw_queryobj.c
1305 */
1306 void brw_init_common_queryobj_functions(struct dd_function_table *functions);
1307 void gen4_init_queryobj_functions(struct dd_function_table *functions);
1308 void brw_emit_query_begin(struct brw_context *brw);
1309 void brw_emit_query_end(struct brw_context *brw);
1310 void brw_query_counter(struct gl_context *ctx, struct gl_query_object *q);
1311 bool brw_is_query_pipelined(struct brw_query_object *query);
1312 uint64_t brw_raw_timestamp_delta(struct brw_context *brw,
1313 uint64_t time0, uint64_t time1);
1314
1315 /** gen6_queryobj.c */
1316 void gen6_init_queryobj_functions(struct dd_function_table *functions);
1317 void brw_write_timestamp(struct brw_context *brw, struct brw_bo *bo, int idx);
1318 void brw_write_depth_count(struct brw_context *brw, struct brw_bo *bo, int idx);
1319
1320 /** hsw_queryobj.c */
1321 void hsw_overflow_result_to_gpr0(struct brw_context *brw,
1322 struct brw_query_object *query,
1323 int count);
1324 void hsw_init_queryobj_functions(struct dd_function_table *functions);
1325
1326 /** brw_conditional_render.c */
1327 void brw_init_conditional_render_functions(struct dd_function_table *functions);
1328 bool brw_check_conditional_render(struct brw_context *brw);
1329
1330 /** intel_batchbuffer.c */
1331 void brw_load_register_mem(struct brw_context *brw,
1332 uint32_t reg,
1333 struct brw_bo *bo,
1334 uint32_t offset);
1335 void brw_load_register_mem64(struct brw_context *brw,
1336 uint32_t reg,
1337 struct brw_bo *bo,
1338 uint32_t offset);
1339 void brw_store_register_mem32(struct brw_context *brw,
1340 struct brw_bo *bo, uint32_t reg, uint32_t offset);
1341 void brw_store_register_mem64(struct brw_context *brw,
1342 struct brw_bo *bo, uint32_t reg, uint32_t offset);
1343 void brw_load_register_imm32(struct brw_context *brw,
1344 uint32_t reg, uint32_t imm);
1345 void brw_load_register_imm64(struct brw_context *brw,
1346 uint32_t reg, uint64_t imm);
1347 void brw_load_register_reg(struct brw_context *brw, uint32_t dst,
1348 uint32_t src);
1349 void brw_load_register_reg64(struct brw_context *brw, uint32_t dst,
1350 uint32_t src);
1351 void brw_store_data_imm32(struct brw_context *brw, struct brw_bo *bo,
1352 uint32_t offset, uint32_t imm);
1353 void brw_store_data_imm64(struct brw_context *brw, struct brw_bo *bo,
1354 uint32_t offset, uint64_t imm);
1355
1356 /*======================================================================
1357 * intel_tex_validate.c
1358 */
1359 void brw_validate_textures( struct brw_context *brw );
1360
1361
1362 /*======================================================================
1363 * brw_program.c
1364 */
1365 void brwInitFragProgFuncs( struct dd_function_table *functions );
1366
1367 void brw_get_scratch_bo(struct brw_context *brw,
1368 struct brw_bo **scratch_bo, int size);
1369 void brw_alloc_stage_scratch(struct brw_context *brw,
1370 struct brw_stage_state *stage_state,
1371 unsigned per_thread_size);
1372 void brw_init_shader_time(struct brw_context *brw);
1373 int brw_get_shader_time_index(struct brw_context *brw,
1374 struct gl_program *prog,
1375 enum shader_time_shader_type type,
1376 bool is_glsl_sh);
1377 void brw_collect_and_report_shader_time(struct brw_context *brw);
1378 void brw_destroy_shader_time(struct brw_context *brw);
1379
1380 /* brw_urb.c
1381 */
1382 void brw_calculate_urb_fence(struct brw_context *brw, unsigned csize,
1383 unsigned vsize, unsigned sfsize);
1384 void brw_upload_urb_fence(struct brw_context *brw);
1385
1386 /* brw_curbe.c
1387 */
1388 void brw_upload_cs_urb_state(struct brw_context *brw);
1389
1390 /* brw_vs.c */
1391 gl_clip_plane *brw_select_clip_planes(struct gl_context *ctx);
1392
1393 /* brw_draw_upload.c */
1394 unsigned brw_get_vertex_surface_type(struct brw_context *brw,
1395 const struct gl_vertex_format *glformat);
1396
1397 static inline unsigned
1398 brw_get_index_type(unsigned index_size)
1399 {
1400 /* The hw needs 0x00, 0x01, and 0x02 for ubyte, ushort, and uint,
1401 * respectively.
1402 */
1403 return index_size >> 1;
1404 }
1405
1406 void brw_prepare_vertices(struct brw_context *brw);
1407
1408 /* brw_wm_surface_state.c */
1409 void brw_update_buffer_texture_surface(struct gl_context *ctx,
1410 unsigned unit,
1411 uint32_t *surf_offset);
1412 void
1413 brw_update_sol_surface(struct brw_context *brw,
1414 struct gl_buffer_object *buffer_obj,
1415 uint32_t *out_offset, unsigned num_vector_components,
1416 unsigned stride_dwords, unsigned offset_dwords);
1417 void brw_upload_ubo_surfaces(struct brw_context *brw, struct gl_program *prog,
1418 struct brw_stage_state *stage_state,
1419 struct brw_stage_prog_data *prog_data);
1420 void brw_upload_image_surfaces(struct brw_context *brw,
1421 const struct gl_program *prog,
1422 struct brw_stage_state *stage_state,
1423 struct brw_stage_prog_data *prog_data);
1424
1425 /* brw_surface_formats.c */
1426 void intel_screen_init_surface_formats(struct intel_screen *screen);
1427 void brw_init_surface_formats(struct brw_context *brw);
1428 bool brw_render_target_supported(struct brw_context *brw,
1429 struct gl_renderbuffer *rb);
1430 uint32_t brw_depth_format(struct brw_context *brw, mesa_format format);
1431
1432 /* brw_performance_query.c */
1433 void brw_init_performance_queries(struct brw_context *brw);
1434
1435 /* intel_extensions.c */
1436 extern void intelInitExtensions(struct gl_context *ctx);
1437
1438 /* intel_state.c */
1439 extern int intel_translate_shadow_compare_func(GLenum func);
1440 extern int intel_translate_compare_func(GLenum func);
1441 extern int intel_translate_stencil_op(GLenum op);
1442
1443 /* brw_sync.c */
1444 void brw_init_syncobj_functions(struct dd_function_table *functions);
1445
1446 /* gen6_sol.c */
1447 struct gl_transform_feedback_object *
1448 brw_new_transform_feedback(struct gl_context *ctx, GLuint name);
1449 void
1450 brw_delete_transform_feedback(struct gl_context *ctx,
1451 struct gl_transform_feedback_object *obj);
1452 void
1453 brw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1454 struct gl_transform_feedback_object *obj);
1455 void
1456 brw_end_transform_feedback(struct gl_context *ctx,
1457 struct gl_transform_feedback_object *obj);
1458 void
1459 brw_pause_transform_feedback(struct gl_context *ctx,
1460 struct gl_transform_feedback_object *obj);
1461 void
1462 brw_resume_transform_feedback(struct gl_context *ctx,
1463 struct gl_transform_feedback_object *obj);
1464 void
1465 brw_save_primitives_written_counters(struct brw_context *brw,
1466 struct brw_transform_feedback_object *obj);
1467 GLsizei
1468 brw_get_transform_feedback_vertex_count(struct gl_context *ctx,
1469 struct gl_transform_feedback_object *obj,
1470 GLuint stream);
1471
1472 /* gen7_sol_state.c */
1473 void
1474 gen7_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1475 struct gl_transform_feedback_object *obj);
1476 void
1477 gen7_end_transform_feedback(struct gl_context *ctx,
1478 struct gl_transform_feedback_object *obj);
1479 void
1480 gen7_pause_transform_feedback(struct gl_context *ctx,
1481 struct gl_transform_feedback_object *obj);
1482 void
1483 gen7_resume_transform_feedback(struct gl_context *ctx,
1484 struct gl_transform_feedback_object *obj);
1485
1486 /* hsw_sol.c */
1487 void
1488 hsw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1489 struct gl_transform_feedback_object *obj);
1490 void
1491 hsw_end_transform_feedback(struct gl_context *ctx,
1492 struct gl_transform_feedback_object *obj);
1493 void
1494 hsw_pause_transform_feedback(struct gl_context *ctx,
1495 struct gl_transform_feedback_object *obj);
1496 void
1497 hsw_resume_transform_feedback(struct gl_context *ctx,
1498 struct gl_transform_feedback_object *obj);
1499
1500 /* brw_blorp_blit.cpp */
1501 GLbitfield
1502 brw_blorp_framebuffer(struct brw_context *brw,
1503 struct gl_framebuffer *readFb,
1504 struct gl_framebuffer *drawFb,
1505 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1506 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
1507 GLbitfield mask, GLenum filter);
1508
1509 bool
1510 brw_blorp_copytexsubimage(struct brw_context *brw,
1511 struct gl_renderbuffer *src_rb,
1512 struct gl_texture_image *dst_image,
1513 int slice,
1514 int srcX0, int srcY0,
1515 int dstX0, int dstY0,
1516 int width, int height);
1517
1518 /* brw_generate_mipmap.c */
1519 void brw_generate_mipmap(struct gl_context *ctx, GLenum target,
1520 struct gl_texture_object *tex_obj);
1521
1522 void
1523 gen6_get_sample_position(struct gl_context *ctx,
1524 struct gl_framebuffer *fb,
1525 GLuint index,
1526 GLfloat *result);
1527
1528 /* gen8_multisample_state.c */
1529 void gen8_emit_3dstate_sample_pattern(struct brw_context *brw);
1530
1531 /* gen7_l3_state.c */
1532 void brw_emit_l3_state(struct brw_context *brw);
1533
1534 /* gen7_urb.c */
1535 void
1536 gen7_emit_push_constant_state(struct brw_context *brw, unsigned vs_size,
1537 unsigned hs_size, unsigned ds_size,
1538 unsigned gs_size, unsigned fs_size);
1539
1540 void
1541 gen6_upload_urb(struct brw_context *brw, unsigned vs_size,
1542 bool gs_present, unsigned gs_size);
1543 void
1544 gen7_upload_urb(struct brw_context *brw, unsigned vs_size,
1545 bool gs_present, bool tess_present);
1546
1547 /* brw_reset.c */
1548 extern GLenum
1549 brw_get_graphics_reset_status(struct gl_context *ctx);
1550 void
1551 brw_check_for_reset(struct brw_context *brw);
1552
1553 /* brw_compute.c */
1554 extern void
1555 brw_init_compute_functions(struct dd_function_table *functions);
1556
1557 /* brw_program_binary.c */
1558 extern void
1559 brw_program_binary_init(unsigned device_id);
1560 extern void
1561 brw_get_program_binary_driver_sha1(struct gl_context *ctx, uint8_t *sha1);
1562 void brw_serialize_program_binary(struct gl_context *ctx,
1563 struct gl_shader_program *sh_prog,
1564 struct gl_program *prog);
1565 extern void
1566 brw_deserialize_program_binary(struct gl_context *ctx,
1567 struct gl_shader_program *shProg,
1568 struct gl_program *prog);
1569 void
1570 brw_program_serialize_nir(struct gl_context *ctx, struct gl_program *prog);
1571 void
1572 brw_program_deserialize_driver_blob(struct gl_context *ctx,
1573 struct gl_program *prog,
1574 gl_shader_stage stage);
1575
1576 /*======================================================================
1577 * Inline conversion functions. These are better-typed than the
1578 * macros used previously:
1579 */
1580 static inline struct brw_context *
1581 brw_context( struct gl_context *ctx )
1582 {
1583 return (struct brw_context *)ctx;
1584 }
1585
1586 static inline struct brw_program *
1587 brw_program(struct gl_program *p)
1588 {
1589 return (struct brw_program *) p;
1590 }
1591
1592 static inline const struct brw_program *
1593 brw_program_const(const struct gl_program *p)
1594 {
1595 return (const struct brw_program *) p;
1596 }
1597
1598 static inline bool
1599 brw_depth_writes_enabled(const struct brw_context *brw)
1600 {
1601 const struct gl_context *ctx = &brw->ctx;
1602
1603 /* We consider depth writes disabled if the depth function is GL_EQUAL,
1604 * because it would just overwrite the existing depth value with itself.
1605 *
1606 * These bonus depth writes not only use bandwidth, but they also can
1607 * prevent early depth processing. For example, if the pixel shader
1608 * discards, the hardware must invoke the to determine whether or not
1609 * to do the depth write. If writes are disabled, we may still be able
1610 * to do the depth test before the shader, and skip the shader execution.
1611 *
1612 * The Broadwell 3DSTATE_WM_DEPTH_STENCIL documentation also contains
1613 * a programming note saying to disable depth writes for EQUAL.
1614 */
1615 return ctx->Depth.Test && ctx->Depth.Mask && ctx->Depth.Func != GL_EQUAL;
1616 }
1617
1618 void
1619 brw_emit_depthbuffer(struct brw_context *brw);
1620
1621 uint32_t get_hw_prim_for_gl_prim(int mode);
1622
1623 void
1624 gen6_upload_push_constants(struct brw_context *brw,
1625 const struct gl_program *prog,
1626 const struct brw_stage_prog_data *prog_data,
1627 struct brw_stage_state *stage_state);
1628
1629 bool
1630 gen9_use_linear_1d_layout(const struct brw_context *brw,
1631 const struct intel_mipmap_tree *mt);
1632
1633 /* brw_queryformat.c */
1634 void brw_query_internal_format(struct gl_context *ctx, GLenum target,
1635 GLenum internalFormat, GLenum pname,
1636 GLint *params);
1637
1638 #ifdef __cplusplus
1639 }
1640 #endif
1641
1642 #endif