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