i965: Implement ARB_compute_variable_group_size
[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 /** BO for post-sync nonzero writes for gen6 workaround. */
727 struct brw_bo *workaround_bo;
728 uint8_t pipe_controls_since_last_cs_stall;
729
730 /**
731 * Set of struct brw_bo * that have been rendered to within this batchbuffer
732 * and would need flushing before being used from another cache domain that
733 * isn't coherent with it (i.e. the sampler).
734 */
735 struct hash_table *render_cache;
736
737 /**
738 * Set of struct brw_bo * that have been used as a depth buffer within this
739 * batchbuffer and would need flushing before being used from another cache
740 * domain that isn't coherent with it (i.e. the sampler).
741 */
742 struct set *depth_cache;
743
744 /**
745 * Number of resets observed in the system at context creation.
746 *
747 * This is tracked in the context so that we can determine that another
748 * reset has occurred.
749 */
750 uint32_t reset_count;
751
752 struct intel_batchbuffer batch;
753
754 struct brw_uploader upload;
755
756 /**
757 * Set if rendering has occurred to the drawable's front buffer.
758 *
759 * This is used in the DRI2 case to detect that glFlush should also copy
760 * the contents of the fake front buffer to the real front buffer.
761 */
762 bool front_buffer_dirty;
763
764 /**
765 * True if the __DRIdrawable's current __DRIimageBufferMask is
766 * __DRI_IMAGE_BUFFER_SHARED.
767 */
768 bool is_shared_buffer_bound;
769
770 /**
771 * True if a shared buffer is bound and it has received any rendering since
772 * the previous __DRImutableRenderBufferLoaderExtension::displaySharedBuffer().
773 */
774 bool is_shared_buffer_dirty;
775
776 /** Framerate throttling: @{ */
777 struct brw_bo *throttle_batch[2];
778
779 /* Limit the number of outstanding SwapBuffers by waiting for an earlier
780 * frame of rendering to complete. This gives a very precise cap to the
781 * latency between input and output such that rendering never gets more
782 * than a frame behind the user. (With the caveat that we technically are
783 * not using the SwapBuffers itself as a barrier but the first batch
784 * submitted afterwards, which may be immediately prior to the next
785 * SwapBuffers.)
786 */
787 bool need_swap_throttle;
788
789 /** General throttling, not caught by throttling between SwapBuffers */
790 bool need_flush_throttle;
791 /** @} */
792
793 GLuint stats_wm;
794
795 /**
796 * drirc options:
797 * @{
798 */
799 bool always_flush_batch;
800 bool always_flush_cache;
801 bool disable_throttling;
802 bool precompile;
803 bool dual_color_blend_by_location;
804
805 driOptionCache optionCache;
806 /** @} */
807
808 GLuint primitive; /**< Hardware primitive, such as _3DPRIM_TRILIST. */
809
810 bool object_preemption; /**< Object level preemption enabled. */
811
812 GLenum reduced_primitive;
813
814 /**
815 * Set if we're either a debug context or the INTEL_DEBUG=perf environment
816 * variable is set, this is the flag indicating to do expensive work that
817 * might lead to a perf_debug() call.
818 */
819 bool perf_debug;
820
821 uint64_t max_gtt_map_object_size;
822
823 bool has_hiz;
824 bool has_separate_stencil;
825 bool has_swizzling;
826
827 /** Derived stencil states. */
828 bool stencil_enabled;
829 bool stencil_two_sided;
830 bool stencil_write_enabled;
831 /** Derived polygon state. */
832 bool polygon_front_bit; /**< 0=GL_CCW, 1=GL_CW */
833
834 struct isl_device isl_dev;
835
836 struct blorp_context blorp;
837
838 GLuint NewGLState;
839 struct {
840 struct brw_state_flags pipelines[BRW_NUM_PIPELINES];
841 } state;
842
843 enum brw_pipeline last_pipeline;
844
845 struct brw_cache cache;
846
847 /* Whether a meta-operation is in progress. */
848 bool meta_in_progress;
849
850 /* Whether the last depth/stencil packets were both NULL. */
851 bool no_depth_or_stencil;
852
853 /* The last PMA stall bits programmed. */
854 uint32_t pma_stall_bits;
855
856 /* Whether INTEL_black_render is active. */
857 bool frontend_noop;
858
859 struct {
860 struct {
861 /**
862 * Either the value of gl_BaseVertex for indexed draw calls or the
863 * value of the argument <first> for non-indexed draw calls for the
864 * current _mesa_prim.
865 */
866 int firstvertex;
867
868 /** The value of gl_BaseInstance for the current _mesa_prim. */
869 int gl_baseinstance;
870 } params;
871
872 /**
873 * Buffer and offset used for GL_ARB_shader_draw_parameters which will
874 * point to the indirect buffer for indirect draw calls.
875 */
876 struct brw_bo *draw_params_bo;
877 uint32_t draw_params_offset;
878
879 struct {
880 /**
881 * The value of gl_DrawID for the current _mesa_prim. This always comes
882 * in from it's own vertex buffer since it's not part of the indirect
883 * draw parameters.
884 */
885 int gl_drawid;
886
887 /**
888 * Stores if the current _mesa_prim is an indexed or non-indexed draw
889 * (~0/0). Useful to calculate gl_BaseVertex as an AND of firstvertex
890 * and is_indexed_draw.
891 */
892 int is_indexed_draw;
893 } derived_params;
894
895 /**
896 * Buffer and offset used for GL_ARB_shader_draw_parameters which contains
897 * parameters that are not present in the indirect buffer. They will go in
898 * their own vertex element.
899 */
900 struct brw_bo *derived_draw_params_bo;
901 uint32_t derived_draw_params_offset;
902
903 /**
904 * Pointer to the the buffer storing the indirect draw parameters. It
905 * currently only stores the number of requested draw calls but more
906 * parameters could potentially be added.
907 */
908 struct brw_bo *draw_params_count_bo;
909 uint32_t draw_params_count_offset;
910
911 /**
912 * Draw indirect buffer.
913 */
914 unsigned draw_indirect_stride;
915 GLsizeiptr draw_indirect_offset;
916 struct gl_buffer_object *draw_indirect_data;
917 } draw;
918
919 struct {
920 /**
921 * For gl_NumWorkGroups: If num_work_groups_bo is non NULL, then it is
922 * an indirect call, and num_work_groups_offset is valid. Otherwise,
923 * num_work_groups is set based on glDispatchCompute.
924 */
925 struct brw_bo *num_work_groups_bo;
926 GLintptr num_work_groups_offset;
927 const GLuint *num_work_groups;
928 /**
929 * This is only used alongside ARB_compute_variable_group_size when the
930 * local work group size is variable, otherwise it's NULL.
931 */
932 const GLuint *group_size;
933 } compute;
934
935 struct {
936 struct brw_vertex_element inputs[VERT_ATTRIB_MAX];
937 struct brw_vertex_buffer buffers[VERT_ATTRIB_MAX];
938
939 struct brw_vertex_element *enabled[VERT_ATTRIB_MAX];
940 GLuint nr_enabled;
941 GLuint nr_buffers;
942
943 /* Summary of size and varying of active arrays, so we can check
944 * for changes to this state:
945 */
946 bool index_bounds_valid;
947 unsigned int min_index, max_index;
948
949 /* Offset from start of vertex buffer so we can avoid redefining
950 * the same VB packed over and over again.
951 */
952 unsigned int start_vertex_bias;
953
954 /**
955 * Certain vertex attribute formats aren't natively handled by the
956 * hardware and require special VS code to fix up their values.
957 *
958 * These bitfields indicate which workarounds are needed.
959 */
960 uint8_t attrib_wa_flags[VERT_ATTRIB_MAX];
961
962 /* High bits of the last seen vertex buffer address (for workarounds). */
963 uint16_t last_bo_high_bits[33];
964 } vb;
965
966 struct {
967 /**
968 * Index buffer for this draw_prims call.
969 *
970 * Updates are signaled by BRW_NEW_INDICES.
971 */
972 const struct _mesa_index_buffer *ib;
973
974 /* Updates are signaled by BRW_NEW_INDEX_BUFFER. */
975 struct brw_bo *bo;
976 uint32_t size;
977 unsigned index_size;
978
979 /* Offset to index buffer index to use in CMD_3D_PRIM so that we can
980 * avoid re-uploading the IB packet over and over if we're actually
981 * referencing the same index buffer.
982 */
983 unsigned int start_vertex_offset;
984
985 /* High bits of the last seen index buffer address (for workarounds). */
986 uint16_t last_bo_high_bits;
987
988 /* Used to understand is GPU state of primitive restart is up to date */
989 bool enable_cut_index;
990 } ib;
991
992 /* Active vertex program:
993 */
994 struct gl_program *programs[MESA_SHADER_STAGES];
995
996 /**
997 * Number of samples in ctx->DrawBuffer, updated by BRW_NEW_NUM_SAMPLES so
998 * that we don't have to reemit that state every time we change FBOs.
999 */
1000 unsigned int num_samples;
1001
1002 /* BRW_NEW_URB_ALLOCATIONS:
1003 */
1004 struct {
1005 GLuint vsize; /* vertex size plus header in urb registers */
1006 GLuint gsize; /* GS output size in urb registers */
1007 GLuint hsize; /* Tessellation control output size in urb registers */
1008 GLuint dsize; /* Tessellation evaluation output size in urb registers */
1009 GLuint csize; /* constant buffer size in urb registers */
1010 GLuint sfsize; /* setup data size in urb registers */
1011
1012 bool constrained;
1013
1014 GLuint nr_vs_entries;
1015 GLuint nr_hs_entries;
1016 GLuint nr_ds_entries;
1017 GLuint nr_gs_entries;
1018 GLuint nr_clip_entries;
1019 GLuint nr_sf_entries;
1020 GLuint nr_cs_entries;
1021
1022 GLuint vs_start;
1023 GLuint hs_start;
1024 GLuint ds_start;
1025 GLuint gs_start;
1026 GLuint clip_start;
1027 GLuint sf_start;
1028 GLuint cs_start;
1029 /**
1030 * URB size in the current configuration. The units this is expressed
1031 * in are somewhat inconsistent, see gen_device_info::urb::size.
1032 *
1033 * FINISHME: Represent the URB size consistently in KB on all platforms.
1034 */
1035 GLuint size;
1036
1037 /* True if the most recently sent _3DSTATE_URB message allocated
1038 * URB space for the GS.
1039 */
1040 bool gs_present;
1041
1042 /* True if the most recently sent _3DSTATE_URB message allocated
1043 * URB space for the HS and DS.
1044 */
1045 bool tess_present;
1046 } urb;
1047
1048
1049 /* BRW_NEW_PUSH_CONSTANT_ALLOCATION */
1050 struct {
1051 GLuint wm_start; /**< pos of first wm const in CURBE buffer */
1052 GLuint wm_size; /**< number of float[4] consts, multiple of 16 */
1053 GLuint clip_start;
1054 GLuint clip_size;
1055 GLuint vs_start;
1056 GLuint vs_size;
1057 GLuint total_size;
1058
1059 /**
1060 * Pointer to the (intel_upload.c-generated) BO containing the uniforms
1061 * for upload to the CURBE.
1062 */
1063 struct brw_bo *curbe_bo;
1064 /** Offset within curbe_bo of space for current curbe entry */
1065 GLuint curbe_offset;
1066 } curbe;
1067
1068 /**
1069 * Layout of vertex data exiting the geometry portion of the pipleine.
1070 * This comes from the last enabled shader stage (GS, DS, or VS).
1071 *
1072 * BRW_NEW_VUE_MAP_GEOM_OUT is flagged when the VUE map changes.
1073 */
1074 struct brw_vue_map vue_map_geom_out;
1075
1076 struct {
1077 struct brw_stage_state base;
1078 } vs;
1079
1080 struct {
1081 struct brw_stage_state base;
1082 } tcs;
1083
1084 struct {
1085 struct brw_stage_state base;
1086 } tes;
1087
1088 struct {
1089 struct brw_stage_state base;
1090
1091 /**
1092 * True if the 3DSTATE_GS command most recently emitted to the 3D
1093 * pipeline enabled the GS; false otherwise.
1094 */
1095 bool enabled;
1096 } gs;
1097
1098 struct {
1099 struct brw_ff_gs_prog_data *prog_data;
1100
1101 bool prog_active;
1102 /** Offset in the program cache to the CLIP program pre-gen6 */
1103 uint32_t prog_offset;
1104 uint32_t state_offset;
1105
1106 uint32_t bind_bo_offset;
1107 /**
1108 * Surface offsets for the binding table. We only need surfaces to
1109 * implement transform feedback so BRW_MAX_SOL_BINDINGS is all that we
1110 * need in this case.
1111 */
1112 uint32_t surf_offset[BRW_MAX_SOL_BINDINGS];
1113 } ff_gs;
1114
1115 struct {
1116 struct brw_clip_prog_data *prog_data;
1117
1118 /** Offset in the program cache to the CLIP program pre-gen6 */
1119 uint32_t prog_offset;
1120
1121 /* Offset in the batch to the CLIP state on pre-gen6. */
1122 uint32_t state_offset;
1123
1124 /* As of gen6, this is the offset in the batch to the CLIP VP,
1125 * instead of vp_bo.
1126 */
1127 uint32_t vp_offset;
1128
1129 /**
1130 * The number of viewports to use. If gl_ViewportIndex is written,
1131 * we can have up to ctx->Const.MaxViewports viewports. If not,
1132 * the viewport index is always 0, so we can only emit one.
1133 */
1134 uint8_t viewport_count;
1135 } clip;
1136
1137
1138 struct {
1139 struct brw_sf_prog_data *prog_data;
1140
1141 /** Offset in the program cache to the CLIP program pre-gen6 */
1142 uint32_t prog_offset;
1143 uint32_t state_offset;
1144 uint32_t vp_offset;
1145 } sf;
1146
1147 struct {
1148 struct brw_stage_state base;
1149
1150 /**
1151 * Buffer object used in place of multisampled null render targets on
1152 * Gen6. See brw_emit_null_surface_state().
1153 */
1154 struct brw_bo *multisampled_null_render_target_bo;
1155
1156 float offset_clamp;
1157 } wm;
1158
1159 struct {
1160 struct brw_stage_state base;
1161 } cs;
1162
1163 struct {
1164 uint32_t state_offset;
1165 uint32_t blend_state_offset;
1166 uint32_t depth_stencil_state_offset;
1167 uint32_t vp_offset;
1168 } cc;
1169
1170 struct {
1171 struct brw_query_object *obj;
1172 bool begin_emitted;
1173 } query;
1174
1175 struct {
1176 enum brw_predicate_state state;
1177 bool supported;
1178 } predicate;
1179
1180 struct gen_perf_context *perf_ctx;
1181
1182 int num_atoms[BRW_NUM_PIPELINES];
1183 const struct brw_tracked_state render_atoms[76];
1184 const struct brw_tracked_state compute_atoms[11];
1185
1186 const enum isl_format *mesa_to_isl_render_format;
1187 const bool *mesa_format_supports_render;
1188
1189 /* PrimitiveRestart */
1190 struct {
1191 bool in_progress;
1192 bool enable_cut_index;
1193 } prim_restart;
1194
1195 /** Computed depth/stencil/hiz state from the current attached
1196 * renderbuffers, valid only during the drawing state upload loop after
1197 * brw_workaround_depthstencil_alignment().
1198 */
1199 struct {
1200 /* Inter-tile (page-aligned) byte offsets. */
1201 uint32_t depth_offset;
1202 /* Intra-tile x,y offsets for drawing to combined depth-stencil. Only
1203 * used for Gen < 6.
1204 */
1205 uint32_t tile_x, tile_y;
1206 } depthstencil;
1207
1208 uint32_t num_instances;
1209 int basevertex;
1210 int baseinstance;
1211
1212 struct {
1213 const struct gen_l3_config *config;
1214 } l3;
1215
1216 struct {
1217 struct brw_bo *bo;
1218 const char **names;
1219 int *ids;
1220 enum shader_time_shader_type *types;
1221 struct shader_times *cumulative;
1222 int num_entries;
1223 int max_entries;
1224 double report_time;
1225 } shader_time;
1226
1227 struct brw_fast_clear_state *fast_clear_state;
1228
1229 /* Array of aux usages to use for drawing. Aux usage for render targets is
1230 * a bit more complex than simply calling a single function so we need some
1231 * way of passing it form brw_draw.c to surface state setup.
1232 */
1233 enum isl_aux_usage draw_aux_usage[MAX_DRAW_BUFFERS];
1234
1235 enum gen9_astc5x5_wa_tex_type gen9_astc5x5_wa_tex_mask;
1236
1237 /** Last rendering scale argument provided to brw_emit_hashing_mode(). */
1238 unsigned current_hash_scale;
1239
1240 __DRIcontext *driContext;
1241 struct intel_screen *screen;
1242 };
1243
1244 /* brw_clear.c */
1245 extern void intelInitClearFuncs(struct dd_function_table *functions);
1246
1247 /*======================================================================
1248 * brw_context.c
1249 */
1250 extern const char *const brw_vendor_string;
1251
1252 extern const char *
1253 brw_get_renderer_string(const struct intel_screen *screen);
1254
1255 enum {
1256 DRI_CONF_BO_REUSE_DISABLED,
1257 DRI_CONF_BO_REUSE_ALL
1258 };
1259
1260 void intel_update_renderbuffers(__DRIcontext *context,
1261 __DRIdrawable *drawable);
1262 void intel_prepare_render(struct brw_context *brw);
1263
1264 void gen9_apply_single_tex_astc5x5_wa(struct brw_context *brw,
1265 mesa_format format,
1266 enum isl_aux_usage aux_usage);
1267
1268 void brw_predraw_resolve_inputs(struct brw_context *brw, bool rendering,
1269 bool *draw_aux_buffer_disabled);
1270
1271 void intel_resolve_for_dri2_flush(struct brw_context *brw,
1272 __DRIdrawable *drawable);
1273
1274 GLboolean brwCreateContext(gl_api api,
1275 const struct gl_config *mesaVis,
1276 __DRIcontext *driContextPriv,
1277 const struct __DriverContextConfig *ctx_config,
1278 unsigned *error,
1279 void *sharedContextPrivate);
1280
1281 /*======================================================================
1282 * brw_misc_state.c
1283 */
1284 void brw_workaround_depthstencil_alignment(struct brw_context *brw,
1285 GLbitfield clear_mask);
1286 void brw_emit_hashing_mode(struct brw_context *brw, unsigned width,
1287 unsigned height, unsigned scale);
1288
1289 /* brw_object_purgeable.c */
1290 void brw_init_object_purgeable_functions(struct dd_function_table *functions);
1291
1292 /*======================================================================
1293 * brw_queryobj.c
1294 */
1295 void brw_init_common_queryobj_functions(struct dd_function_table *functions);
1296 void gen4_init_queryobj_functions(struct dd_function_table *functions);
1297 void brw_emit_query_begin(struct brw_context *brw);
1298 void brw_emit_query_end(struct brw_context *brw);
1299 void brw_query_counter(struct gl_context *ctx, struct gl_query_object *q);
1300 bool brw_is_query_pipelined(struct brw_query_object *query);
1301 uint64_t brw_raw_timestamp_delta(struct brw_context *brw,
1302 uint64_t time0, uint64_t time1);
1303
1304 /** gen6_queryobj.c */
1305 void gen6_init_queryobj_functions(struct dd_function_table *functions);
1306 void brw_write_timestamp(struct brw_context *brw, struct brw_bo *bo, int idx);
1307 void brw_write_depth_count(struct brw_context *brw, struct brw_bo *bo, int idx);
1308
1309 /** hsw_queryobj.c */
1310 void hsw_overflow_result_to_gpr0(struct brw_context *brw,
1311 struct brw_query_object *query,
1312 int count);
1313 void hsw_init_queryobj_functions(struct dd_function_table *functions);
1314
1315 /** brw_conditional_render.c */
1316 void brw_init_conditional_render_functions(struct dd_function_table *functions);
1317 bool brw_check_conditional_render(struct brw_context *brw);
1318
1319 /** intel_batchbuffer.c */
1320 void brw_load_register_mem(struct brw_context *brw,
1321 uint32_t reg,
1322 struct brw_bo *bo,
1323 uint32_t offset);
1324 void brw_load_register_mem64(struct brw_context *brw,
1325 uint32_t reg,
1326 struct brw_bo *bo,
1327 uint32_t offset);
1328 void brw_store_register_mem32(struct brw_context *brw,
1329 struct brw_bo *bo, uint32_t reg, uint32_t offset);
1330 void brw_store_register_mem64(struct brw_context *brw,
1331 struct brw_bo *bo, uint32_t reg, uint32_t offset);
1332 void brw_load_register_imm32(struct brw_context *brw,
1333 uint32_t reg, uint32_t imm);
1334 void brw_load_register_imm64(struct brw_context *brw,
1335 uint32_t reg, uint64_t imm);
1336 void brw_load_register_reg(struct brw_context *brw, uint32_t dst,
1337 uint32_t src);
1338 void brw_load_register_reg64(struct brw_context *brw, uint32_t dst,
1339 uint32_t src);
1340 void brw_store_data_imm32(struct brw_context *brw, struct brw_bo *bo,
1341 uint32_t offset, uint32_t imm);
1342 void brw_store_data_imm64(struct brw_context *brw, struct brw_bo *bo,
1343 uint32_t offset, uint64_t imm);
1344
1345 /*======================================================================
1346 * intel_tex_validate.c
1347 */
1348 void brw_validate_textures( struct brw_context *brw );
1349
1350
1351 /*======================================================================
1352 * brw_program.c
1353 */
1354 void brwInitFragProgFuncs( struct dd_function_table *functions );
1355
1356 void brw_get_scratch_bo(struct brw_context *brw,
1357 struct brw_bo **scratch_bo, int size);
1358 void brw_alloc_stage_scratch(struct brw_context *brw,
1359 struct brw_stage_state *stage_state,
1360 unsigned per_thread_size);
1361 void brw_init_shader_time(struct brw_context *brw);
1362 int brw_get_shader_time_index(struct brw_context *brw,
1363 struct gl_program *prog,
1364 enum shader_time_shader_type type,
1365 bool is_glsl_sh);
1366 void brw_collect_and_report_shader_time(struct brw_context *brw);
1367 void brw_destroy_shader_time(struct brw_context *brw);
1368
1369 /* brw_urb.c
1370 */
1371 void brw_calculate_urb_fence(struct brw_context *brw, unsigned csize,
1372 unsigned vsize, unsigned sfsize);
1373 void brw_upload_urb_fence(struct brw_context *brw);
1374
1375 /* brw_curbe.c
1376 */
1377 void brw_upload_cs_urb_state(struct brw_context *brw);
1378
1379 /* brw_vs.c */
1380 gl_clip_plane *brw_select_clip_planes(struct gl_context *ctx);
1381
1382 /* brw_draw_upload.c */
1383 unsigned brw_get_vertex_surface_type(struct brw_context *brw,
1384 const struct gl_vertex_format *glformat);
1385
1386 static inline unsigned
1387 brw_get_index_type(unsigned index_size)
1388 {
1389 /* The hw needs 0x00, 0x01, and 0x02 for ubyte, ushort, and uint,
1390 * respectively.
1391 */
1392 return index_size >> 1;
1393 }
1394
1395 void brw_prepare_vertices(struct brw_context *brw);
1396
1397 /* brw_wm_surface_state.c */
1398 void brw_update_buffer_texture_surface(struct gl_context *ctx,
1399 unsigned unit,
1400 uint32_t *surf_offset);
1401 void
1402 brw_update_sol_surface(struct brw_context *brw,
1403 struct gl_buffer_object *buffer_obj,
1404 uint32_t *out_offset, unsigned num_vector_components,
1405 unsigned stride_dwords, unsigned offset_dwords);
1406 void brw_upload_ubo_surfaces(struct brw_context *brw, struct gl_program *prog,
1407 struct brw_stage_state *stage_state,
1408 struct brw_stage_prog_data *prog_data);
1409 void brw_upload_image_surfaces(struct brw_context *brw,
1410 const struct gl_program *prog,
1411 struct brw_stage_state *stage_state,
1412 struct brw_stage_prog_data *prog_data);
1413
1414 /* brw_surface_formats.c */
1415 void intel_screen_init_surface_formats(struct intel_screen *screen);
1416 void brw_init_surface_formats(struct brw_context *brw);
1417 bool brw_render_target_supported(struct brw_context *brw,
1418 struct gl_renderbuffer *rb);
1419 uint32_t brw_depth_format(struct brw_context *brw, mesa_format format);
1420
1421 /* brw_performance_query.c */
1422 void brw_init_performance_queries(struct brw_context *brw);
1423
1424 /* intel_extensions.c */
1425 extern void intelInitExtensions(struct gl_context *ctx);
1426
1427 /* intel_state.c */
1428 extern int intel_translate_shadow_compare_func(GLenum func);
1429 extern int intel_translate_compare_func(GLenum func);
1430 extern int intel_translate_stencil_op(GLenum op);
1431
1432 /* brw_sync.c */
1433 void brw_init_syncobj_functions(struct dd_function_table *functions);
1434
1435 /* gen6_sol.c */
1436 struct gl_transform_feedback_object *
1437 brw_new_transform_feedback(struct gl_context *ctx, GLuint name);
1438 void
1439 brw_delete_transform_feedback(struct gl_context *ctx,
1440 struct gl_transform_feedback_object *obj);
1441 void
1442 brw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1443 struct gl_transform_feedback_object *obj);
1444 void
1445 brw_end_transform_feedback(struct gl_context *ctx,
1446 struct gl_transform_feedback_object *obj);
1447 void
1448 brw_pause_transform_feedback(struct gl_context *ctx,
1449 struct gl_transform_feedback_object *obj);
1450 void
1451 brw_resume_transform_feedback(struct gl_context *ctx,
1452 struct gl_transform_feedback_object *obj);
1453 void
1454 brw_save_primitives_written_counters(struct brw_context *brw,
1455 struct brw_transform_feedback_object *obj);
1456 GLsizei
1457 brw_get_transform_feedback_vertex_count(struct gl_context *ctx,
1458 struct gl_transform_feedback_object *obj,
1459 GLuint stream);
1460
1461 /* gen7_sol_state.c */
1462 void
1463 gen7_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1464 struct gl_transform_feedback_object *obj);
1465 void
1466 gen7_end_transform_feedback(struct gl_context *ctx,
1467 struct gl_transform_feedback_object *obj);
1468 void
1469 gen7_pause_transform_feedback(struct gl_context *ctx,
1470 struct gl_transform_feedback_object *obj);
1471 void
1472 gen7_resume_transform_feedback(struct gl_context *ctx,
1473 struct gl_transform_feedback_object *obj);
1474
1475 /* hsw_sol.c */
1476 void
1477 hsw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1478 struct gl_transform_feedback_object *obj);
1479 void
1480 hsw_end_transform_feedback(struct gl_context *ctx,
1481 struct gl_transform_feedback_object *obj);
1482 void
1483 hsw_pause_transform_feedback(struct gl_context *ctx,
1484 struct gl_transform_feedback_object *obj);
1485 void
1486 hsw_resume_transform_feedback(struct gl_context *ctx,
1487 struct gl_transform_feedback_object *obj);
1488
1489 /* brw_blorp_blit.cpp */
1490 GLbitfield
1491 brw_blorp_framebuffer(struct brw_context *brw,
1492 struct gl_framebuffer *readFb,
1493 struct gl_framebuffer *drawFb,
1494 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1495 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
1496 GLbitfield mask, GLenum filter);
1497
1498 bool
1499 brw_blorp_copytexsubimage(struct brw_context *brw,
1500 struct gl_renderbuffer *src_rb,
1501 struct gl_texture_image *dst_image,
1502 int slice,
1503 int srcX0, int srcY0,
1504 int dstX0, int dstY0,
1505 int width, int height);
1506
1507 /* brw_generate_mipmap.c */
1508 void brw_generate_mipmap(struct gl_context *ctx, GLenum target,
1509 struct gl_texture_object *tex_obj);
1510
1511 void
1512 gen6_get_sample_position(struct gl_context *ctx,
1513 struct gl_framebuffer *fb,
1514 GLuint index,
1515 GLfloat *result);
1516 void
1517 gen6_set_sample_maps(struct gl_context *ctx);
1518
1519 /* gen8_multisample_state.c */
1520 void gen8_emit_3dstate_sample_pattern(struct brw_context *brw);
1521
1522 /* gen7_l3_state.c */
1523 void brw_emit_l3_state(struct brw_context *brw);
1524
1525 /* gen7_urb.c */
1526 void
1527 gen7_emit_push_constant_state(struct brw_context *brw, unsigned vs_size,
1528 unsigned hs_size, unsigned ds_size,
1529 unsigned gs_size, unsigned fs_size);
1530
1531 void
1532 gen6_upload_urb(struct brw_context *brw, unsigned vs_size,
1533 bool gs_present, unsigned gs_size);
1534 void
1535 gen7_upload_urb(struct brw_context *brw, unsigned vs_size,
1536 bool gs_present, bool tess_present);
1537
1538 /* brw_reset.c */
1539 extern GLenum
1540 brw_get_graphics_reset_status(struct gl_context *ctx);
1541 void
1542 brw_check_for_reset(struct brw_context *brw);
1543
1544 /* brw_compute.c */
1545 extern void
1546 brw_init_compute_functions(struct dd_function_table *functions);
1547
1548 /* brw_program_binary.c */
1549 extern void
1550 brw_program_binary_init(unsigned device_id);
1551 extern void
1552 brw_get_program_binary_driver_sha1(struct gl_context *ctx, uint8_t *sha1);
1553 void brw_serialize_program_binary(struct gl_context *ctx,
1554 struct gl_shader_program *sh_prog,
1555 struct gl_program *prog);
1556 extern void
1557 brw_deserialize_program_binary(struct gl_context *ctx,
1558 struct gl_shader_program *shProg,
1559 struct gl_program *prog);
1560 void
1561 brw_program_serialize_nir(struct gl_context *ctx, struct gl_program *prog);
1562 void
1563 brw_program_deserialize_driver_blob(struct gl_context *ctx,
1564 struct gl_program *prog,
1565 gl_shader_stage stage);
1566
1567 /*======================================================================
1568 * Inline conversion functions. These are better-typed than the
1569 * macros used previously:
1570 */
1571 static inline struct brw_context *
1572 brw_context( struct gl_context *ctx )
1573 {
1574 return (struct brw_context *)ctx;
1575 }
1576
1577 static inline struct brw_program *
1578 brw_program(struct gl_program *p)
1579 {
1580 return (struct brw_program *) p;
1581 }
1582
1583 static inline const struct brw_program *
1584 brw_program_const(const struct gl_program *p)
1585 {
1586 return (const struct brw_program *) p;
1587 }
1588
1589 static inline bool
1590 brw_depth_writes_enabled(const struct brw_context *brw)
1591 {
1592 const struct gl_context *ctx = &brw->ctx;
1593
1594 /* We consider depth writes disabled if the depth function is GL_EQUAL,
1595 * because it would just overwrite the existing depth value with itself.
1596 *
1597 * These bonus depth writes not only use bandwidth, but they also can
1598 * prevent early depth processing. For example, if the pixel shader
1599 * discards, the hardware must invoke the to determine whether or not
1600 * to do the depth write. If writes are disabled, we may still be able
1601 * to do the depth test before the shader, and skip the shader execution.
1602 *
1603 * The Broadwell 3DSTATE_WM_DEPTH_STENCIL documentation also contains
1604 * a programming note saying to disable depth writes for EQUAL.
1605 */
1606 return ctx->Depth.Test && ctx->Depth.Mask && ctx->Depth.Func != GL_EQUAL;
1607 }
1608
1609 void
1610 brw_emit_depthbuffer(struct brw_context *brw);
1611
1612 uint32_t get_hw_prim_for_gl_prim(int mode);
1613
1614 void
1615 gen6_upload_push_constants(struct brw_context *brw,
1616 const struct gl_program *prog,
1617 const struct brw_stage_prog_data *prog_data,
1618 struct brw_stage_state *stage_state);
1619
1620 bool
1621 gen9_use_linear_1d_layout(const struct brw_context *brw,
1622 const struct intel_mipmap_tree *mt);
1623
1624 /* brw_queryformat.c */
1625 void brw_query_internal_format(struct gl_context *ctx, GLenum target,
1626 GLenum internalFormat, GLenum pname,
1627 GLint *params);
1628
1629 #ifdef __cplusplus
1630 }
1631 #endif
1632
1633 #endif