freedreno/ir3: Implement lowering passes for VS and GS
[mesa.git] / src / freedreno / ir3 / ir3_shader.h
1 /*
2 * Copyright (C) 2014 Rob Clark <robclark@freedesktop.org>
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 FROM,
20 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 * SOFTWARE.
22 *
23 * Authors:
24 * Rob Clark <robclark@freedesktop.org>
25 */
26
27 #ifndef IR3_SHADER_H_
28 #define IR3_SHADER_H_
29
30 #include <stdio.h>
31
32 #include "c11/threads.h"
33 #include "compiler/shader_enums.h"
34 #include "compiler/nir/nir.h"
35 #include "util/bitscan.h"
36
37 #include "ir3.h"
38
39 struct glsl_type;
40
41 /* driver param indices: */
42 enum ir3_driver_param {
43 /* compute shader driver params: */
44 IR3_DP_NUM_WORK_GROUPS_X = 0,
45 IR3_DP_NUM_WORK_GROUPS_Y = 1,
46 IR3_DP_NUM_WORK_GROUPS_Z = 2,
47 IR3_DP_LOCAL_GROUP_SIZE_X = 4,
48 IR3_DP_LOCAL_GROUP_SIZE_Y = 5,
49 IR3_DP_LOCAL_GROUP_SIZE_Z = 6,
50 /* NOTE: gl_NumWorkGroups should be vec4 aligned because
51 * glDispatchComputeIndirect() needs to load these from
52 * the info->indirect buffer. Keep that in mind when/if
53 * adding any addition CS driver params.
54 */
55 IR3_DP_CS_COUNT = 8, /* must be aligned to vec4 */
56
57 /* vertex shader driver params: */
58 IR3_DP_VTXID_BASE = 0,
59 IR3_DP_VTXCNT_MAX = 1,
60 /* user-clip-plane components, up to 8x vec4's: */
61 IR3_DP_UCP0_X = 4,
62 /* .... */
63 IR3_DP_UCP7_W = 35,
64 IR3_DP_VS_COUNT = 36 /* must be aligned to vec4 */
65 };
66
67 #define IR3_MAX_SHADER_BUFFERS 32
68 #define IR3_MAX_SHADER_IMAGES 32
69 #define IR3_MAX_SO_BUFFERS 4
70 #define IR3_MAX_SO_OUTPUTS 64
71 #define IR3_MAX_CONSTANT_BUFFERS 32
72
73
74 /**
75 * Describes the layout of shader consts. This includes:
76 * + Driver lowered UBO ranges
77 * + SSBO sizes
78 * + Image sizes/dimensions
79 * + Driver params (ie. IR3_DP_*)
80 * + TFBO addresses (for generations that do not have hardware streamout)
81 * + Lowered immediates
82 *
83 * For consts needed to pass internal values to shader which may or may not
84 * be required, rather than allocating worst-case const space, we scan the
85 * shader and allocate consts as-needed:
86 *
87 * + SSBO sizes: only needed if shader has a get_buffer_size intrinsic
88 * for a given SSBO
89 *
90 * + Image dimensions: needed to calculate pixel offset, but only for
91 * images that have a image_store intrinsic
92 *
93 * Layout of constant registers, each section aligned to vec4. Note
94 * that pointer size (ubo, etc) changes depending on generation.
95 *
96 * user consts
97 * UBO addresses
98 * SSBO sizes
99 * if (vertex shader) {
100 * driver params (IR3_DP_*)
101 * if (stream_output.num_outputs > 0)
102 * stream-out addresses
103 * } else if (compute_shader) {
104 * driver params (IR3_DP_*)
105 * }
106 * immediates
107 *
108 * Immediates go last mostly because they are inserted in the CP pass
109 * after the nir -> ir3 frontend.
110 *
111 * Note UBO size in bytes should be aligned to vec4
112 */
113 struct ir3_const_state {
114 unsigned num_ubos;
115 unsigned num_driver_params; /* scalar */
116
117 struct {
118 /* user const start at zero */
119 unsigned ubo;
120 /* NOTE that a3xx might need a section for SSBO addresses too */
121 unsigned ssbo_sizes;
122 unsigned image_dims;
123 unsigned driver_param;
124 unsigned tfbo;
125 unsigned immediate;
126 } offsets;
127
128 struct {
129 uint32_t mask; /* bitmask of SSBOs that have get_buffer_size */
130 uint32_t count; /* number of consts allocated */
131 /* one const allocated per SSBO which has get_buffer_size,
132 * ssbo_sizes.off[ssbo_id] is offset from start of ssbo_sizes
133 * consts:
134 */
135 uint32_t off[IR3_MAX_SHADER_BUFFERS];
136 } ssbo_size;
137
138 struct {
139 uint32_t mask; /* bitmask of images that have image_store */
140 uint32_t count; /* number of consts allocated */
141 /* three const allocated per image which has image_store:
142 * + cpp (bytes per pixel)
143 * + pitch (y pitch)
144 * + array_pitch (z pitch)
145 */
146 uint32_t off[IR3_MAX_SHADER_IMAGES];
147 } image_dims;
148
149 unsigned immediate_idx;
150 unsigned immediates_count;
151 unsigned immediates_size;
152 struct {
153 uint32_t val[4];
154 } *immediates;
155 };
156
157 /**
158 * A single output for vertex transform feedback.
159 */
160 struct ir3_stream_output {
161 unsigned register_index:6; /**< 0 to 63 (OUT index) */
162 unsigned start_component:2; /** 0 to 3 */
163 unsigned num_components:3; /** 1 to 4 */
164 unsigned output_buffer:3; /**< 0 to PIPE_MAX_SO_BUFFERS */
165 unsigned dst_offset:16; /**< offset into the buffer in dwords */
166 unsigned stream:2; /**< 0 to 3 */
167 };
168
169 /**
170 * Stream output for vertex transform feedback.
171 */
172 struct ir3_stream_output_info {
173 unsigned num_outputs;
174 /** stride for an entire vertex for each buffer in dwords */
175 uint16_t stride[IR3_MAX_SO_BUFFERS];
176
177 /**
178 * Array of stream outputs, in the order they are to be written in.
179 * Selected components are tightly packed into the output buffer.
180 */
181 struct ir3_stream_output output[IR3_MAX_SO_OUTPUTS];
182 };
183
184 /* Configuration key used to identify a shader variant.. different
185 * shader variants can be used to implement features not supported
186 * in hw (two sided color), binning-pass vertex shader, etc.
187 */
188 struct ir3_shader_key {
189 union {
190 struct {
191 /*
192 * Combined Vertex/Fragment shader parameters:
193 */
194 unsigned ucp_enables : 8;
195
196 /* do we need to check {v,f}saturate_{s,t,r}? */
197 unsigned has_per_samp : 1;
198
199 /*
200 * Vertex shader variant parameters:
201 */
202 unsigned vclamp_color : 1;
203
204 /*
205 * Fragment shader variant parameters:
206 */
207 unsigned sample_shading : 1;
208 unsigned msaa : 1;
209 unsigned color_two_side : 1;
210 unsigned half_precision : 1;
211 /* used when shader needs to handle flat varyings (a4xx)
212 * for front/back color inputs to frag shader:
213 */
214 unsigned rasterflat : 1;
215 unsigned fclamp_color : 1;
216
217 unsigned has_gs : 1;
218 };
219 uint32_t global;
220 };
221
222 /* bitmask of sampler which needs coords clamped for vertex
223 * shader:
224 */
225 uint16_t vsaturate_s, vsaturate_t, vsaturate_r;
226
227 /* bitmask of sampler which needs coords clamped for frag
228 * shader:
229 */
230 uint16_t fsaturate_s, fsaturate_t, fsaturate_r;
231
232 /* bitmask of ms shifts */
233 uint32_t vsamples, fsamples;
234
235 /* bitmask of samplers which need astc srgb workaround: */
236 uint16_t vastc_srgb, fastc_srgb;
237 };
238
239 static inline bool
240 ir3_shader_key_equal(struct ir3_shader_key *a, struct ir3_shader_key *b)
241 {
242 /* slow-path if we need to check {v,f}saturate_{s,t,r} */
243 if (a->has_per_samp || b->has_per_samp)
244 return memcmp(a, b, sizeof(struct ir3_shader_key)) == 0;
245 return a->global == b->global;
246 }
247
248 /* will the two keys produce different lowering for a fragment shader? */
249 static inline bool
250 ir3_shader_key_changes_fs(struct ir3_shader_key *key, struct ir3_shader_key *last_key)
251 {
252 if (last_key->has_per_samp || key->has_per_samp) {
253 if ((last_key->fsaturate_s != key->fsaturate_s) ||
254 (last_key->fsaturate_t != key->fsaturate_t) ||
255 (last_key->fsaturate_r != key->fsaturate_r) ||
256 (last_key->fsamples != key->fsamples) ||
257 (last_key->fastc_srgb != key->fastc_srgb))
258 return true;
259 }
260
261 if (last_key->fclamp_color != key->fclamp_color)
262 return true;
263
264 if (last_key->color_two_side != key->color_two_side)
265 return true;
266
267 if (last_key->half_precision != key->half_precision)
268 return true;
269
270 if (last_key->rasterflat != key->rasterflat)
271 return true;
272
273 if (last_key->ucp_enables != key->ucp_enables)
274 return true;
275
276 return false;
277 }
278
279 /* will the two keys produce different lowering for a vertex shader? */
280 static inline bool
281 ir3_shader_key_changes_vs(struct ir3_shader_key *key, struct ir3_shader_key *last_key)
282 {
283 if (last_key->has_per_samp || key->has_per_samp) {
284 if ((last_key->vsaturate_s != key->vsaturate_s) ||
285 (last_key->vsaturate_t != key->vsaturate_t) ||
286 (last_key->vsaturate_r != key->vsaturate_r) ||
287 (last_key->vsamples != key->vsamples) ||
288 (last_key->vastc_srgb != key->vastc_srgb))
289 return true;
290 }
291
292 if (last_key->vclamp_color != key->vclamp_color)
293 return true;
294
295 if (last_key->ucp_enables != key->ucp_enables)
296 return true;
297
298 return false;
299 }
300
301 /* clears shader-key flags which don't apply to the given shader
302 * stage
303 */
304 static inline void
305 ir3_normalize_key(struct ir3_shader_key *key, gl_shader_stage type)
306 {
307 switch (type) {
308 case MESA_SHADER_FRAGMENT:
309 if (key->has_per_samp) {
310 key->vsaturate_s = 0;
311 key->vsaturate_t = 0;
312 key->vsaturate_r = 0;
313 key->vastc_srgb = 0;
314 key->vsamples = 0;
315 key->has_gs = false; /* FS doesn't care */
316 }
317 break;
318 case MESA_SHADER_VERTEX:
319 case MESA_SHADER_GEOMETRY:
320 key->color_two_side = false;
321 key->half_precision = false;
322 key->rasterflat = false;
323 if (key->has_per_samp) {
324 key->fsaturate_s = 0;
325 key->fsaturate_t = 0;
326 key->fsaturate_r = 0;
327 key->fastc_srgb = 0;
328 key->fsamples = 0;
329 }
330 break;
331 default:
332 /* TODO */
333 break;
334 }
335 }
336
337 /**
338 * On a4xx+a5xx, Images share state with textures and SSBOs:
339 *
340 * + Uses texture (cat5) state/instruction (isam) to read
341 * + Uses SSBO state and instructions (cat6) to write and for atomics
342 *
343 * Starting with a6xx, Images and SSBOs are basically the same thing,
344 * with texture state and isam also used for SSBO reads.
345 *
346 * On top of that, gallium makes the SSBO (shader_buffers) state semi
347 * sparse, with the first half of the state space used for atomic
348 * counters lowered to atomic buffers. We could ignore this, but I
349 * don't think we could *really* handle the case of a single shader
350 * that used the max # of textures + images + SSBOs. And once we are
351 * offsetting images by num_ssbos (or visa versa) to map them into
352 * the same hardware state, the hardware state has become coupled to
353 * the shader state, so at this point we might as well just use a
354 * mapping table to remap things from image/SSBO idx to hw idx.
355 *
356 * To make things less (more?) confusing, for the hw "SSBO" state
357 * (since it is really both SSBO and Image) I'll use the name "IBO"
358 */
359 struct ir3_ibo_mapping {
360 #define IBO_INVALID 0xff
361 /* Maps logical SSBO state to hw state: */
362 uint8_t ssbo_to_ibo[IR3_MAX_SHADER_BUFFERS];
363 uint8_t ssbo_to_tex[IR3_MAX_SHADER_BUFFERS];
364
365 /* Maps logical Image state to hw state: */
366 uint8_t image_to_ibo[IR3_MAX_SHADER_IMAGES];
367 uint8_t image_to_tex[IR3_MAX_SHADER_IMAGES];
368
369 /* Maps hw state back to logical SSBO or Image state:
370 *
371 * note IBO_SSBO ORd into values to indicate that the
372 * hw slot is used for SSBO state vs Image state.
373 */
374 #define IBO_SSBO 0x80
375 uint8_t ibo_to_image[32];
376 uint8_t tex_to_image[32];
377
378 uint8_t num_ibo;
379 uint8_t num_tex; /* including real textures */
380 uint8_t tex_base; /* the number of real textures, ie. image/ssbo start here */
381 };
382
383 /* Represents half register in regid */
384 #define HALF_REG_ID 0x100
385
386 struct ir3_shader_variant {
387 struct fd_bo *bo;
388
389 /* variant id (for debug) */
390 uint32_t id;
391
392 struct ir3_shader_key key;
393
394 /* vertex shaders can have an extra version for hwbinning pass,
395 * which is pointed to by so->binning:
396 */
397 bool binning_pass;
398 // union {
399 struct ir3_shader_variant *binning;
400 struct ir3_shader_variant *nonbinning;
401 // };
402
403 struct ir3_info info;
404 struct ir3 *ir;
405
406 /* Levels of nesting of flow control:
407 */
408 unsigned branchstack;
409
410 unsigned max_sun;
411 unsigned loops;
412
413 /* the instructions length is in units of instruction groups
414 * (4 instructions for a3xx, 16 instructions for a4xx.. each
415 * instruction is 2 dwords):
416 */
417 unsigned instrlen;
418
419 /* the constants length is in units of vec4's, and is the sum of
420 * the uniforms and the built-in compiler constants
421 */
422 unsigned constlen;
423
424 /* About Linkage:
425 * + Let the frag shader determine the position/compmask for the
426 * varyings, since it is the place where we know if the varying
427 * is actually used, and if so, which components are used. So
428 * what the hw calls "outloc" is taken from the "inloc" of the
429 * frag shader.
430 * + From the vert shader, we only need the output regid
431 */
432
433 bool frag_coord, frag_face, color0_mrt;
434
435 /* NOTE: for input/outputs, slot is:
436 * gl_vert_attrib - for VS inputs
437 * gl_varying_slot - for VS output / FS input
438 * gl_frag_result - for FS output
439 */
440
441 /* varyings/outputs: */
442 unsigned outputs_count;
443 struct {
444 uint8_t slot;
445 uint8_t regid;
446 bool half : 1;
447 } outputs[32 + 2]; /* +POSITION +PSIZE */
448 bool writes_pos, writes_smask, writes_psize;
449
450 /* attributes (VS) / varyings (FS):
451 * Note that sysval's should come *after* normal inputs.
452 */
453 unsigned inputs_count;
454 struct {
455 uint8_t slot;
456 uint8_t regid;
457 uint8_t compmask;
458 /* location of input (ie. offset passed to bary.f, etc). This
459 * matches the SP_VS_VPC_DST_REG.OUTLOCn value (a3xx and a4xx
460 * have the OUTLOCn value offset by 8, presumably to account
461 * for gl_Position/gl_PointSize)
462 */
463 uint8_t inloc;
464 /* vertex shader specific: */
465 bool sysval : 1; /* slot is a gl_system_value */
466 /* fragment shader specific: */
467 bool bary : 1; /* fetched varying (vs one loaded into reg) */
468 bool rasterflat : 1; /* special handling for emit->rasterflat */
469 bool use_ldlv : 1; /* internal to ir3_compiler_nir */
470 bool half : 1;
471 enum glsl_interp_mode interpolate;
472 } inputs[32 + 2]; /* +POSITION +FACE */
473
474 /* sum of input components (scalar). For frag shaders, it only counts
475 * the varying inputs:
476 */
477 unsigned total_in;
478
479 /* For frag shaders, the total number of inputs (not scalar,
480 * ie. SP_VS_PARAM_REG.TOTALVSOUTVAR)
481 */
482 unsigned varying_in;
483
484 /* Remapping table to map Image and SSBO to hw state: */
485 struct ir3_ibo_mapping image_mapping;
486
487 /* number of samplers/textures (which are currently 1:1): */
488 int num_samp;
489
490 /* is there an implicit sampler to read framebuffer (FS only).. if
491 * so the sampler-idx is 'num_samp - 1' (ie. it is appended after
492 * the last "real" texture)
493 */
494 bool fb_read;
495
496 /* do we have one or more SSBO instructions: */
497 bool has_ssbo;
498
499 /* do we need derivatives: */
500 bool need_pixlod;
501
502 /* do we have kill, image write, etc (which prevents early-z): */
503 bool no_earlyz;
504
505 bool per_samp;
506
507 /* for astc srgb workaround, the number/base of additional
508 * alpha tex states we need, and index of original tex states
509 */
510 struct {
511 unsigned base, count;
512 unsigned orig_idx[16];
513 } astc_srgb;
514
515 /* shader variants form a linked list: */
516 struct ir3_shader_variant *next;
517
518 /* replicated here to avoid passing extra ptrs everywhere: */
519 gl_shader_stage type;
520 struct ir3_shader *shader;
521 };
522
523 struct ir3_ubo_range {
524 uint32_t offset; /* start offset of this block in const register file */
525 uint32_t start, end; /* range of block that's actually used */
526 };
527
528 struct ir3_ubo_analysis_state
529 {
530 struct ir3_ubo_range range[IR3_MAX_CONSTANT_BUFFERS];
531 uint32_t size;
532 uint32_t lower_count;
533 uint32_t cmdstream_size; /* for per-gen backend to stash required cmdstream size */
534 };
535
536
537 struct ir3_shader {
538 gl_shader_stage type;
539
540 /* shader id (for debug): */
541 uint32_t id;
542 uint32_t variant_count;
543
544 /* so we know when we can disable TGSI related hacks: */
545 bool from_tgsi;
546
547 struct ir3_compiler *compiler;
548
549 struct ir3_ubo_analysis_state ubo_state;
550 struct ir3_const_state const_state;
551
552 struct nir_shader *nir;
553 struct ir3_stream_output_info stream_output;
554
555 struct ir3_shader_variant *variants;
556 mtx_t variants_lock;
557
558 uint32_t output_size; /* Size in dwords of all outputs for VS, size of entire patch for HS. */
559
560 /* Map from driver_location to byte offset in per-primitive storage */
561 unsigned output_loc[32];
562 };
563
564 void * ir3_shader_assemble(struct ir3_shader_variant *v, uint32_t gpu_id);
565 struct ir3_shader_variant * ir3_shader_get_variant(struct ir3_shader *shader,
566 struct ir3_shader_key *key, bool binning_pass, bool *created);
567 struct ir3_shader * ir3_shader_from_nir(struct ir3_compiler *compiler, nir_shader *nir);
568 void ir3_shader_destroy(struct ir3_shader *shader);
569 void ir3_shader_disasm(struct ir3_shader_variant *so, uint32_t *bin, FILE *out);
570 uint64_t ir3_shader_outputs(const struct ir3_shader *so);
571
572 int
573 ir3_glsl_type_size(const struct glsl_type *type, bool bindless);
574
575 static inline const char *
576 ir3_shader_stage(struct ir3_shader *shader)
577 {
578 switch (shader->type) {
579 case MESA_SHADER_VERTEX: return "VERT";
580 case MESA_SHADER_TESS_CTRL: return "TCS";
581 case MESA_SHADER_TESS_EVAL: return "TES";
582 case MESA_SHADER_GEOMETRY: return "GEOM";
583 case MESA_SHADER_FRAGMENT: return "FRAG";
584 case MESA_SHADER_COMPUTE: return "CL";
585 default:
586 unreachable("invalid type");
587 return NULL;
588 }
589 }
590
591 /*
592 * Helper/util:
593 */
594
595 static inline int
596 ir3_find_output(const struct ir3_shader_variant *so, gl_varying_slot slot)
597 {
598 int j;
599
600 for (j = 0; j < so->outputs_count; j++)
601 if (so->outputs[j].slot == slot)
602 return j;
603
604 /* it seems optional to have a OUT.BCOLOR[n] for each OUT.COLOR[n]
605 * in the vertex shader.. but the fragment shader doesn't know this
606 * so it will always have both IN.COLOR[n] and IN.BCOLOR[n]. So
607 * at link time if there is no matching OUT.BCOLOR[n], we must map
608 * OUT.COLOR[n] to IN.BCOLOR[n]. And visa versa if there is only
609 * a OUT.BCOLOR[n] but no matching OUT.COLOR[n]
610 */
611 if (slot == VARYING_SLOT_BFC0) {
612 slot = VARYING_SLOT_COL0;
613 } else if (slot == VARYING_SLOT_BFC1) {
614 slot = VARYING_SLOT_COL1;
615 } else if (slot == VARYING_SLOT_COL0) {
616 slot = VARYING_SLOT_BFC0;
617 } else if (slot == VARYING_SLOT_COL1) {
618 slot = VARYING_SLOT_BFC1;
619 } else {
620 return 0;
621 }
622
623 for (j = 0; j < so->outputs_count; j++)
624 if (so->outputs[j].slot == slot)
625 return j;
626
627 debug_assert(0);
628
629 return 0;
630 }
631
632 static inline int
633 ir3_next_varying(const struct ir3_shader_variant *so, int i)
634 {
635 while (++i < so->inputs_count)
636 if (so->inputs[i].compmask && so->inputs[i].bary)
637 break;
638 return i;
639 }
640
641 struct ir3_shader_linkage {
642 uint8_t max_loc;
643 uint8_t cnt;
644 struct {
645 uint8_t regid;
646 uint8_t compmask;
647 uint8_t loc;
648 } var[32];
649 };
650
651 static inline void
652 ir3_link_add(struct ir3_shader_linkage *l, uint8_t regid, uint8_t compmask, uint8_t loc)
653 {
654 int i = l->cnt++;
655
656 debug_assert(i < ARRAY_SIZE(l->var));
657
658 l->var[i].regid = regid;
659 l->var[i].compmask = compmask;
660 l->var[i].loc = loc;
661 l->max_loc = MAX2(l->max_loc, loc + util_last_bit(compmask));
662 }
663
664 static inline void
665 ir3_link_shaders(struct ir3_shader_linkage *l,
666 const struct ir3_shader_variant *vs,
667 const struct ir3_shader_variant *fs)
668 {
669 int j = -1, k;
670
671 while (l->cnt < ARRAY_SIZE(l->var)) {
672 j = ir3_next_varying(fs, j);
673
674 if (j >= fs->inputs_count)
675 break;
676
677 if (fs->inputs[j].inloc >= fs->total_in)
678 continue;
679
680 k = ir3_find_output(vs, fs->inputs[j].slot);
681
682 ir3_link_add(l, vs->outputs[k].regid,
683 fs->inputs[j].compmask, fs->inputs[j].inloc);
684 }
685 }
686
687 static inline uint32_t
688 ir3_find_output_regid(const struct ir3_shader_variant *so, unsigned slot)
689 {
690 int j;
691 for (j = 0; j < so->outputs_count; j++)
692 if (so->outputs[j].slot == slot) {
693 uint32_t regid = so->outputs[j].regid;
694 if (so->outputs[j].half)
695 regid |= HALF_REG_ID;
696 return regid;
697 }
698 return regid(63, 0);
699 }
700
701 #define VARYING_SLOT_GS_HEADER_IR3 (VARYING_SLOT_MAX + 0)
702 #define VARYING_SLOT_GS_VERTEX_FLAGS_IR3 (VARYING_SLOT_MAX + 1)
703
704
705 static inline uint32_t
706 ir3_find_sysval_regid(const struct ir3_shader_variant *so, unsigned slot)
707 {
708 int j;
709 for (j = 0; j < so->inputs_count; j++)
710 if (so->inputs[j].sysval && (so->inputs[j].slot == slot))
711 return so->inputs[j].regid;
712 return regid(63, 0);
713 }
714
715 /* calculate register footprint in terms of half-regs (ie. one full
716 * reg counts as two half-regs).
717 */
718 static inline uint32_t
719 ir3_shader_halfregs(const struct ir3_shader_variant *v)
720 {
721 return (2 * (v->info.max_reg + 1)) + (v->info.max_half_reg + 1);
722 }
723
724 #endif /* IR3_SHADER_H_ */