~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/intel/compiler/brw_compiler.h

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

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