gallium/u_threaded: convert dividing by index_size to a bit shift
[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
55 #ifdef __cplusplus
56 extern "C" {
57 #endif
58 /* Glossary:
59 *
60 * URB - uniform resource buffer. A mid-sized buffer which is
61 * partitioned between the fixed function units and used for passing
62 * values (vertices, primitives, constants) between them.
63 *
64 * CURBE - constant URB entry. An urb region (entry) used to hold
65 * constant values which the fixed function units can be instructed to
66 * preload into the GRF when spawning a thread.
67 *
68 * VUE - vertex URB entry. An urb entry holding a vertex and usually
69 * a vertex header. The header contains control information and
70 * things like primitive type, Begin/end flags and clip codes.
71 *
72 * PUE - primitive URB entry. An urb entry produced by the setup (SF)
73 * unit holding rasterization and interpolation parameters.
74 *
75 * GRF - general register file. One of several register files
76 * addressable by programmed threads. The inputs (r0, payload, curbe,
77 * urb) of the thread are preloaded to this area before the thread is
78 * spawned. The registers are individually 8 dwords wide and suitable
79 * for general usage. Registers holding thread input values are not
80 * special and may be overwritten.
81 *
82 * MRF - message register file. Threads communicate (and terminate)
83 * by sending messages. Message parameters are placed in contiguous
84 * MRF registers. All program output is via these messages. URB
85 * entries are populated by sending a message to the shared URB
86 * function containing the new data, together with a control word,
87 * often an unmodified copy of R0.
88 *
89 * R0 - GRF register 0. Typically holds control information used when
90 * sending messages to other threads.
91 *
92 * EU or GEN4 EU: The name of the programmable subsystem of the
93 * i965 hardware. Threads are executed by the EU, the registers
94 * described above are part of the EU architecture.
95 *
96 * Fixed function units:
97 *
98 * CS - Command streamer. Notional first unit, little software
99 * interaction. Holds the URB entries used for constant data, ie the
100 * CURBEs.
101 *
102 * VF/VS - Vertex Fetch / Vertex Shader. The fixed function part of
103 * this unit is responsible for pulling vertices out of vertex buffers
104 * in vram and injecting them into the processing pipe as VUEs. If
105 * enabled, it first passes them to a VS thread which is a good place
106 * for the driver to implement any active vertex shader.
107 *
108 * HS - Hull Shader (Tessellation Control Shader)
109 *
110 * TE - Tessellation Engine (Tessellation Primitive Generation)
111 *
112 * DS - Domain Shader (Tessellation Evaluation Shader)
113 *
114 * GS - Geometry Shader. This corresponds to a new DX10 concept. If
115 * enabled, incoming strips etc are passed to GS threads in individual
116 * line/triangle/point units. The GS thread may perform arbitary
117 * computation and emit whatever primtives with whatever vertices it
118 * chooses. This makes GS an excellent place to implement GL's
119 * unfilled polygon modes, though of course it is capable of much
120 * more. Additionally, GS is used to translate away primitives not
121 * handled by latter units, including Quads and Lineloops.
122 *
123 * CS - Clipper. Mesa's clipping algorithms are imported to run on
124 * this unit. The fixed function part performs cliptesting against
125 * the 6 fixed clipplanes and makes descisions on whether or not the
126 * incoming primitive needs to be passed to a thread for clipping.
127 * User clip planes are handled via cooperation with the VS thread.
128 *
129 * SF - Strips Fans or Setup: Triangles are prepared for
130 * rasterization. Interpolation coefficients are calculated.
131 * Flatshading and two-side lighting usually performed here.
132 *
133 * WM - Windower. Interpolation of vertex attributes performed here.
134 * Fragment shader implemented here. SIMD aspects of EU taken full
135 * advantage of, as pixels are processed in blocks of 16.
136 *
137 * CC - Color Calculator. No EU threads associated with this unit.
138 * Handles blending and (presumably) depth and stencil testing.
139 */
140
141 struct brw_context;
142 struct brw_inst;
143 struct brw_vs_prog_key;
144 struct brw_vue_prog_key;
145 struct brw_wm_prog_key;
146 struct brw_wm_prog_data;
147 struct brw_cs_prog_key;
148 struct brw_cs_prog_data;
149
150 enum brw_pipeline {
151 BRW_RENDER_PIPELINE,
152 BRW_COMPUTE_PIPELINE,
153
154 BRW_NUM_PIPELINES
155 };
156
157 enum brw_cache_id {
158 BRW_CACHE_FS_PROG,
159 BRW_CACHE_BLORP_PROG,
160 BRW_CACHE_SF_PROG,
161 BRW_CACHE_VS_PROG,
162 BRW_CACHE_FF_GS_PROG,
163 BRW_CACHE_GS_PROG,
164 BRW_CACHE_TCS_PROG,
165 BRW_CACHE_TES_PROG,
166 BRW_CACHE_CLIP_PROG,
167 BRW_CACHE_CS_PROG,
168
169 BRW_MAX_CACHE
170 };
171
172 enum gen9_astc5x5_wa_tex_type {
173 GEN9_ASTC5X5_WA_TEX_TYPE_ASTC5x5 = 1 << 0,
174 GEN9_ASTC5X5_WA_TEX_TYPE_AUX = 1 << 1,
175 };
176
177 enum brw_state_id {
178 /* brw_cache_ids must come first - see brw_program_cache.c */
179 BRW_STATE_URB_FENCE = BRW_MAX_CACHE,
180 BRW_STATE_FRAGMENT_PROGRAM,
181 BRW_STATE_GEOMETRY_PROGRAM,
182 BRW_STATE_TESS_PROGRAMS,
183 BRW_STATE_VERTEX_PROGRAM,
184 BRW_STATE_REDUCED_PRIMITIVE,
185 BRW_STATE_PATCH_PRIMITIVE,
186 BRW_STATE_PRIMITIVE,
187 BRW_STATE_CONTEXT,
188 BRW_STATE_PSP,
189 BRW_STATE_SURFACES,
190 BRW_STATE_BINDING_TABLE_POINTERS,
191 BRW_STATE_INDICES,
192 BRW_STATE_VERTICES,
193 BRW_STATE_DEFAULT_TESS_LEVELS,
194 BRW_STATE_BATCH,
195 BRW_STATE_INDEX_BUFFER,
196 BRW_STATE_VS_CONSTBUF,
197 BRW_STATE_TCS_CONSTBUF,
198 BRW_STATE_TES_CONSTBUF,
199 BRW_STATE_GS_CONSTBUF,
200 BRW_STATE_PROGRAM_CACHE,
201 BRW_STATE_STATE_BASE_ADDRESS,
202 BRW_STATE_VUE_MAP_GEOM_OUT,
203 BRW_STATE_TRANSFORM_FEEDBACK,
204 BRW_STATE_RASTERIZER_DISCARD,
205 BRW_STATE_STATS_WM,
206 BRW_STATE_UNIFORM_BUFFER,
207 BRW_STATE_IMAGE_UNITS,
208 BRW_STATE_META_IN_PROGRESS,
209 BRW_STATE_PUSH_CONSTANT_ALLOCATION,
210 BRW_STATE_NUM_SAMPLES,
211 BRW_STATE_TEXTURE_BUFFER,
212 BRW_STATE_GEN4_UNIT_STATE,
213 BRW_STATE_CC_VP,
214 BRW_STATE_SF_VP,
215 BRW_STATE_CLIP_VP,
216 BRW_STATE_SAMPLER_STATE_TABLE,
217 BRW_STATE_VS_ATTRIB_WORKAROUNDS,
218 BRW_STATE_COMPUTE_PROGRAM,
219 BRW_STATE_CS_WORK_GROUPS,
220 BRW_STATE_URB_SIZE,
221 BRW_STATE_CC_STATE,
222 BRW_STATE_BLORP,
223 BRW_STATE_VIEWPORT_COUNT,
224 BRW_STATE_CONSERVATIVE_RASTERIZATION,
225 BRW_STATE_DRAW_CALL,
226 BRW_STATE_AUX,
227 BRW_NUM_STATE_BITS
228 };
229
230 /**
231 * BRW_NEW_*_PROG_DATA and BRW_NEW_*_PROGRAM are similar, but distinct.
232 *
233 * BRW_NEW_*_PROGRAM relates to the gl_shader_program/gl_program structures.
234 * When the currently bound shader program differs from the previous draw
235 * call, these will be flagged. They cover brw->{stage}_program and
236 * ctx->{Stage}Program->_Current.
237 *
238 * BRW_NEW_*_PROG_DATA is flagged when the effective shaders change, from a
239 * driver perspective. Even if the same shader is bound at the API level,
240 * we may need to switch between multiple versions of that shader to handle
241 * changes in non-orthagonal state.
242 *
243 * Additionally, multiple shader programs may have identical vertex shaders
244 * (for example), or compile down to the same code in the backend. We combine
245 * those into a single program cache entry.
246 *
247 * BRW_NEW_*_PROG_DATA occurs when switching program cache entries, which
248 * covers the brw_*_prog_data structures, and brw->*.prog_offset.
249 */
250 #define BRW_NEW_FS_PROG_DATA (1ull << BRW_CACHE_FS_PROG)
251 /* XXX: The BRW_NEW_BLORP_BLIT_PROG_DATA dirty bit is unused (as BLORP doesn't
252 * use the normal state upload paths), but the cache is still used. To avoid
253 * polluting the brw_program_cache code with special cases, we retain the
254 * dirty bit for now. It should eventually be removed.
255 */
256 #define BRW_NEW_BLORP_BLIT_PROG_DATA (1ull << BRW_CACHE_BLORP_PROG)
257 #define BRW_NEW_SF_PROG_DATA (1ull << BRW_CACHE_SF_PROG)
258 #define BRW_NEW_VS_PROG_DATA (1ull << BRW_CACHE_VS_PROG)
259 #define BRW_NEW_FF_GS_PROG_DATA (1ull << BRW_CACHE_FF_GS_PROG)
260 #define BRW_NEW_GS_PROG_DATA (1ull << BRW_CACHE_GS_PROG)
261 #define BRW_NEW_TCS_PROG_DATA (1ull << BRW_CACHE_TCS_PROG)
262 #define BRW_NEW_TES_PROG_DATA (1ull << BRW_CACHE_TES_PROG)
263 #define BRW_NEW_CLIP_PROG_DATA (1ull << BRW_CACHE_CLIP_PROG)
264 #define BRW_NEW_CS_PROG_DATA (1ull << BRW_CACHE_CS_PROG)
265 #define BRW_NEW_URB_FENCE (1ull << BRW_STATE_URB_FENCE)
266 #define BRW_NEW_FRAGMENT_PROGRAM (1ull << BRW_STATE_FRAGMENT_PROGRAM)
267 #define BRW_NEW_GEOMETRY_PROGRAM (1ull << BRW_STATE_GEOMETRY_PROGRAM)
268 #define BRW_NEW_TESS_PROGRAMS (1ull << BRW_STATE_TESS_PROGRAMS)
269 #define BRW_NEW_VERTEX_PROGRAM (1ull << BRW_STATE_VERTEX_PROGRAM)
270 #define BRW_NEW_REDUCED_PRIMITIVE (1ull << BRW_STATE_REDUCED_PRIMITIVE)
271 #define BRW_NEW_PATCH_PRIMITIVE (1ull << BRW_STATE_PATCH_PRIMITIVE)
272 #define BRW_NEW_PRIMITIVE (1ull << BRW_STATE_PRIMITIVE)
273 #define BRW_NEW_CONTEXT (1ull << BRW_STATE_CONTEXT)
274 #define BRW_NEW_PSP (1ull << BRW_STATE_PSP)
275 #define BRW_NEW_SURFACES (1ull << BRW_STATE_SURFACES)
276 #define BRW_NEW_BINDING_TABLE_POINTERS (1ull << BRW_STATE_BINDING_TABLE_POINTERS)
277 #define BRW_NEW_INDICES (1ull << BRW_STATE_INDICES)
278 #define BRW_NEW_VERTICES (1ull << BRW_STATE_VERTICES)
279 #define BRW_NEW_DEFAULT_TESS_LEVELS (1ull << BRW_STATE_DEFAULT_TESS_LEVELS)
280 /**
281 * Used for any batch entry with a relocated pointer that will be used
282 * by any 3D rendering.
283 */
284 #define BRW_NEW_BATCH (1ull << BRW_STATE_BATCH)
285 /** \see brw.state.depth_region */
286 #define BRW_NEW_INDEX_BUFFER (1ull << BRW_STATE_INDEX_BUFFER)
287 #define BRW_NEW_VS_CONSTBUF (1ull << BRW_STATE_VS_CONSTBUF)
288 #define BRW_NEW_TCS_CONSTBUF (1ull << BRW_STATE_TCS_CONSTBUF)
289 #define BRW_NEW_TES_CONSTBUF (1ull << BRW_STATE_TES_CONSTBUF)
290 #define BRW_NEW_GS_CONSTBUF (1ull << BRW_STATE_GS_CONSTBUF)
291 #define BRW_NEW_PROGRAM_CACHE (1ull << BRW_STATE_PROGRAM_CACHE)
292 #define BRW_NEW_STATE_BASE_ADDRESS (1ull << BRW_STATE_STATE_BASE_ADDRESS)
293 #define BRW_NEW_VUE_MAP_GEOM_OUT (1ull << BRW_STATE_VUE_MAP_GEOM_OUT)
294 #define BRW_NEW_VIEWPORT_COUNT (1ull << BRW_STATE_VIEWPORT_COUNT)
295 #define BRW_NEW_TRANSFORM_FEEDBACK (1ull << BRW_STATE_TRANSFORM_FEEDBACK)
296 #define BRW_NEW_RASTERIZER_DISCARD (1ull << BRW_STATE_RASTERIZER_DISCARD)
297 #define BRW_NEW_STATS_WM (1ull << BRW_STATE_STATS_WM)
298 #define BRW_NEW_UNIFORM_BUFFER (1ull << BRW_STATE_UNIFORM_BUFFER)
299 #define BRW_NEW_IMAGE_UNITS (1ull << BRW_STATE_IMAGE_UNITS)
300 #define BRW_NEW_META_IN_PROGRESS (1ull << BRW_STATE_META_IN_PROGRESS)
301 #define BRW_NEW_PUSH_CONSTANT_ALLOCATION (1ull << BRW_STATE_PUSH_CONSTANT_ALLOCATION)
302 #define BRW_NEW_NUM_SAMPLES (1ull << BRW_STATE_NUM_SAMPLES)
303 #define BRW_NEW_TEXTURE_BUFFER (1ull << BRW_STATE_TEXTURE_BUFFER)
304 #define BRW_NEW_GEN4_UNIT_STATE (1ull << BRW_STATE_GEN4_UNIT_STATE)
305 #define BRW_NEW_CC_VP (1ull << BRW_STATE_CC_VP)
306 #define BRW_NEW_SF_VP (1ull << BRW_STATE_SF_VP)
307 #define BRW_NEW_CLIP_VP (1ull << BRW_STATE_CLIP_VP)
308 #define BRW_NEW_SAMPLER_STATE_TABLE (1ull << BRW_STATE_SAMPLER_STATE_TABLE)
309 #define BRW_NEW_VS_ATTRIB_WORKAROUNDS (1ull << BRW_STATE_VS_ATTRIB_WORKAROUNDS)
310 #define BRW_NEW_COMPUTE_PROGRAM (1ull << BRW_STATE_COMPUTE_PROGRAM)
311 #define BRW_NEW_CS_WORK_GROUPS (1ull << BRW_STATE_CS_WORK_GROUPS)
312 #define BRW_NEW_URB_SIZE (1ull << BRW_STATE_URB_SIZE)
313 #define BRW_NEW_CC_STATE (1ull << BRW_STATE_CC_STATE)
314 #define BRW_NEW_BLORP (1ull << BRW_STATE_BLORP)
315 #define BRW_NEW_CONSERVATIVE_RASTERIZATION (1ull << BRW_STATE_CONSERVATIVE_RASTERIZATION)
316 #define BRW_NEW_DRAW_CALL (1ull << BRW_STATE_DRAW_CALL)
317 #define BRW_NEW_AUX_STATE (1ull << BRW_STATE_AUX)
318
319 struct brw_state_flags {
320 /** State update flags signalled by mesa internals */
321 GLuint mesa;
322 /**
323 * State update flags signalled as the result of brw_tracked_state updates
324 */
325 uint64_t brw;
326 };
327
328
329 /** Subclass of Mesa program */
330 struct brw_program {
331 struct gl_program program;
332 GLuint id;
333
334 bool compiled_once;
335 };
336
337
338 struct brw_ff_gs_prog_data {
339 GLuint urb_read_length;
340 GLuint total_grf;
341
342 /**
343 * Gen6 transform feedback: Amount by which the streaming vertex buffer
344 * indices should be incremented each time the GS is invoked.
345 */
346 unsigned svbi_postincrement_value;
347 };
348
349 /** Number of texture sampler units */
350 #define BRW_MAX_TEX_UNIT 32
351
352 /** Max number of UBOs in a shader */
353 #define BRW_MAX_UBO 14
354
355 /** Max number of SSBOs in a shader */
356 #define BRW_MAX_SSBO 12
357
358 /** Max number of atomic counter buffer objects in a shader */
359 #define BRW_MAX_ABO 16
360
361 /** Max number of image uniforms in a shader */
362 #define BRW_MAX_IMAGES 32
363
364 /** Maximum number of actual buffers used for stream output */
365 #define BRW_MAX_SOL_BUFFERS 4
366
367 #define BRW_MAX_SURFACES (BRW_MAX_DRAW_BUFFERS + \
368 BRW_MAX_TEX_UNIT * 2 + /* normal, gather */ \
369 BRW_MAX_UBO + \
370 BRW_MAX_SSBO + \
371 BRW_MAX_ABO + \
372 BRW_MAX_IMAGES + \
373 2 + /* shader time, pull constants */ \
374 1 /* cs num work groups */)
375
376 struct brw_cache {
377 struct brw_context *brw;
378
379 struct brw_cache_item **items;
380 struct brw_bo *bo;
381 void *map;
382 GLuint size, n_items;
383
384 uint32_t next_offset;
385 };
386
387 #define perf_debug(...) do { \
388 static GLuint msg_id = 0; \
389 if (unlikely(INTEL_DEBUG & DEBUG_PERF)) \
390 dbg_printf(__VA_ARGS__); \
391 if (brw->perf_debug) \
392 _mesa_gl_debugf(&brw->ctx, &msg_id, \
393 MESA_DEBUG_SOURCE_API, \
394 MESA_DEBUG_TYPE_PERFORMANCE, \
395 MESA_DEBUG_SEVERITY_MEDIUM, \
396 __VA_ARGS__); \
397 } while(0)
398
399 #define WARN_ONCE(cond, fmt...) do { \
400 if (unlikely(cond)) { \
401 static bool _warned = false; \
402 static GLuint msg_id = 0; \
403 if (!_warned) { \
404 fprintf(stderr, "WARNING: "); \
405 fprintf(stderr, fmt); \
406 _warned = true; \
407 \
408 _mesa_gl_debugf(ctx, &msg_id, \
409 MESA_DEBUG_SOURCE_API, \
410 MESA_DEBUG_TYPE_OTHER, \
411 MESA_DEBUG_SEVERITY_HIGH, fmt); \
412 } \
413 } \
414 } while (0)
415
416 /* Considered adding a member to this struct to document which flags
417 * an update might raise so that ordering of the state atoms can be
418 * checked or derived at runtime. Dropped the idea in favor of having
419 * a debug mode where the state is monitored for flags which are
420 * raised that have already been tested against.
421 */
422 struct brw_tracked_state {
423 struct brw_state_flags dirty;
424 void (*emit)( struct brw_context *brw );
425 };
426
427 enum shader_time_shader_type {
428 ST_NONE,
429 ST_VS,
430 ST_TCS,
431 ST_TES,
432 ST_GS,
433 ST_FS8,
434 ST_FS16,
435 ST_FS32,
436 ST_CS,
437 };
438
439 struct brw_vertex_buffer {
440 /** Buffer object containing the uploaded vertex data */
441 struct brw_bo *bo;
442 uint32_t offset;
443 uint32_t size;
444 /** Byte stride between elements in the uploaded array */
445 GLuint stride;
446 GLuint step_rate;
447 };
448 struct brw_vertex_element {
449 const struct gl_array_attributes *glattrib;
450 const struct gl_vertex_buffer_binding *glbinding;
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 struct gl_buffer_object *draw_indirect_data;
915 } draw;
916
917 struct {
918 /**
919 * For gl_NumWorkGroups: If num_work_groups_bo is non NULL, then it is
920 * an indirect call, and num_work_groups_offset is valid. Otherwise,
921 * num_work_groups is set based on glDispatchCompute.
922 */
923 struct brw_bo *num_work_groups_bo;
924 GLintptr num_work_groups_offset;
925 const GLuint *num_work_groups;
926 } compute;
927
928 struct {
929 struct brw_vertex_element inputs[VERT_ATTRIB_MAX];
930 struct brw_vertex_buffer buffers[VERT_ATTRIB_MAX];
931
932 struct brw_vertex_element *enabled[VERT_ATTRIB_MAX];
933 GLuint nr_enabled;
934 GLuint nr_buffers;
935
936 /* Summary of size and varying of active arrays, so we can check
937 * for changes to this state:
938 */
939 bool index_bounds_valid;
940 unsigned int min_index, max_index;
941
942 /* Offset from start of vertex buffer so we can avoid redefining
943 * the same VB packed over and over again.
944 */
945 unsigned int start_vertex_bias;
946
947 /**
948 * Certain vertex attribute formats aren't natively handled by the
949 * hardware and require special VS code to fix up their values.
950 *
951 * These bitfields indicate which workarounds are needed.
952 */
953 uint8_t attrib_wa_flags[VERT_ATTRIB_MAX];
954
955 /* High bits of the last seen vertex buffer address (for workarounds). */
956 uint16_t last_bo_high_bits[33];
957 } vb;
958
959 struct {
960 /**
961 * Index buffer for this draw_prims call.
962 *
963 * Updates are signaled by BRW_NEW_INDICES.
964 */
965 const struct _mesa_index_buffer *ib;
966
967 /* Updates are signaled by BRW_NEW_INDEX_BUFFER. */
968 struct brw_bo *bo;
969 uint32_t size;
970 unsigned index_size;
971
972 /* Offset to index buffer index to use in CMD_3D_PRIM so that we can
973 * avoid re-uploading the IB packet over and over if we're actually
974 * referencing the same index buffer.
975 */
976 unsigned int start_vertex_offset;
977
978 /* High bits of the last seen index buffer address (for workarounds). */
979 uint16_t last_bo_high_bits;
980
981 /* Used to understand is GPU state of primitive restart is up to date */
982 bool enable_cut_index;
983 } ib;
984
985 /* Active vertex program:
986 */
987 struct gl_program *programs[MESA_SHADER_STAGES];
988
989 /**
990 * Number of samples in ctx->DrawBuffer, updated by BRW_NEW_NUM_SAMPLES so
991 * that we don't have to reemit that state every time we change FBOs.
992 */
993 unsigned int num_samples;
994
995 /* BRW_NEW_URB_ALLOCATIONS:
996 */
997 struct {
998 GLuint vsize; /* vertex size plus header in urb registers */
999 GLuint gsize; /* GS output size in urb registers */
1000 GLuint hsize; /* Tessellation control output size in urb registers */
1001 GLuint dsize; /* Tessellation evaluation output size in urb registers */
1002 GLuint csize; /* constant buffer size in urb registers */
1003 GLuint sfsize; /* setup data size in urb registers */
1004
1005 bool constrained;
1006
1007 GLuint nr_vs_entries;
1008 GLuint nr_hs_entries;
1009 GLuint nr_ds_entries;
1010 GLuint nr_gs_entries;
1011 GLuint nr_clip_entries;
1012 GLuint nr_sf_entries;
1013 GLuint nr_cs_entries;
1014
1015 GLuint vs_start;
1016 GLuint hs_start;
1017 GLuint ds_start;
1018 GLuint gs_start;
1019 GLuint clip_start;
1020 GLuint sf_start;
1021 GLuint cs_start;
1022 /**
1023 * URB size in the current configuration. The units this is expressed
1024 * in are somewhat inconsistent, see gen_device_info::urb::size.
1025 *
1026 * FINISHME: Represent the URB size consistently in KB on all platforms.
1027 */
1028 GLuint size;
1029
1030 /* True if the most recently sent _3DSTATE_URB message allocated
1031 * URB space for the GS.
1032 */
1033 bool gs_present;
1034
1035 /* True if the most recently sent _3DSTATE_URB message allocated
1036 * URB space for the HS and DS.
1037 */
1038 bool tess_present;
1039 } urb;
1040
1041
1042 /* BRW_NEW_PUSH_CONSTANT_ALLOCATION */
1043 struct {
1044 GLuint wm_start; /**< pos of first wm const in CURBE buffer */
1045 GLuint wm_size; /**< number of float[4] consts, multiple of 16 */
1046 GLuint clip_start;
1047 GLuint clip_size;
1048 GLuint vs_start;
1049 GLuint vs_size;
1050 GLuint total_size;
1051
1052 /**
1053 * Pointer to the (intel_upload.c-generated) BO containing the uniforms
1054 * for upload to the CURBE.
1055 */
1056 struct brw_bo *curbe_bo;
1057 /** Offset within curbe_bo of space for current curbe entry */
1058 GLuint curbe_offset;
1059 } curbe;
1060
1061 /**
1062 * Layout of vertex data exiting the geometry portion of the pipleine.
1063 * This comes from the last enabled shader stage (GS, DS, or VS).
1064 *
1065 * BRW_NEW_VUE_MAP_GEOM_OUT is flagged when the VUE map changes.
1066 */
1067 struct brw_vue_map vue_map_geom_out;
1068
1069 struct {
1070 struct brw_stage_state base;
1071 } vs;
1072
1073 struct {
1074 struct brw_stage_state base;
1075 } tcs;
1076
1077 struct {
1078 struct brw_stage_state base;
1079 } tes;
1080
1081 struct {
1082 struct brw_stage_state base;
1083
1084 /**
1085 * True if the 3DSTATE_GS command most recently emitted to the 3D
1086 * pipeline enabled the GS; false otherwise.
1087 */
1088 bool enabled;
1089 } gs;
1090
1091 struct {
1092 struct brw_ff_gs_prog_data *prog_data;
1093
1094 bool prog_active;
1095 /** Offset in the program cache to the CLIP program pre-gen6 */
1096 uint32_t prog_offset;
1097 uint32_t state_offset;
1098
1099 uint32_t bind_bo_offset;
1100 /**
1101 * Surface offsets for the binding table. We only need surfaces to
1102 * implement transform feedback so BRW_MAX_SOL_BINDINGS is all that we
1103 * need in this case.
1104 */
1105 uint32_t surf_offset[BRW_MAX_SOL_BINDINGS];
1106 } ff_gs;
1107
1108 struct {
1109 struct brw_clip_prog_data *prog_data;
1110
1111 /** Offset in the program cache to the CLIP program pre-gen6 */
1112 uint32_t prog_offset;
1113
1114 /* Offset in the batch to the CLIP state on pre-gen6. */
1115 uint32_t state_offset;
1116
1117 /* As of gen6, this is the offset in the batch to the CLIP VP,
1118 * instead of vp_bo.
1119 */
1120 uint32_t vp_offset;
1121
1122 /**
1123 * The number of viewports to use. If gl_ViewportIndex is written,
1124 * we can have up to ctx->Const.MaxViewports viewports. If not,
1125 * the viewport index is always 0, so we can only emit one.
1126 */
1127 uint8_t viewport_count;
1128 } clip;
1129
1130
1131 struct {
1132 struct brw_sf_prog_data *prog_data;
1133
1134 /** Offset in the program cache to the CLIP program pre-gen6 */
1135 uint32_t prog_offset;
1136 uint32_t state_offset;
1137 uint32_t vp_offset;
1138 } sf;
1139
1140 struct {
1141 struct brw_stage_state base;
1142
1143 /**
1144 * Buffer object used in place of multisampled null render targets on
1145 * Gen6. See brw_emit_null_surface_state().
1146 */
1147 struct brw_bo *multisampled_null_render_target_bo;
1148
1149 float offset_clamp;
1150 } wm;
1151
1152 struct {
1153 struct brw_stage_state base;
1154 } cs;
1155
1156 struct {
1157 uint32_t state_offset;
1158 uint32_t blend_state_offset;
1159 uint32_t depth_stencil_state_offset;
1160 uint32_t vp_offset;
1161 } cc;
1162
1163 struct {
1164 struct brw_query_object *obj;
1165 bool begin_emitted;
1166 } query;
1167
1168 struct {
1169 enum brw_predicate_state state;
1170 bool supported;
1171 } predicate;
1172
1173 struct gen_perf_context *perf_ctx;
1174
1175 int num_atoms[BRW_NUM_PIPELINES];
1176 const struct brw_tracked_state render_atoms[76];
1177 const struct brw_tracked_state compute_atoms[11];
1178
1179 const enum isl_format *mesa_to_isl_render_format;
1180 const bool *mesa_format_supports_render;
1181
1182 /* PrimitiveRestart */
1183 struct {
1184 bool in_progress;
1185 bool enable_cut_index;
1186 } prim_restart;
1187
1188 /** Computed depth/stencil/hiz state from the current attached
1189 * renderbuffers, valid only during the drawing state upload loop after
1190 * brw_workaround_depthstencil_alignment().
1191 */
1192 struct {
1193 /* Inter-tile (page-aligned) byte offsets. */
1194 uint32_t depth_offset;
1195 /* Intra-tile x,y offsets for drawing to combined depth-stencil. Only
1196 * used for Gen < 6.
1197 */
1198 uint32_t tile_x, tile_y;
1199 } depthstencil;
1200
1201 uint32_t num_instances;
1202 int basevertex;
1203 int baseinstance;
1204
1205 struct {
1206 const struct gen_l3_config *config;
1207 } l3;
1208
1209 struct {
1210 struct brw_bo *bo;
1211 const char **names;
1212 int *ids;
1213 enum shader_time_shader_type *types;
1214 struct shader_times *cumulative;
1215 int num_entries;
1216 int max_entries;
1217 double report_time;
1218 } shader_time;
1219
1220 struct brw_fast_clear_state *fast_clear_state;
1221
1222 /* Array of aux usages to use for drawing. Aux usage for render targets is
1223 * a bit more complex than simply calling a single function so we need some
1224 * way of passing it form brw_draw.c to surface state setup.
1225 */
1226 enum isl_aux_usage draw_aux_usage[MAX_DRAW_BUFFERS];
1227
1228 enum gen9_astc5x5_wa_tex_type gen9_astc5x5_wa_tex_mask;
1229
1230 /** Last rendering scale argument provided to brw_emit_hashing_mode(). */
1231 unsigned current_hash_scale;
1232
1233 __DRIcontext *driContext;
1234 struct intel_screen *screen;
1235 };
1236
1237 /* brw_clear.c */
1238 extern void intelInitClearFuncs(struct dd_function_table *functions);
1239
1240 /*======================================================================
1241 * brw_context.c
1242 */
1243 extern const char *const brw_vendor_string;
1244
1245 extern const char *
1246 brw_get_renderer_string(const struct intel_screen *screen);
1247
1248 enum {
1249 DRI_CONF_BO_REUSE_DISABLED,
1250 DRI_CONF_BO_REUSE_ALL
1251 };
1252
1253 void intel_update_renderbuffers(__DRIcontext *context,
1254 __DRIdrawable *drawable);
1255 void intel_prepare_render(struct brw_context *brw);
1256
1257 void gen9_apply_single_tex_astc5x5_wa(struct brw_context *brw,
1258 mesa_format format,
1259 enum isl_aux_usage aux_usage);
1260
1261 void brw_predraw_resolve_inputs(struct brw_context *brw, bool rendering,
1262 bool *draw_aux_buffer_disabled);
1263
1264 void intel_resolve_for_dri2_flush(struct brw_context *brw,
1265 __DRIdrawable *drawable);
1266
1267 GLboolean brwCreateContext(gl_api api,
1268 const struct gl_config *mesaVis,
1269 __DRIcontext *driContextPriv,
1270 const struct __DriverContextConfig *ctx_config,
1271 unsigned *error,
1272 void *sharedContextPrivate);
1273
1274 /*======================================================================
1275 * brw_misc_state.c
1276 */
1277 void brw_workaround_depthstencil_alignment(struct brw_context *brw,
1278 GLbitfield clear_mask);
1279 void brw_emit_hashing_mode(struct brw_context *brw, unsigned width,
1280 unsigned height, unsigned scale);
1281
1282 /* brw_object_purgeable.c */
1283 void brw_init_object_purgeable_functions(struct dd_function_table *functions);
1284
1285 /*======================================================================
1286 * brw_queryobj.c
1287 */
1288 void brw_init_common_queryobj_functions(struct dd_function_table *functions);
1289 void gen4_init_queryobj_functions(struct dd_function_table *functions);
1290 void brw_emit_query_begin(struct brw_context *brw);
1291 void brw_emit_query_end(struct brw_context *brw);
1292 void brw_query_counter(struct gl_context *ctx, struct gl_query_object *q);
1293 bool brw_is_query_pipelined(struct brw_query_object *query);
1294 uint64_t brw_raw_timestamp_delta(struct brw_context *brw,
1295 uint64_t time0, uint64_t time1);
1296
1297 /** gen6_queryobj.c */
1298 void gen6_init_queryobj_functions(struct dd_function_table *functions);
1299 void brw_write_timestamp(struct brw_context *brw, struct brw_bo *bo, int idx);
1300 void brw_write_depth_count(struct brw_context *brw, struct brw_bo *bo, int idx);
1301
1302 /** hsw_queryobj.c */
1303 void hsw_overflow_result_to_gpr0(struct brw_context *brw,
1304 struct brw_query_object *query,
1305 int count);
1306 void hsw_init_queryobj_functions(struct dd_function_table *functions);
1307
1308 /** brw_conditional_render.c */
1309 void brw_init_conditional_render_functions(struct dd_function_table *functions);
1310 bool brw_check_conditional_render(struct brw_context *brw);
1311
1312 /** intel_batchbuffer.c */
1313 void brw_load_register_mem(struct brw_context *brw,
1314 uint32_t reg,
1315 struct brw_bo *bo,
1316 uint32_t offset);
1317 void brw_load_register_mem64(struct brw_context *brw,
1318 uint32_t reg,
1319 struct brw_bo *bo,
1320 uint32_t offset);
1321 void brw_store_register_mem32(struct brw_context *brw,
1322 struct brw_bo *bo, uint32_t reg, uint32_t offset);
1323 void brw_store_register_mem64(struct brw_context *brw,
1324 struct brw_bo *bo, uint32_t reg, uint32_t offset);
1325 void brw_load_register_imm32(struct brw_context *brw,
1326 uint32_t reg, uint32_t imm);
1327 void brw_load_register_imm64(struct brw_context *brw,
1328 uint32_t reg, uint64_t imm);
1329 void brw_load_register_reg(struct brw_context *brw, uint32_t dst,
1330 uint32_t src);
1331 void brw_load_register_reg64(struct brw_context *brw, uint32_t dst,
1332 uint32_t src);
1333 void brw_store_data_imm32(struct brw_context *brw, struct brw_bo *bo,
1334 uint32_t offset, uint32_t imm);
1335 void brw_store_data_imm64(struct brw_context *brw, struct brw_bo *bo,
1336 uint32_t offset, uint64_t imm);
1337
1338 /*======================================================================
1339 * intel_tex_validate.c
1340 */
1341 void brw_validate_textures( struct brw_context *brw );
1342
1343
1344 /*======================================================================
1345 * brw_program.c
1346 */
1347 void brwInitFragProgFuncs( struct dd_function_table *functions );
1348
1349 void brw_get_scratch_bo(struct brw_context *brw,
1350 struct brw_bo **scratch_bo, int size);
1351 void brw_alloc_stage_scratch(struct brw_context *brw,
1352 struct brw_stage_state *stage_state,
1353 unsigned per_thread_size);
1354 void brw_init_shader_time(struct brw_context *brw);
1355 int brw_get_shader_time_index(struct brw_context *brw,
1356 struct gl_program *prog,
1357 enum shader_time_shader_type type,
1358 bool is_glsl_sh);
1359 void brw_collect_and_report_shader_time(struct brw_context *brw);
1360 void brw_destroy_shader_time(struct brw_context *brw);
1361
1362 /* brw_urb.c
1363 */
1364 void brw_calculate_urb_fence(struct brw_context *brw, unsigned csize,
1365 unsigned vsize, unsigned sfsize);
1366 void brw_upload_urb_fence(struct brw_context *brw);
1367
1368 /* brw_curbe.c
1369 */
1370 void brw_upload_cs_urb_state(struct brw_context *brw);
1371
1372 /* brw_vs.c */
1373 gl_clip_plane *brw_select_clip_planes(struct gl_context *ctx);
1374
1375 /* brw_draw_upload.c */
1376 unsigned brw_get_vertex_surface_type(struct brw_context *brw,
1377 const struct gl_vertex_format *glformat);
1378
1379 static inline unsigned
1380 brw_get_index_type(unsigned index_size)
1381 {
1382 /* The hw needs 0x00, 0x01, and 0x02 for ubyte, ushort, and uint,
1383 * respectively.
1384 */
1385 return index_size >> 1;
1386 }
1387
1388 void brw_prepare_vertices(struct brw_context *brw);
1389
1390 /* brw_wm_surface_state.c */
1391 void brw_update_buffer_texture_surface(struct gl_context *ctx,
1392 unsigned unit,
1393 uint32_t *surf_offset);
1394 void
1395 brw_update_sol_surface(struct brw_context *brw,
1396 struct gl_buffer_object *buffer_obj,
1397 uint32_t *out_offset, unsigned num_vector_components,
1398 unsigned stride_dwords, unsigned offset_dwords);
1399 void brw_upload_ubo_surfaces(struct brw_context *brw, struct gl_program *prog,
1400 struct brw_stage_state *stage_state,
1401 struct brw_stage_prog_data *prog_data);
1402 void brw_upload_image_surfaces(struct brw_context *brw,
1403 const struct gl_program *prog,
1404 struct brw_stage_state *stage_state,
1405 struct brw_stage_prog_data *prog_data);
1406
1407 /* brw_surface_formats.c */
1408 void intel_screen_init_surface_formats(struct intel_screen *screen);
1409 void brw_init_surface_formats(struct brw_context *brw);
1410 bool brw_render_target_supported(struct brw_context *brw,
1411 struct gl_renderbuffer *rb);
1412 uint32_t brw_depth_format(struct brw_context *brw, mesa_format format);
1413
1414 /* brw_performance_query.c */
1415 void brw_init_performance_queries(struct brw_context *brw);
1416
1417 /* intel_extensions.c */
1418 extern void intelInitExtensions(struct gl_context *ctx);
1419
1420 /* intel_state.c */
1421 extern int intel_translate_shadow_compare_func(GLenum func);
1422 extern int intel_translate_compare_func(GLenum func);
1423 extern int intel_translate_stencil_op(GLenum op);
1424
1425 /* brw_sync.c */
1426 void brw_init_syncobj_functions(struct dd_function_table *functions);
1427
1428 /* gen6_sol.c */
1429 struct gl_transform_feedback_object *
1430 brw_new_transform_feedback(struct gl_context *ctx, GLuint name);
1431 void
1432 brw_delete_transform_feedback(struct gl_context *ctx,
1433 struct gl_transform_feedback_object *obj);
1434 void
1435 brw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1436 struct gl_transform_feedback_object *obj);
1437 void
1438 brw_end_transform_feedback(struct gl_context *ctx,
1439 struct gl_transform_feedback_object *obj);
1440 void
1441 brw_pause_transform_feedback(struct gl_context *ctx,
1442 struct gl_transform_feedback_object *obj);
1443 void
1444 brw_resume_transform_feedback(struct gl_context *ctx,
1445 struct gl_transform_feedback_object *obj);
1446 void
1447 brw_save_primitives_written_counters(struct brw_context *brw,
1448 struct brw_transform_feedback_object *obj);
1449 GLsizei
1450 brw_get_transform_feedback_vertex_count(struct gl_context *ctx,
1451 struct gl_transform_feedback_object *obj,
1452 GLuint stream);
1453
1454 /* gen7_sol_state.c */
1455 void
1456 gen7_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1457 struct gl_transform_feedback_object *obj);
1458 void
1459 gen7_end_transform_feedback(struct gl_context *ctx,
1460 struct gl_transform_feedback_object *obj);
1461 void
1462 gen7_pause_transform_feedback(struct gl_context *ctx,
1463 struct gl_transform_feedback_object *obj);
1464 void
1465 gen7_resume_transform_feedback(struct gl_context *ctx,
1466 struct gl_transform_feedback_object *obj);
1467
1468 /* hsw_sol.c */
1469 void
1470 hsw_begin_transform_feedback(struct gl_context *ctx, GLenum mode,
1471 struct gl_transform_feedback_object *obj);
1472 void
1473 hsw_end_transform_feedback(struct gl_context *ctx,
1474 struct gl_transform_feedback_object *obj);
1475 void
1476 hsw_pause_transform_feedback(struct gl_context *ctx,
1477 struct gl_transform_feedback_object *obj);
1478 void
1479 hsw_resume_transform_feedback(struct gl_context *ctx,
1480 struct gl_transform_feedback_object *obj);
1481
1482 /* brw_blorp_blit.cpp */
1483 GLbitfield
1484 brw_blorp_framebuffer(struct brw_context *brw,
1485 struct gl_framebuffer *readFb,
1486 struct gl_framebuffer *drawFb,
1487 GLint srcX0, GLint srcY0, GLint srcX1, GLint srcY1,
1488 GLint dstX0, GLint dstY0, GLint dstX1, GLint dstY1,
1489 GLbitfield mask, GLenum filter);
1490
1491 bool
1492 brw_blorp_copytexsubimage(struct brw_context *brw,
1493 struct gl_renderbuffer *src_rb,
1494 struct gl_texture_image *dst_image,
1495 int slice,
1496 int srcX0, int srcY0,
1497 int dstX0, int dstY0,
1498 int width, int height);
1499
1500 /* brw_generate_mipmap.c */
1501 void brw_generate_mipmap(struct gl_context *ctx, GLenum target,
1502 struct gl_texture_object *tex_obj);
1503
1504 void
1505 gen6_get_sample_position(struct gl_context *ctx,
1506 struct gl_framebuffer *fb,
1507 GLuint index,
1508 GLfloat *result);
1509 void
1510 gen6_set_sample_maps(struct gl_context *ctx);
1511
1512 /* gen8_multisample_state.c */
1513 void gen8_emit_3dstate_sample_pattern(struct brw_context *brw);
1514
1515 /* gen7_l3_state.c */
1516 void brw_emit_l3_state(struct brw_context *brw);
1517
1518 /* gen7_urb.c */
1519 void
1520 gen7_emit_push_constant_state(struct brw_context *brw, unsigned vs_size,
1521 unsigned hs_size, unsigned ds_size,
1522 unsigned gs_size, unsigned fs_size);
1523
1524 void
1525 gen6_upload_urb(struct brw_context *brw, unsigned vs_size,
1526 bool gs_present, unsigned gs_size);
1527 void
1528 gen7_upload_urb(struct brw_context *brw, unsigned vs_size,
1529 bool gs_present, bool tess_present);
1530
1531 /* brw_reset.c */
1532 extern GLenum
1533 brw_get_graphics_reset_status(struct gl_context *ctx);
1534 void
1535 brw_check_for_reset(struct brw_context *brw);
1536
1537 /* brw_compute.c */
1538 extern void
1539 brw_init_compute_functions(struct dd_function_table *functions);
1540
1541 /* brw_program_binary.c */
1542 extern void
1543 brw_program_binary_init(unsigned device_id);
1544 extern void
1545 brw_get_program_binary_driver_sha1(struct gl_context *ctx, uint8_t *sha1);
1546 void brw_serialize_program_binary(struct gl_context *ctx,
1547 struct gl_shader_program *sh_prog,
1548 struct gl_program *prog);
1549 extern void
1550 brw_deserialize_program_binary(struct gl_context *ctx,
1551 struct gl_shader_program *shProg,
1552 struct gl_program *prog);
1553 void
1554 brw_program_serialize_nir(struct gl_context *ctx, struct gl_program *prog);
1555 void
1556 brw_program_deserialize_driver_blob(struct gl_context *ctx,
1557 struct gl_program *prog,
1558 gl_shader_stage stage);
1559
1560 /*======================================================================
1561 * Inline conversion functions. These are better-typed than the
1562 * macros used previously:
1563 */
1564 static inline struct brw_context *
1565 brw_context( struct gl_context *ctx )
1566 {
1567 return (struct brw_context *)ctx;
1568 }
1569
1570 static inline struct brw_program *
1571 brw_program(struct gl_program *p)
1572 {
1573 return (struct brw_program *) p;
1574 }
1575
1576 static inline const struct brw_program *
1577 brw_program_const(const struct gl_program *p)
1578 {
1579 return (const struct brw_program *) p;
1580 }
1581
1582 static inline bool
1583 brw_depth_writes_enabled(const struct brw_context *brw)
1584 {
1585 const struct gl_context *ctx = &brw->ctx;
1586
1587 /* We consider depth writes disabled if the depth function is GL_EQUAL,
1588 * because it would just overwrite the existing depth value with itself.
1589 *
1590 * These bonus depth writes not only use bandwidth, but they also can
1591 * prevent early depth processing. For example, if the pixel shader
1592 * discards, the hardware must invoke the to determine whether or not
1593 * to do the depth write. If writes are disabled, we may still be able
1594 * to do the depth test before the shader, and skip the shader execution.
1595 *
1596 * The Broadwell 3DSTATE_WM_DEPTH_STENCIL documentation also contains
1597 * a programming note saying to disable depth writes for EQUAL.
1598 */
1599 return ctx->Depth.Test && ctx->Depth.Mask && ctx->Depth.Func != GL_EQUAL;
1600 }
1601
1602 void
1603 brw_emit_depthbuffer(struct brw_context *brw);
1604
1605 uint32_t get_hw_prim_for_gl_prim(int mode);
1606
1607 void
1608 gen6_upload_push_constants(struct brw_context *brw,
1609 const struct gl_program *prog,
1610 const struct brw_stage_prog_data *prog_data,
1611 struct brw_stage_state *stage_state);
1612
1613 bool
1614 gen9_use_linear_1d_layout(const struct brw_context *brw,
1615 const struct intel_mipmap_tree *mt);
1616
1617 /* brw_queryformat.c */
1618 void brw_query_internal_format(struct gl_context *ctx, GLenum target,
1619 GLenum internalFormat, GLenum pname,
1620 GLint *params);
1621
1622 #ifdef __cplusplus
1623 }
1624 #endif
1625
1626 #endif