intel/blorp: Plumb the stage through blorp upload_shader
[mesa.git] / src / gallium / drivers / iris / iris_context.h
1 /*
2 * Copyright © 2017 Intel Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * on the rights to use, copy, modify, merge, publish, distribute, sub
8 * license, and/or sell copies of the Software, and to permit persons to whom
9 * the Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
13 * Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHOR(S) AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
21 * USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23 #ifndef IRIS_CONTEXT_H
24 #define IRIS_CONTEXT_H
25
26 #include "pipe/p_context.h"
27 #include "pipe/p_state.h"
28 #include "util/u_debug.h"
29 #include "intel/blorp/blorp.h"
30 #include "intel/dev/gen_debug.h"
31 #include "intel/common/gen_l3_config.h"
32 #include "intel/compiler/brw_compiler.h"
33 #include "iris_batch.h"
34 #include "iris_binder.h"
35 #include "iris_fence.h"
36 #include "iris_resource.h"
37 #include "iris_screen.h"
38
39 struct iris_bo;
40 struct iris_context;
41 struct blorp_batch;
42 struct blorp_params;
43
44 #define IRIS_MAX_TEXTURE_BUFFER_SIZE (1 << 27)
45 #define IRIS_MAX_TEXTURE_SAMPLERS 32
46 /* IRIS_MAX_ABOS and IRIS_MAX_SSBOS must be the same. */
47 #define IRIS_MAX_ABOS 16
48 #define IRIS_MAX_SSBOS 16
49 #define IRIS_MAX_VIEWPORTS 16
50 #define IRIS_MAX_CLIP_PLANES 8
51
52 enum iris_param_domain {
53 BRW_PARAM_DOMAIN_BUILTIN = 0,
54 BRW_PARAM_DOMAIN_IMAGE,
55 };
56
57 enum {
58 DRI_CONF_BO_REUSE_DISABLED,
59 DRI_CONF_BO_REUSE_ALL
60 };
61
62 #define BRW_PARAM(domain, val) (BRW_PARAM_DOMAIN_##domain << 24 | (val))
63 #define BRW_PARAM_DOMAIN(param) ((uint32_t)(param) >> 24)
64 #define BRW_PARAM_VALUE(param) ((uint32_t)(param) & 0x00ffffff)
65 #define BRW_PARAM_IMAGE(idx, offset) BRW_PARAM(IMAGE, ((idx) << 8) | (offset))
66 #define BRW_PARAM_IMAGE_IDX(value) (BRW_PARAM_VALUE(value) >> 8)
67 #define BRW_PARAM_IMAGE_OFFSET(value)(BRW_PARAM_VALUE(value) & 0xf)
68
69 /**
70 * Dirty flags. When state changes, we flag some combination of these
71 * to indicate that particular GPU commands need to be re-emitted.
72 *
73 * Each bit typically corresponds to a single 3DSTATE_* command packet, but
74 * in rare cases they map to a group of related packets that need to be
75 * emitted together.
76 *
77 * See iris_upload_render_state().
78 */
79 #define IRIS_DIRTY_COLOR_CALC_STATE (1ull << 0)
80 #define IRIS_DIRTY_POLYGON_STIPPLE (1ull << 1)
81 #define IRIS_DIRTY_SCISSOR_RECT (1ull << 2)
82 #define IRIS_DIRTY_WM_DEPTH_STENCIL (1ull << 3)
83 #define IRIS_DIRTY_CC_VIEWPORT (1ull << 4)
84 #define IRIS_DIRTY_SF_CL_VIEWPORT (1ull << 5)
85 #define IRIS_DIRTY_PS_BLEND (1ull << 6)
86 #define IRIS_DIRTY_BLEND_STATE (1ull << 7)
87 #define IRIS_DIRTY_RASTER (1ull << 8)
88 #define IRIS_DIRTY_CLIP (1ull << 9)
89 #define IRIS_DIRTY_SBE (1ull << 10)
90 #define IRIS_DIRTY_LINE_STIPPLE (1ull << 11)
91 #define IRIS_DIRTY_VERTEX_ELEMENTS (1ull << 12)
92 #define IRIS_DIRTY_MULTISAMPLE (1ull << 13)
93 #define IRIS_DIRTY_VERTEX_BUFFERS (1ull << 14)
94 #define IRIS_DIRTY_SAMPLE_MASK (1ull << 15)
95 #define IRIS_DIRTY_SAMPLER_STATES_VS (1ull << 16)
96 #define IRIS_DIRTY_SAMPLER_STATES_TCS (1ull << 17)
97 #define IRIS_DIRTY_SAMPLER_STATES_TES (1ull << 18)
98 #define IRIS_DIRTY_SAMPLER_STATES_GS (1ull << 19)
99 #define IRIS_DIRTY_SAMPLER_STATES_PS (1ull << 20)
100 #define IRIS_DIRTY_SAMPLER_STATES_CS (1ull << 21)
101 #define IRIS_DIRTY_UNCOMPILED_VS (1ull << 22)
102 #define IRIS_DIRTY_UNCOMPILED_TCS (1ull << 23)
103 #define IRIS_DIRTY_UNCOMPILED_TES (1ull << 24)
104 #define IRIS_DIRTY_UNCOMPILED_GS (1ull << 25)
105 #define IRIS_DIRTY_UNCOMPILED_FS (1ull << 26)
106 #define IRIS_DIRTY_UNCOMPILED_CS (1ull << 27)
107 #define IRIS_DIRTY_VS (1ull << 28)
108 #define IRIS_DIRTY_TCS (1ull << 29)
109 #define IRIS_DIRTY_TES (1ull << 30)
110 #define IRIS_DIRTY_GS (1ull << 31)
111 #define IRIS_DIRTY_FS (1ull << 32)
112 #define IRIS_DIRTY_CS (1ull << 33)
113 #define IRIS_DIRTY_URB (1ull << 34)
114 #define IRIS_SHIFT_FOR_DIRTY_CONSTANTS 35
115 #define IRIS_DIRTY_CONSTANTS_VS (1ull << 35)
116 #define IRIS_DIRTY_CONSTANTS_TCS (1ull << 36)
117 #define IRIS_DIRTY_CONSTANTS_TES (1ull << 37)
118 #define IRIS_DIRTY_CONSTANTS_GS (1ull << 38)
119 #define IRIS_DIRTY_CONSTANTS_FS (1ull << 39)
120 #define IRIS_DIRTY_CONSTANTS_CS (1ull << 40)
121 #define IRIS_DIRTY_DEPTH_BUFFER (1ull << 41)
122 #define IRIS_DIRTY_WM (1ull << 42)
123 #define IRIS_DIRTY_BINDINGS_VS (1ull << 43)
124 #define IRIS_DIRTY_BINDINGS_TCS (1ull << 44)
125 #define IRIS_DIRTY_BINDINGS_TES (1ull << 45)
126 #define IRIS_DIRTY_BINDINGS_GS (1ull << 46)
127 #define IRIS_DIRTY_BINDINGS_FS (1ull << 47)
128 #define IRIS_DIRTY_BINDINGS_CS (1ull << 48)
129 #define IRIS_DIRTY_SO_BUFFERS (1ull << 49)
130 #define IRIS_DIRTY_SO_DECL_LIST (1ull << 50)
131 #define IRIS_DIRTY_STREAMOUT (1ull << 51)
132 #define IRIS_DIRTY_VF_SGVS (1ull << 52)
133 #define IRIS_DIRTY_VF (1ull << 53)
134 #define IRIS_DIRTY_VF_TOPOLOGY (1ull << 54)
135 #define IRIS_DIRTY_RENDER_RESOLVES_AND_FLUSHES (1ull << 55)
136 #define IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES (1ull << 56)
137 #define IRIS_DIRTY_VF_STATISTICS (1ull << 57)
138 #define IRIS_DIRTY_PMA_FIX (1ull << 58)
139 #define IRIS_DIRTY_DEPTH_BOUNDS (1ull << 59)
140 #define IRIS_DIRTY_RENDER_BUFFER (1ull << 60)
141
142 #define IRIS_ALL_DIRTY_FOR_COMPUTE (IRIS_DIRTY_CS | \
143 IRIS_DIRTY_SAMPLER_STATES_CS | \
144 IRIS_DIRTY_UNCOMPILED_CS | \
145 IRIS_DIRTY_CONSTANTS_CS | \
146 IRIS_DIRTY_BINDINGS_CS | \
147 IRIS_DIRTY_COMPUTE_RESOLVES_AND_FLUSHES)
148
149 #define IRIS_ALL_DIRTY_FOR_RENDER ~IRIS_ALL_DIRTY_FOR_COMPUTE
150
151 #define IRIS_ALL_DIRTY_BINDINGS (IRIS_DIRTY_BINDINGS_VS | \
152 IRIS_DIRTY_BINDINGS_TCS | \
153 IRIS_DIRTY_BINDINGS_TES | \
154 IRIS_DIRTY_BINDINGS_GS | \
155 IRIS_DIRTY_BINDINGS_FS | \
156 IRIS_DIRTY_BINDINGS_CS | \
157 IRIS_DIRTY_RENDER_BUFFER)
158
159 /**
160 * Non-orthogonal state (NOS) dependency flags.
161 *
162 * Shader programs may depend on non-orthogonal state. These flags are
163 * used to indicate that a shader's key depends on the state provided by
164 * a certain Gallium CSO. Changing any CSOs marked as a dependency will
165 * cause the driver to re-compute the shader key, possibly triggering a
166 * shader recompile.
167 */
168 enum iris_nos_dep {
169 IRIS_NOS_FRAMEBUFFER,
170 IRIS_NOS_DEPTH_STENCIL_ALPHA,
171 IRIS_NOS_RASTERIZER,
172 IRIS_NOS_BLEND,
173 IRIS_NOS_LAST_VUE_MAP,
174
175 IRIS_NOS_COUNT,
176 };
177
178 /** @{
179 *
180 * Program cache keys for state based recompiles.
181 */
182
183 struct iris_base_prog_key {
184 unsigned program_string_id;
185 };
186
187 struct iris_vue_prog_key {
188 struct iris_base_prog_key base;
189
190 unsigned nr_userclip_plane_consts:4;
191 };
192
193 struct iris_vs_prog_key {
194 struct iris_vue_prog_key vue;
195 };
196
197 struct iris_tcs_prog_key {
198 struct iris_vue_prog_key vue;
199
200 uint16_t tes_primitive_mode;
201
202 uint8_t input_vertices;
203
204 bool quads_workaround;
205
206 /** A bitfield of per-patch outputs written. */
207 uint32_t patch_outputs_written;
208
209 /** A bitfield of per-vertex outputs written. */
210 uint64_t outputs_written;
211 };
212
213 struct iris_tes_prog_key {
214 struct iris_vue_prog_key vue;
215
216 /** A bitfield of per-patch inputs read. */
217 uint32_t patch_inputs_read;
218
219 /** A bitfield of per-vertex inputs read. */
220 uint64_t inputs_read;
221 };
222
223 struct iris_gs_prog_key {
224 struct iris_vue_prog_key vue;
225 };
226
227 struct iris_fs_prog_key {
228 struct iris_base_prog_key base;
229
230 unsigned nr_color_regions:5;
231 bool flat_shade:1;
232 bool alpha_test_replicate_alpha:1;
233 bool alpha_to_coverage:1;
234 bool clamp_fragment_color:1;
235 bool persample_interp:1;
236 bool multisample_fbo:1;
237 bool force_dual_color_blend:1;
238 bool coherent_fb_fetch:1;
239
240 uint8_t color_outputs_valid;
241 uint64_t input_slots_valid;
242 };
243
244 struct iris_cs_prog_key {
245 struct iris_base_prog_key base;
246 };
247
248 /** @} */
249
250 struct iris_depth_stencil_alpha_state;
251
252 /**
253 * Cache IDs for the in-memory program cache (ice->shaders.cache).
254 */
255 enum iris_program_cache_id {
256 IRIS_CACHE_VS = MESA_SHADER_VERTEX,
257 IRIS_CACHE_TCS = MESA_SHADER_TESS_CTRL,
258 IRIS_CACHE_TES = MESA_SHADER_TESS_EVAL,
259 IRIS_CACHE_GS = MESA_SHADER_GEOMETRY,
260 IRIS_CACHE_FS = MESA_SHADER_FRAGMENT,
261 IRIS_CACHE_CS = MESA_SHADER_COMPUTE,
262 IRIS_CACHE_BLORP,
263 };
264
265 /** @{
266 *
267 * Defines for PIPE_CONTROL operations, which trigger cache flushes,
268 * synchronization, pipelined memory writes, and so on.
269 *
270 * The bits here are not the actual hardware values. The actual fields
271 * move between various generations, so we just have flags for each
272 * potential operation, and use genxml to encode the actual packet.
273 */
274 enum pipe_control_flags
275 {
276 PIPE_CONTROL_FLUSH_LLC = (1 << 1),
277 PIPE_CONTROL_LRI_POST_SYNC_OP = (1 << 2),
278 PIPE_CONTROL_STORE_DATA_INDEX = (1 << 3),
279 PIPE_CONTROL_CS_STALL = (1 << 4),
280 PIPE_CONTROL_GLOBAL_SNAPSHOT_COUNT_RESET = (1 << 5),
281 PIPE_CONTROL_SYNC_GFDT = (1 << 6),
282 PIPE_CONTROL_TLB_INVALIDATE = (1 << 7),
283 PIPE_CONTROL_MEDIA_STATE_CLEAR = (1 << 8),
284 PIPE_CONTROL_WRITE_IMMEDIATE = (1 << 9),
285 PIPE_CONTROL_WRITE_DEPTH_COUNT = (1 << 10),
286 PIPE_CONTROL_WRITE_TIMESTAMP = (1 << 11),
287 PIPE_CONTROL_DEPTH_STALL = (1 << 12),
288 PIPE_CONTROL_RENDER_TARGET_FLUSH = (1 << 13),
289 PIPE_CONTROL_INSTRUCTION_INVALIDATE = (1 << 14),
290 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE = (1 << 15),
291 PIPE_CONTROL_INDIRECT_STATE_POINTERS_DISABLE = (1 << 16),
292 PIPE_CONTROL_NOTIFY_ENABLE = (1 << 17),
293 PIPE_CONTROL_FLUSH_ENABLE = (1 << 18),
294 PIPE_CONTROL_DATA_CACHE_FLUSH = (1 << 19),
295 PIPE_CONTROL_VF_CACHE_INVALIDATE = (1 << 20),
296 PIPE_CONTROL_CONST_CACHE_INVALIDATE = (1 << 21),
297 PIPE_CONTROL_STATE_CACHE_INVALIDATE = (1 << 22),
298 PIPE_CONTROL_STALL_AT_SCOREBOARD = (1 << 23),
299 PIPE_CONTROL_DEPTH_CACHE_FLUSH = (1 << 24),
300 PIPE_CONTROL_TILE_CACHE_FLUSH = (1 << 25),
301 PIPE_CONTROL_FLUSH_HDC = (1 << 26),
302 };
303
304 #define PIPE_CONTROL_CACHE_FLUSH_BITS \
305 (PIPE_CONTROL_DEPTH_CACHE_FLUSH | \
306 PIPE_CONTROL_DATA_CACHE_FLUSH | \
307 PIPE_CONTROL_RENDER_TARGET_FLUSH)
308
309 #define PIPE_CONTROL_CACHE_INVALIDATE_BITS \
310 (PIPE_CONTROL_STATE_CACHE_INVALIDATE | \
311 PIPE_CONTROL_CONST_CACHE_INVALIDATE | \
312 PIPE_CONTROL_VF_CACHE_INVALIDATE | \
313 PIPE_CONTROL_TEXTURE_CACHE_INVALIDATE | \
314 PIPE_CONTROL_INSTRUCTION_INVALIDATE)
315
316 enum iris_predicate_state {
317 /* The first two states are used if we can determine whether to draw
318 * without having to look at the values in the query object buffer. This
319 * will happen if there is no conditional render in progress, if the query
320 * object is already completed or if something else has already added
321 * samples to the preliminary result.
322 */
323 IRIS_PREDICATE_STATE_RENDER,
324 IRIS_PREDICATE_STATE_DONT_RENDER,
325
326 /* In this case whether to draw or not depends on the result of an
327 * MI_PREDICATE command so the predicate enable bit needs to be checked.
328 */
329 IRIS_PREDICATE_STATE_USE_BIT,
330 };
331
332 /** @} */
333
334 /**
335 * An uncompiled, API-facing shader. This is the Gallium CSO for shaders.
336 * It primarily contains the NIR for the shader.
337 *
338 * Each API-facing shader can be compiled into multiple shader variants,
339 * based on non-orthogonal state dependencies, recorded in the shader key.
340 *
341 * See iris_compiled_shader, which represents a compiled shader variant.
342 */
343 struct iris_uncompiled_shader {
344 struct nir_shader *nir;
345
346 struct pipe_stream_output_info stream_output;
347
348 /* A SHA1 of the serialized NIR for the disk cache. */
349 unsigned char nir_sha1[20];
350
351 unsigned program_id;
352
353 /** Bitfield of (1 << IRIS_NOS_*) flags. */
354 unsigned nos;
355
356 /** Have any shader variants been compiled yet? */
357 bool compiled_once;
358
359 /** Should we use ALT mode for math? Useful for ARB programs. */
360 bool use_alt_mode;
361
362 bool needs_edge_flag;
363
364 /* Whether shader uses atomic operations. */
365 bool uses_atomic_load_store;
366
367 /** Constant data scraped from the shader by nir_opt_large_constants */
368 struct pipe_resource *const_data;
369
370 /** Surface state for const_data */
371 struct iris_state_ref const_data_state;
372 };
373
374 enum iris_surface_group {
375 IRIS_SURFACE_GROUP_RENDER_TARGET,
376 IRIS_SURFACE_GROUP_RENDER_TARGET_READ,
377 IRIS_SURFACE_GROUP_CS_WORK_GROUPS,
378 IRIS_SURFACE_GROUP_TEXTURE,
379 IRIS_SURFACE_GROUP_IMAGE,
380 IRIS_SURFACE_GROUP_UBO,
381 IRIS_SURFACE_GROUP_SSBO,
382
383 IRIS_SURFACE_GROUP_COUNT,
384 };
385
386 enum {
387 /* Invalid value for a binding table index. */
388 IRIS_SURFACE_NOT_USED = 0xa0a0a0a0,
389 };
390
391 struct iris_binding_table {
392 uint32_t size_bytes;
393
394 /** Number of surfaces in each group, before compacting. */
395 uint32_t sizes[IRIS_SURFACE_GROUP_COUNT];
396
397 /** Initial offset of each group. */
398 uint32_t offsets[IRIS_SURFACE_GROUP_COUNT];
399
400 /** Mask of surfaces used in each group. */
401 uint64_t used_mask[IRIS_SURFACE_GROUP_COUNT];
402 };
403
404 /**
405 * A compiled shader variant, containing a pointer to the GPU assembly,
406 * as well as program data and other packets needed by state upload.
407 *
408 * There can be several iris_compiled_shader variants per API-level shader
409 * (iris_uncompiled_shader), due to state-based recompiles (brw_*_prog_key).
410 */
411 struct iris_compiled_shader {
412 /** Reference to the uploaded assembly. */
413 struct iris_state_ref assembly;
414
415 /** Pointer to the assembly in the BO's map. */
416 void *map;
417
418 /** The program data (owned by the program cache hash table) */
419 struct brw_stage_prog_data *prog_data;
420
421 /** A list of system values to be uploaded as uniforms. */
422 enum brw_param_builtin *system_values;
423 unsigned num_system_values;
424
425 /** Number of constbufs expected by the shader. */
426 unsigned num_cbufs;
427
428 /**
429 * Derived 3DSTATE_STREAMOUT and 3DSTATE_SO_DECL_LIST packets
430 * (the VUE-based information for transform feedback outputs).
431 */
432 uint32_t *streamout;
433
434 struct iris_binding_table bt;
435
436 /**
437 * Shader packets and other data derived from prog_data. These must be
438 * completely determined from prog_data.
439 */
440 uint8_t derived_data[0];
441 };
442
443 /**
444 * API context state that is replicated per shader stage.
445 */
446 struct iris_shader_state {
447 /** Uniform Buffers */
448 struct pipe_shader_buffer constbuf[PIPE_MAX_CONSTANT_BUFFERS];
449 struct iris_state_ref constbuf_surf_state[PIPE_MAX_CONSTANT_BUFFERS];
450
451 bool sysvals_need_upload;
452
453 /** Shader Storage Buffers */
454 struct pipe_shader_buffer ssbo[PIPE_MAX_SHADER_BUFFERS];
455 struct iris_state_ref ssbo_surf_state[PIPE_MAX_SHADER_BUFFERS];
456
457 /** Shader Storage Images (image load store) */
458 struct iris_image_view image[PIPE_MAX_SHADER_IMAGES];
459
460 struct iris_state_ref sampler_table;
461 struct iris_sampler_state *samplers[IRIS_MAX_TEXTURE_SAMPLERS];
462 struct iris_sampler_view *textures[IRIS_MAX_TEXTURE_SAMPLERS];
463
464 /** Bitfield of which constant buffers are bound (non-null). */
465 uint32_t bound_cbufs;
466
467 /** Bitfield of which image views are bound (non-null). */
468 uint32_t bound_image_views;
469
470 /** Bitfield of which sampler views are bound (non-null). */
471 uint32_t bound_sampler_views;
472
473 /** Bitfield of which shader storage buffers are bound (non-null). */
474 uint32_t bound_ssbos;
475
476 /** Bitfield of which shader storage buffers are writable. */
477 uint32_t writable_ssbos;
478 };
479
480 /**
481 * Gallium CSO for stream output (transform feedback) targets.
482 */
483 struct iris_stream_output_target {
484 struct pipe_stream_output_target base;
485
486 /** Storage holding the offset where we're writing in the buffer */
487 struct iris_state_ref offset;
488
489 /** Stride (bytes-per-vertex) during this transform feedback operation */
490 uint16_t stride;
491
492 /** Has 3DSTATE_SO_BUFFER actually been emitted, zeroing the offsets? */
493 bool zeroed;
494 };
495
496 /**
497 * Virtual table for generation-specific (genxml) function calls.
498 */
499 struct iris_vtable {
500 void (*destroy_state)(struct iris_context *ice);
501 void (*init_render_context)(struct iris_batch *batch);
502 void (*init_compute_context)(struct iris_batch *batch);
503 void (*upload_render_state)(struct iris_context *ice,
504 struct iris_batch *batch,
505 const struct pipe_draw_info *draw);
506 void (*update_surface_base_address)(struct iris_batch *batch,
507 struct iris_binder *binder);
508 void (*upload_compute_state)(struct iris_context *ice,
509 struct iris_batch *batch,
510 const struct pipe_grid_info *grid);
511 void (*rebind_buffer)(struct iris_context *ice,
512 struct iris_resource *res);
513 void (*resolve_conditional_render)(struct iris_context *ice);
514 void (*load_register_reg32)(struct iris_batch *batch, uint32_t dst,
515 uint32_t src);
516 void (*load_register_reg64)(struct iris_batch *batch, uint32_t dst,
517 uint32_t src);
518 void (*load_register_imm32)(struct iris_batch *batch, uint32_t reg,
519 uint32_t val);
520 void (*load_register_imm64)(struct iris_batch *batch, uint32_t reg,
521 uint64_t val);
522 void (*load_register_mem32)(struct iris_batch *batch, uint32_t reg,
523 struct iris_bo *bo, uint32_t offset);
524 void (*load_register_mem64)(struct iris_batch *batch, uint32_t reg,
525 struct iris_bo *bo, uint32_t offset);
526 void (*store_register_mem32)(struct iris_batch *batch, uint32_t reg,
527 struct iris_bo *bo, uint32_t offset,
528 bool predicated);
529 void (*store_register_mem64)(struct iris_batch *batch, uint32_t reg,
530 struct iris_bo *bo, uint32_t offset,
531 bool predicated);
532 void (*store_data_imm32)(struct iris_batch *batch,
533 struct iris_bo *bo, uint32_t offset,
534 uint32_t value);
535 void (*store_data_imm64)(struct iris_batch *batch,
536 struct iris_bo *bo, uint32_t offset,
537 uint64_t value);
538 void (*copy_mem_mem)(struct iris_batch *batch,
539 struct iris_bo *dst_bo, uint32_t dst_offset,
540 struct iris_bo *src_bo, uint32_t src_offset,
541 unsigned bytes);
542 void (*emit_raw_pipe_control)(struct iris_batch *batch,
543 const char *reason, uint32_t flags,
544 struct iris_bo *bo, uint32_t offset,
545 uint64_t imm);
546
547 void (*emit_mi_report_perf_count)(struct iris_batch *batch,
548 struct iris_bo *bo,
549 uint32_t offset_in_bytes,
550 uint32_t report_id);
551
552 unsigned (*derived_program_state_size)(enum iris_program_cache_id id);
553 void (*store_derived_program_state)(struct iris_context *ice,
554 enum iris_program_cache_id cache_id,
555 struct iris_compiled_shader *shader);
556 uint32_t *(*create_so_decl_list)(const struct pipe_stream_output_info *sol,
557 const struct brw_vue_map *vue_map);
558 void (*populate_vs_key)(const struct iris_context *ice,
559 const struct shader_info *info,
560 gl_shader_stage last_stage,
561 struct iris_vs_prog_key *key);
562 void (*populate_tcs_key)(const struct iris_context *ice,
563 struct iris_tcs_prog_key *key);
564 void (*populate_tes_key)(const struct iris_context *ice,
565 const struct shader_info *info,
566 gl_shader_stage last_stage,
567 struct iris_tes_prog_key *key);
568 void (*populate_gs_key)(const struct iris_context *ice,
569 const struct shader_info *info,
570 gl_shader_stage last_stage,
571 struct iris_gs_prog_key *key);
572 void (*populate_fs_key)(const struct iris_context *ice,
573 const struct shader_info *info,
574 struct iris_fs_prog_key *key);
575 void (*populate_cs_key)(const struct iris_context *ice,
576 struct iris_cs_prog_key *key);
577 void (*lost_genx_state)(struct iris_context *ice, struct iris_batch *batch);
578 };
579
580 /**
581 * A pool containing SAMPLER_BORDER_COLOR_STATE entries.
582 *
583 * See iris_border_color.c for more information.
584 */
585 struct iris_border_color_pool {
586 struct iris_bo *bo;
587 void *map;
588 unsigned insert_point;
589
590 /** Map from border colors to offsets in the buffer. */
591 struct hash_table *ht;
592 };
593
594 /**
595 * The API context (derived from pipe_context).
596 *
597 * Most driver state is tracked here.
598 */
599 struct iris_context {
600 struct pipe_context ctx;
601
602 /** A debug callback for KHR_debug output. */
603 struct pipe_debug_callback dbg;
604
605 /** A device reset status callback for notifying that the GPU is hosed. */
606 struct pipe_device_reset_callback reset;
607
608 /** Slab allocator for iris_transfer_map objects. */
609 struct slab_child_pool transfer_pool;
610
611 struct iris_vtable vtbl;
612
613 struct blorp_context blorp;
614
615 struct iris_batch batches[IRIS_BATCH_COUNT];
616
617 struct u_upload_mgr *query_buffer_uploader;
618
619 struct {
620 struct {
621 /**
622 * Either the value of BaseVertex for indexed draw calls or the value
623 * of the argument <first> for non-indexed draw calls.
624 */
625 int firstvertex;
626 int baseinstance;
627 } params;
628
629 /**
630 * Are the above values the ones stored in the draw_params buffer?
631 * If so, we can compare them against new values to see if anything
632 * changed. If not, we need to assume they changed.
633 */
634 bool params_valid;
635
636 /**
637 * Resource and offset that stores draw_parameters from the indirect
638 * buffer or to the buffer that stures the previous values for non
639 * indirect draws.
640 */
641 struct iris_state_ref draw_params;
642
643 struct {
644 /**
645 * The value of DrawID. This always comes in from it's own vertex
646 * buffer since it's not part of the indirect draw parameters.
647 */
648 int drawid;
649
650 /**
651 * Stores if an indexed or non-indexed draw (~0/0). Useful to
652 * calculate BaseVertex as an AND of firstvertex and is_indexed_draw.
653 */
654 int is_indexed_draw;
655 } derived_params;
656
657 /**
658 * Resource and offset used for GL_ARB_shader_draw_parameters which
659 * contains parameters that are not present in the indirect buffer as
660 * drawid and is_indexed_draw. They will go in their own vertex element.
661 */
662 struct iris_state_ref derived_draw_params;
663 } draw;
664
665 struct {
666 struct iris_uncompiled_shader *uncompiled[MESA_SHADER_STAGES];
667 struct iris_compiled_shader *prog[MESA_SHADER_STAGES];
668 struct brw_vue_map *last_vue_map;
669
670 struct u_upload_mgr *uploader;
671 struct hash_table *cache;
672
673 /** Is a GS or TES outputting points or lines? */
674 bool output_topology_is_points_or_lines;
675
676 /**
677 * Scratch buffers for various sizes and stages.
678 *
679 * Indexed by the "Per-Thread Scratch Space" field's 4-bit encoding,
680 * and shader stage.
681 */
682 struct iris_bo *scratch_bos[1 << 4][MESA_SHADER_STAGES];
683 } shaders;
684
685 struct {
686 struct iris_query *query;
687 bool condition;
688 } condition;
689
690 struct gen_perf_context *perf_ctx;
691
692 /** Frame number for debug prints */
693 uint32_t frame;
694
695 struct {
696 uint64_t dirty;
697 uint64_t dirty_for_nos[IRIS_NOS_COUNT];
698
699 unsigned num_viewports;
700 unsigned sample_mask;
701 struct iris_blend_state *cso_blend;
702 struct iris_rasterizer_state *cso_rast;
703 struct iris_depth_stencil_alpha_state *cso_zsa;
704 struct iris_vertex_element_state *cso_vertex_elements;
705 struct pipe_blend_color blend_color;
706 struct pipe_poly_stipple poly_stipple;
707 struct pipe_viewport_state viewports[IRIS_MAX_VIEWPORTS];
708 struct pipe_scissor_state scissors[IRIS_MAX_VIEWPORTS];
709 struct pipe_stencil_ref stencil_ref;
710 struct pipe_framebuffer_state framebuffer;
711 struct pipe_clip_state clip_planes;
712
713 float default_outer_level[4];
714 float default_inner_level[2];
715
716 /** Bitfield of which vertex buffers are bound (non-null). */
717 uint64_t bound_vertex_buffers;
718
719 bool primitive_restart;
720 unsigned cut_index;
721 enum pipe_prim_type prim_mode:8;
722 bool prim_is_points_or_lines;
723 uint8_t vertices_per_patch;
724
725 bool window_space_position;
726
727 /** The last compute grid size */
728 uint32_t last_grid[3];
729 /** Reference to the BO containing the compute grid size */
730 struct iris_state_ref grid_size;
731 /** Reference to the SURFACE_STATE for the compute grid resource */
732 struct iris_state_ref grid_surf_state;
733
734 /**
735 * Array of aux usages for drawing, altered to account for any
736 * self-dependencies from resources bound for sampling and rendering.
737 */
738 enum isl_aux_usage draw_aux_usage[BRW_MAX_DRAW_BUFFERS];
739
740 enum gen_urb_deref_block_size urb_deref_block_size;
741
742 /** Bitfield of whether color blending is enabled for RT[i] */
743 uint8_t blend_enables;
744
745 /** Are depth writes enabled? (Depth buffer may or may not exist.) */
746 bool depth_writes_enabled;
747
748 /** Are stencil writes enabled? (Stencil buffer may or may not exist.) */
749 bool stencil_writes_enabled;
750
751 /** GenX-specific current state */
752 struct iris_genx_state *genx;
753
754 struct iris_shader_state shaders[MESA_SHADER_STAGES];
755
756 /** Do vertex shader uses shader draw parameters ? */
757 bool vs_uses_draw_params;
758 bool vs_uses_derived_draw_params;
759 bool vs_needs_sgvs_element;
760
761 /** Do vertex shader uses edge flag ? */
762 bool vs_needs_edge_flag;
763
764 /** Do any samplers need border color? One bit per shader stage. */
765 uint8_t need_border_colors;
766
767 struct pipe_stream_output_target *so_target[PIPE_MAX_SO_BUFFERS];
768 bool streamout_active;
769
770 bool statistics_counters_enabled;
771
772 /** Current conditional rendering mode */
773 enum iris_predicate_state predicate;
774
775 /**
776 * Query BO with a MI_PREDICATE_RESULT snapshot calculated on the
777 * render context that needs to be uploaded to the compute context.
778 */
779 struct iris_bo *compute_predicate;
780
781 /** Is a PIPE_QUERY_PRIMITIVES_GENERATED query active? */
782 bool prims_generated_query_active;
783
784 /** 3DSTATE_STREAMOUT and 3DSTATE_SO_DECL_LIST packets */
785 uint32_t *streamout;
786
787 /** The SURFACE_STATE for a 1x1x1 null surface. */
788 struct iris_state_ref unbound_tex;
789
790 /** The SURFACE_STATE for a framebuffer-sized null surface. */
791 struct iris_state_ref null_fb;
792
793 struct u_upload_mgr *surface_uploader;
794 struct u_upload_mgr *dynamic_uploader;
795
796 struct iris_binder binder;
797
798 struct iris_border_color_pool border_color_pool;
799
800 /** The high 16-bits of the last VBO/index buffer addresses */
801 uint16_t last_vbo_high_bits[33];
802 uint16_t last_index_bo_high_bits;
803
804 /**
805 * Resources containing streamed state which our render context
806 * currently points to. Used to re-add these to the validation
807 * list when we start a new batch and haven't resubmitted commands.
808 */
809 struct {
810 struct pipe_resource *cc_vp;
811 struct pipe_resource *sf_cl_vp;
812 struct pipe_resource *color_calc;
813 struct pipe_resource *scissor;
814 struct pipe_resource *blend;
815 struct pipe_resource *index_buffer;
816 struct pipe_resource *cs_thread_ids;
817 struct pipe_resource *cs_desc;
818 } last_res;
819
820 /** Records the size of variable-length state for INTEL_DEBUG=bat */
821 struct hash_table_u64 *sizes;
822
823 /** Last rendering scale argument provided to genX(emit_hashing_mode). */
824 unsigned current_hash_scale;
825 } state;
826 };
827
828 #define perf_debug(dbg, ...) do { \
829 if (INTEL_DEBUG & DEBUG_PERF) \
830 dbg_printf(__VA_ARGS__); \
831 if (unlikely(dbg)) \
832 pipe_debug_message(dbg, PERF_INFO, __VA_ARGS__); \
833 } while(0)
834
835 double get_time(void);
836
837 struct pipe_context *
838 iris_create_context(struct pipe_screen *screen, void *priv, unsigned flags);
839
840 void iris_lost_context_state(struct iris_batch *batch);
841
842 void iris_init_blit_functions(struct pipe_context *ctx);
843 void iris_init_clear_functions(struct pipe_context *ctx);
844 void iris_init_program_functions(struct pipe_context *ctx);
845 void iris_init_resource_functions(struct pipe_context *ctx);
846 void iris_init_perfquery_functions(struct pipe_context *ctx);
847 void iris_update_compiled_shaders(struct iris_context *ice);
848 void iris_update_compiled_compute_shader(struct iris_context *ice);
849 void iris_fill_cs_push_const_buffer(struct brw_cs_prog_data *cs_prog_data,
850 uint32_t *dst);
851
852
853 /* iris_blit.c */
854 void iris_blorp_surf_for_resource(struct iris_vtable *vtbl,
855 struct isl_device *isl_dev,
856 struct blorp_surf *surf,
857 struct pipe_resource *p_res,
858 enum isl_aux_usage aux_usage,
859 unsigned level,
860 bool is_render_target);
861 void iris_copy_region(struct blorp_context *blorp,
862 struct iris_batch *batch,
863 struct pipe_resource *dst,
864 unsigned dst_level,
865 unsigned dstx, unsigned dsty, unsigned dstz,
866 struct pipe_resource *src,
867 unsigned src_level,
868 const struct pipe_box *src_box);
869
870 /* iris_draw.c */
871
872 void iris_draw_vbo(struct pipe_context *ctx, const struct pipe_draw_info *info);
873 void iris_launch_grid(struct pipe_context *, const struct pipe_grid_info *);
874
875 /* iris_pipe_control.c */
876
877 void iris_emit_pipe_control_flush(struct iris_batch *batch,
878 const char *reason, uint32_t flags);
879 void iris_emit_pipe_control_write(struct iris_batch *batch,
880 const char *reason, uint32_t flags,
881 struct iris_bo *bo, uint32_t offset,
882 uint64_t imm);
883 void iris_emit_end_of_pipe_sync(struct iris_batch *batch,
884 const char *reason, uint32_t flags);
885 void iris_flush_all_caches(struct iris_batch *batch);
886
887 #define iris_handle_always_flush_cache(batch) \
888 if (unlikely(batch->screen->driconf.always_flush_cache)) \
889 iris_flush_all_caches(batch);
890
891 void iris_init_flush_functions(struct pipe_context *ctx);
892
893 /* iris_border_color.c */
894
895 void iris_init_border_color_pool(struct iris_context *ice);
896 void iris_destroy_border_color_pool(struct iris_context *ice);
897 void iris_border_color_pool_reserve(struct iris_context *ice, unsigned count);
898 uint32_t iris_upload_border_color(struct iris_context *ice,
899 union pipe_color_union *color);
900
901 /* iris_program.c */
902 void iris_upload_ubo_ssbo_surf_state(struct iris_context *ice,
903 struct pipe_shader_buffer *buf,
904 struct iris_state_ref *surf_state,
905 bool ssbo);
906 const struct shader_info *iris_get_shader_info(const struct iris_context *ice,
907 gl_shader_stage stage);
908 struct iris_bo *iris_get_scratch_space(struct iris_context *ice,
909 unsigned per_thread_scratch,
910 gl_shader_stage stage);
911 uint32_t iris_group_index_to_bti(const struct iris_binding_table *bt,
912 enum iris_surface_group group,
913 uint32_t index);
914 uint32_t iris_bti_to_group_index(const struct iris_binding_table *bt,
915 enum iris_surface_group group,
916 uint32_t bti);
917
918 /* iris_disk_cache.c */
919
920 void iris_disk_cache_store(struct disk_cache *cache,
921 const struct iris_uncompiled_shader *ish,
922 const struct iris_compiled_shader *shader,
923 const void *prog_key,
924 uint32_t prog_key_size);
925 struct iris_compiled_shader *
926 iris_disk_cache_retrieve(struct iris_context *ice,
927 const struct iris_uncompiled_shader *ish,
928 const void *prog_key,
929 uint32_t prog_key_size);
930
931 /* iris_program_cache.c */
932
933 void iris_init_program_cache(struct iris_context *ice);
934 void iris_destroy_program_cache(struct iris_context *ice);
935 void iris_print_program_cache(struct iris_context *ice);
936 struct iris_compiled_shader *iris_find_cached_shader(struct iris_context *ice,
937 enum iris_program_cache_id,
938 uint32_t key_size,
939 const void *key);
940 struct iris_compiled_shader *iris_upload_shader(struct iris_context *ice,
941 enum iris_program_cache_id,
942 uint32_t key_size,
943 const void *key,
944 const void *assembly,
945 struct brw_stage_prog_data *,
946 uint32_t *streamout,
947 enum brw_param_builtin *sysv,
948 unsigned num_system_values,
949 unsigned num_cbufs,
950 const struct iris_binding_table *bt);
951 const void *iris_find_previous_compile(const struct iris_context *ice,
952 enum iris_program_cache_id cache_id,
953 unsigned program_string_id);
954 bool iris_blorp_lookup_shader(struct blorp_batch *blorp_batch,
955 const void *key,
956 uint32_t key_size,
957 uint32_t *kernel_out,
958 void *prog_data_out);
959 bool iris_blorp_upload_shader(struct blorp_batch *blorp_batch, uint32_t stage,
960 const void *key, uint32_t key_size,
961 const void *kernel, uint32_t kernel_size,
962 const struct brw_stage_prog_data *prog_data,
963 uint32_t prog_data_size,
964 uint32_t *kernel_out,
965 void *prog_data_out);
966
967 /* iris_resolve.c */
968
969 void iris_predraw_resolve_inputs(struct iris_context *ice,
970 struct iris_batch *batch,
971 bool *draw_aux_buffer_disabled,
972 gl_shader_stage stage,
973 bool consider_framebuffer);
974 void iris_predraw_resolve_framebuffer(struct iris_context *ice,
975 struct iris_batch *batch,
976 bool *draw_aux_buffer_disabled);
977 void iris_postdraw_update_resolve_tracking(struct iris_context *ice,
978 struct iris_batch *batch);
979 void iris_cache_sets_clear(struct iris_batch *batch);
980 void iris_flush_depth_and_render_caches(struct iris_batch *batch);
981 void iris_cache_flush_for_read(struct iris_batch *batch, struct iris_bo *bo);
982 void iris_cache_flush_for_render(struct iris_batch *batch,
983 struct iris_bo *bo,
984 enum isl_format format,
985 enum isl_aux_usage aux_usage);
986 void iris_render_cache_add_bo(struct iris_batch *batch,
987 struct iris_bo *bo,
988 enum isl_format format,
989 enum isl_aux_usage aux_usage);
990 void iris_cache_flush_for_depth(struct iris_batch *batch, struct iris_bo *bo);
991 void iris_depth_cache_add_bo(struct iris_batch *batch, struct iris_bo *bo);
992 int iris_get_driver_query_info(struct pipe_screen *pscreen, unsigned index,
993 struct pipe_driver_query_info *info);
994 int iris_get_driver_query_group_info(struct pipe_screen *pscreen,
995 unsigned index,
996 struct pipe_driver_query_group_info *info);
997
998 /* iris_state.c */
999 void gen9_toggle_preemption(struct iris_context *ice,
1000 struct iris_batch *batch,
1001 const struct pipe_draw_info *draw);
1002
1003 #ifdef genX
1004 # include "iris_genx_protos.h"
1005 #else
1006 # define genX(x) gen4_##x
1007 # include "iris_genx_protos.h"
1008 # undef genX
1009 # define genX(x) gen5_##x
1010 # include "iris_genx_protos.h"
1011 # undef genX
1012 # define genX(x) gen6_##x
1013 # include "iris_genx_protos.h"
1014 # undef genX
1015 # define genX(x) gen7_##x
1016 # include "iris_genx_protos.h"
1017 # undef genX
1018 # define genX(x) gen75_##x
1019 # include "iris_genx_protos.h"
1020 # undef genX
1021 # define genX(x) gen8_##x
1022 # include "iris_genx_protos.h"
1023 # undef genX
1024 # define genX(x) gen9_##x
1025 # include "iris_genx_protos.h"
1026 # undef genX
1027 # define genX(x) gen10_##x
1028 # include "iris_genx_protos.h"
1029 # undef genX
1030 # define genX(x) gen11_##x
1031 # include "iris_genx_protos.h"
1032 # undef genX
1033 # define genX(x) gen12_##x
1034 # include "iris_genx_protos.h"
1035 # undef genX
1036 #endif
1037
1038 #endif