Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/intel/compiler/brw_compiler.h
4550 views
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
#ifndef BRW_COMPILER_H
25
#define BRW_COMPILER_H
26
27
#include <stdio.h>
28
#include "dev/intel_device_info.h"
29
#include "main/macros.h"
30
#include "main/mtypes.h"
31
#include "util/ralloc.h"
32
33
#ifdef __cplusplus
34
extern "C" {
35
#endif
36
37
struct ra_regs;
38
struct nir_shader;
39
struct brw_program;
40
41
typedef struct nir_shader nir_shader;
42
43
struct brw_compiler {
44
const struct intel_device_info *devinfo;
45
46
struct {
47
struct ra_regs *regs;
48
49
/**
50
* Array of the ra classes for the unaligned contiguous register
51
* block sizes used.
52
*/
53
struct ra_class **classes;
54
} vec4_reg_set;
55
56
struct {
57
struct ra_regs *regs;
58
59
/**
60
* Array of the ra classes for the unaligned contiguous register
61
* block sizes used, indexed by register size.
62
*/
63
struct ra_class *classes[16];
64
65
/**
66
* ra class for the aligned barycentrics we use for PLN, which doesn't
67
* appear in *classes.
68
*/
69
struct ra_class *aligned_bary_class;
70
} fs_reg_sets[3];
71
72
void (*shader_debug_log)(void *, const char *str, ...) PRINTFLIKE(2, 3);
73
void (*shader_perf_log)(void *, const char *str, ...) PRINTFLIKE(2, 3);
74
75
bool scalar_stage[MESA_ALL_SHADER_STAGES];
76
bool use_tcs_8_patch;
77
struct gl_shader_compiler_options glsl_compiler_options[MESA_ALL_SHADER_STAGES];
78
79
/**
80
* Apply workarounds for SIN and COS output range problems.
81
* This can negatively impact performance.
82
*/
83
bool precise_trig;
84
85
/**
86
* Is 3DSTATE_CONSTANT_*'s Constant Buffer 0 relative to Dynamic State
87
* Base Address? (If not, it's a normal GPU address.)
88
*/
89
bool constant_buffer_0_is_relative;
90
91
/**
92
* Whether or not the driver supports pull constants. If not, the compiler
93
* will attempt to push everything.
94
*/
95
bool supports_pull_constants;
96
97
/**
98
* Whether or not the driver supports NIR shader constants. This controls
99
* whether nir_opt_large_constants will be run.
100
*/
101
bool supports_shader_constants;
102
103
/**
104
* Whether or not the driver wants uniform params to be compacted by the
105
* back-end compiler.
106
*/
107
bool compact_params;
108
109
/**
110
* Whether or not the driver wants variable group size to be lowered by the
111
* back-end compiler.
112
*/
113
bool lower_variable_group_size;
114
115
/**
116
* Whether indirect UBO loads should use the sampler or go through the
117
* data/constant cache. For the sampler, UBO surface states have to be set
118
* up with VK_FORMAT_R32G32B32A32_FLOAT whereas if it's going through the
119
* constant or data cache, UBOs must use VK_FORMAT_RAW.
120
*/
121
bool indirect_ubos_use_sampler;
122
};
123
124
/**
125
* We use a constant subgroup size of 32. It really only needs to be a
126
* maximum and, since we do SIMD32 for compute shaders in some cases, it
127
* needs to be at least 32. SIMD8 and SIMD16 shaders will still claim a
128
* subgroup size of 32 but will act as if 16 or 24 of those channels are
129
* disabled.
130
*/
131
#define BRW_SUBGROUP_SIZE 32
132
133
static inline bool
134
brw_shader_stage_is_bindless(gl_shader_stage stage)
135
{
136
return stage >= MESA_SHADER_RAYGEN &&
137
stage <= MESA_SHADER_CALLABLE;
138
}
139
140
/**
141
* Program key structures.
142
*
143
* When drawing, we look for the currently bound shaders in the program
144
* cache. This is essentially a hash table lookup, and these are the keys.
145
*
146
* Sometimes OpenGL features specified as state need to be simulated via
147
* shader code, due to a mismatch between the API and the hardware. This
148
* is often referred to as "non-orthagonal state" or "NOS". We store NOS
149
* in the program key so it's considered when searching for a program. If
150
* we haven't seen a particular combination before, we have to recompile a
151
* new specialized version.
152
*
153
* Shader compilation should not look up state in gl_context directly, but
154
* instead use the copy in the program key. This guarantees recompiles will
155
* happen correctly.
156
*
157
* @{
158
*/
159
160
enum PACKED gfx6_gather_sampler_wa {
161
WA_SIGN = 1, /* whether we need to sign extend */
162
WA_8BIT = 2, /* if we have an 8bit format needing wa */
163
WA_16BIT = 4, /* if we have a 16bit format needing wa */
164
};
165
166
/**
167
* Sampler information needed by VS, WM, and GS program cache keys.
168
*/
169
struct brw_sampler_prog_key_data {
170
/**
171
* EXT_texture_swizzle and DEPTH_TEXTURE_MODE swizzles.
172
*/
173
uint16_t swizzles[MAX_SAMPLERS];
174
175
uint32_t gl_clamp_mask[3];
176
177
/**
178
* For RG32F, gather4's channel select is broken.
179
*/
180
uint32_t gather_channel_quirk_mask;
181
182
/**
183
* Whether this sampler uses the compressed multisample surface layout.
184
*/
185
uint32_t compressed_multisample_layout_mask;
186
187
/**
188
* Whether this sampler is using 16x multisampling. If so fetching from
189
* this sampler will be handled with a different instruction, ld2dms_w
190
* instead of ld2dms.
191
*/
192
uint32_t msaa_16;
193
194
/**
195
* For Sandybridge, which shader w/a we need for gather quirks.
196
*/
197
enum gfx6_gather_sampler_wa gfx6_gather_wa[MAX_SAMPLERS];
198
199
/**
200
* Texture units that have a YUV image bound.
201
*/
202
uint32_t y_u_v_image_mask;
203
uint32_t y_uv_image_mask;
204
uint32_t yx_xuxv_image_mask;
205
uint32_t xy_uxvx_image_mask;
206
uint32_t ayuv_image_mask;
207
uint32_t xyuv_image_mask;
208
uint32_t bt709_mask;
209
uint32_t bt2020_mask;
210
211
/* Scale factor for each texture. */
212
float scale_factors[32];
213
};
214
215
/** An enum representing what kind of input gl_SubgroupSize is. */
216
enum PACKED brw_subgroup_size_type
217
{
218
BRW_SUBGROUP_SIZE_API_CONSTANT, /**< Default Vulkan behavior */
219
BRW_SUBGROUP_SIZE_UNIFORM, /**< OpenGL behavior */
220
BRW_SUBGROUP_SIZE_VARYING, /**< VK_EXT_subgroup_size_control */
221
222
/* These enums are specifically chosen so that the value of the enum is
223
* also the subgroup size. If any new values are added, they must respect
224
* this invariant.
225
*/
226
BRW_SUBGROUP_SIZE_REQUIRE_8 = 8, /**< VK_EXT_subgroup_size_control */
227
BRW_SUBGROUP_SIZE_REQUIRE_16 = 16, /**< VK_EXT_subgroup_size_control */
228
BRW_SUBGROUP_SIZE_REQUIRE_32 = 32, /**< VK_EXT_subgroup_size_control */
229
};
230
231
struct brw_base_prog_key {
232
unsigned program_string_id;
233
234
enum brw_subgroup_size_type subgroup_size_type;
235
bool robust_buffer_access;
236
struct brw_sampler_prog_key_data tex;
237
};
238
239
/**
240
* The VF can't natively handle certain types of attributes, such as GL_FIXED
241
* or most 10_10_10_2 types. These flags enable various VS workarounds to
242
* "fix" attributes at the beginning of shaders.
243
*/
244
#define BRW_ATTRIB_WA_COMPONENT_MASK 7 /* mask for GL_FIXED scale channel count */
245
#define BRW_ATTRIB_WA_NORMALIZE 8 /* normalize in shader */
246
#define BRW_ATTRIB_WA_BGRA 16 /* swap r/b channels in shader */
247
#define BRW_ATTRIB_WA_SIGN 32 /* interpret as signed in shader */
248
#define BRW_ATTRIB_WA_SCALE 64 /* interpret as scaled in shader */
249
250
/**
251
* OpenGL attribute slots fall in [0, VERT_ATTRIB_MAX - 1] with the range
252
* [VERT_ATTRIB_GENERIC0, VERT_ATTRIB_MAX - 1] reserved for up to 16 user
253
* input vertex attributes. In Vulkan, we expose up to 28 user vertex input
254
* attributes that are mapped to slots also starting at VERT_ATTRIB_GENERIC0.
255
*/
256
#define MAX_GL_VERT_ATTRIB VERT_ATTRIB_MAX
257
#define MAX_VK_VERT_ATTRIB (VERT_ATTRIB_GENERIC0 + 28)
258
259
/**
260
* Max number of binding table entries used for stream output.
261
*
262
* From the OpenGL 3.0 spec, table 6.44 (Transform Feedback State), the
263
* minimum value of MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS is 64.
264
*
265
* On Gfx6, the size of transform feedback data is limited not by the number
266
* of components but by the number of binding table entries we set aside. We
267
* use one binding table entry for a float, one entry for a vector, and one
268
* entry per matrix column. Since the only way we can communicate our
269
* transform feedback capabilities to the client is via
270
* MAX_TRANSFORM_FEEDBACK_INTERLEAVED_COMPONENTS, we need to plan for the
271
* worst case, in which all the varyings are floats, so we use up one binding
272
* table entry per component. Therefore we need to set aside at least 64
273
* binding table entries for use by transform feedback.
274
*
275
* Note: since we don't currently pack varyings, it is currently impossible
276
* for the client to actually use up all of these binding table entries--if
277
* all of their varyings were floats, they would run out of varying slots and
278
* fail to link. But that's a bug, so it seems prudent to go ahead and
279
* allocate the number of binding table entries we will need once the bug is
280
* fixed.
281
*/
282
#define BRW_MAX_SOL_BINDINGS 64
283
284
/** The program key for Vertex Shaders. */
285
struct brw_vs_prog_key {
286
struct brw_base_prog_key base;
287
288
/**
289
* Per-attribute workaround flags
290
*
291
* For each attribute, a combination of BRW_ATTRIB_WA_*.
292
*
293
* For OpenGL, where we expose a maximum of 16 user input atttributes
294
* we only need up to VERT_ATTRIB_MAX slots, however, in Vulkan
295
* slots preceding VERT_ATTRIB_GENERIC0 are unused and we can
296
* expose up to 28 user input vertex attributes that are mapped to slots
297
* starting at VERT_ATTRIB_GENERIC0, so this array needs to be large
298
* enough to hold this many slots.
299
*/
300
uint8_t gl_attrib_wa_flags[MAX2(MAX_GL_VERT_ATTRIB, MAX_VK_VERT_ATTRIB)];
301
302
bool copy_edgeflag:1;
303
304
bool clamp_vertex_color:1;
305
306
/**
307
* How many user clipping planes are being uploaded to the vertex shader as
308
* push constants.
309
*
310
* These are used for lowering legacy gl_ClipVertex/gl_Position clipping to
311
* clip distances.
312
*/
313
unsigned nr_userclip_plane_consts:4;
314
315
/**
316
* For pre-Gfx6 hardware, a bitfield indicating which texture coordinates
317
* are going to be replaced with point coordinates (as a consequence of a
318
* call to glTexEnvi(GL_POINT_SPRITE, GL_COORD_REPLACE, GL_TRUE)). Because
319
* our SF thread requires exact matching between VS outputs and FS inputs,
320
* these texture coordinates will need to be unconditionally included in
321
* the VUE, even if they aren't written by the vertex shader.
322
*/
323
uint8_t point_coord_replace;
324
};
325
326
/** The program key for Tessellation Control Shaders. */
327
struct brw_tcs_prog_key
328
{
329
struct brw_base_prog_key base;
330
331
GLenum tes_primitive_mode;
332
333
unsigned input_vertices;
334
335
/** A bitfield of per-patch outputs written. */
336
uint32_t patch_outputs_written;
337
338
/** A bitfield of per-vertex outputs written. */
339
uint64_t outputs_written;
340
341
bool quads_workaround;
342
};
343
344
/** The program key for Tessellation Evaluation Shaders. */
345
struct brw_tes_prog_key
346
{
347
struct brw_base_prog_key base;
348
349
/** A bitfield of per-patch inputs read. */
350
uint32_t patch_inputs_read;
351
352
/** A bitfield of per-vertex inputs read. */
353
uint64_t inputs_read;
354
355
/**
356
* How many user clipping planes are being uploaded to the tessellation
357
* evaluation shader as push constants.
358
*
359
* These are used for lowering legacy gl_ClipVertex/gl_Position clipping to
360
* clip distances.
361
*/
362
unsigned nr_userclip_plane_consts:4;
363
};
364
365
/** The program key for Geometry Shaders. */
366
struct brw_gs_prog_key
367
{
368
struct brw_base_prog_key base;
369
370
/**
371
* How many user clipping planes are being uploaded to the geometry shader
372
* as push constants.
373
*
374
* These are used for lowering legacy gl_ClipVertex/gl_Position clipping to
375
* clip distances.
376
*/
377
unsigned nr_userclip_plane_consts:4;
378
};
379
380
enum brw_sf_primitive {
381
BRW_SF_PRIM_POINTS = 0,
382
BRW_SF_PRIM_LINES = 1,
383
BRW_SF_PRIM_TRIANGLES = 2,
384
BRW_SF_PRIM_UNFILLED_TRIS = 3,
385
};
386
387
struct brw_sf_prog_key {
388
uint64_t attrs;
389
bool contains_flat_varying;
390
unsigned char interp_mode[65]; /* BRW_VARYING_SLOT_COUNT */
391
uint8_t point_sprite_coord_replace;
392
enum brw_sf_primitive primitive:2;
393
bool do_twoside_color:1;
394
bool frontface_ccw:1;
395
bool do_point_sprite:1;
396
bool do_point_coord:1;
397
bool sprite_origin_lower_left:1;
398
bool userclip_active:1;
399
};
400
401
enum brw_clip_mode {
402
BRW_CLIP_MODE_NORMAL = 0,
403
BRW_CLIP_MODE_CLIP_ALL = 1,
404
BRW_CLIP_MODE_CLIP_NON_REJECTED = 2,
405
BRW_CLIP_MODE_REJECT_ALL = 3,
406
BRW_CLIP_MODE_ACCEPT_ALL = 4,
407
BRW_CLIP_MODE_KERNEL_CLIP = 5,
408
};
409
410
enum brw_clip_fill_mode {
411
BRW_CLIP_FILL_MODE_LINE = 0,
412
BRW_CLIP_FILL_MODE_POINT = 1,
413
BRW_CLIP_FILL_MODE_FILL = 2,
414
BRW_CLIP_FILL_MODE_CULL = 3,
415
};
416
417
/* Note that if unfilled primitives are being emitted, we have to fix
418
* up polygon offset and flatshading at this point:
419
*/
420
struct brw_clip_prog_key {
421
uint64_t attrs;
422
bool contains_flat_varying;
423
bool contains_noperspective_varying;
424
unsigned char interp_mode[65]; /* BRW_VARYING_SLOT_COUNT */
425
unsigned primitive:4;
426
unsigned nr_userclip:4;
427
bool pv_first:1;
428
bool do_unfilled:1;
429
enum brw_clip_fill_mode fill_cw:2; /* includes cull information */
430
enum brw_clip_fill_mode fill_ccw:2; /* includes cull information */
431
bool offset_cw:1;
432
bool offset_ccw:1;
433
bool copy_bfc_cw:1;
434
bool copy_bfc_ccw:1;
435
enum brw_clip_mode clip_mode:3;
436
437
float offset_factor;
438
float offset_units;
439
float offset_clamp;
440
};
441
442
/* A big lookup table is used to figure out which and how many
443
* additional regs will inserted before the main payload in the WM
444
* program execution. These mainly relate to depth and stencil
445
* processing and the early-depth-test optimization.
446
*/
447
enum brw_wm_iz_bits {
448
BRW_WM_IZ_PS_KILL_ALPHATEST_BIT = 0x1,
449
BRW_WM_IZ_PS_COMPUTES_DEPTH_BIT = 0x2,
450
BRW_WM_IZ_DEPTH_WRITE_ENABLE_BIT = 0x4,
451
BRW_WM_IZ_DEPTH_TEST_ENABLE_BIT = 0x8,
452
BRW_WM_IZ_STENCIL_WRITE_ENABLE_BIT = 0x10,
453
BRW_WM_IZ_STENCIL_TEST_ENABLE_BIT = 0x20,
454
BRW_WM_IZ_BIT_MAX = 0x40
455
};
456
457
enum brw_wm_aa_enable {
458
BRW_WM_AA_NEVER,
459
BRW_WM_AA_SOMETIMES,
460
BRW_WM_AA_ALWAYS
461
};
462
463
/** The program key for Fragment/Pixel Shaders. */
464
struct brw_wm_prog_key {
465
struct brw_base_prog_key base;
466
467
/* Some collection of BRW_WM_IZ_* */
468
uint8_t iz_lookup;
469
bool stats_wm:1;
470
bool flat_shade:1;
471
unsigned nr_color_regions:5;
472
bool alpha_test_replicate_alpha:1;
473
bool alpha_to_coverage:1;
474
bool clamp_fragment_color:1;
475
bool persample_interp:1;
476
bool multisample_fbo:1;
477
bool frag_coord_adds_sample_pos:1;
478
enum brw_wm_aa_enable line_aa:2;
479
bool high_quality_derivatives:1;
480
bool force_dual_color_blend:1;
481
bool coherent_fb_fetch:1;
482
bool ignore_sample_mask_out:1;
483
bool coarse_pixel:1;
484
485
uint8_t color_outputs_valid;
486
uint64_t input_slots_valid;
487
GLenum alpha_test_func; /* < For Gfx4/5 MRT alpha test */
488
float alpha_test_ref;
489
};
490
491
struct brw_cs_prog_key {
492
struct brw_base_prog_key base;
493
};
494
495
struct brw_bs_prog_key {
496
struct brw_base_prog_key base;
497
};
498
499
struct brw_ff_gs_prog_key {
500
uint64_t attrs;
501
502
/**
503
* Hardware primitive type being drawn, e.g. _3DPRIM_TRILIST.
504
*/
505
unsigned primitive:8;
506
507
unsigned pv_first:1;
508
unsigned need_gs_prog:1;
509
510
/**
511
* Number of varyings that are output to transform feedback.
512
*/
513
unsigned num_transform_feedback_bindings:7; /* 0-BRW_MAX_SOL_BINDINGS */
514
515
/**
516
* Map from the index of a transform feedback binding table entry to the
517
* gl_varying_slot that should be streamed out through that binding table
518
* entry.
519
*/
520
unsigned char transform_feedback_bindings[BRW_MAX_SOL_BINDINGS];
521
522
/**
523
* Map from the index of a transform feedback binding table entry to the
524
* swizzles that should be used when streaming out data through that
525
* binding table entry.
526
*/
527
unsigned char transform_feedback_swizzles[BRW_MAX_SOL_BINDINGS];
528
};
529
530
/* brw_any_prog_key is any of the keys that map to an API stage */
531
union brw_any_prog_key {
532
struct brw_base_prog_key base;
533
struct brw_vs_prog_key vs;
534
struct brw_tcs_prog_key tcs;
535
struct brw_tes_prog_key tes;
536
struct brw_gs_prog_key gs;
537
struct brw_wm_prog_key wm;
538
struct brw_cs_prog_key cs;
539
struct brw_bs_prog_key bs;
540
};
541
542
/*
543
* Image metadata structure as laid out in the shader parameter
544
* buffer. Entries have to be 16B-aligned for the vec4 back-end to be
545
* able to use them. That's okay because the padding and any unused
546
* entries [most of them except when we're doing untyped surface
547
* access] will be removed by the uniform packing pass.
548
*/
549
#define BRW_IMAGE_PARAM_OFFSET_OFFSET 0
550
#define BRW_IMAGE_PARAM_SIZE_OFFSET 4
551
#define BRW_IMAGE_PARAM_STRIDE_OFFSET 8
552
#define BRW_IMAGE_PARAM_TILING_OFFSET 12
553
#define BRW_IMAGE_PARAM_SWIZZLING_OFFSET 16
554
#define BRW_IMAGE_PARAM_SIZE 20
555
556
struct brw_image_param {
557
/** Offset applied to the X and Y surface coordinates. */
558
uint32_t offset[2];
559
560
/** Surface X, Y and Z dimensions. */
561
uint32_t size[3];
562
563
/** X-stride in bytes, Y-stride in pixels, horizontal slice stride in
564
* pixels, vertical slice stride in pixels.
565
*/
566
uint32_t stride[4];
567
568
/** Log2 of the tiling modulus in the X, Y and Z dimension. */
569
uint32_t tiling[3];
570
571
/**
572
* Right shift to apply for bit 6 address swizzling. Two different
573
* swizzles can be specified and will be applied one after the other. The
574
* resulting address will be:
575
*
576
* addr' = addr ^ ((1 << 6) & ((addr >> swizzling[0]) ^
577
* (addr >> swizzling[1])))
578
*
579
* Use \c 0xff if any of the swizzles is not required.
580
*/
581
uint32_t swizzling[2];
582
};
583
584
/** Max number of render targets in a shader */
585
#define BRW_MAX_DRAW_BUFFERS 8
586
587
/**
588
* Binding table index for the first gfx6 SOL binding.
589
*/
590
#define BRW_GFX6_SOL_BINDING_START 0
591
592
/**
593
* Stride in bytes between shader_time entries.
594
*
595
* We separate entries by a cacheline to reduce traffic between EUs writing to
596
* different entries.
597
*/
598
#define BRW_SHADER_TIME_STRIDE 64
599
600
struct brw_ubo_range
601
{
602
uint16_t block;
603
uint8_t start;
604
uint8_t length;
605
};
606
607
/* We reserve the first 2^16 values for builtins */
608
#define BRW_PARAM_IS_BUILTIN(param) (((param) & 0xffff0000) == 0)
609
610
enum brw_param_builtin {
611
BRW_PARAM_BUILTIN_ZERO,
612
613
BRW_PARAM_BUILTIN_CLIP_PLANE_0_X,
614
BRW_PARAM_BUILTIN_CLIP_PLANE_0_Y,
615
BRW_PARAM_BUILTIN_CLIP_PLANE_0_Z,
616
BRW_PARAM_BUILTIN_CLIP_PLANE_0_W,
617
BRW_PARAM_BUILTIN_CLIP_PLANE_1_X,
618
BRW_PARAM_BUILTIN_CLIP_PLANE_1_Y,
619
BRW_PARAM_BUILTIN_CLIP_PLANE_1_Z,
620
BRW_PARAM_BUILTIN_CLIP_PLANE_1_W,
621
BRW_PARAM_BUILTIN_CLIP_PLANE_2_X,
622
BRW_PARAM_BUILTIN_CLIP_PLANE_2_Y,
623
BRW_PARAM_BUILTIN_CLIP_PLANE_2_Z,
624
BRW_PARAM_BUILTIN_CLIP_PLANE_2_W,
625
BRW_PARAM_BUILTIN_CLIP_PLANE_3_X,
626
BRW_PARAM_BUILTIN_CLIP_PLANE_3_Y,
627
BRW_PARAM_BUILTIN_CLIP_PLANE_3_Z,
628
BRW_PARAM_BUILTIN_CLIP_PLANE_3_W,
629
BRW_PARAM_BUILTIN_CLIP_PLANE_4_X,
630
BRW_PARAM_BUILTIN_CLIP_PLANE_4_Y,
631
BRW_PARAM_BUILTIN_CLIP_PLANE_4_Z,
632
BRW_PARAM_BUILTIN_CLIP_PLANE_4_W,
633
BRW_PARAM_BUILTIN_CLIP_PLANE_5_X,
634
BRW_PARAM_BUILTIN_CLIP_PLANE_5_Y,
635
BRW_PARAM_BUILTIN_CLIP_PLANE_5_Z,
636
BRW_PARAM_BUILTIN_CLIP_PLANE_5_W,
637
BRW_PARAM_BUILTIN_CLIP_PLANE_6_X,
638
BRW_PARAM_BUILTIN_CLIP_PLANE_6_Y,
639
BRW_PARAM_BUILTIN_CLIP_PLANE_6_Z,
640
BRW_PARAM_BUILTIN_CLIP_PLANE_6_W,
641
BRW_PARAM_BUILTIN_CLIP_PLANE_7_X,
642
BRW_PARAM_BUILTIN_CLIP_PLANE_7_Y,
643
BRW_PARAM_BUILTIN_CLIP_PLANE_7_Z,
644
BRW_PARAM_BUILTIN_CLIP_PLANE_7_W,
645
646
BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_X,
647
BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_Y,
648
BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_Z,
649
BRW_PARAM_BUILTIN_TESS_LEVEL_OUTER_W,
650
BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_X,
651
BRW_PARAM_BUILTIN_TESS_LEVEL_INNER_Y,
652
653
BRW_PARAM_BUILTIN_PATCH_VERTICES_IN,
654
655
BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_X,
656
BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Y,
657
BRW_PARAM_BUILTIN_BASE_WORK_GROUP_ID_Z,
658
BRW_PARAM_BUILTIN_SUBGROUP_ID,
659
BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_X,
660
BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_Y,
661
BRW_PARAM_BUILTIN_WORK_GROUP_SIZE_Z,
662
BRW_PARAM_BUILTIN_WORK_DIM,
663
};
664
665
#define BRW_PARAM_BUILTIN_CLIP_PLANE(idx, comp) \
666
(BRW_PARAM_BUILTIN_CLIP_PLANE_0_X + ((idx) << 2) + (comp))
667
668
#define BRW_PARAM_BUILTIN_IS_CLIP_PLANE(param) \
669
((param) >= BRW_PARAM_BUILTIN_CLIP_PLANE_0_X && \
670
(param) <= BRW_PARAM_BUILTIN_CLIP_PLANE_7_W)
671
672
#define BRW_PARAM_BUILTIN_CLIP_PLANE_IDX(param) \
673
(((param) - BRW_PARAM_BUILTIN_CLIP_PLANE_0_X) >> 2)
674
675
#define BRW_PARAM_BUILTIN_CLIP_PLANE_COMP(param) \
676
(((param) - BRW_PARAM_BUILTIN_CLIP_PLANE_0_X) & 0x3)
677
678
enum brw_shader_reloc_id {
679
BRW_SHADER_RELOC_CONST_DATA_ADDR_LOW,
680
BRW_SHADER_RELOC_CONST_DATA_ADDR_HIGH,
681
BRW_SHADER_RELOC_SHADER_START_OFFSET,
682
BRW_SHADER_RELOC_RESUME_SBT_ADDR_LOW,
683
BRW_SHADER_RELOC_RESUME_SBT_ADDR_HIGH,
684
};
685
686
enum brw_shader_reloc_type {
687
/** An arbitrary 32-bit value */
688
BRW_SHADER_RELOC_TYPE_U32,
689
/** A MOV instruction with an immediate source */
690
BRW_SHADER_RELOC_TYPE_MOV_IMM,
691
};
692
693
/** Represents a code relocation
694
*
695
* Relocatable constants are immediates in the code which we want to be able
696
* to replace post-compile with the actual value.
697
*/
698
struct brw_shader_reloc {
699
/** The 32-bit ID of the relocatable constant */
700
uint32_t id;
701
702
/** Type of this relocation */
703
enum brw_shader_reloc_type type;
704
705
/** The offset in the shader to the relocated value
706
*
707
* For MOV_IMM relocs, this is an offset to the MOV instruction. This
708
* allows us to do some sanity checking while we update the value.
709
*/
710
uint32_t offset;
711
712
/** Value to be added to the relocated value before it is written */
713
uint32_t delta;
714
};
715
716
/** A value to write to a relocation */
717
struct brw_shader_reloc_value {
718
/** The 32-bit ID of the relocatable constant */
719
uint32_t id;
720
721
/** The value with which to replace the relocated immediate */
722
uint32_t value;
723
};
724
725
struct brw_stage_prog_data {
726
struct {
727
/** size of our binding table. */
728
uint32_t size_bytes;
729
730
/** @{
731
* surface indices for the various groups of surfaces
732
*/
733
uint32_t pull_constants_start;
734
uint32_t texture_start;
735
uint32_t gather_texture_start;
736
uint32_t ubo_start;
737
uint32_t ssbo_start;
738
uint32_t image_start;
739
uint32_t shader_time_start;
740
uint32_t plane_start[3];
741
/** @} */
742
} binding_table;
743
744
struct brw_ubo_range ubo_ranges[4];
745
746
GLuint nr_params; /**< number of float params/constants */
747
GLuint nr_pull_params;
748
749
gl_shader_stage stage;
750
751
/* zero_push_reg is a bitfield which indicates what push registers (if any)
752
* should be zeroed by SW at the start of the shader. The corresponding
753
* push_reg_mask_param specifies the param index (in 32-bit units) where
754
* the actual runtime 64-bit mask will be pushed. The shader will zero
755
* push reg i if
756
*
757
* reg_used & zero_push_reg & ~*push_reg_mask_param & (1ull << i)
758
*
759
* If this field is set, brw_compiler::compact_params must be false.
760
*/
761
uint64_t zero_push_reg;
762
unsigned push_reg_mask_param;
763
764
unsigned curb_read_length;
765
unsigned total_scratch;
766
unsigned total_shared;
767
768
unsigned program_size;
769
770
unsigned const_data_size;
771
unsigned const_data_offset;
772
773
unsigned num_relocs;
774
const struct brw_shader_reloc *relocs;
775
776
/** Does this program pull from any UBO or other constant buffers? */
777
bool has_ubo_pull;
778
779
/**
780
* Register where the thread expects to find input data from the URB
781
* (typically uniforms, followed by vertex or fragment attributes).
782
*/
783
unsigned dispatch_grf_start_reg;
784
785
bool use_alt_mode; /**< Use ALT floating point mode? Otherwise, IEEE. */
786
787
/* 32-bit identifiers for all push/pull parameters. These can be anything
788
* the driver wishes them to be; the core of the back-end compiler simply
789
* re-arranges them. The one restriction is that the bottom 2^16 values
790
* are reserved for builtins defined in the brw_param_builtin enum defined
791
* above.
792
*/
793
uint32_t *param;
794
uint32_t *pull_param;
795
796
/* Whether shader uses atomic operations. */
797
bool uses_atomic_load_store;
798
};
799
800
static inline uint32_t *
801
brw_stage_prog_data_add_params(struct brw_stage_prog_data *prog_data,
802
unsigned nr_new_params)
803
{
804
unsigned old_nr_params = prog_data->nr_params;
805
prog_data->nr_params += nr_new_params;
806
prog_data->param = reralloc(ralloc_parent(prog_data->param),
807
prog_data->param, uint32_t,
808
prog_data->nr_params);
809
return prog_data->param + old_nr_params;
810
}
811
812
enum brw_barycentric_mode {
813
BRW_BARYCENTRIC_PERSPECTIVE_PIXEL = 0,
814
BRW_BARYCENTRIC_PERSPECTIVE_CENTROID = 1,
815
BRW_BARYCENTRIC_PERSPECTIVE_SAMPLE = 2,
816
BRW_BARYCENTRIC_NONPERSPECTIVE_PIXEL = 3,
817
BRW_BARYCENTRIC_NONPERSPECTIVE_CENTROID = 4,
818
BRW_BARYCENTRIC_NONPERSPECTIVE_SAMPLE = 5,
819
BRW_BARYCENTRIC_MODE_COUNT = 6
820
};
821
#define BRW_BARYCENTRIC_NONPERSPECTIVE_BITS \
822
((1 << BRW_BARYCENTRIC_NONPERSPECTIVE_PIXEL) | \
823
(1 << BRW_BARYCENTRIC_NONPERSPECTIVE_CENTROID) | \
824
(1 << BRW_BARYCENTRIC_NONPERSPECTIVE_SAMPLE))
825
826
enum brw_pixel_shader_computed_depth_mode {
827
BRW_PSCDEPTH_OFF = 0, /* PS does not compute depth */
828
BRW_PSCDEPTH_ON = 1, /* PS computes depth; no guarantee about value */
829
BRW_PSCDEPTH_ON_GE = 2, /* PS guarantees output depth >= source depth */
830
BRW_PSCDEPTH_ON_LE = 3, /* PS guarantees output depth <= source depth */
831
};
832
833
/* Data about a particular attempt to compile a program. Note that
834
* there can be many of these, each in a different GL state
835
* corresponding to a different brw_wm_prog_key struct, with different
836
* compiled programs.
837
*/
838
struct brw_wm_prog_data {
839
struct brw_stage_prog_data base;
840
841
GLuint num_varying_inputs;
842
843
uint8_t reg_blocks_8;
844
uint8_t reg_blocks_16;
845
uint8_t reg_blocks_32;
846
847
uint8_t dispatch_grf_start_reg_16;
848
uint8_t dispatch_grf_start_reg_32;
849
uint32_t prog_offset_16;
850
uint32_t prog_offset_32;
851
852
struct {
853
/** @{
854
* surface indices the WM-specific surfaces
855
*/
856
uint32_t render_target_read_start;
857
/** @} */
858
} binding_table;
859
860
uint8_t computed_depth_mode;
861
bool computed_stencil;
862
863
bool early_fragment_tests;
864
bool post_depth_coverage;
865
bool inner_coverage;
866
bool dispatch_8;
867
bool dispatch_16;
868
bool dispatch_32;
869
bool dual_src_blend;
870
bool persample_dispatch;
871
bool uses_pos_offset;
872
bool uses_omask;
873
bool uses_kill;
874
bool uses_src_depth;
875
bool uses_src_w;
876
bool uses_depth_w_coefficients;
877
bool uses_sample_mask;
878
bool has_render_target_reads;
879
bool has_side_effects;
880
bool pulls_bary;
881
882
bool contains_flat_varying;
883
bool contains_noperspective_varying;
884
885
/**
886
* Shader is ran at the coarse pixel shading dispatch rate (3DSTATE_CPS).
887
*/
888
bool per_coarse_pixel_dispatch;
889
890
/**
891
* Mask of which interpolation modes are required by the fragment shader.
892
* Used in hardware setup on gfx6+.
893
*/
894
uint32_t barycentric_interp_modes;
895
896
/**
897
* Mask of which FS inputs are marked flat by the shader source. This is
898
* needed for setting up 3DSTATE_SF/SBE.
899
*/
900
uint32_t flat_inputs;
901
902
/**
903
* The FS inputs
904
*/
905
uint64_t inputs;
906
907
/* Mapping of VUE slots to interpolation modes.
908
* Used by the Gfx4-5 clip/sf/wm stages.
909
*/
910
unsigned char interp_mode[65]; /* BRW_VARYING_SLOT_COUNT */
911
912
/**
913
* Map from gl_varying_slot to the position within the FS setup data
914
* payload where the varying's attribute vertex deltas should be delivered.
915
* For varying slots that are not used by the FS, the value is -1.
916
*/
917
int urb_setup[VARYING_SLOT_MAX];
918
919
/**
920
* Cache structure into the urb_setup array above that contains the
921
* attribute numbers of active varyings out of urb_setup.
922
* The actual count is stored in urb_setup_attribs_count.
923
*/
924
uint8_t urb_setup_attribs[VARYING_SLOT_MAX];
925
uint8_t urb_setup_attribs_count;
926
};
927
928
/** Returns the SIMD width corresponding to a given KSP index
929
*
930
* The "Variable Pixel Dispatch" table in the PRM (which can be found, for
931
* example in Vol. 7 of the SKL PRM) has a mapping from dispatch widths to
932
* kernel start pointer (KSP) indices that is based on what dispatch widths
933
* are enabled. This function provides, effectively, the reverse mapping.
934
*
935
* If the given KSP is valid with respect to the SIMD8/16/32 enables, a SIMD
936
* width of 8, 16, or 32 is returned. If the KSP is invalid, 0 is returned.
937
*/
938
static inline unsigned
939
brw_fs_simd_width_for_ksp(unsigned ksp_idx, bool simd8_enabled,
940
bool simd16_enabled, bool simd32_enabled)
941
{
942
/* This function strictly ignores contiguous dispatch */
943
switch (ksp_idx) {
944
case 0:
945
return simd8_enabled ? 8 :
946
(simd16_enabled && !simd32_enabled) ? 16 :
947
(simd32_enabled && !simd16_enabled) ? 32 : 0;
948
case 1:
949
return (simd32_enabled && (simd16_enabled || simd8_enabled)) ? 32 : 0;
950
case 2:
951
return (simd16_enabled && (simd32_enabled || simd8_enabled)) ? 16 : 0;
952
default:
953
unreachable("Invalid KSP index");
954
}
955
}
956
957
#define brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx) \
958
brw_fs_simd_width_for_ksp((ksp_idx), (wm_state)._8PixelDispatchEnable, \
959
(wm_state)._16PixelDispatchEnable, \
960
(wm_state)._32PixelDispatchEnable)
961
962
#define brw_wm_state_has_ksp(wm_state, ksp_idx) \
963
(brw_wm_state_simd_width_for_ksp((wm_state), (ksp_idx)) != 0)
964
965
static inline uint32_t
966
_brw_wm_prog_data_prog_offset(const struct brw_wm_prog_data *prog_data,
967
unsigned simd_width)
968
{
969
switch (simd_width) {
970
case 8: return 0;
971
case 16: return prog_data->prog_offset_16;
972
case 32: return prog_data->prog_offset_32;
973
default: return 0;
974
}
975
}
976
977
#define brw_wm_prog_data_prog_offset(prog_data, wm_state, ksp_idx) \
978
_brw_wm_prog_data_prog_offset(prog_data, \
979
brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx))
980
981
static inline uint8_t
982
_brw_wm_prog_data_dispatch_grf_start_reg(const struct brw_wm_prog_data *prog_data,
983
unsigned simd_width)
984
{
985
switch (simd_width) {
986
case 8: return prog_data->base.dispatch_grf_start_reg;
987
case 16: return prog_data->dispatch_grf_start_reg_16;
988
case 32: return prog_data->dispatch_grf_start_reg_32;
989
default: return 0;
990
}
991
}
992
993
#define brw_wm_prog_data_dispatch_grf_start_reg(prog_data, wm_state, ksp_idx) \
994
_brw_wm_prog_data_dispatch_grf_start_reg(prog_data, \
995
brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx))
996
997
static inline uint8_t
998
_brw_wm_prog_data_reg_blocks(const struct brw_wm_prog_data *prog_data,
999
unsigned simd_width)
1000
{
1001
switch (simd_width) {
1002
case 8: return prog_data->reg_blocks_8;
1003
case 16: return prog_data->reg_blocks_16;
1004
case 32: return prog_data->reg_blocks_32;
1005
default: return 0;
1006
}
1007
}
1008
1009
#define brw_wm_prog_data_reg_blocks(prog_data, wm_state, ksp_idx) \
1010
_brw_wm_prog_data_reg_blocks(prog_data, \
1011
brw_wm_state_simd_width_for_ksp(wm_state, ksp_idx))
1012
1013
struct brw_push_const_block {
1014
unsigned dwords; /* Dword count, not reg aligned */
1015
unsigned regs;
1016
unsigned size; /* Bytes, register aligned */
1017
};
1018
1019
struct brw_cs_prog_data {
1020
struct brw_stage_prog_data base;
1021
1022
unsigned local_size[3];
1023
1024
/* Program offsets for the 8/16/32 SIMD variants. Multiple variants are
1025
* kept when using variable group size, and the right one can only be
1026
* decided at dispatch time.
1027
*/
1028
unsigned prog_offset[3];
1029
1030
/* Bitmask indicating which program offsets are valid. */
1031
unsigned prog_mask;
1032
1033
/* Bitmask indicating which programs have spilled. */
1034
unsigned prog_spilled;
1035
1036
bool uses_barrier;
1037
bool uses_num_work_groups;
1038
bool uses_inline_data;
1039
bool uses_btd_stack_ids;
1040
1041
struct {
1042
struct brw_push_const_block cross_thread;
1043
struct brw_push_const_block per_thread;
1044
} push;
1045
1046
struct {
1047
/** @{
1048
* surface indices the CS-specific surfaces
1049
*/
1050
uint32_t work_groups_start;
1051
/** @} */
1052
} binding_table;
1053
};
1054
1055
static inline uint32_t
1056
brw_cs_prog_data_prog_offset(const struct brw_cs_prog_data *prog_data,
1057
unsigned dispatch_width)
1058
{
1059
assert(dispatch_width == 8 ||
1060
dispatch_width == 16 ||
1061
dispatch_width == 32);
1062
const unsigned index = dispatch_width / 16;
1063
assert(prog_data->prog_mask & (1 << index));
1064
return prog_data->prog_offset[index];
1065
}
1066
1067
struct brw_bs_prog_data {
1068
struct brw_stage_prog_data base;
1069
1070
/** SIMD size of the root shader */
1071
uint8_t simd_size;
1072
1073
/** Maximum stack size of all shaders */
1074
uint32_t max_stack_size;
1075
1076
/** Offset into the shader where the resume SBT is located */
1077
uint32_t resume_sbt_offset;
1078
};
1079
1080
struct brw_ff_gs_prog_data {
1081
unsigned urb_read_length;
1082
unsigned total_grf;
1083
1084
/**
1085
* Gfx6 transform feedback: Amount by which the streaming vertex buffer
1086
* indices should be incremented each time the GS is invoked.
1087
*/
1088
unsigned svbi_postincrement_value;
1089
};
1090
1091
/**
1092
* Enum representing the i965-specific vertex results that don't correspond
1093
* exactly to any element of gl_varying_slot. The values of this enum are
1094
* assigned such that they don't conflict with gl_varying_slot.
1095
*/
1096
typedef enum
1097
{
1098
BRW_VARYING_SLOT_NDC = VARYING_SLOT_MAX,
1099
BRW_VARYING_SLOT_PAD,
1100
/**
1101
* Technically this is not a varying but just a placeholder that
1102
* compile_sf_prog() inserts into its VUE map to cause the gl_PointCoord
1103
* builtin variable to be compiled correctly. see compile_sf_prog() for
1104
* more info.
1105
*/
1106
BRW_VARYING_SLOT_PNTC,
1107
BRW_VARYING_SLOT_COUNT
1108
} brw_varying_slot;
1109
1110
/**
1111
* We always program SF to start reading at an offset of 1 (2 varying slots)
1112
* from the start of the vertex URB entry. This causes it to skip:
1113
* - VARYING_SLOT_PSIZ and BRW_VARYING_SLOT_NDC on gfx4-5
1114
* - VARYING_SLOT_PSIZ and VARYING_SLOT_POS on gfx6+
1115
*/
1116
#define BRW_SF_URB_ENTRY_READ_OFFSET 1
1117
1118
/**
1119
* Bitmask indicating which fragment shader inputs represent varyings (and
1120
* hence have to be delivered to the fragment shader by the SF/SBE stage).
1121
*/
1122
#define BRW_FS_VARYING_INPUT_MASK \
1123
(BITFIELD64_RANGE(0, VARYING_SLOT_MAX) & \
1124
~VARYING_BIT_POS & ~VARYING_BIT_FACE)
1125
1126
/**
1127
* Data structure recording the relationship between the gl_varying_slot enum
1128
* and "slots" within the vertex URB entry (VUE). A "slot" is defined as a
1129
* single octaword within the VUE (128 bits).
1130
*
1131
* Note that each BRW register contains 256 bits (2 octawords), so when
1132
* accessing the VUE in URB_NOSWIZZLE mode, each register corresponds to two
1133
* consecutive VUE slots. When accessing the VUE in URB_INTERLEAVED mode (as
1134
* in a vertex shader), each register corresponds to a single VUE slot, since
1135
* it contains data for two separate vertices.
1136
*/
1137
struct brw_vue_map {
1138
/**
1139
* Bitfield representing all varying slots that are (a) stored in this VUE
1140
* map, and (b) actually written by the shader. Does not include any of
1141
* the additional varying slots defined in brw_varying_slot.
1142
*/
1143
uint64_t slots_valid;
1144
1145
/**
1146
* Is this VUE map for a separate shader pipeline?
1147
*
1148
* Separable programs (GL_ARB_separate_shader_objects) can be mixed and matched
1149
* without the linker having a chance to dead code eliminate unused varyings.
1150
*
1151
* This means that we have to use a fixed slot layout, based on the output's
1152
* location field, rather than assigning slots in a compact contiguous block.
1153
*/
1154
bool separate;
1155
1156
/**
1157
* Map from gl_varying_slot value to VUE slot. For gl_varying_slots that are
1158
* not stored in a slot (because they are not written, or because
1159
* additional processing is applied before storing them in the VUE), the
1160
* value is -1.
1161
*/
1162
signed char varying_to_slot[VARYING_SLOT_TESS_MAX];
1163
1164
/**
1165
* Map from VUE slot to gl_varying_slot value. For slots that do not
1166
* directly correspond to a gl_varying_slot, the value comes from
1167
* brw_varying_slot.
1168
*
1169
* For slots that are not in use, the value is BRW_VARYING_SLOT_PAD.
1170
*/
1171
signed char slot_to_varying[VARYING_SLOT_TESS_MAX];
1172
1173
/**
1174
* Total number of VUE slots in use
1175
*/
1176
int num_slots;
1177
1178
/**
1179
* Number of per-patch VUE slots. Only valid for tessellation control
1180
* shader outputs and tessellation evaluation shader inputs.
1181
*/
1182
int num_per_patch_slots;
1183
1184
/**
1185
* Number of per-vertex VUE slots. Only valid for tessellation control
1186
* shader outputs and tessellation evaluation shader inputs.
1187
*/
1188
int num_per_vertex_slots;
1189
};
1190
1191
void brw_print_vue_map(FILE *fp, const struct brw_vue_map *vue_map,
1192
gl_shader_stage stage);
1193
1194
/**
1195
* Convert a VUE slot number into a byte offset within the VUE.
1196
*/
1197
static inline GLuint brw_vue_slot_to_offset(GLuint slot)
1198
{
1199
return 16*slot;
1200
}
1201
1202
/**
1203
* Convert a vertex output (brw_varying_slot) into a byte offset within the
1204
* VUE.
1205
*/
1206
static inline
1207
GLuint brw_varying_to_offset(const struct brw_vue_map *vue_map, GLuint varying)
1208
{
1209
return brw_vue_slot_to_offset(vue_map->varying_to_slot[varying]);
1210
}
1211
1212
void brw_compute_vue_map(const struct intel_device_info *devinfo,
1213
struct brw_vue_map *vue_map,
1214
uint64_t slots_valid,
1215
bool separate_shader,
1216
uint32_t pos_slots);
1217
1218
void brw_compute_tess_vue_map(struct brw_vue_map *const vue_map,
1219
uint64_t slots_valid,
1220
uint32_t is_patch);
1221
1222
/* brw_interpolation_map.c */
1223
void brw_setup_vue_interpolation(const struct brw_vue_map *vue_map,
1224
struct nir_shader *nir,
1225
struct brw_wm_prog_data *prog_data);
1226
1227
enum shader_dispatch_mode {
1228
DISPATCH_MODE_4X1_SINGLE = 0,
1229
DISPATCH_MODE_4X2_DUAL_INSTANCE = 1,
1230
DISPATCH_MODE_4X2_DUAL_OBJECT = 2,
1231
DISPATCH_MODE_SIMD8 = 3,
1232
1233
DISPATCH_MODE_TCS_SINGLE_PATCH = 0,
1234
DISPATCH_MODE_TCS_8_PATCH = 2,
1235
};
1236
1237
/**
1238
* @defgroup Tessellator parameter enumerations.
1239
*
1240
* These correspond to the hardware values in 3DSTATE_TE, and are provided
1241
* as part of the tessellation evaluation shader.
1242
*
1243
* @{
1244
*/
1245
enum brw_tess_partitioning {
1246
BRW_TESS_PARTITIONING_INTEGER = 0,
1247
BRW_TESS_PARTITIONING_ODD_FRACTIONAL = 1,
1248
BRW_TESS_PARTITIONING_EVEN_FRACTIONAL = 2,
1249
};
1250
1251
enum brw_tess_output_topology {
1252
BRW_TESS_OUTPUT_TOPOLOGY_POINT = 0,
1253
BRW_TESS_OUTPUT_TOPOLOGY_LINE = 1,
1254
BRW_TESS_OUTPUT_TOPOLOGY_TRI_CW = 2,
1255
BRW_TESS_OUTPUT_TOPOLOGY_TRI_CCW = 3,
1256
};
1257
1258
enum brw_tess_domain {
1259
BRW_TESS_DOMAIN_QUAD = 0,
1260
BRW_TESS_DOMAIN_TRI = 1,
1261
BRW_TESS_DOMAIN_ISOLINE = 2,
1262
};
1263
/** @} */
1264
1265
struct brw_vue_prog_data {
1266
struct brw_stage_prog_data base;
1267
struct brw_vue_map vue_map;
1268
1269
/** Should the hardware deliver input VUE handles for URB pull loads? */
1270
bool include_vue_handles;
1271
1272
GLuint urb_read_length;
1273
GLuint total_grf;
1274
1275
uint32_t clip_distance_mask;
1276
uint32_t cull_distance_mask;
1277
1278
/* Used for calculating urb partitions. In the VS, this is the size of the
1279
* URB entry used for both input and output to the thread. In the GS, this
1280
* is the size of the URB entry used for output.
1281
*/
1282
GLuint urb_entry_size;
1283
1284
enum shader_dispatch_mode dispatch_mode;
1285
};
1286
1287
struct brw_vs_prog_data {
1288
struct brw_vue_prog_data base;
1289
1290
GLbitfield64 inputs_read;
1291
GLbitfield64 double_inputs_read;
1292
1293
unsigned nr_attribute_slots;
1294
1295
bool uses_vertexid;
1296
bool uses_instanceid;
1297
bool uses_is_indexed_draw;
1298
bool uses_firstvertex;
1299
bool uses_baseinstance;
1300
bool uses_drawid;
1301
};
1302
1303
struct brw_tcs_prog_data
1304
{
1305
struct brw_vue_prog_data base;
1306
1307
/** Should the non-SINGLE_PATCH payload provide primitive ID? */
1308
bool include_primitive_id;
1309
1310
/** Number vertices in output patch */
1311
int instances;
1312
1313
/** Track patch count threshold */
1314
int patch_count_threshold;
1315
};
1316
1317
1318
struct brw_tes_prog_data
1319
{
1320
struct brw_vue_prog_data base;
1321
1322
enum brw_tess_partitioning partitioning;
1323
enum brw_tess_output_topology output_topology;
1324
enum brw_tess_domain domain;
1325
};
1326
1327
struct brw_gs_prog_data
1328
{
1329
struct brw_vue_prog_data base;
1330
1331
unsigned vertices_in;
1332
1333
/**
1334
* Size of an output vertex, measured in HWORDS (32 bytes).
1335
*/
1336
unsigned output_vertex_size_hwords;
1337
1338
unsigned output_topology;
1339
1340
/**
1341
* Size of the control data (cut bits or StreamID bits), in hwords (32
1342
* bytes). 0 if there is no control data.
1343
*/
1344
unsigned control_data_header_size_hwords;
1345
1346
/**
1347
* Format of the control data (either GFX7_GS_CONTROL_DATA_FORMAT_GSCTL_SID
1348
* if the control data is StreamID bits, or
1349
* GFX7_GS_CONTROL_DATA_FORMAT_GSCTL_CUT if the control data is cut bits).
1350
* Ignored if control_data_header_size is 0.
1351
*/
1352
unsigned control_data_format;
1353
1354
bool include_primitive_id;
1355
1356
/**
1357
* The number of vertices emitted, if constant - otherwise -1.
1358
*/
1359
int static_vertex_count;
1360
1361
int invocations;
1362
1363
/**
1364
* Gfx6: Provoking vertex convention for odd-numbered triangles
1365
* in tristrips.
1366
*/
1367
GLuint pv_first:1;
1368
1369
/**
1370
* Gfx6: Number of varyings that are output to transform feedback.
1371
*/
1372
GLuint num_transform_feedback_bindings:7; /* 0-BRW_MAX_SOL_BINDINGS */
1373
1374
/**
1375
* Gfx6: Map from the index of a transform feedback binding table entry to the
1376
* gl_varying_slot that should be streamed out through that binding table
1377
* entry.
1378
*/
1379
unsigned char transform_feedback_bindings[64 /* BRW_MAX_SOL_BINDINGS */];
1380
1381
/**
1382
* Gfx6: Map from the index of a transform feedback binding table entry to the
1383
* swizzles that should be used when streaming out data through that
1384
* binding table entry.
1385
*/
1386
unsigned char transform_feedback_swizzles[64 /* BRW_MAX_SOL_BINDINGS */];
1387
};
1388
1389
struct brw_sf_prog_data {
1390
uint32_t urb_read_length;
1391
uint32_t total_grf;
1392
1393
/* Each vertex may have upto 12 attributes, 4 components each,
1394
* except WPOS which requires only 2. (11*4 + 2) == 44 ==> 11
1395
* rows.
1396
*
1397
* Actually we use 4 for each, so call it 12 rows.
1398
*/
1399
unsigned urb_entry_size;
1400
};
1401
1402
struct brw_clip_prog_data {
1403
uint32_t curb_read_length; /* user planes? */
1404
uint32_t clip_mode;
1405
uint32_t urb_read_length;
1406
uint32_t total_grf;
1407
};
1408
1409
/* brw_any_prog_data is prog_data for any stage that maps to an API stage */
1410
union brw_any_prog_data {
1411
struct brw_stage_prog_data base;
1412
struct brw_vue_prog_data vue;
1413
struct brw_vs_prog_data vs;
1414
struct brw_tcs_prog_data tcs;
1415
struct brw_tes_prog_data tes;
1416
struct brw_gs_prog_data gs;
1417
struct brw_wm_prog_data wm;
1418
struct brw_cs_prog_data cs;
1419
struct brw_bs_prog_data bs;
1420
};
1421
1422
#define DEFINE_PROG_DATA_DOWNCAST(STAGE, CHECK) \
1423
static inline struct brw_##STAGE##_prog_data * \
1424
brw_##STAGE##_prog_data(struct brw_stage_prog_data *prog_data) \
1425
{ \
1426
if (prog_data) \
1427
assert(CHECK); \
1428
return (struct brw_##STAGE##_prog_data *) prog_data; \
1429
} \
1430
static inline const struct brw_##STAGE##_prog_data * \
1431
brw_##STAGE##_prog_data_const(const struct brw_stage_prog_data *prog_data) \
1432
{ \
1433
if (prog_data) \
1434
assert(CHECK); \
1435
return (const struct brw_##STAGE##_prog_data *) prog_data; \
1436
}
1437
1438
DEFINE_PROG_DATA_DOWNCAST(vs, prog_data->stage == MESA_SHADER_VERTEX)
1439
DEFINE_PROG_DATA_DOWNCAST(tcs, prog_data->stage == MESA_SHADER_TESS_CTRL)
1440
DEFINE_PROG_DATA_DOWNCAST(tes, prog_data->stage == MESA_SHADER_TESS_EVAL)
1441
DEFINE_PROG_DATA_DOWNCAST(gs, prog_data->stage == MESA_SHADER_GEOMETRY)
1442
DEFINE_PROG_DATA_DOWNCAST(wm, prog_data->stage == MESA_SHADER_FRAGMENT)
1443
DEFINE_PROG_DATA_DOWNCAST(cs, prog_data->stage == MESA_SHADER_COMPUTE)
1444
DEFINE_PROG_DATA_DOWNCAST(bs, brw_shader_stage_is_bindless(prog_data->stage))
1445
1446
DEFINE_PROG_DATA_DOWNCAST(vue, prog_data->stage == MESA_SHADER_VERTEX ||
1447
prog_data->stage == MESA_SHADER_TESS_CTRL ||
1448
prog_data->stage == MESA_SHADER_TESS_EVAL ||
1449
prog_data->stage == MESA_SHADER_GEOMETRY)
1450
1451
/* These are not really brw_stage_prog_data. */
1452
DEFINE_PROG_DATA_DOWNCAST(ff_gs, true)
1453
DEFINE_PROG_DATA_DOWNCAST(clip, true)
1454
DEFINE_PROG_DATA_DOWNCAST(sf, true)
1455
#undef DEFINE_PROG_DATA_DOWNCAST
1456
1457
struct brw_compile_stats {
1458
uint32_t dispatch_width; /**< 0 for vec4 */
1459
uint32_t instructions;
1460
uint32_t sends;
1461
uint32_t loops;
1462
uint32_t cycles;
1463
uint32_t spills;
1464
uint32_t fills;
1465
};
1466
1467
/** @} */
1468
1469
struct brw_compiler *
1470
brw_compiler_create(void *mem_ctx, const struct intel_device_info *devinfo);
1471
1472
/**
1473
* Returns a compiler configuration for use with disk shader cache
1474
*
1475
* This value only needs to change for settings that can cause different
1476
* program generation between two runs on the same hardware.
1477
*
1478
* For example, it doesn't need to be different for gen 8 and gen 9 hardware,
1479
* but it does need to be different if INTEL_DEBUG=nocompact is or isn't used.
1480
*/
1481
uint64_t
1482
brw_get_compiler_config_value(const struct brw_compiler *compiler);
1483
1484
unsigned
1485
brw_prog_data_size(gl_shader_stage stage);
1486
1487
unsigned
1488
brw_prog_key_size(gl_shader_stage stage);
1489
1490
void
1491
brw_prog_key_set_id(union brw_any_prog_key *key, gl_shader_stage, unsigned id);
1492
1493
/**
1494
* Parameters for compiling a vertex shader.
1495
*
1496
* Some of these will be modified during the shader compilation.
1497
*/
1498
struct brw_compile_vs_params {
1499
nir_shader *nir;
1500
1501
const struct brw_vs_prog_key *key;
1502
struct brw_vs_prog_data *prog_data;
1503
1504
bool edgeflag_is_last; /* true for gallium */
1505
bool shader_time;
1506
int shader_time_index;
1507
1508
struct brw_compile_stats *stats;
1509
1510
void *log_data;
1511
1512
char *error_str;
1513
1514
/* If unset, DEBUG_VS is used. */
1515
uint64_t debug_flag;
1516
};
1517
1518
/**
1519
* Compile a vertex shader.
1520
*
1521
* Returns the final assembly and updates the parameters structure.
1522
*/
1523
const unsigned *
1524
brw_compile_vs(const struct brw_compiler *compiler,
1525
void *mem_ctx,
1526
struct brw_compile_vs_params *params);
1527
1528
/**
1529
* Compile a tessellation control shader.
1530
*
1531
* Returns the final assembly and the program's size.
1532
*/
1533
const unsigned *
1534
brw_compile_tcs(const struct brw_compiler *compiler,
1535
void *log_data,
1536
void *mem_ctx,
1537
const struct brw_tcs_prog_key *key,
1538
struct brw_tcs_prog_data *prog_data,
1539
nir_shader *nir,
1540
int shader_time_index,
1541
struct brw_compile_stats *stats,
1542
char **error_str);
1543
1544
/**
1545
* Compile a tessellation evaluation shader.
1546
*
1547
* Returns the final assembly and the program's size.
1548
*/
1549
const unsigned *
1550
brw_compile_tes(const struct brw_compiler *compiler, void *log_data,
1551
void *mem_ctx,
1552
const struct brw_tes_prog_key *key,
1553
const struct brw_vue_map *input_vue_map,
1554
struct brw_tes_prog_data *prog_data,
1555
nir_shader *nir,
1556
int shader_time_index,
1557
struct brw_compile_stats *stats,
1558
char **error_str);
1559
1560
/**
1561
* Compile a vertex shader.
1562
*
1563
* Returns the final assembly and the program's size.
1564
*/
1565
const unsigned *
1566
brw_compile_gs(const struct brw_compiler *compiler, void *log_data,
1567
void *mem_ctx,
1568
const struct brw_gs_prog_key *key,
1569
struct brw_gs_prog_data *prog_data,
1570
nir_shader *nir,
1571
int shader_time_index,
1572
struct brw_compile_stats *stats,
1573
char **error_str);
1574
1575
/**
1576
* Compile a strips and fans shader.
1577
*
1578
* This is a fixed-function shader determined entirely by the shader key and
1579
* a VUE map.
1580
*
1581
* Returns the final assembly and the program's size.
1582
*/
1583
const unsigned *
1584
brw_compile_sf(const struct brw_compiler *compiler,
1585
void *mem_ctx,
1586
const struct brw_sf_prog_key *key,
1587
struct brw_sf_prog_data *prog_data,
1588
struct brw_vue_map *vue_map,
1589
unsigned *final_assembly_size);
1590
1591
/**
1592
* Compile a clipper shader.
1593
*
1594
* This is a fixed-function shader determined entirely by the shader key and
1595
* a VUE map.
1596
*
1597
* Returns the final assembly and the program's size.
1598
*/
1599
const unsigned *
1600
brw_compile_clip(const struct brw_compiler *compiler,
1601
void *mem_ctx,
1602
const struct brw_clip_prog_key *key,
1603
struct brw_clip_prog_data *prog_data,
1604
struct brw_vue_map *vue_map,
1605
unsigned *final_assembly_size);
1606
1607
/**
1608
* Parameters for compiling a fragment shader.
1609
*
1610
* Some of these will be modified during the shader compilation.
1611
*/
1612
struct brw_compile_fs_params {
1613
nir_shader *nir;
1614
1615
const struct brw_wm_prog_key *key;
1616
struct brw_wm_prog_data *prog_data;
1617
const struct brw_vue_map *vue_map;
1618
1619
bool shader_time;
1620
int shader_time_index8;
1621
int shader_time_index16;
1622
int shader_time_index32;
1623
1624
bool allow_spilling;
1625
bool use_rep_send;
1626
1627
struct brw_compile_stats *stats;
1628
1629
void *log_data;
1630
1631
char *error_str;
1632
1633
/* If unset, DEBUG_WM is used. */
1634
uint64_t debug_flag;
1635
};
1636
1637
/**
1638
* Compile a fragment shader.
1639
*
1640
* Returns the final assembly and updates the parameters structure.
1641
*/
1642
const unsigned *
1643
brw_compile_fs(const struct brw_compiler *compiler,
1644
void *mem_ctx,
1645
struct brw_compile_fs_params *params);
1646
1647
/**
1648
* Parameters for compiling a compute shader.
1649
*
1650
* Some of these will be modified during the shader compilation.
1651
*/
1652
struct brw_compile_cs_params {
1653
nir_shader *nir;
1654
1655
const struct brw_cs_prog_key *key;
1656
struct brw_cs_prog_data *prog_data;
1657
1658
bool shader_time;
1659
int shader_time_index;
1660
1661
struct brw_compile_stats *stats;
1662
1663
void *log_data;
1664
1665
char *error_str;
1666
};
1667
1668
/**
1669
* Compile a compute shader.
1670
*
1671
* Returns the final assembly and updates the parameters structure.
1672
*/
1673
const unsigned *
1674
brw_compile_cs(const struct brw_compiler *compiler,
1675
void *mem_ctx,
1676
struct brw_compile_cs_params *params);
1677
1678
/**
1679
* Compile a Ray Tracing shader.
1680
*
1681
* Returns the final assembly and the program's size.
1682
*/
1683
const unsigned *
1684
brw_compile_bs(const struct brw_compiler *compiler, void *log_data,
1685
void *mem_ctx,
1686
const struct brw_bs_prog_key *key,
1687
struct brw_bs_prog_data *prog_data,
1688
struct nir_shader *shader,
1689
unsigned num_resume_shaders,
1690
struct nir_shader **resume_shaders,
1691
struct brw_compile_stats *stats,
1692
char **error_str);
1693
1694
/**
1695
* Compile a fixed function geometry shader.
1696
*
1697
* Returns the final assembly and the program's size.
1698
*/
1699
const unsigned *
1700
brw_compile_ff_gs_prog(struct brw_compiler *compiler,
1701
void *mem_ctx,
1702
const struct brw_ff_gs_prog_key *key,
1703
struct brw_ff_gs_prog_data *prog_data,
1704
struct brw_vue_map *vue_map,
1705
unsigned *final_assembly_size);
1706
1707
void brw_debug_key_recompile(const struct brw_compiler *c, void *log,
1708
gl_shader_stage stage,
1709
const struct brw_base_prog_key *old_key,
1710
const struct brw_base_prog_key *key);
1711
1712
/* Shared Local Memory Size is specified as powers of two,
1713
* and also have a Gen-dependent minimum value if not zero.
1714
*/
1715
static inline uint32_t
1716
intel_calculate_slm_size(unsigned gen, uint32_t bytes)
1717
{
1718
assert(bytes <= 64 * 1024);
1719
if (bytes > 0)
1720
return MAX2(util_next_power_of_two(bytes), gen >= 9 ? 1024 : 4096);
1721
else
1722
return 0;
1723
}
1724
1725
static inline uint32_t
1726
encode_slm_size(unsigned gen, uint32_t bytes)
1727
{
1728
uint32_t slm_size = 0;
1729
1730
/* Shared Local Memory is specified as powers of two, and encoded in
1731
* INTERFACE_DESCRIPTOR_DATA with the following representations:
1732
*
1733
* Size | 0 kB | 1 kB | 2 kB | 4 kB | 8 kB | 16 kB | 32 kB | 64 kB |
1734
* -------------------------------------------------------------------
1735
* Gfx7-8 | 0 | none | none | 1 | 2 | 4 | 8 | 16 |
1736
* -------------------------------------------------------------------
1737
* Gfx9+ | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
1738
*/
1739
1740
if (bytes > 0) {
1741
slm_size = intel_calculate_slm_size(gen, bytes);
1742
assert(util_is_power_of_two_nonzero(slm_size));
1743
1744
if (gen >= 9) {
1745
/* Turn an exponent of 10 (1024 kB) into 1. */
1746
assert(slm_size >= 1024);
1747
slm_size = ffs(slm_size) - 10;
1748
} else {
1749
assert(slm_size >= 4096);
1750
/* Convert to the pre-Gfx9 representation. */
1751
slm_size = slm_size / 4096;
1752
}
1753
}
1754
1755
return slm_size;
1756
}
1757
1758
unsigned
1759
brw_cs_push_const_total_size(const struct brw_cs_prog_data *cs_prog_data,
1760
unsigned threads);
1761
1762
void
1763
brw_write_shader_relocs(const struct intel_device_info *devinfo,
1764
void *program,
1765
const struct brw_stage_prog_data *prog_data,
1766
struct brw_shader_reloc_value *values,
1767
unsigned num_values);
1768
1769
struct brw_cs_dispatch_info {
1770
uint32_t group_size;
1771
uint32_t simd_size;
1772
uint32_t threads;
1773
1774
/* RightExecutionMask field used in GPGPU_WALKER. */
1775
uint32_t right_mask;
1776
};
1777
1778
/**
1779
* Get the dispatch information for a shader to be used with GPGPU_WALKER and
1780
* similar instructions.
1781
*
1782
* If override_local_size is not NULL, it must to point to a 3-element that
1783
* will override the value from prog_data->local_size. This is used by
1784
* ARB_compute_variable_group_size, where the size is set only at dispatch
1785
* time (so prog_data is outdated).
1786
*/
1787
struct brw_cs_dispatch_info
1788
brw_cs_get_dispatch_info(const struct intel_device_info *devinfo,
1789
const struct brw_cs_prog_data *prog_data,
1790
const unsigned *override_local_size);
1791
1792
/**
1793
* Return true if the given shader stage is dispatched contiguously by the
1794
* relevant fixed function starting from channel 0 of the SIMD thread, which
1795
* implies that the dispatch mask of a thread can be assumed to have the form
1796
* '2^n - 1' for some n.
1797
*/
1798
static inline bool
1799
brw_stage_has_packed_dispatch(ASSERTED const struct intel_device_info *devinfo,
1800
gl_shader_stage stage,
1801
const struct brw_stage_prog_data *prog_data)
1802
{
1803
/* The code below makes assumptions about the hardware's thread dispatch
1804
* behavior that could be proven wrong in future generations -- Make sure
1805
* to do a full test run with brw_fs_test_dispatch_packing() hooked up to
1806
* the NIR front-end before changing this assertion.
1807
*/
1808
assert(devinfo->ver <= 12);
1809
1810
switch (stage) {
1811
case MESA_SHADER_FRAGMENT: {
1812
/* The PSD discards subspans coming in with no lit samples, which in the
1813
* per-pixel shading case implies that each subspan will either be fully
1814
* lit (due to the VMask being used to allow derivative computations),
1815
* or not dispatched at all. In per-sample dispatch mode individual
1816
* samples from the same subspan have a fixed relative location within
1817
* the SIMD thread, so dispatch of unlit samples cannot be avoided in
1818
* general and we should return false.
1819
*/
1820
const struct brw_wm_prog_data *wm_prog_data =
1821
(const struct brw_wm_prog_data *)prog_data;
1822
return !wm_prog_data->persample_dispatch;
1823
}
1824
case MESA_SHADER_COMPUTE:
1825
/* Compute shaders will be spawned with either a fully enabled dispatch
1826
* mask or with whatever bottom/right execution mask was given to the
1827
* GPGPU walker command to be used along the workgroup edges -- In both
1828
* cases the dispatch mask is required to be tightly packed for our
1829
* invocation index calculations to work.
1830
*/
1831
return true;
1832
default:
1833
/* Most remaining fixed functions are limited to use a packed dispatch
1834
* mask due to the hardware representation of the dispatch mask as a
1835
* single counter representing the number of enabled channels.
1836
*/
1837
return true;
1838
}
1839
}
1840
1841
/**
1842
* Computes the first varying slot in the URB produced by the previous stage
1843
* that is used in the next stage. We do this by testing the varying slots in
1844
* the previous stage's vue map against the inputs read in the next stage.
1845
*
1846
* Note that:
1847
*
1848
* - Each URB offset contains two varying slots and we can only skip a
1849
* full offset if both slots are unused, so the value we return here is always
1850
* rounded down to the closest multiple of two.
1851
*
1852
* - gl_Layer and gl_ViewportIndex don't have their own varying slots, they are
1853
* part of the vue header, so if these are read we can't skip anything.
1854
*/
1855
static inline int
1856
brw_compute_first_urb_slot_required(uint64_t inputs_read,
1857
const struct brw_vue_map *prev_stage_vue_map)
1858
{
1859
if ((inputs_read & (VARYING_BIT_LAYER | VARYING_BIT_VIEWPORT)) == 0) {
1860
for (int i = 0; i < prev_stage_vue_map->num_slots; i++) {
1861
int varying = prev_stage_vue_map->slot_to_varying[i];
1862
if (varying > 0 && (inputs_read & BITFIELD64_BIT(varying)) != 0)
1863
return ROUND_DOWN_TO(i, 2);
1864
}
1865
}
1866
1867
return 0;
1868
}
1869
1870
#ifdef __cplusplus
1871
} /* extern "C" */
1872
#endif
1873
1874
#endif /* BRW_COMPILER_H */
1875
1876