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