1 /*
2 * Copyright © 2010 - 2015 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 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * 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 NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21 * IN THE SOFTWARE.
22 */
23
24 #pragma once
25
26 #include <stdio.h>
27 #include "c11/threads.h"
28 #include "dev/intel_device_info.h"
29 #include "isl/isl.h"
30 #include "util/macros.h"
31 #include "util/mesa-sha1.h"
32 #include "util/enum_operators.h"
33 #include "util/ralloc.h"
34 #include "util/u_math.h"
35 #include "util/u_printf.h"
36 #include "brw_isa_info.h"
37 #include "intel_shader_enums.h"
38
39 #ifdef __cplusplus
40 extern "C" {
41 #endif
42
43 struct ra_regs;
44 struct nir_shader;
45 struct shader_info;
46
47 struct nir_shader_compiler_options;
48 typedef struct nir_shader nir_shader;
49
50 #define REG_CLASS_COUNT 20
51
52 struct brw_compiler {
53 const struct intel_device_info *devinfo;
54
55 /* This lock must be taken if the compiler is to be modified in any way,
56 * including adding something to the ralloc child list.
57 */
58 mtx_t mutex;
59
60 struct brw_isa_info isa;
61
62 struct {
63 struct ra_regs *regs;
64
65 /**
66 * Array of the ra classes for the unaligned contiguous register
67 * block sizes used, indexed by register size.
68 */
69 struct ra_class *classes[REG_CLASS_COUNT];
70 } reg_set;
71
72 void (*shader_debug_log)(void *, unsigned *id, const char *str, ...) PRINTFLIKE(3, 4);
73 void (*shader_perf_log)(void *, unsigned *id, const char *str, ...) PRINTFLIKE(3, 4);
74
75 bool use_tcs_multi_patch;
76 struct nir_shader_compiler_options *nir_options[MESA_ALL_SHADER_STAGES];
77
78 /**
79 * Apply workarounds for SIN and COS output range problems.
80 * This can negatively impact performance.
81 */
82 bool precise_trig;
83
84 /**
85 * Whether indirect UBO loads should use the sampler or go through the
86 * data/constant cache. For the sampler, UBO surface states have to be set
87 * up with VK_FORMAT_R32G32B32A32_FLOAT whereas if it's going through the
88 * constant or data cache, UBOs must use VK_FORMAT_RAW.
89 */
90 bool indirect_ubos_use_sampler;
91
92 /**
93 * Gfx12.5+ has a bit in the SEND instruction extending the bindless
94 * surface offset range from 20 to 26 bits, effectively giving us 4Gb of
95 * bindless surface descriptors instead of 64Mb previously.
96 */
97 bool extended_bindless_surface_offset;
98
99 /**
100 * Gfx11+ has a bit in the dword 3 of the sampler message header that
101 * indicates whether the sampler handle is relative to the dynamic state
102 * base address (0) or the bindless sampler base address (1). The driver
103 * can select this.
104 */
105 bool use_bindless_sampler_offset;
106
107 /**
108 * Should DPAS instructions be lowered?
109 *
110 * This will be set for all platforms before Gfx12.5. It may also be set
111 * platforms that support DPAS for testing purposes.
112 */
113 bool lower_dpas;
114
115 /**
116 * Calling the ra_allocate function after each register spill can take
117 * several minutes. This option speeds up shader compilation by spilling
118 * more registers after the ra_allocate failure. Required for
119 * Cyberpunk 2077, which uses a watchdog thread to terminate the process
120 * in case the render thread hasn't responded within 2 minutes.
121 */
122 int spilling_rate;
123
124 struct nir_shader *clc_shader;
125
126 struct {
127 unsigned mue_header_packing;
128 bool mue_compaction;
129 } mesh;
130 };
131
132 #define brw_shader_debug_log(compiler, data, fmt, ... ) do { \
133 static unsigned id = 0; \
134 compiler->shader_debug_log(data, &id, fmt, ##__VA_ARGS__); \
135 } while (0)
136
137 #define brw_shader_perf_log(compiler, data, fmt, ... ) do { \
138 static unsigned id = 0; \
139 compiler->shader_perf_log(data, &id, fmt, ##__VA_ARGS__); \
140 } while (0)
141
142 /**
143 * We use a constant subgroup size of 32. It really only needs to be a
144 * maximum and, since we do SIMD32 for compute shaders in some cases, it
145 * needs to be at least 32. SIMD8 and SIMD16 shaders will still claim a
146 * subgroup size of 32 but will act as if 16 or 24 of those channels are
147 * disabled.
148 */
149 #define BRW_SUBGROUP_SIZE 32
150
151 static inline bool
brw_shader_stage_is_bindless(gl_shader_stage stage)152 brw_shader_stage_is_bindless(gl_shader_stage stage)
153 {
154 return stage >= MESA_SHADER_RAYGEN &&
155 stage <= MESA_SHADER_CALLABLE;
156 }
157
158 static inline bool
brw_shader_stage_requires_bindless_resources(gl_shader_stage stage)159 brw_shader_stage_requires_bindless_resources(gl_shader_stage stage)
160 {
161 return brw_shader_stage_is_bindless(stage) || gl_shader_stage_is_mesh(stage);
162 }
163
164 static inline bool
brw_shader_stage_has_inline_data(const struct intel_device_info * devinfo,gl_shader_stage stage)165 brw_shader_stage_has_inline_data(const struct intel_device_info *devinfo,
166 gl_shader_stage stage)
167 {
168 return stage == MESA_SHADER_MESH || stage == MESA_SHADER_TASK ||
169 (stage == MESA_SHADER_COMPUTE && devinfo->verx10 >= 125);
170 }
171
172 /**
173 * Program key structures.
174 *
175 * When drawing, we look for the currently bound shaders in the program
176 * cache. This is essentially a hash table lookup, and these are the keys.
177 *
178 * Sometimes OpenGL features specified as state need to be simulated via
179 * shader code, due to a mismatch between the API and the hardware. This
180 * is often referred to as "non-orthagonal state" or "NOS". We store NOS
181 * in the program key so it's considered when searching for a program. If
182 * we haven't seen a particular combination before, we have to recompile a
183 * new specialized version.
184 *
185 * Shader compilation should not look up state in gl_context directly, but
186 * instead use the copy in the program key. This guarantees recompiles will
187 * happen correctly.
188 *
189 * @{
190 */
191
192 #define BRW_MAX_SAMPLERS 32
193
194 /* Provide explicit padding for each member, to ensure that the compiler
195 * initializes every bit in the shader cache keys. The keys will be compared
196 * with memcmp.
197 */
198 PRAGMA_DIAGNOSTIC_PUSH
199 PRAGMA_DIAGNOSTIC_ERROR(-Wpadded)
200
201 enum brw_robustness_flags {
202 BRW_ROBUSTNESS_UBO = BITFIELD_BIT(0),
203 BRW_ROBUSTNESS_SSBO = BITFIELD_BIT(1),
204 };
205
206 struct brw_base_prog_key {
207 unsigned program_string_id;
208
209 enum brw_robustness_flags robust_flags:2;
210
211 unsigned padding:22;
212
213 /**
214 * Apply workarounds for SIN and COS input range problems.
215 * This limits input range for SIN and COS to [-2p : 2p] to
216 * avoid precision issues.
217 */
218 bool limit_trig_input_range;
219 };
220
221 /**
222 * OpenGL attribute slots fall in [0, VERT_ATTRIB_MAX - 1] with the range
223 * [VERT_ATTRIB_GENERIC0, VERT_ATTRIB_MAX - 1] reserved for up to 16 user
224 * input vertex attributes. In Vulkan, we expose up to 28 user vertex input
225 * attributes that are mapped to slots also starting at VERT_ATTRIB_GENERIC0.
226 */
227 #define MAX_GL_VERT_ATTRIB VERT_ATTRIB_MAX
228 #define MAX_VK_VERT_ATTRIB (VERT_ATTRIB_GENERIC0 + 28)
229
230 /** The program key for Vertex Shaders. */
231 struct brw_vs_prog_key {
232 struct brw_base_prog_key base;
233 };
234
235 /** The program key for Tessellation Control Shaders. */
236 struct brw_tcs_prog_key
237 {
238 struct brw_base_prog_key base;
239
240 /** A bitfield of per-vertex outputs written. */
241 uint64_t outputs_written;
242
243 enum tess_primitive_mode _tes_primitive_mode;
244
245 /** Number of input vertices, 0 means dynamic */
246 unsigned input_vertices;
247
248 /** A bitfield of per-patch outputs written. */
249 uint32_t patch_outputs_written;
250
251 uint32_t padding;
252 };
253
254 #define BRW_MAX_TCS_INPUT_VERTICES (32)
255
256 static inline uint32_t
brw_tcs_prog_key_input_vertices(const struct brw_tcs_prog_key * key)257 brw_tcs_prog_key_input_vertices(const struct brw_tcs_prog_key *key)
258 {
259 return key->input_vertices != 0 ?
260 key->input_vertices : BRW_MAX_TCS_INPUT_VERTICES;
261 }
262
263 /** The program key for Tessellation Evaluation Shaders. */
264 struct brw_tes_prog_key
265 {
266 struct brw_base_prog_key base;
267
268 /** A bitfield of per-vertex inputs read. */
269 uint64_t inputs_read;
270
271 /** A bitfield of per-patch inputs read. */
272 uint32_t patch_inputs_read;
273
274 uint32_t padding;
275 };
276
277 /** The program key for Geometry Shaders. */
278 struct brw_gs_prog_key
279 {
280 struct brw_base_prog_key base;
281 };
282
283 struct brw_task_prog_key
284 {
285 struct brw_base_prog_key base;
286 };
287
288 struct brw_mesh_prog_key
289 {
290 struct brw_base_prog_key base;
291
292 bool compact_mue:1;
293 unsigned padding:31;
294 };
295
296 /** The program key for Fragment/Pixel Shaders. */
297 struct brw_wm_prog_key {
298 struct brw_base_prog_key base;
299
300 uint64_t input_slots_valid;
301 uint8_t color_outputs_valid;
302
303 /* Some collection of BRW_WM_IZ_* */
304 bool flat_shade:1;
305 unsigned nr_color_regions:5;
306 bool alpha_test_replicate_alpha:1;
307 enum intel_sometimes alpha_to_coverage:2;
308 bool clamp_fragment_color:1;
309
310 bool force_dual_color_blend:1;
311
312 /** Whether or inputs are interpolated at sample rate by default
313 *
314 * This corresponds to the sample shading API bit in Vulkan or OpenGL which
315 * controls how inputs with no interpolation qualifier are interpolated.
316 * This is distinct from the way that using gl_SampleID or similar requires
317 * us to run per-sample. Even when running per-sample due to gl_SampleID,
318 * we may still interpolate unqualified inputs at the pixel center.
319 */
320 enum intel_sometimes persample_interp:2;
321
322 /* Whether or not we are running on a multisampled framebuffer */
323 enum intel_sometimes multisample_fbo:2;
324
325 /* Whether the preceding shader stage is mesh */
326 enum intel_sometimes mesh_input:2;
327
328 bool coherent_fb_fetch:1;
329 bool ignore_sample_mask_out:1;
330 bool coarse_pixel:1;
331 bool null_push_constant_tbimr_workaround:1;
332
333 uint64_t padding:35;
334 };
335
336 struct brw_cs_prog_key {
337 struct brw_base_prog_key base;
338 };
339
340 struct brw_bs_prog_key {
341 struct brw_base_prog_key base;
342
343 /* Represents enum enum brw_rt_ray_flags values given at pipeline creation
344 * to be combined with ray_flags handed to the traceRayEXT() calls by the
345 * shader.
346 */
347 uint32_t pipeline_ray_flags;
348 };
349
350 /* brw_any_prog_key is any of the keys that map to an API stage */
351 union brw_any_prog_key {
352 struct brw_base_prog_key base;
353 struct brw_vs_prog_key vs;
354 struct brw_tcs_prog_key tcs;
355 struct brw_tes_prog_key tes;
356 struct brw_gs_prog_key gs;
357 struct brw_wm_prog_key wm;
358 struct brw_cs_prog_key cs;
359 struct brw_bs_prog_key bs;
360 struct brw_task_prog_key task;
361 struct brw_mesh_prog_key mesh;
362 };
363
364 PRAGMA_DIAGNOSTIC_POP
365
366 /** Max number of render targets in a shader */
367 #define BRW_MAX_DRAW_BUFFERS 8
368
369 struct brw_ubo_range
370 {
371 uint16_t block;
372
373 /* In units of 32-byte registers */
374 uint8_t start;
375 uint8_t length;
376 };
377
378 /* We reserve the first 2^16 values for builtins */
379 #define BRW_PARAM_IS_BUILTIN(param) (((param) & 0xffff0000) == 0)
380
381 enum brw_param_builtin {
382 BRW_PARAM_BUILTIN_ZERO,
383
384 BRW_PARAM_BUILTIN_CLIP_PLANE_0_X,
385 BRW_PARAM_BUILTIN_CLIP_PLANE_0_Y,
386 BRW_PARAM_BUILTIN_CLIP_PLANE_0_Z,
387 BRW_PARAM_BUILTIN_CLIP_PLANE_0_W,
388 BRW_PARAM_BUILTIN_CLIP_PLANE_1_X,
389 BRW_PARAM_BUILTIN_CLIP_PLANE_1_Y,
390 BRW_PARAM_BUILTIN_CLIP_PLANE_1_Z,
391 BRW_PARAM_BUILTIN_CLIP_PLANE_1_W,
392 BRW_PARAM_BUILTIN_CLIP_PLANE_2_X,
393 BRW_PARAM_BUILTIN_CLIP_PLANE_2_Y,
394 BRW_PARAM_BUILTIN_CLIP_PLANE_2_Z,
395 BRW_PARAM_BUILTIN_CLIP_PLANE_2_W,
396 BRW_PARAM_BUILTIN_CLIP_PLANE_3_X,
397 BRW_PARAM_BUILTIN_CLIP_PLANE_3_Y,
398 BRW_PARAM_BUILTIN_CLIP_PLANE_3_Z,
399 BRW_PARAM_BUILTIN_CLIP_PLANE_3_W,
400 BRW_PARAM_BUILTIN_CLIP_PLANE_4_X,
401 BRW_PARAM_BUILTIN_CLIP_PLANE_4_Y,
402 BRW_PARAM_BUILTIN_CLIP_PLANE_4_Z,
403 BRW_PARAM_BUILTIN_CLIP_PLANE_4_W,
404 BRW_PARAM_BUILTIN_CLIP_PLANE_5_X,
405 BRW_PARAM_BUILTIN_CLIP_PLANE_5_Y,
406 BRW_PARAM_BUILTIN_CLIP_PLANE_5_Z,
407 BRW_PARAM_BUILTIN_CLIP_PLANE_5_W,
408 BRW_PARAM_BUILTIN_CLIP_PLANE_6_X,
409 BRW_PARAM_BUILTIN_CLIP_PLANE_6_Y,
410 BRW_PARAM_BUILTIN_CLIP_PLANE_6_Z,
411 BRW_PARAM_BUILTIN_CLIP_PLANE_6_W,
412 BRW_PARAM_BUILTIN_CLIP_PLANE_7_X,
413 BRW_PARAM_BUILTIN_CLIP_PLANE_7_Y,
414 BRW_PARAM_BUILTIN_CLIP_PLANE_7_Z,
415 BRW_PARAM_BUILTIN_CLIP_PLANE_7_W,
416
417 BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X,
418 BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_Y,
419 BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_Z,
420 BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_W,
421 BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_X,
422 BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_Y,
423
424 BRW_PARAM_BUILTIN_PATCH_VERTICES_IN,
425
426 BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_X,
427 BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Y,
428 BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Z,
429 BRW_PARAM_BUILTIN_SUBGROUP_ID,
430 BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_X,
431 BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_Y,
432 BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_Z,
433 BRW_PARAM_BUILTIN_WORK_DIM,
434 };
435
436 #define BRW_PARAM_BUILTIN_CLIP_PLANE(idx, comp) \
437 (BRW_PARAM_BUILTIN_CLIP_PLANE_0_X + ((idx) << 2) + (comp))
438
439 #define BRW_PARAM_BUILTIN_IS_CLIP_PLANE(param) \
440 ((param) >= BRW_PARAM_BUILTIN_CLIP_PLANE_0_X && \
441 (param) <= BRW_PARAM_BUILTIN_CLIP_PLANE_7_W)
442
443 #define BRW_PARAM_BUILTIN_CLIP_PLANE_IDX(param) \
444 (((param) - BRW_PARAM_BUILTIN_CLIP_PLANE_0_X) >> 2)
445
446 #define BRW_PARAM_BUILTIN_CLIP_PLANE_COMP(param) \
447 (((param) - BRW_PARAM_BUILTIN_CLIP_PLANE_0_X) & 0x3)
448
449 #define BRW_MAX_EMBEDDED_SAMPLERS (4096)
450
451 enum brw_shader_reloc_id {
452 BRW_SHADER_RELOC_CONST_DATA_ADDR_LOW,
453 BRW_SHADER_RELOC_CONST_DATA_ADDR_HIGH,
454 BRW_SHADER_RELOC_SHADER_START_OFFSET,
455 BRW_SHADER_RELOC_RESUME_SBT_ADDR_LOW,
456 BRW_SHADER_RELOC_RESUME_SBT_ADDR_HIGH,
457 BRW_SHADER_RELOC_DESCRIPTORS_ADDR_HIGH,
458 BRW_SHADER_RELOC_DESCRIPTORS_BUFFER_ADDR_HIGH,
459 BRW_SHADER_RELOC_EMBEDDED_SAMPLER_HANDLE,
460 BRW_SHADER_RELOC_LAST_EMBEDDED_SAMPLER_HANDLE =
461 BRW_SHADER_RELOC_EMBEDDED_SAMPLER_HANDLE + BRW_MAX_EMBEDDED_SAMPLERS - 1,
462 BRW_SHADER_RELOC_PRINTF_BUFFER_ADDR_LOW,
463 BRW_SHADER_RELOC_PRINTF_BUFFER_ADDR_HIGH,
464 BRW_SHADER_RELOC_PRINTF_BASE_IDENTIFIER,
465 BRW_SHADER_RELOC_PRINTF_BUFFER_SIZE,
466 };
467
468 enum brw_shader_reloc_type {
469 /** An arbitrary 32-bit value */
470 BRW_SHADER_RELOC_TYPE_U32,
471 /** A MOV instruction with an immediate source */
472 BRW_SHADER_RELOC_TYPE_MOV_IMM,
473 };
474
475 /** Represents a code relocation
476 *
477 * Relocatable constants are immediates in the code which we want to be able
478 * to replace post-compile with the actual value.
479 */
480 struct brw_shader_reloc {
481 /** The 32-bit ID of the relocatable constant */
482 uint32_t id;
483
484 /** Type of this relocation */
485 enum brw_shader_reloc_type type;
486
487 /** The offset in the shader to the relocated value
488 *
489 * For MOV_IMM relocs, this is an offset to the MOV instruction. This
490 * allows us to do some sanity checking while we update the value.
491 */
492 uint32_t offset;
493
494 /** Value to be added to the relocated value before it is written */
495 uint32_t delta;
496 };
497
498 /** A value to write to a relocation */
499 struct brw_shader_reloc_value {
500 /** The 32-bit ID of the relocatable constant */
501 uint32_t id;
502
503 /** The value with which to replace the relocated immediate */
504 uint32_t value;
505 };
506
507 struct brw_stage_prog_data {
508 struct brw_ubo_range ubo_ranges[4];
509
510 unsigned nr_params; /**< number of float params/constants */
511
512 gl_shader_stage stage;
513
514 /* zero_push_reg is a bitfield which indicates what push registers (if any)
515 * should be zeroed by SW at the start of the shader. The corresponding
516 * push_reg_mask_param specifies the param index (in 32-bit units) where
517 * the actual runtime 64-bit mask will be pushed. The shader will zero
518 * push reg i if
519 *
520 * reg_used & zero_push_reg & ~*push_reg_mask_param & (1ull << i)
521 *
522 * If this field is set, brw_compiler::compact_params must be false.
523 */
524 uint64_t zero_push_reg;
525 unsigned push_reg_mask_param;
526
527 unsigned curb_read_length;
528 unsigned total_scratch;
529 unsigned total_shared;
530
531 unsigned program_size;
532
533 unsigned const_data_size;
534 unsigned const_data_offset;
535
536 unsigned num_relocs;
537 const struct brw_shader_reloc *relocs;
538
539 /** Does this program pull from any UBO or other constant buffers? */
540 bool has_ubo_pull;
541
542 /** How many ray queries objects in this shader. */
543 unsigned ray_queries;
544
545 /**
546 * Register where the thread expects to find input data from the URB
547 * (typically uniforms, followed by vertex or fragment attributes).
548 */
549 unsigned dispatch_grf_start_reg;
550
551 /** Number of GRF registers used. */
552 unsigned grf_used;
553
554 bool use_alt_mode; /**< Use ALT floating point mode? Otherwise, IEEE. */
555
556 /* 32-bit identifiers for all push/pull parameters. These can be anything
557 * the driver wishes them to be; the core of the back-end compiler simply
558 * re-arranges them. The one restriction is that the bottom 2^16 values
559 * are reserved for builtins defined in the brw_param_builtin enum defined
560 * above.
561 */
562 uint32_t *param;
563
564 /* Whether shader uses atomic operations. */
565 bool uses_atomic_load_store;
566
567 /* Printf descriptions contained by the shader */
568 uint32_t printf_info_count;
569 u_printf_info *printf_info;
570 };
571
572 /**
573 * Convert a number of GRF registers used (grf_used in prog_data) into
574 * a number of GRF register blocks supported by the hardware on PTL+.
575 */
576 static inline unsigned
ptl_register_blocks(unsigned grf_used)577 ptl_register_blocks(unsigned grf_used)
578 {
579 const unsigned n = DIV_ROUND_UP(grf_used, 32) - 1;
580 return (n < 6 ? n : 7);
581 }
582
583 static inline uint32_t *
brw_stage_prog_data_add_params(struct brw_stage_prog_data * prog_data,unsigned nr_new_params)584 brw_stage_prog_data_add_params(struct brw_stage_prog_data *prog_data,
585 unsigned nr_new_params)
586 {
587 unsigned old_nr_params = prog_data->nr_params;
588 prog_data->nr_params += nr_new_params;
589 prog_data->param = reralloc(ralloc_parent(prog_data->param),
590 prog_data->param, uint32_t,
591 prog_data->nr_params);
592 return prog_data->param + old_nr_params;
593 }
594
595 void
596 brw_stage_prog_data_add_printf(struct brw_stage_prog_data *prog_data,
597 void *mem_ctx,
598 const u_printf_info *print);
599
600 enum brw_pixel_shader_computed_depth_mode {
601 BRW_PSCDEPTH_OFF = 0, /* PS does not compute depth */
602 BRW_PSCDEPTH_ON = 1, /* PS computes depth; no guarantee about value */
603 BRW_PSCDEPTH_ON_GE = 2, /* PS guarantees output depth >= source depth */
604 BRW_PSCDEPTH_ON_LE = 3, /* PS guarantees output depth <= source depth */
605 };
606
607 /* Data about a particular attempt to compile a program. Note that
608 * there can be many of these, each in a different GL state
609 * corresponding to a different brw_wm_prog_key struct, with different
610 * compiled programs.
611 */
612 struct brw_wm_prog_data {
613 struct brw_stage_prog_data base;
614
615 unsigned num_per_primitive_inputs;
616 unsigned num_varying_inputs;
617
618 uint8_t dispatch_grf_start_reg_16;
619 uint8_t dispatch_grf_start_reg_32;
620 uint32_t prog_offset_16;
621 uint32_t prog_offset_32;
622
623 uint8_t computed_depth_mode;
624
625 /**
626 * Number of polygons handled in parallel by the multi-polygon PS
627 * kernel.
628 */
629 uint8_t max_polygons;
630
631 /**
632 * Dispatch width of the multi-polygon PS kernel, or 0 if no
633 * multi-polygon kernel was built.
634 */
635 uint8_t dispatch_multi;
636
637 bool computed_stencil;
638 bool early_fragment_tests;
639 bool post_depth_coverage;
640 bool inner_coverage;
641 bool dispatch_8;
642 bool dispatch_16;
643 bool dispatch_32;
644 bool dual_src_blend;
645 bool uses_pos_offset;
646 bool uses_omask;
647 bool uses_kill;
648 bool uses_src_depth;
649 bool uses_src_w;
650 bool uses_depth_w_coefficients;
651 bool uses_pc_bary_coefficients;
652 bool uses_npc_bary_coefficients;
653 bool uses_sample_offsets;
654 bool uses_sample_mask;
655 bool uses_vmask;
656 bool has_side_effects;
657 bool pulls_bary;
658
659 bool contains_flat_varying;
660 bool contains_noperspective_varying;
661
662 /** True if the shader wants sample shading
663 *
664 * This corresponds to whether or not a gl_SampleId, gl_SamplePosition, or
665 * a sample-qualified input are used in the shader. It is independent of
666 * GL_MIN_SAMPLE_SHADING_VALUE in GL or minSampleShading in Vulkan.
667 */
668 bool sample_shading;
669
670 /** Min sample shading value
671 *
672 * Not used by the compiler, but useful for restore from the cache. The
673 * driver is expected to write the value it wants.
674 */
675 float min_sample_shading;
676
677 /** Should this shader be dispatched per-sample */
678 enum intel_sometimes persample_dispatch;
679
680 /**
681 * Shader is ran at the coarse pixel shading dispatch rate (3DSTATE_CPS).
682 */
683 enum intel_sometimes coarse_pixel_dispatch;
684
685 /**
686 * Shader writes the SampleMask and this is AND-ed with the API's
687 * SampleMask to generate a new coverage mask.
688 */
689 enum intel_sometimes alpha_to_coverage;
690
691 unsigned msaa_flags_param;
692
693 /**
694 * Mask of which interpolation modes are required by the fragment shader.
695 * Those interpolations are delivered as part of the thread payload. Used
696 * in hardware setup on gfx6+.
697 */
698 uint32_t barycentric_interp_modes;
699
700 /**
701 * Whether nonperspective interpolation modes are used by the
702 * barycentric_interp_modes or fragment shader through interpolator messages.
703 */
704 bool uses_nonperspective_interp_modes;
705
706 /**
707 * Mask of which FS inputs are marked flat by the shader source. This is
708 * needed for setting up 3DSTATE_SF/SBE.
709 */
710 uint32_t flat_inputs;
711
712 /**
713 * The FS inputs
714 */
715 uint64_t inputs;
716
717 /**
718 * Map from gl_varying_slot to the position within the FS setup data
719 * payload where the varying's attribute vertex deltas should be delivered.
720 * For varying slots that are not used by the FS, the value is -1.
721 */
722 int urb_setup[VARYING_SLOT_MAX];
723 int urb_setup_channel[VARYING_SLOT_MAX];
724
725 /**
726 * Cache structure into the urb_setup array above that contains the
727 * attribute numbers of active varyings out of urb_setup.
728 * The actual count is stored in urb_setup_attribs_count.
729 */
730 uint8_t urb_setup_attribs[VARYING_SLOT_MAX];
731 uint8_t urb_setup_attribs_count;
732 };
733
734 #ifdef GFX_VERx10
735
736 #if GFX_VERx10 >= 200
737
738 /** Returns the SIMD width corresponding to a given KSP index
739 *
740 * The "Variable Pixel Dispatch" table in the PRM (which can be found, for
741 * example in Vol. 7 of the SKL PRM) has a mapping from dispatch widths to
742 * kernel start pointer (KSP) indices that is based on what dispatch widths
743 * are enabled. This function provides, effectively, the reverse mapping.
744 *
745 * If the given KSP is enabled, a SIMD width of 8, 16, or 32 is
746 * returned. Note that for a multipolygon dispatch kernel 8 is always
747 * returned, since multipolygon kernels use the "_8" fields from
748 * brw_wm_prog_data regardless of their SIMD width. If the KSP is
749 * invalid, 0 is returned.
750 */
751 static inline unsigned
brw_fs_simd_width_for_ksp(unsigned ksp_idx,bool enabled,unsigned width_sel)752 brw_fs_simd_width_for_ksp(unsigned ksp_idx, bool enabled, unsigned width_sel)
753 {
754 assert(ksp_idx < 2);
755 return !enabled ? 0 :
756 width_sel ? 32 :
757 16;
758 }
759
760 #define brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx) \
761 (ksp_idx == 0 && (wm_state).Kernel0MaximumPolysperThread ? 8 : \
762 ksp_idx == 0 ? brw_fs_simd_width_for_ksp(ksp_idx, (wm_state).Kernel0Enable, \
763 (wm_state).Kernel0SIMDWidth): \
764 brw_fs_simd_width_for_ksp(ksp_idx, (wm_state).Kernel1Enable, \
765 (wm_state).Kernel1SIMDWidth))
766
767 #else
768
769 /** Returns the SIMD width corresponding to a given KSP index
770 *
771 * The "Variable Pixel Dispatch" table in the PRM (which can be found, for
772 * example in Vol. 7 of the SKL PRM) has a mapping from dispatch widths to
773 * kernel start pointer (KSP) indices that is based on what dispatch widths
774 * are enabled. This function provides, effectively, the reverse mapping.
775 *
776 * If the given KSP is valid with respect to the SIMD8/16/32 enables, a SIMD
777 * width of 8, 16, or 32 is returned. If the KSP is invalid, 0 is returned.
778 */
779 static inline unsigned
brw_fs_simd_width_for_ksp(unsigned ksp_idx,bool simd8_enabled,bool simd16_enabled,bool simd32_enabled)780 brw_fs_simd_width_for_ksp(unsigned ksp_idx, bool simd8_enabled,
781 bool simd16_enabled, bool simd32_enabled)
782 {
783 /* This function strictly ignores contiguous dispatch */
784 switch (ksp_idx) {
785 case 0:
786 return simd8_enabled ? 8 :
787 (simd16_enabled && !simd32_enabled) ? 16 :
788 (simd32_enabled && !simd16_enabled) ? 32 : 0;
789 case 1:
790 return (simd32_enabled && (simd16_enabled || simd8_enabled)) ? 32 : 0;
791 case 2:
792 return (simd16_enabled && (simd32_enabled || simd8_enabled)) ? 16 : 0;
793 default:
794 unreachable("Invalid KSP index");
795 }
796 }
797
798 #define brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx) \
799 brw_fs_simd_width_for_ksp((ksp_idx), (wm_state)._8PixelDispatchEnable, \
800 (wm_state)._16PixelDispatchEnable, \
801 (wm_state)._32PixelDispatchEnable)
802
803 #endif
804
805 #endif
806
807 #define brw_wm_state_has_ksp(wm_state, ksp_idx) \
808 (brw_wm_state_simd_width_for_ksp((wm_state), (ksp_idx)) != 0)
809
810 static inline uint32_t
_brw_wm_prog_data_prog_offset(const struct brw_wm_prog_data * prog_data,unsigned simd_width)811 _brw_wm_prog_data_prog_offset(const struct brw_wm_prog_data *prog_data,
812 unsigned simd_width)
813 {
814 switch (simd_width) {
815 case 8: return 0;
816 case 16: return prog_data->prog_offset_16;
817 case 32: return prog_data->prog_offset_32;
818 default: return 0;
819 }
820 }
821
822 #define brw_wm_prog_data_prog_offset(prog_data, wm_state, ksp_idx) \
823 _brw_wm_prog_data_prog_offset(prog_data, \
824 brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx))
825
826 static inline uint8_t
_brw_wm_prog_data_dispatch_grf_start_reg(const struct brw_wm_prog_data * prog_data,unsigned simd_width)827 _brw_wm_prog_data_dispatch_grf_start_reg(const struct brw_wm_prog_data *prog_data,
828 unsigned simd_width)
829 {
830 switch (simd_width) {
831 case 8: return prog_data->base.dispatch_grf_start_reg;
832 case 16: return prog_data->dispatch_grf_start_reg_16;
833 case 32: return prog_data->dispatch_grf_start_reg_32;
834 default: return 0;
835 }
836 }
837
838 #define brw_wm_prog_data_dispatch_grf_start_reg(prog_data, wm_state, ksp_idx) \
839 _brw_wm_prog_data_dispatch_grf_start_reg(prog_data, \
840 brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx))
841
842 static inline bool
brw_wm_prog_data_is_persample(const struct brw_wm_prog_data * prog_data,enum intel_msaa_flags pushed_msaa_flags)843 brw_wm_prog_data_is_persample(const struct brw_wm_prog_data *prog_data,
844 enum intel_msaa_flags pushed_msaa_flags)
845 {
846 return intel_fs_is_persample(prog_data->persample_dispatch,
847 prog_data->sample_shading,
848 pushed_msaa_flags);
849 }
850
851 static inline uint32_t
wm_prog_data_barycentric_modes(const struct brw_wm_prog_data * prog_data,enum intel_msaa_flags pushed_msaa_flags)852 wm_prog_data_barycentric_modes(const struct brw_wm_prog_data *prog_data,
853 enum intel_msaa_flags pushed_msaa_flags)
854 {
855 return intel_fs_barycentric_modes(prog_data->persample_dispatch,
856 prog_data->barycentric_interp_modes,
857 pushed_msaa_flags);
858 }
859
860 static inline bool
brw_wm_prog_data_is_coarse(const struct brw_wm_prog_data * prog_data,enum intel_msaa_flags pushed_msaa_flags)861 brw_wm_prog_data_is_coarse(const struct brw_wm_prog_data *prog_data,
862 enum intel_msaa_flags pushed_msaa_flags)
863 {
864 return intel_fs_is_coarse(prog_data->coarse_pixel_dispatch,
865 pushed_msaa_flags);
866 }
867
868 struct brw_push_const_block {
869 unsigned dwords; /* Dword count, not reg aligned */
870 unsigned regs;
871 unsigned size; /* Bytes, register aligned */
872 };
873
874 struct brw_cs_prog_data {
875 struct brw_stage_prog_data base;
876
877 unsigned local_size[3];
878
879 /* Program offsets for the 8/16/32 SIMD variants. Multiple variants are
880 * kept when using variable group size, and the right one can only be
881 * decided at dispatch time.
882 */
883 unsigned prog_offset[3];
884
885 /* Bitmask indicating which program offsets are valid. */
886 unsigned prog_mask;
887
888 /* Bitmask indicating which programs have spilled. */
889 unsigned prog_spilled;
890
891 bool uses_barrier;
892 bool uses_num_work_groups;
893 bool uses_inline_data;
894 bool uses_btd_stack_ids;
895 bool uses_systolic;
896 uint8_t generate_local_id;
897 enum intel_compute_walk_order walk_order;
898
899 /* True if shader has any sample operation */
900 bool uses_sampler;
901
902 struct {
903 struct brw_push_const_block cross_thread;
904 struct brw_push_const_block per_thread;
905 } push;
906 };
907
908 static inline uint32_t
brw_cs_prog_data_prog_offset(const struct brw_cs_prog_data * prog_data,unsigned dispatch_width)909 brw_cs_prog_data_prog_offset(const struct brw_cs_prog_data *prog_data,
910 unsigned dispatch_width)
911 {
912 assert(dispatch_width == 8 ||
913 dispatch_width == 16 ||
914 dispatch_width == 32);
915 const unsigned index = dispatch_width / 16;
916 assert(prog_data->prog_mask & (1 << index));
917 return prog_data->prog_offset[index];
918 }
919
920 struct brw_bs_prog_data {
921 struct brw_stage_prog_data base;
922
923 /** SIMD size of the root shader */
924 uint8_t simd_size;
925
926 /** Maximum stack size of all shaders */
927 uint32_t max_stack_size;
928
929 /** Offset into the shader where the resume SBT is located */
930 uint32_t resume_sbt_offset;
931
932 /** Number of resume shaders */
933 uint32_t num_resume_shaders;
934 };
935
936 /**
937 * Enum representing the i965-specific vertex results that don't correspond
938 * exactly to any element of gl_varying_slot. The values of this enum are
939 * assigned such that they don't conflict with gl_varying_slot.
940 */
941 typedef enum
942 {
943 BRW_VARYING_SLOT_PAD = VARYING_SLOT_MAX,
944 BRW_VARYING_SLOT_COUNT
945 } brw_varying_slot;
946
947 /**
948 * Bitmask indicating which fragment shader inputs represent varyings (and
949 * hence have to be delivered to the fragment shader by the SF/SBE stage).
950 */
951 #define BRW_FS_VARYING_INPUT_MASK \
952 (BITFIELD64_RANGE(0, VARYING_SLOT_MAX) & \
953 ~VARYING_BIT_POS & ~VARYING_BIT_FACE)
954
955 void brw_print_vue_map(FILE *fp, const struct intel_vue_map *vue_map,
956 gl_shader_stage stage);
957
958 /**
959 * Convert a VUE slot number into a byte offset within the VUE.
960 */
brw_vue_slot_to_offset(unsigned slot)961 static inline unsigned brw_vue_slot_to_offset(unsigned slot)
962 {
963 return 16*slot;
964 }
965
966 /**
967 * Convert a vertex output (brw_varying_slot) into a byte offset within the
968 * VUE.
969 */
970 static inline unsigned
brw_varying_to_offset(const struct intel_vue_map * vue_map,unsigned varying)971 brw_varying_to_offset(const struct intel_vue_map *vue_map, unsigned varying)
972 {
973 return brw_vue_slot_to_offset(vue_map->varying_to_slot[varying]);
974 }
975
976 void brw_compute_vue_map(const struct intel_device_info *devinfo,
977 struct intel_vue_map *vue_map,
978 uint64_t slots_valid,
979 bool separate_shader,
980 uint32_t pos_slots);
981
982 void brw_compute_tess_vue_map(struct intel_vue_map *const vue_map,
983 uint64_t slots_valid,
984 uint32_t is_patch);
985
986 struct brw_vue_prog_data {
987 struct brw_stage_prog_data base;
988 struct intel_vue_map vue_map;
989
990 /** Should the hardware deliver input VUE handles for URB pull loads? */
991 bool include_vue_handles;
992
993 unsigned urb_read_length;
994 unsigned total_grf;
995
996 uint32_t clip_distance_mask;
997 uint32_t cull_distance_mask;
998
999 /* Used for calculating urb partitions. In the VS, this is the size of the
1000 * URB entry used for both input and output to the thread. In the GS, this
1001 * is the size of the URB entry used for output.
1002 */
1003 unsigned urb_entry_size;
1004
1005 enum intel_shader_dispatch_mode dispatch_mode;
1006 };
1007
1008 struct brw_vs_prog_data {
1009 struct brw_vue_prog_data base;
1010
1011 uint64_t inputs_read;
1012 uint64_t double_inputs_read;
1013
1014 unsigned nr_attribute_slots;
1015
1016 bool uses_vertexid;
1017 bool uses_instanceid;
1018 bool uses_is_indexed_draw;
1019 bool uses_firstvertex;
1020 bool uses_baseinstance;
1021 bool uses_drawid;
1022 };
1023
1024 struct brw_tcs_prog_data
1025 {
1026 struct brw_vue_prog_data base;
1027
1028 /** Should the non-SINGLE_PATCH payload provide primitive ID? */
1029 bool include_primitive_id;
1030
1031 /** Number vertices in output patch */
1032 int instances;
1033
1034 /** Track patch count threshold */
1035 int patch_count_threshold;
1036 };
1037
1038
1039 struct brw_tes_prog_data
1040 {
1041 struct brw_vue_prog_data base;
1042
1043 enum intel_tess_partitioning partitioning;
1044 enum intel_tess_output_topology output_topology;
1045 enum intel_tess_domain domain;
1046 bool include_primitive_id;
1047 };
1048
1049 struct brw_gs_prog_data
1050 {
1051 struct brw_vue_prog_data base;
1052
1053 unsigned vertices_in;
1054
1055 /**
1056 * Size of an output vertex, measured in HWORDS (32 bytes).
1057 */
1058 unsigned output_vertex_size_hwords;
1059
1060 unsigned output_topology;
1061
1062 /**
1063 * Size of the control data (cut bits or StreamID bits), in hwords (32
1064 * bytes). 0 if there is no control data.
1065 */
1066 unsigned control_data_header_size_hwords;
1067
1068 /**
1069 * Format of the control data (either GFX7_GS_CONTROL_DATA_FORMAT_GSCTL_SID
1070 * if the control data is StreamID bits, or
1071 * GFX7_GS_CONTROL_DATA_FORMAT_GSCTL_CUT if the control data is cut bits).
1072 * Ignored if control_data_header_size is 0.
1073 */
1074 unsigned control_data_format;
1075
1076 bool include_primitive_id;
1077
1078 /**
1079 * The number of vertices emitted, if constant - otherwise -1.
1080 */
1081 int static_vertex_count;
1082
1083 int invocations;
1084 };
1085
1086 struct brw_tue_map {
1087 uint32_t size_dw;
1088
1089 uint32_t per_task_data_start_dw;
1090 };
1091
1092 struct brw_mue_map {
1093 int32_t start_dw[VARYING_SLOT_MAX];
1094 uint32_t len_dw[VARYING_SLOT_MAX];
1095 uint32_t per_primitive_indices_dw;
1096
1097 uint32_t size_dw;
1098
1099 uint32_t max_primitives;
1100 uint32_t per_primitive_start_dw;
1101 uint32_t per_primitive_header_size_dw;
1102 uint32_t per_primitive_data_size_dw;
1103 uint32_t per_primitive_pitch_dw;
1104 bool user_data_in_primitive_header;
1105
1106 uint32_t max_vertices;
1107 uint32_t per_vertex_start_dw;
1108 uint32_t per_vertex_header_size_dw;
1109 uint32_t per_vertex_data_size_dw;
1110 uint32_t per_vertex_pitch_dw;
1111 bool user_data_in_vertex_header;
1112 };
1113
1114 struct brw_task_prog_data {
1115 struct brw_cs_prog_data base;
1116 struct brw_tue_map map;
1117 bool uses_drawid;
1118 };
1119
1120 enum brw_mesh_index_format {
1121 BRW_INDEX_FORMAT_U32,
1122 BRW_INDEX_FORMAT_U888X,
1123 };
1124
1125 struct brw_mesh_prog_data {
1126 struct brw_cs_prog_data base;
1127 struct brw_mue_map map;
1128
1129 uint32_t clip_distance_mask;
1130 uint32_t cull_distance_mask;
1131 uint16_t primitive_type;
1132
1133 enum brw_mesh_index_format index_format;
1134
1135 bool uses_drawid;
1136 bool autostrip_enable;
1137 };
1138
1139 /* brw_any_prog_data is prog_data for any stage that maps to an API stage */
1140 union brw_any_prog_data {
1141 struct brw_stage_prog_data base;
1142 struct brw_vue_prog_data vue;
1143 struct brw_vs_prog_data vs;
1144 struct brw_tcs_prog_data tcs;
1145 struct brw_tes_prog_data tes;
1146 struct brw_gs_prog_data gs;
1147 struct brw_wm_prog_data wm;
1148 struct brw_cs_prog_data cs;
1149 struct brw_bs_prog_data bs;
1150 struct brw_task_prog_data task;
1151 struct brw_mesh_prog_data mesh;
1152 };
1153
1154 #define DEFINE_PROG_DATA_DOWNCAST(STAGE, CHECK) \
1155 static inline struct brw_##STAGE##_prog_data * \
1156 brw_##STAGE##_prog_data(struct brw_stage_prog_data *prog_data) \
1157 { \
1158 if (prog_data) \
1159 assert(CHECK); \
1160 return (struct brw_##STAGE##_prog_data *) prog_data; \
1161 } \
1162 static inline const struct brw_##STAGE##_prog_data * \
1163 brw_##STAGE##_prog_data_const(const struct brw_stage_prog_data *prog_data) \
1164 { \
1165 if (prog_data) \
1166 assert(CHECK); \
1167 return (const struct brw_##STAGE##_prog_data *) prog_data; \
1168 }
1169
1170 DEFINE_PROG_DATA_DOWNCAST(vs, prog_data->stage == MESA_SHADER_VERTEX)
1171 DEFINE_PROG_DATA_DOWNCAST(tcs, prog_data->stage == MESA_SHADER_TESS_CTRL)
1172 DEFINE_PROG_DATA_DOWNCAST(tes, prog_data->stage == MESA_SHADER_TESS_EVAL)
1173 DEFINE_PROG_DATA_DOWNCAST(gs, prog_data->stage == MESA_SHADER_GEOMETRY)
1174 DEFINE_PROG_DATA_DOWNCAST(wm, prog_data->stage == MESA_SHADER_FRAGMENT)
1175 DEFINE_PROG_DATA_DOWNCAST(cs, gl_shader_stage_uses_workgroup(prog_data->stage))
1176 DEFINE_PROG_DATA_DOWNCAST(bs, brw_shader_stage_is_bindless(prog_data->stage))
1177
1178 DEFINE_PROG_DATA_DOWNCAST(vue, prog_data->stage == MESA_SHADER_VERTEX ||
1179 prog_data->stage == MESA_SHADER_TESS_CTRL ||
1180 prog_data->stage == MESA_SHADER_TESS_EVAL ||
1181 prog_data->stage == MESA_SHADER_GEOMETRY)
1182
1183 DEFINE_PROG_DATA_DOWNCAST(task, prog_data->stage == MESA_SHADER_TASK)
1184 DEFINE_PROG_DATA_DOWNCAST(mesh, prog_data->stage == MESA_SHADER_MESH)
1185
1186 #undef DEFINE_PROG_DATA_DOWNCAST
1187
1188 struct brw_compile_stats {
1189 uint32_t dispatch_width; /**< 0 for vec4 */
1190 uint32_t max_polygons;
1191 uint32_t max_dispatch_width;
1192 uint32_t instructions;
1193 uint32_t sends;
1194 uint32_t loops;
1195 uint32_t cycles;
1196 uint32_t spills;
1197 uint32_t fills;
1198 uint32_t max_live_registers;
1199 uint32_t non_ssa_registers_after_nir;
1200 };
1201
1202 /** @} */
1203
1204 struct brw_compiler *
1205 brw_compiler_create(void *mem_ctx, const struct intel_device_info *devinfo);
1206
1207 /**
1208 * Returns a compiler configuration for use with disk shader cache
1209 *
1210 * This value only needs to change for settings that can cause different
1211 * program generation between two runs on the same hardware.
1212 *
1213 * For example, it doesn't need to be different for gen 8 and gen 9 hardware,
1214 * but it does need to be different if INTEL_DEBUG=nocompact is or isn't used.
1215 */
1216 uint64_t
1217 brw_get_compiler_config_value(const struct brw_compiler *compiler);
1218
1219 /* Provides a string sha1 hash of all device information fields that could
1220 * affect shader compilation.
1221 */
1222 void
1223 brw_device_sha1(char *hex, const struct intel_device_info *devinfo);
1224
1225 /* For callers computing their own UUID or hash. Hashes all device
1226 * information fields that could affect shader compilation into the provided
1227 * sha1_ctx.
1228 */
1229 void
1230 brw_device_sha1_update(struct mesa_sha1 *sha1_ctx,
1231 const struct intel_device_info *devinfo);
1232
1233 unsigned
1234 brw_prog_data_size(gl_shader_stage stage);
1235
1236 unsigned
1237 brw_prog_key_size(gl_shader_stage stage);
1238
1239 struct brw_compile_params {
1240 void *mem_ctx;
1241
1242 nir_shader *nir;
1243
1244 struct brw_compile_stats *stats;
1245
1246 void *log_data;
1247
1248 char *error_str;
1249
1250 uint64_t debug_flag;
1251
1252 uint32_t source_hash;
1253 };
1254
1255 /**
1256 * Parameters for compiling a vertex shader.
1257 *
1258 * Some of these will be modified during the shader compilation.
1259 */
1260 struct brw_compile_vs_params {
1261 struct brw_compile_params base;
1262
1263 const struct brw_vs_prog_key *key;
1264 struct brw_vs_prog_data *prog_data;
1265 };
1266
1267 /**
1268 * Compile a vertex shader.
1269 *
1270 * Returns the final assembly and updates the parameters structure.
1271 */
1272 const unsigned *
1273 brw_compile_vs(const struct brw_compiler *compiler,
1274 struct brw_compile_vs_params *params);
1275
1276 /**
1277 * Parameters for compiling a tessellation control shader.
1278 *
1279 * Some of these will be modified during the shader compilation.
1280 */
1281 struct brw_compile_tcs_params {
1282 struct brw_compile_params base;
1283
1284 const struct brw_tcs_prog_key *key;
1285 struct brw_tcs_prog_data *prog_data;
1286 };
1287
1288 /**
1289 * Compile a tessellation control shader.
1290 *
1291 * Returns the final assembly and updates the parameters structure.
1292 */
1293 const unsigned *
1294 brw_compile_tcs(const struct brw_compiler *compiler,
1295 struct brw_compile_tcs_params *params);
1296
1297 /**
1298 * Parameters for compiling a tessellation evaluation shader.
1299 *
1300 * Some of these will be modified during the shader compilation.
1301 */
1302 struct brw_compile_tes_params {
1303 struct brw_compile_params base;
1304
1305 const struct brw_tes_prog_key *key;
1306 struct brw_tes_prog_data *prog_data;
1307 const struct intel_vue_map *input_vue_map;
1308 };
1309
1310 /**
1311 * Compile a tessellation evaluation shader.
1312 *
1313 * Returns the final assembly and updates the parameters structure.
1314 */
1315 const unsigned *
1316 brw_compile_tes(const struct brw_compiler *compiler,
1317 struct brw_compile_tes_params *params);
1318
1319 /**
1320 * Parameters for compiling a geometry shader.
1321 *
1322 * Some of these will be modified during the shader compilation.
1323 */
1324 struct brw_compile_gs_params {
1325 struct brw_compile_params base;
1326
1327 const struct brw_gs_prog_key *key;
1328 struct brw_gs_prog_data *prog_data;
1329 };
1330
1331 /**
1332 * Compile a geometry shader.
1333 *
1334 * Returns the final assembly and updates the parameters structure.
1335 */
1336 const unsigned *
1337 brw_compile_gs(const struct brw_compiler *compiler,
1338 struct brw_compile_gs_params *params);
1339
1340 struct brw_compile_task_params {
1341 struct brw_compile_params base;
1342
1343 const struct brw_task_prog_key *key;
1344 struct brw_task_prog_data *prog_data;
1345 };
1346
1347 const unsigned *
1348 brw_compile_task(const struct brw_compiler *compiler,
1349 struct brw_compile_task_params *params);
1350
1351 struct brw_compile_mesh_params {
1352 struct brw_compile_params base;
1353
1354 const struct brw_mesh_prog_key *key;
1355 struct brw_mesh_prog_data *prog_data;
1356 const struct brw_tue_map *tue_map;
1357 };
1358
1359 const unsigned *
1360 brw_compile_mesh(const struct brw_compiler *compiler,
1361 struct brw_compile_mesh_params *params);
1362
1363 /**
1364 * Parameters for compiling a fragment shader.
1365 *
1366 * Some of these will be modified during the shader compilation.
1367 */
1368 struct brw_compile_fs_params {
1369 struct brw_compile_params base;
1370
1371 const struct brw_wm_prog_key *key;
1372 struct brw_wm_prog_data *prog_data;
1373
1374 const struct intel_vue_map *vue_map;
1375 const struct brw_mue_map *mue_map;
1376
1377 bool allow_spilling;
1378 bool use_rep_send;
1379 uint8_t max_polygons;
1380 };
1381
1382 /**
1383 * Compile a fragment shader.
1384 *
1385 * Returns the final assembly and updates the parameters structure.
1386 */
1387 const unsigned *
1388 brw_compile_fs(const struct brw_compiler *compiler,
1389 struct brw_compile_fs_params *params);
1390
1391 /**
1392 * Parameters for compiling a compute shader.
1393 *
1394 * Some of these will be modified during the shader compilation.
1395 */
1396 struct brw_compile_cs_params {
1397 struct brw_compile_params base;
1398
1399 const struct brw_cs_prog_key *key;
1400 struct brw_cs_prog_data *prog_data;
1401 };
1402
1403 /**
1404 * Compile a compute shader.
1405 *
1406 * Returns the final assembly and updates the parameters structure.
1407 */
1408 const unsigned *
1409 brw_compile_cs(const struct brw_compiler *compiler,
1410 struct brw_compile_cs_params *params);
1411
1412 /**
1413 * Parameters for compiling a Bindless shader.
1414 *
1415 * Some of these will be modified during the shader compilation.
1416 */
1417 struct brw_compile_bs_params {
1418 struct brw_compile_params base;
1419
1420 const struct brw_bs_prog_key *key;
1421 struct brw_bs_prog_data *prog_data;
1422
1423 unsigned num_resume_shaders;
1424 struct nir_shader **resume_shaders;
1425 };
1426
1427 /**
1428 * Compile a Bindless shader.
1429 *
1430 * Returns the final assembly and updates the parameters structure.
1431 */
1432 const unsigned *
1433 brw_compile_bs(const struct brw_compiler *compiler,
1434 struct brw_compile_bs_params *params);
1435
1436 void brw_debug_key_recompile(const struct brw_compiler *c, void *log,
1437 gl_shader_stage stage,
1438 const struct brw_base_prog_key *old_key,
1439 const struct brw_base_prog_key *key);
1440
1441 unsigned
1442 brw_cs_push_const_total_size(const struct brw_cs_prog_data *cs_prog_data,
1443 unsigned threads);
1444
1445 void
1446 brw_write_shader_relocs(const struct brw_isa_info *isa,
1447 void *program,
1448 const struct brw_stage_prog_data *prog_data,
1449 struct brw_shader_reloc_value *values,
1450 unsigned num_values);
1451
1452 /**
1453 * Get the dispatch information for a shader to be used with GPGPU_WALKER and
1454 * similar instructions.
1455 *
1456 * If override_local_size is not NULL, it must to point to a 3-element that
1457 * will override the value from prog_data->local_size. This is used by
1458 * ARB_compute_variable_group_size, where the size is set only at dispatch
1459 * time (so prog_data is outdated).
1460 */
1461 struct intel_cs_dispatch_info
1462 brw_cs_get_dispatch_info(const struct intel_device_info *devinfo,
1463 const struct brw_cs_prog_data *prog_data,
1464 const unsigned *override_local_size);
1465
1466 /**
1467 * Return true if the given shader stage is dispatched contiguously by the
1468 * relevant fixed function starting from channel 0 of the SIMD thread, which
1469 * implies that the dispatch mask of a thread can be assumed to have the form
1470 * '2^n - 1' for some n.
1471 */
1472 static inline bool
brw_stage_has_packed_dispatch(ASSERTED const struct intel_device_info * devinfo,gl_shader_stage stage,unsigned max_polygons,const struct brw_stage_prog_data * prog_data)1473 brw_stage_has_packed_dispatch(ASSERTED const struct intel_device_info *devinfo,
1474 gl_shader_stage stage, unsigned max_polygons,
1475 const struct brw_stage_prog_data *prog_data)
1476 {
1477 /* The code below makes assumptions about the hardware's thread dispatch
1478 * behavior that could be proven wrong in future generations -- Make sure
1479 * to do a full test run with brw_fs_test_dispatch_packing() hooked up to
1480 * the NIR front-end before changing this assertion. It can be temporarily
1481 * enabled by setting the macro below to true.
1482 */
1483 #define ENABLE_FS_TEST_DISPATCH_PACKING false
1484 assert(devinfo->ver <= 30);
1485
1486 switch (stage) {
1487 case MESA_SHADER_FRAGMENT: {
1488 /* The PSD discards subspans coming in with no lit samples, which in the
1489 * per-pixel shading case implies that each subspan will either be fully
1490 * lit (due to the VMask being used to allow derivative computations),
1491 * or not dispatched at all. In per-sample dispatch mode individual
1492 * samples from the same subspan have a fixed relative location within
1493 * the SIMD thread, so dispatch of unlit samples cannot be avoided in
1494 * general and we should return false.
1495 */
1496 const struct brw_wm_prog_data *wm_prog_data =
1497 (const struct brw_wm_prog_data *)prog_data;
1498 return devinfo->verx10 < 125 &&
1499 !wm_prog_data->persample_dispatch &&
1500 wm_prog_data->uses_vmask &&
1501 max_polygons < 2;
1502 }
1503 case MESA_SHADER_COMPUTE:
1504 /* Compute shaders will be spawned with either a fully enabled dispatch
1505 * mask or with whatever bottom/right execution mask was given to the
1506 * GPGPU walker command to be used along the workgroup edges -- In both
1507 * cases the dispatch mask is required to be tightly packed for our
1508 * invocation index calculations to work.
1509 */
1510 return true;
1511 default:
1512 /* Most remaining fixed functions are limited to use a packed dispatch
1513 * mask due to the hardware representation of the dispatch mask as a
1514 * single counter representing the number of enabled channels.
1515 */
1516 return true;
1517 }
1518 }
1519
1520 /**
1521 * Computes the first varying slot in the URB produced by the previous stage
1522 * that is used in the next stage. We do this by testing the varying slots in
1523 * the previous stage's vue map against the inputs read in the next stage.
1524 *
1525 * Note that:
1526 *
1527 * - Each URB offset contains two varying slots and we can only skip a
1528 * full offset if both slots are unused, so the value we return here is always
1529 * rounded down to the closest multiple of two.
1530 *
1531 * - gl_Layer and gl_ViewportIndex don't have their own varying slots, they are
1532 * part of the vue header, so if these are read we can't skip anything.
1533 */
1534 static inline int
brw_compute_first_urb_slot_required(uint64_t inputs_read,const struct intel_vue_map * prev_stage_vue_map)1535 brw_compute_first_urb_slot_required(uint64_t inputs_read,
1536 const struct intel_vue_map *prev_stage_vue_map)
1537 {
1538 if ((inputs_read & (VARYING_BIT_LAYER | VARYING_BIT_VIEWPORT | VARYING_BIT_PRIMITIVE_SHADING_RATE)) == 0) {
1539 for (int i = 0; i < prev_stage_vue_map->num_slots; i++) {
1540 int varying = prev_stage_vue_map->slot_to_varying[i];
1541 if (varying != BRW_VARYING_SLOT_PAD && varying > 0 &&
1542 (inputs_read & BITFIELD64_BIT(varying)) != 0) {
1543 return ROUND_DOWN_TO(i, 2);
1544 }
1545 }
1546 }
1547
1548 return 0;
1549 }
1550
1551 /* From InlineData in 3DSTATE_TASK_SHADER_DATA and 3DSTATE_MESH_SHADER_DATA. */
1552 #define BRW_TASK_MESH_INLINE_DATA_SIZE_DW 8
1553
1554 /* InlineData[0-1] is used for Vulkan descriptor. */
1555 #define BRW_TASK_MESH_PUSH_CONSTANTS_START_DW 2
1556
1557 #define BRW_TASK_MESH_PUSH_CONSTANTS_SIZE_DW \
1558 (BRW_TASK_MESH_INLINE_DATA_SIZE_DW - BRW_TASK_MESH_PUSH_CONSTANTS_START_DW)
1559
1560 /**
1561 * This enum is used as the base indice of the nir_load_topology_id_intel
1562 * intrinsic. This is used to return different values based on some aspect of
1563 * the topology of the device.
1564 */
1565 enum brw_topology_id
1566 {
1567 /* A value based of the DSS identifier the shader is currently running on.
1568 * Be mindful that the DSS ID can be higher than the total number of DSS on
1569 * the device. This is because of the fusing that can occur on different
1570 * parts.
1571 */
1572 BRW_TOPOLOGY_ID_DSS,
1573
1574 /* A value composed of EU ID, thread ID & SIMD lane ID. */
1575 BRW_TOPOLOGY_ID_EU_THREAD_SIMD,
1576 };
1577
1578 #ifdef __cplusplus
1579 } /* extern "C" */
1580 #endif
1581