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