2 * Copyright © 2018 Valve Corporation
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:
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
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
26 #include <unordered_map>
29 #include "vulkan/radv_shader.h"
30 #include "vulkan/radv_descriptor_set.h"
31 #include "vulkan/radv_shader_args.h"
33 #include "ac_exp_param.h"
34 #include "ac_shader_util.h"
36 #include "util/u_math.h"
38 #define MAX_INLINE_PUSH_CONSTS 8
43 uint8_t mask
[VARYING_SLOT_VAR31
+ 1];
44 Temp outputs
[VARYING_SLOT_VAR31
+ 1][4];
48 const struct radv_nir_compiler_options
*options
;
49 struct radv_shader_args
*args
;
52 uint32_t constant_data_offset
;
55 std::unique_ptr
<Temp
[]> allocated
;
56 std::unordered_map
<unsigned, std::array
<Temp
,NIR_MAX_VEC_COMPONENTS
>> allocated_vec
;
57 Stage stage
; /* Stage */
58 bool has_gfx10_wave64_bpermute
= false;
61 uint16_t loop_nest_depth
= 0;
65 bool has_divergent_continue
= false;
66 bool has_divergent_branch
= false;
69 bool is_divergent
= false;
71 bool exec_potentially_empty_discard
= false; /* set to false when loop_nest_depth==0 && parent_if.is_divergent==false */
72 uint16_t exec_potentially_empty_break_depth
= UINT16_MAX
;
73 /* Set to false when loop_nest_depth==exec_potentially_empty_break_depth
74 * and parent_if.is_divergent==false. Called _break but it's also used for
76 bool exec_potentially_empty_break
= false;
77 std::unique_ptr
<unsigned[]> nir_to_aco
; /* NIR block index to ACO block index */
80 Temp arg_temps
[AC_MAX_ARGS
];
83 Temp persp_centroid
, linear_centroid
;
88 /* gathered information */
89 uint64_t input_masks
[MESA_SHADER_COMPUTE
];
90 uint64_t output_masks
[MESA_SHADER_COMPUTE
];
92 /* VS output information */
93 bool export_clip_dists
;
94 unsigned num_clip_distances
;
95 unsigned num_cull_distances
;
97 /* tessellation information */
98 uint32_t tcs_num_inputs
;
99 uint32_t tcs_num_patches
;
101 /* VS, FS or GS output information */
102 output_state outputs
;
105 Temp
get_arg(isel_context
*ctx
, struct ac_arg arg
)
108 return ctx
->arg_temps
[arg
.arg_index
];
111 unsigned get_interp_input(nir_intrinsic_op intrin
, enum glsl_interp_mode interp
)
114 case INTERP_MODE_SMOOTH
:
115 case INTERP_MODE_NONE
:
116 if (intrin
== nir_intrinsic_load_barycentric_pixel
||
117 intrin
== nir_intrinsic_load_barycentric_at_sample
||
118 intrin
== nir_intrinsic_load_barycentric_at_offset
)
119 return S_0286CC_PERSP_CENTER_ENA(1);
120 else if (intrin
== nir_intrinsic_load_barycentric_centroid
)
121 return S_0286CC_PERSP_CENTROID_ENA(1);
122 else if (intrin
== nir_intrinsic_load_barycentric_sample
)
123 return S_0286CC_PERSP_SAMPLE_ENA(1);
125 case INTERP_MODE_NOPERSPECTIVE
:
126 if (intrin
== nir_intrinsic_load_barycentric_pixel
)
127 return S_0286CC_LINEAR_CENTER_ENA(1);
128 else if (intrin
== nir_intrinsic_load_barycentric_centroid
)
129 return S_0286CC_LINEAR_CENTROID_ENA(1);
130 else if (intrin
== nir_intrinsic_load_barycentric_sample
)
131 return S_0286CC_LINEAR_SAMPLE_ENA(1);
139 void init_context(isel_context
*ctx
, nir_shader
*shader
)
141 nir_function_impl
*impl
= nir_shader_get_entrypoint(shader
);
142 unsigned lane_mask_size
= ctx
->program
->lane_mask
.size();
144 ctx
->shader
= shader
;
145 ctx
->divergent_vals
= nir_divergence_analysis(shader
, nir_divergence_view_index_uniform
);
147 std::unique_ptr
<Temp
[]> allocated
{new Temp
[impl
->ssa_alloc
]()};
149 unsigned spi_ps_inputs
= 0;
151 std::unique_ptr
<unsigned[]> nir_to_aco
{new unsigned[impl
->num_blocks
]()};
156 nir_foreach_block(block
, impl
) {
157 nir_foreach_instr(instr
, block
) {
158 switch(instr
->type
) {
159 case nir_instr_type_alu
: {
160 nir_alu_instr
*alu_instr
= nir_instr_as_alu(instr
);
161 unsigned size
= alu_instr
->dest
.dest
.ssa
.num_components
;
162 if (alu_instr
->dest
.dest
.ssa
.bit_size
== 64)
164 RegType type
= RegType::sgpr
;
165 switch(alu_instr
->op
) {
187 case nir_op_fround_even
:
196 case nir_op_pack_half_2x16
:
197 case nir_op_unpack_half_2x16_split_x
:
198 case nir_op_unpack_half_2x16_split_y
:
201 case nir_op_fddx_fine
:
202 case nir_op_fddy_fine
:
203 case nir_op_fddx_coarse
:
204 case nir_op_fddy_coarse
:
205 case nir_op_fquantize2f16
:
207 case nir_op_frexp_sig
:
208 case nir_op_frexp_exp
:
209 case nir_op_cube_face_index
:
210 case nir_op_cube_face_coord
:
211 type
= RegType::vgpr
;
224 size
= lane_mask_size
;
232 type
= ctx
->divergent_vals
[alu_instr
->dest
.dest
.ssa
.index
] ? RegType::vgpr
: RegType::sgpr
;
235 if (alu_instr
->dest
.dest
.ssa
.bit_size
== 1) {
236 size
= lane_mask_size
;
238 if (ctx
->divergent_vals
[alu_instr
->dest
.dest
.ssa
.index
]) {
239 type
= RegType::vgpr
;
241 if (allocated
[alu_instr
->src
[1].src
.ssa
->index
].type() == RegType::vgpr
||
242 allocated
[alu_instr
->src
[2].src
.ssa
->index
].type() == RegType::vgpr
) {
243 type
= RegType::vgpr
;
246 if (alu_instr
->src
[1].src
.ssa
->num_components
== 1 && alu_instr
->src
[2].src
.ssa
->num_components
== 1) {
247 assert(allocated
[alu_instr
->src
[1].src
.ssa
->index
].size() == allocated
[alu_instr
->src
[2].src
.ssa
->index
].size());
248 size
= allocated
[alu_instr
->src
[1].src
.ssa
->index
].size();
253 if (alu_instr
->dest
.dest
.ssa
.bit_size
== 1) {
254 size
= lane_mask_size
;
256 type
= ctx
->divergent_vals
[alu_instr
->dest
.dest
.ssa
.index
] ? RegType::vgpr
: RegType::sgpr
;
260 if (alu_instr
->dest
.dest
.ssa
.bit_size
== 1) {
261 size
= lane_mask_size
;
263 for (unsigned i
= 0; i
< nir_op_infos
[alu_instr
->op
].num_inputs
; i
++) {
264 if (allocated
[alu_instr
->src
[i
].src
.ssa
->index
].type() == RegType::vgpr
)
265 type
= RegType::vgpr
;
270 allocated
[alu_instr
->dest
.dest
.ssa
.index
] = Temp(0, RegClass(type
, size
));
273 case nir_instr_type_load_const
: {
274 unsigned size
= nir_instr_as_load_const(instr
)->def
.num_components
;
275 if (nir_instr_as_load_const(instr
)->def
.bit_size
== 64)
277 else if (nir_instr_as_load_const(instr
)->def
.bit_size
== 1)
278 size
*= lane_mask_size
;
279 allocated
[nir_instr_as_load_const(instr
)->def
.index
] = Temp(0, RegClass(RegType::sgpr
, size
));
282 case nir_instr_type_intrinsic
: {
283 nir_intrinsic_instr
*intrinsic
= nir_instr_as_intrinsic(instr
);
284 if (!nir_intrinsic_infos
[intrinsic
->intrinsic
].has_dest
)
286 unsigned size
= intrinsic
->dest
.ssa
.num_components
;
287 if (intrinsic
->dest
.ssa
.bit_size
== 64)
289 RegType type
= RegType::sgpr
;
290 switch(intrinsic
->intrinsic
) {
291 case nir_intrinsic_load_push_constant
:
292 case nir_intrinsic_load_work_group_id
:
293 case nir_intrinsic_load_num_work_groups
:
294 case nir_intrinsic_load_subgroup_id
:
295 case nir_intrinsic_load_num_subgroups
:
296 case nir_intrinsic_load_first_vertex
:
297 case nir_intrinsic_load_base_instance
:
298 case nir_intrinsic_get_buffer_size
:
299 case nir_intrinsic_vote_all
:
300 case nir_intrinsic_vote_any
:
301 case nir_intrinsic_read_first_invocation
:
302 case nir_intrinsic_read_invocation
:
303 case nir_intrinsic_first_invocation
:
304 type
= RegType::sgpr
;
305 if (intrinsic
->dest
.ssa
.bit_size
== 1)
306 size
= lane_mask_size
;
308 case nir_intrinsic_ballot
:
309 type
= RegType::sgpr
;
311 case nir_intrinsic_load_sample_id
:
312 case nir_intrinsic_load_sample_mask_in
:
313 case nir_intrinsic_load_input
:
314 case nir_intrinsic_load_output
:
315 case nir_intrinsic_load_input_vertex
:
316 case nir_intrinsic_load_per_vertex_input
:
317 case nir_intrinsic_load_per_vertex_output
:
318 case nir_intrinsic_load_vertex_id
:
319 case nir_intrinsic_load_vertex_id_zero_base
:
320 case nir_intrinsic_load_barycentric_sample
:
321 case nir_intrinsic_load_barycentric_pixel
:
322 case nir_intrinsic_load_barycentric_model
:
323 case nir_intrinsic_load_barycentric_centroid
:
324 case nir_intrinsic_load_barycentric_at_sample
:
325 case nir_intrinsic_load_barycentric_at_offset
:
326 case nir_intrinsic_load_interpolated_input
:
327 case nir_intrinsic_load_frag_coord
:
328 case nir_intrinsic_load_sample_pos
:
329 case nir_intrinsic_load_layer_id
:
330 case nir_intrinsic_load_local_invocation_id
:
331 case nir_intrinsic_load_local_invocation_index
:
332 case nir_intrinsic_load_subgroup_invocation
:
333 case nir_intrinsic_load_tess_coord
:
334 case nir_intrinsic_write_invocation_amd
:
335 case nir_intrinsic_mbcnt_amd
:
336 case nir_intrinsic_load_instance_id
:
337 case nir_intrinsic_ssbo_atomic_add
:
338 case nir_intrinsic_ssbo_atomic_imin
:
339 case nir_intrinsic_ssbo_atomic_umin
:
340 case nir_intrinsic_ssbo_atomic_imax
:
341 case nir_intrinsic_ssbo_atomic_umax
:
342 case nir_intrinsic_ssbo_atomic_and
:
343 case nir_intrinsic_ssbo_atomic_or
:
344 case nir_intrinsic_ssbo_atomic_xor
:
345 case nir_intrinsic_ssbo_atomic_exchange
:
346 case nir_intrinsic_ssbo_atomic_comp_swap
:
347 case nir_intrinsic_global_atomic_add
:
348 case nir_intrinsic_global_atomic_imin
:
349 case nir_intrinsic_global_atomic_umin
:
350 case nir_intrinsic_global_atomic_imax
:
351 case nir_intrinsic_global_atomic_umax
:
352 case nir_intrinsic_global_atomic_and
:
353 case nir_intrinsic_global_atomic_or
:
354 case nir_intrinsic_global_atomic_xor
:
355 case nir_intrinsic_global_atomic_exchange
:
356 case nir_intrinsic_global_atomic_comp_swap
:
357 case nir_intrinsic_image_deref_atomic_add
:
358 case nir_intrinsic_image_deref_atomic_umin
:
359 case nir_intrinsic_image_deref_atomic_imin
:
360 case nir_intrinsic_image_deref_atomic_umax
:
361 case nir_intrinsic_image_deref_atomic_imax
:
362 case nir_intrinsic_image_deref_atomic_and
:
363 case nir_intrinsic_image_deref_atomic_or
:
364 case nir_intrinsic_image_deref_atomic_xor
:
365 case nir_intrinsic_image_deref_atomic_exchange
:
366 case nir_intrinsic_image_deref_atomic_comp_swap
:
367 case nir_intrinsic_image_deref_size
:
368 case nir_intrinsic_shared_atomic_add
:
369 case nir_intrinsic_shared_atomic_imin
:
370 case nir_intrinsic_shared_atomic_umin
:
371 case nir_intrinsic_shared_atomic_imax
:
372 case nir_intrinsic_shared_atomic_umax
:
373 case nir_intrinsic_shared_atomic_and
:
374 case nir_intrinsic_shared_atomic_or
:
375 case nir_intrinsic_shared_atomic_xor
:
376 case nir_intrinsic_shared_atomic_exchange
:
377 case nir_intrinsic_shared_atomic_comp_swap
:
378 case nir_intrinsic_load_scratch
:
379 case nir_intrinsic_load_invocation_id
:
380 case nir_intrinsic_load_primitive_id
:
381 type
= RegType::vgpr
;
383 case nir_intrinsic_shuffle
:
384 case nir_intrinsic_quad_broadcast
:
385 case nir_intrinsic_quad_swap_horizontal
:
386 case nir_intrinsic_quad_swap_vertical
:
387 case nir_intrinsic_quad_swap_diagonal
:
388 case nir_intrinsic_quad_swizzle_amd
:
389 case nir_intrinsic_masked_swizzle_amd
:
390 case nir_intrinsic_inclusive_scan
:
391 case nir_intrinsic_exclusive_scan
:
392 if (intrinsic
->dest
.ssa
.bit_size
== 1) {
393 size
= lane_mask_size
;
394 type
= RegType::sgpr
;
395 } else if (!ctx
->divergent_vals
[intrinsic
->dest
.ssa
.index
]) {
396 type
= RegType::sgpr
;
398 type
= RegType::vgpr
;
401 case nir_intrinsic_load_view_index
:
402 type
= ctx
->stage
== fragment_fs
? RegType::vgpr
: RegType::sgpr
;
404 case nir_intrinsic_load_front_face
:
405 case nir_intrinsic_load_helper_invocation
:
406 case nir_intrinsic_is_helper_invocation
:
407 type
= RegType::sgpr
;
408 size
= lane_mask_size
;
410 case nir_intrinsic_reduce
:
411 if (intrinsic
->dest
.ssa
.bit_size
== 1) {
412 size
= lane_mask_size
;
413 type
= RegType::sgpr
;
414 } else if (!ctx
->divergent_vals
[intrinsic
->dest
.ssa
.index
]) {
415 type
= RegType::sgpr
;
417 type
= RegType::vgpr
;
420 case nir_intrinsic_load_ubo
:
421 case nir_intrinsic_load_ssbo
:
422 case nir_intrinsic_load_global
:
423 case nir_intrinsic_vulkan_resource_index
:
424 type
= ctx
->divergent_vals
[intrinsic
->dest
.ssa
.index
] ? RegType::vgpr
: RegType::sgpr
;
426 /* due to copy propagation, the swizzled imov is removed if num dest components == 1 */
427 case nir_intrinsic_load_shared
:
428 if (ctx
->divergent_vals
[intrinsic
->dest
.ssa
.index
])
429 type
= RegType::vgpr
;
431 type
= RegType::sgpr
;
434 for (unsigned i
= 0; i
< nir_intrinsic_infos
[intrinsic
->intrinsic
].num_srcs
; i
++) {
435 if (allocated
[intrinsic
->src
[i
].ssa
->index
].type() == RegType::vgpr
)
436 type
= RegType::vgpr
;
440 allocated
[intrinsic
->dest
.ssa
.index
] = Temp(0, RegClass(type
, size
));
442 switch(intrinsic
->intrinsic
) {
443 case nir_intrinsic_load_barycentric_sample
:
444 case nir_intrinsic_load_barycentric_pixel
:
445 case nir_intrinsic_load_barycentric_centroid
:
446 case nir_intrinsic_load_barycentric_at_sample
:
447 case nir_intrinsic_load_barycentric_at_offset
: {
448 glsl_interp_mode mode
= (glsl_interp_mode
)nir_intrinsic_interp_mode(intrinsic
);
449 spi_ps_inputs
|= get_interp_input(intrinsic
->intrinsic
, mode
);
452 case nir_intrinsic_load_barycentric_model
:
453 spi_ps_inputs
|= S_0286CC_PERSP_PULL_MODEL_ENA(1);
455 case nir_intrinsic_load_front_face
:
456 spi_ps_inputs
|= S_0286CC_FRONT_FACE_ENA(1);
458 case nir_intrinsic_load_frag_coord
:
459 case nir_intrinsic_load_sample_pos
: {
460 uint8_t mask
= nir_ssa_def_components_read(&intrinsic
->dest
.ssa
);
461 for (unsigned i
= 0; i
< 4; i
++) {
463 spi_ps_inputs
|= S_0286CC_POS_X_FLOAT_ENA(1) << i
;
468 case nir_intrinsic_load_sample_id
:
469 spi_ps_inputs
|= S_0286CC_ANCILLARY_ENA(1);
471 case nir_intrinsic_load_sample_mask_in
:
472 spi_ps_inputs
|= S_0286CC_ANCILLARY_ENA(1);
473 spi_ps_inputs
|= S_0286CC_SAMPLE_COVERAGE_ENA(1);
480 case nir_instr_type_tex
: {
481 nir_tex_instr
* tex
= nir_instr_as_tex(instr
);
482 unsigned size
= tex
->dest
.ssa
.num_components
;
484 if (tex
->dest
.ssa
.bit_size
== 64)
486 if (tex
->op
== nir_texop_texture_samples
)
487 assert(!ctx
->divergent_vals
[tex
->dest
.ssa
.index
]);
488 if (ctx
->divergent_vals
[tex
->dest
.ssa
.index
])
489 allocated
[tex
->dest
.ssa
.index
] = Temp(0, RegClass(RegType::vgpr
, size
));
491 allocated
[tex
->dest
.ssa
.index
] = Temp(0, RegClass(RegType::sgpr
, size
));
494 case nir_instr_type_parallel_copy
: {
495 nir_foreach_parallel_copy_entry(entry
, nir_instr_as_parallel_copy(instr
)) {
496 allocated
[entry
->dest
.ssa
.index
] = allocated
[entry
->src
.ssa
->index
];
500 case nir_instr_type_ssa_undef
: {
501 unsigned size
= nir_instr_as_ssa_undef(instr
)->def
.num_components
;
502 if (nir_instr_as_ssa_undef(instr
)->def
.bit_size
== 64)
504 allocated
[nir_instr_as_ssa_undef(instr
)->def
.index
] = Temp(0, RegClass(RegType::sgpr
, size
));
507 case nir_instr_type_phi
: {
508 nir_phi_instr
* phi
= nir_instr_as_phi(instr
);
510 unsigned size
= phi
->dest
.ssa
.num_components
;
512 if (phi
->dest
.ssa
.bit_size
== 1) {
513 assert(size
== 1 && "multiple components not yet supported on boolean phis.");
514 type
= RegType::sgpr
;
515 size
*= lane_mask_size
;
516 allocated
[phi
->dest
.ssa
.index
] = Temp(0, RegClass(type
, size
));
520 if (ctx
->divergent_vals
[phi
->dest
.ssa
.index
]) {
521 type
= RegType::vgpr
;
523 type
= RegType::sgpr
;
524 nir_foreach_phi_src (src
, phi
) {
525 if (allocated
[src
->src
.ssa
->index
].type() == RegType::vgpr
)
526 type
= RegType::vgpr
;
527 if (allocated
[src
->src
.ssa
->index
].type() == RegType::none
)
532 size
*= phi
->dest
.ssa
.bit_size
== 64 ? 2 : 1;
533 RegClass rc
= RegClass(type
, size
);
534 if (rc
!= allocated
[phi
->dest
.ssa
.index
].regClass()) {
537 nir_foreach_phi_src(src
, phi
)
538 assert(allocated
[src
->src
.ssa
->index
].size() == rc
.size());
540 allocated
[phi
->dest
.ssa
.index
] = Temp(0, rc
);
550 if (G_0286CC_POS_W_FLOAT_ENA(spi_ps_inputs
)) {
551 /* If POS_W_FLOAT (11) is enabled, at least one of PERSP_* must be enabled too */
552 spi_ps_inputs
|= S_0286CC_PERSP_CENTER_ENA(1);
555 if (!(spi_ps_inputs
& 0x7F)) {
556 /* At least one of PERSP_* (0xF) or LINEAR_* (0x70) must be enabled */
557 spi_ps_inputs
|= S_0286CC_PERSP_CENTER_ENA(1);
560 ctx
->program
->config
->spi_ps_input_ena
= spi_ps_inputs
;
561 ctx
->program
->config
->spi_ps_input_addr
= spi_ps_inputs
;
563 for (unsigned i
= 0; i
< impl
->ssa_alloc
; i
++)
564 allocated
[i
] = Temp(ctx
->program
->allocateId(), allocated
[i
].regClass());
566 ctx
->allocated
.reset(allocated
.release());
567 ctx
->cf_info
.nir_to_aco
.reset(nir_to_aco
.release());
570 Pseudo_instruction
*add_startpgm(struct isel_context
*ctx
)
572 unsigned arg_count
= ctx
->args
->ac
.arg_count
;
573 if (ctx
->stage
== fragment_fs
) {
574 /* LLVM optimizes away unused FS inputs and computes spi_ps_input_addr
575 * itself and then communicates the results back via the ELF binary.
576 * Mirror what LLVM does by re-mapping the VGPR arguments here.
578 * TODO: If we made the FS input scanning code into a separate pass that
579 * could run before argument setup, then this wouldn't be necessary
582 struct ac_shader_args
*args
= &ctx
->args
->ac
;
584 for (unsigned i
= 0, vgpr_arg
= 0, vgpr_reg
= 0; i
< args
->arg_count
; i
++) {
585 if (args
->args
[i
].file
!= AC_ARG_VGPR
) {
590 if (!(ctx
->program
->config
->spi_ps_input_addr
& (1 << vgpr_arg
))) {
591 args
->args
[i
].skip
= true;
593 args
->args
[i
].offset
= vgpr_reg
;
594 vgpr_reg
+= args
->args
[i
].size
;
601 aco_ptr
<Pseudo_instruction
> startpgm
{create_instruction
<Pseudo_instruction
>(aco_opcode::p_startpgm
, Format::PSEUDO
, 0, arg_count
+ 1)};
602 for (unsigned i
= 0, arg
= 0; i
< ctx
->args
->ac
.arg_count
; i
++) {
603 if (ctx
->args
->ac
.args
[i
].skip
)
606 enum ac_arg_regfile file
= ctx
->args
->ac
.args
[i
].file
;
607 unsigned size
= ctx
->args
->ac
.args
[i
].size
;
608 unsigned reg
= ctx
->args
->ac
.args
[i
].offset
;
609 RegClass type
= RegClass(file
== AC_ARG_SGPR
? RegType::sgpr
: RegType::vgpr
, size
);
610 Temp dst
= Temp
{ctx
->program
->allocateId(), type
};
611 ctx
->arg_temps
[i
] = dst
;
612 startpgm
->definitions
[arg
] = Definition(dst
);
613 startpgm
->definitions
[arg
].setFixed(PhysReg
{file
== AC_ARG_SGPR
? reg
: reg
+ 256});
616 startpgm
->definitions
[arg_count
] = Definition
{ctx
->program
->allocateId(), exec
, ctx
->program
->lane_mask
};
617 Pseudo_instruction
*instr
= startpgm
.get();
618 ctx
->block
->instructions
.push_back(std::move(startpgm
));
620 /* Stash these in the program so that they can be accessed later when
623 ctx
->program
->private_segment_buffer
= get_arg(ctx
, ctx
->args
->ring_offsets
);
624 ctx
->program
->scratch_offset
= get_arg(ctx
, ctx
->args
->scratch_offset
);
630 type_size(const struct glsl_type
*type
, bool bindless
)
632 // TODO: don't we need type->std430_base_alignment() here?
633 return glsl_count_attribute_slots(type
, false);
637 shared_var_info(const struct glsl_type
*type
, unsigned *size
, unsigned *align
)
639 assert(glsl_type_is_vector_or_scalar(type
));
641 uint32_t comp_size
= glsl_type_is_boolean(type
)
642 ? 4 : glsl_get_bit_size(type
) / 8;
643 unsigned length
= glsl_get_vector_elements(type
);
644 *size
= comp_size
* length
,
649 mem_vectorize_callback(unsigned align
, unsigned bit_size
,
650 unsigned num_components
, unsigned high_offset
,
651 nir_intrinsic_instr
*low
, nir_intrinsic_instr
*high
)
653 if ((bit_size
!= 32 && bit_size
!= 64) || num_components
> 4)
656 /* >128 bit loads are split except with SMEM */
657 if (bit_size
* num_components
> 128)
660 switch (low
->intrinsic
) {
661 case nir_intrinsic_load_ubo
:
662 case nir_intrinsic_load_ssbo
:
663 case nir_intrinsic_store_ssbo
:
664 case nir_intrinsic_load_push_constant
:
665 return align
% 4 == 0;
666 case nir_intrinsic_load_deref
:
667 case nir_intrinsic_store_deref
:
668 assert(nir_src_as_deref(low
->src
[0])->mode
== nir_var_mem_shared
);
670 case nir_intrinsic_load_shared
:
671 case nir_intrinsic_store_shared
:
672 if (bit_size
* num_components
> 64) /* 96 and 128 bit loads require 128 bit alignment and are split otherwise */
673 return align
% 16 == 0;
675 return align
% 4 == 0;
683 setup_vs_output_info(isel_context
*ctx
, nir_shader
*nir
,
684 bool export_prim_id
, bool export_clip_dists
,
685 radv_vs_output_info
*outinfo
)
687 memset(outinfo
->vs_output_param_offset
, AC_EXP_PARAM_UNDEFINED
,
688 sizeof(outinfo
->vs_output_param_offset
));
690 outinfo
->param_exports
= 0;
691 int pos_written
= 0x1;
692 if (outinfo
->writes_pointsize
|| outinfo
->writes_viewport_index
|| outinfo
->writes_layer
)
693 pos_written
|= 1 << 1;
695 uint64_t mask
= ctx
->output_masks
[nir
->info
.stage
];
697 int idx
= u_bit_scan64(&mask
);
698 if (idx
>= VARYING_SLOT_VAR0
|| idx
== VARYING_SLOT_LAYER
|| idx
== VARYING_SLOT_PRIMITIVE_ID
||
699 ((idx
== VARYING_SLOT_CLIP_DIST0
|| idx
== VARYING_SLOT_CLIP_DIST1
) && export_clip_dists
)) {
700 if (outinfo
->vs_output_param_offset
[idx
] == AC_EXP_PARAM_UNDEFINED
)
701 outinfo
->vs_output_param_offset
[idx
] = outinfo
->param_exports
++;
704 if (outinfo
->writes_layer
&&
705 outinfo
->vs_output_param_offset
[VARYING_SLOT_LAYER
] == AC_EXP_PARAM_UNDEFINED
) {
706 /* when ctx->options->key.has_multiview_view_index = true, the layer
707 * variable isn't declared in NIR and it's isel's job to get the layer */
708 outinfo
->vs_output_param_offset
[VARYING_SLOT_LAYER
] = outinfo
->param_exports
++;
711 if (export_prim_id
) {
712 assert(outinfo
->vs_output_param_offset
[VARYING_SLOT_PRIMITIVE_ID
] == AC_EXP_PARAM_UNDEFINED
);
713 outinfo
->vs_output_param_offset
[VARYING_SLOT_PRIMITIVE_ID
] = outinfo
->param_exports
++;
716 ctx
->export_clip_dists
= export_clip_dists
;
717 ctx
->num_clip_distances
= util_bitcount(outinfo
->clip_dist_mask
);
718 ctx
->num_cull_distances
= util_bitcount(outinfo
->cull_dist_mask
);
720 assert(ctx
->num_clip_distances
+ ctx
->num_cull_distances
<= 8);
722 if (ctx
->num_clip_distances
+ ctx
->num_cull_distances
> 0)
723 pos_written
|= 1 << 2;
724 if (ctx
->num_clip_distances
+ ctx
->num_cull_distances
> 4)
725 pos_written
|= 1 << 3;
727 outinfo
->pos_exports
= util_bitcount(pos_written
);
731 setup_vs_variables(isel_context
*ctx
, nir_shader
*nir
)
733 nir_foreach_variable(variable
, &nir
->inputs
)
735 variable
->data
.driver_location
= variable
->data
.location
* 4;
737 nir_foreach_variable(variable
, &nir
->outputs
)
739 if (ctx
->stage
== vertex_geometry_gs
)
740 variable
->data
.driver_location
= util_bitcount64(ctx
->output_masks
[nir
->info
.stage
] & ((1ull << variable
->data
.location
) - 1ull)) * 4;
741 else if (ctx
->stage
== vertex_es
||
742 ctx
->stage
== vertex_ls
||
743 ctx
->stage
== vertex_tess_control_hs
)
744 // TODO: make this more compact
745 variable
->data
.driver_location
= shader_io_get_unique_index((gl_varying_slot
) variable
->data
.location
) * 4;
746 else if (ctx
->stage
== vertex_vs
)
747 variable
->data
.driver_location
= variable
->data
.location
* 4;
749 unreachable("Unsupported VS stage");
752 if (ctx
->stage
== vertex_vs
) {
753 radv_vs_output_info
*outinfo
= &ctx
->program
->info
->vs
.outinfo
;
754 setup_vs_output_info(ctx
, nir
, outinfo
->export_prim_id
,
755 ctx
->options
->key
.vs_common_out
.export_clip_dists
, outinfo
);
756 } else if (ctx
->stage
== vertex_geometry_gs
|| ctx
->stage
== vertex_es
) {
757 /* TODO: radv_nir_shader_info_pass() already sets this but it's larger
758 * than it needs to be in order to set it better, we have to improve
759 * radv_nir_shader_info_pass() because gfx9_get_gs_info() uses
760 * esgs_itemsize and has to be done before compilation
762 /* radv_es_output_info *outinfo = &ctx->program->info->vs.es_info;
763 outinfo->esgs_itemsize = util_bitcount64(ctx->output_masks[nir->info.stage]) * 16u; */
767 void setup_gs_variables(isel_context
*ctx
, nir_shader
*nir
)
769 if (ctx
->stage
== vertex_geometry_gs
|| ctx
->stage
== tess_eval_geometry_gs
) {
770 nir_foreach_variable(variable
, &nir
->inputs
) {
771 variable
->data
.driver_location
= util_bitcount64(ctx
->input_masks
[nir
->info
.stage
] & ((1ull << variable
->data
.location
) - 1ull)) * 4;
773 } else if (ctx
->stage
== geometry_gs
) {
774 //TODO: make this more compact
775 nir_foreach_variable(variable
, &nir
->inputs
) {
776 variable
->data
.driver_location
= shader_io_get_unique_index((gl_varying_slot
)variable
->data
.location
) * 4;
779 unreachable("Unsupported GS stage.");
782 nir_foreach_variable(variable
, &nir
->outputs
) {
783 variable
->data
.driver_location
= variable
->data
.location
* 4;
786 if (ctx
->stage
== vertex_geometry_gs
)
787 ctx
->program
->info
->gs
.es_type
= MESA_SHADER_VERTEX
;
788 else if (ctx
->stage
== tess_eval_geometry_gs
)
789 ctx
->program
->info
->gs
.es_type
= MESA_SHADER_TESS_EVAL
;
793 setup_tcs_variables(isel_context
*ctx
, nir_shader
*nir
)
795 switch (ctx
->stage
) {
796 case tess_control_hs
:
797 ctx
->tcs_num_inputs
= ctx
->args
->options
->key
.tcs
.num_inputs
;
799 case vertex_tess_control_hs
:
800 ctx
->tcs_num_inputs
= util_last_bit64(ctx
->args
->shader_info
->vs
.ls_outputs_written
);
803 unreachable("Unsupported TCS shader stage");
806 ctx
->tcs_num_patches
= get_tcs_num_patches(
807 ctx
->args
->options
->key
.tcs
.input_vertices
,
808 nir
->info
.tess
.tcs_vertices_out
,
810 ctx
->args
->shader_info
->tcs
.outputs_written
,
811 ctx
->args
->shader_info
->tcs
.patch_outputs_written
,
812 ctx
->args
->options
->tess_offchip_block_dw_size
,
813 ctx
->args
->options
->chip_class
,
814 ctx
->args
->options
->family
);
815 unsigned lds_size
= calculate_tess_lds_size(
816 ctx
->args
->options
->key
.tcs
.input_vertices
,
817 nir
->info
.tess
.tcs_vertices_out
,
819 ctx
->tcs_num_patches
,
820 ctx
->args
->shader_info
->tcs
.outputs_written
,
821 ctx
->args
->shader_info
->tcs
.patch_outputs_written
);
823 ctx
->args
->shader_info
->tcs
.num_patches
= ctx
->tcs_num_patches
;
824 ctx
->args
->shader_info
->tcs
.lds_size
= lds_size
;
825 ctx
->program
->config
->lds_size
= (lds_size
+ ctx
->program
->lds_alloc_granule
- 1) /
826 ctx
->program
->lds_alloc_granule
;
828 nir_foreach_variable(variable
, &nir
->inputs
) {
829 variable
->data
.driver_location
= shader_io_get_unique_index((gl_varying_slot
) variable
->data
.location
) * 4;
832 nir_foreach_variable(variable
, &nir
->outputs
) {
833 variable
->data
.driver_location
= shader_io_get_unique_index((gl_varying_slot
) variable
->data
.location
) * 4;
838 setup_tes_variables(isel_context
*ctx
, nir_shader
*nir
)
840 ctx
->tcs_num_patches
= ctx
->args
->options
->key
.tes
.num_patches
;
842 nir_foreach_variable(variable
, &nir
->inputs
) {
843 variable
->data
.driver_location
= shader_io_get_unique_index((gl_varying_slot
) variable
->data
.location
) * 4;
846 nir_foreach_variable(variable
, &nir
->outputs
) {
847 if (ctx
->stage
== tess_eval_vs
)
848 variable
->data
.driver_location
= variable
->data
.location
* 4;
849 else if (ctx
->stage
== tess_eval_es
)
850 variable
->data
.driver_location
= shader_io_get_unique_index((gl_varying_slot
) variable
->data
.location
) * 4;
851 else if (ctx
->stage
== tess_eval_geometry_gs
)
852 variable
->data
.driver_location
= util_bitcount64(ctx
->output_masks
[nir
->info
.stage
] & ((1ull << variable
->data
.location
) - 1ull)) * 4;
854 unreachable("Unsupported TES shader stage");
857 if (ctx
->stage
== tess_eval_vs
) {
858 radv_vs_output_info
*outinfo
= &ctx
->program
->info
->tes
.outinfo
;
859 setup_vs_output_info(ctx
, nir
, outinfo
->export_prim_id
,
860 ctx
->options
->key
.vs_common_out
.export_clip_dists
, outinfo
);
865 setup_variables(isel_context
*ctx
, nir_shader
*nir
)
867 switch (nir
->info
.stage
) {
868 case MESA_SHADER_FRAGMENT
: {
869 nir_foreach_variable(variable
, &nir
->outputs
)
871 int idx
= variable
->data
.location
+ variable
->data
.index
;
872 variable
->data
.driver_location
= idx
* 4;
876 case MESA_SHADER_COMPUTE
: {
877 ctx
->program
->config
->lds_size
= (nir
->info
.cs
.shared_size
+ ctx
->program
->lds_alloc_granule
- 1) /
878 ctx
->program
->lds_alloc_granule
;
881 case MESA_SHADER_VERTEX
: {
882 setup_vs_variables(ctx
, nir
);
885 case MESA_SHADER_GEOMETRY
: {
886 setup_gs_variables(ctx
, nir
);
889 case MESA_SHADER_TESS_CTRL
: {
890 setup_tcs_variables(ctx
, nir
);
893 case MESA_SHADER_TESS_EVAL
: {
894 setup_tes_variables(ctx
, nir
);
898 unreachable("Unhandled shader stage.");
903 get_io_masks(isel_context
*ctx
, unsigned shader_count
, struct nir_shader
*const *shaders
)
905 for (unsigned i
= 0; i
< shader_count
; i
++) {
906 nir_shader
*nir
= shaders
[i
];
907 if (nir
->info
.stage
== MESA_SHADER_COMPUTE
)
910 uint64_t output_mask
= 0;
911 nir_foreach_variable(variable
, &nir
->outputs
) {
912 const glsl_type
*type
= variable
->type
;
913 if (nir_is_per_vertex_io(variable
, nir
->info
.stage
))
914 type
= type
->fields
.array
;
915 unsigned slots
= type
->count_attribute_slots(false);
916 if (variable
->data
.compact
) {
917 unsigned component_count
= variable
->data
.location_frac
+ type
->length
;
918 slots
= (component_count
+ 3) / 4;
920 output_mask
|= ((1ull << slots
) - 1) << variable
->data
.location
;
923 uint64_t input_mask
= 0;
924 nir_foreach_variable(variable
, &nir
->inputs
) {
925 const glsl_type
*type
= variable
->type
;
926 if (nir_is_per_vertex_io(variable
, nir
->info
.stage
))
927 type
= type
->fields
.array
;
928 unsigned slots
= type
->count_attribute_slots(false);
929 if (variable
->data
.compact
) {
930 unsigned component_count
= variable
->data
.location_frac
+ type
->length
;
931 slots
= (component_count
+ 3) / 4;
933 input_mask
|= ((1ull << slots
) - 1) << variable
->data
.location
;
936 ctx
->output_masks
[nir
->info
.stage
] |= output_mask
;
937 if (i
+ 1 < shader_count
)
938 ctx
->input_masks
[shaders
[i
+ 1]->info
.stage
] |= output_mask
;
940 ctx
->input_masks
[nir
->info
.stage
] |= input_mask
;
942 ctx
->output_masks
[shaders
[i
- 1]->info
.stage
] |= input_mask
;
947 setup_nir(isel_context
*ctx
, nir_shader
*nir
)
949 Program
*program
= ctx
->program
;
951 /* align and copy constant data */
952 while (program
->constant_data
.size() % 4u)
953 program
->constant_data
.push_back(0);
954 ctx
->constant_data_offset
= program
->constant_data
.size();
955 program
->constant_data
.insert(program
->constant_data
.end(),
956 (uint8_t*)nir
->constant_data
,
957 (uint8_t*)nir
->constant_data
+ nir
->constant_data_size
);
959 /* the variable setup has to be done before lower_io / CSE */
960 setup_variables(ctx
, nir
);
962 /* optimize and lower memory operations */
963 bool lower_to_scalar
= false;
964 bool lower_pack
= false;
965 if (nir_opt_load_store_vectorize(nir
,
966 (nir_variable_mode
)(nir_var_mem_ssbo
| nir_var_mem_ubo
|
967 nir_var_mem_push_const
| nir_var_mem_shared
),
968 mem_vectorize_callback
)) {
969 lower_to_scalar
= true;
972 if (nir
->info
.stage
!= MESA_SHADER_COMPUTE
)
973 nir_lower_io(nir
, (nir_variable_mode
)(nir_var_shader_in
| nir_var_shader_out
), type_size
, (nir_lower_io_options
)0);
974 nir_lower_explicit_io(nir
, nir_var_mem_global
, nir_address_format_64bit_global
);
977 nir_lower_alu_to_scalar(nir
, NULL
, NULL
);
981 /* lower ALU operations */
982 // TODO: implement logic64 in aco, it's more effective for sgprs
983 nir_lower_int64(nir
, nir
->options
->lower_int64_options
);
985 nir_opt_idiv_const(nir
, 32);
986 nir_lower_idiv(nir
, nir_lower_idiv_precise
);
988 /* optimize the lowered ALU operations */
989 bool more_algebraic
= true;
990 while (more_algebraic
) {
991 more_algebraic
= false;
992 NIR_PASS_V(nir
, nir_copy_prop
);
993 NIR_PASS_V(nir
, nir_opt_dce
);
994 NIR_PASS_V(nir
, nir_opt_constant_folding
);
995 NIR_PASS(more_algebraic
, nir
, nir_opt_algebraic
);
998 /* Do late algebraic optimization to turn add(a, neg(b)) back into
999 * subs, then the mandatory cleanup after algebraic. Note that it may
1000 * produce fnegs, and if so then we need to keep running to squash
1003 bool more_late_algebraic
= true;
1004 while (more_late_algebraic
) {
1005 more_late_algebraic
= false;
1006 NIR_PASS(more_late_algebraic
, nir
, nir_opt_algebraic_late
);
1007 NIR_PASS_V(nir
, nir_opt_constant_folding
);
1008 NIR_PASS_V(nir
, nir_copy_prop
);
1009 NIR_PASS_V(nir
, nir_opt_dce
);
1010 NIR_PASS_V(nir
, nir_opt_cse
);
1013 /* cleanup passes */
1014 nir_lower_load_const_to_scalar(nir
);
1015 nir_opt_shrink_load(nir
);
1016 nir_move_options move_opts
= (nir_move_options
)(
1017 nir_move_const_undef
| nir_move_load_ubo
| nir_move_load_input
|
1018 nir_move_comparisons
| nir_move_copies
);
1019 nir_opt_sink(nir
, move_opts
);
1020 nir_opt_move(nir
, move_opts
);
1021 nir_convert_to_lcssa(nir
, true, false);
1022 nir_lower_phis_to_scalar(nir
);
1024 nir_function_impl
*func
= nir_shader_get_entrypoint(nir
);
1025 nir_index_ssa_defs(func
);
1026 nir_metadata_require(func
, nir_metadata_block_index
);
1030 setup_isel_context(Program
* program
,
1031 unsigned shader_count
,
1032 struct nir_shader
*const *shaders
,
1033 ac_shader_config
* config
,
1034 struct radv_shader_args
*args
,
1035 bool is_gs_copy_shader
)
1038 for (unsigned i
= 0; i
< shader_count
; i
++) {
1039 switch (shaders
[i
]->info
.stage
) {
1040 case MESA_SHADER_VERTEX
:
1041 program
->stage
|= sw_vs
;
1043 case MESA_SHADER_TESS_CTRL
:
1044 program
->stage
|= sw_tcs
;
1046 case MESA_SHADER_TESS_EVAL
:
1047 program
->stage
|= sw_tes
;
1049 case MESA_SHADER_GEOMETRY
:
1050 program
->stage
|= is_gs_copy_shader
? sw_gs_copy
: sw_gs
;
1052 case MESA_SHADER_FRAGMENT
:
1053 program
->stage
|= sw_fs
;
1055 case MESA_SHADER_COMPUTE
:
1056 program
->stage
|= sw_cs
;
1059 unreachable("Shader stage not implemented");
1062 bool gfx9_plus
= args
->options
->chip_class
>= GFX9
;
1063 bool ngg
= args
->shader_info
->is_ngg
&& args
->options
->chip_class
>= GFX10
;
1064 if (program
->stage
== sw_vs
&& args
->shader_info
->vs
.as_es
)
1065 program
->stage
|= hw_es
;
1066 else if (program
->stage
== sw_vs
&& !args
->shader_info
->vs
.as_ls
)
1067 program
->stage
|= hw_vs
;
1068 else if (program
->stage
== sw_gs
)
1069 program
->stage
|= hw_gs
;
1070 else if (program
->stage
== sw_fs
)
1071 program
->stage
|= hw_fs
;
1072 else if (program
->stage
== sw_cs
)
1073 program
->stage
|= hw_cs
;
1074 else if (program
->stage
== sw_gs_copy
)
1075 program
->stage
|= hw_vs
;
1076 else if (program
->stage
== (sw_vs
| sw_gs
) && gfx9_plus
&& !ngg
)
1077 program
->stage
|= hw_gs
;
1078 else if (program
->stage
== sw_vs
&& args
->shader_info
->vs
.as_ls
)
1079 program
->stage
|= hw_ls
; /* GFX6-8: VS is a Local Shader, when tessellation is used */
1080 else if (program
->stage
== sw_tcs
)
1081 program
->stage
|= hw_hs
; /* GFX6-8: TCS is a Hull Shader */
1082 else if (program
->stage
== (sw_vs
| sw_tcs
))
1083 program
->stage
|= hw_hs
; /* GFX9-10: VS+TCS merged into a Hull Shader */
1084 else if (program
->stage
== sw_tes
&& !args
->shader_info
->tes
.as_es
&& !ngg
)
1085 program
->stage
|= hw_vs
; /* GFX6-9: TES without GS uses the HW VS stage (and GFX10/legacy) */
1086 else if (program
->stage
== sw_tes
&& args
->shader_info
->tes
.as_es
&& !ngg
)
1087 program
->stage
|= hw_es
; /* GFX6-8: TES is an Export Shader */
1088 else if (program
->stage
== (sw_tes
| sw_gs
) && gfx9_plus
&& !ngg
)
1089 program
->stage
|= hw_gs
; /* GFX9: TES+GS merged into a GS (and GFX10/legacy) */
1091 unreachable("Shader stage not implemented");
1093 program
->config
= config
;
1094 program
->info
= args
->shader_info
;
1095 program
->chip_class
= args
->options
->chip_class
;
1096 program
->family
= args
->options
->family
;
1097 program
->wave_size
= args
->shader_info
->wave_size
;
1098 program
->lane_mask
= program
->wave_size
== 32 ? s1
: s2
;
1100 program
->lds_alloc_granule
= args
->options
->chip_class
>= GFX7
? 512 : 256;
1101 program
->lds_limit
= args
->options
->chip_class
>= GFX7
? 65536 : 32768;
1102 program
->vgpr_limit
= 256;
1103 program
->vgpr_alloc_granule
= 3;
1105 if (args
->options
->chip_class
>= GFX10
) {
1106 program
->physical_sgprs
= 2560; /* doesn't matter as long as it's at least 128 * 20 */
1107 program
->sgpr_alloc_granule
= 127;
1108 program
->sgpr_limit
= 106;
1109 program
->vgpr_alloc_granule
= program
->wave_size
== 32 ? 7 : 3;
1110 } else if (program
->chip_class
>= GFX8
) {
1111 program
->physical_sgprs
= 800;
1112 program
->sgpr_alloc_granule
= 15;
1113 if (args
->options
->family
== CHIP_TONGA
|| args
->options
->family
== CHIP_ICELAND
)
1114 program
->sgpr_limit
= 94; /* workaround hardware bug */
1116 program
->sgpr_limit
= 102;
1118 program
->physical_sgprs
= 512;
1119 program
->sgpr_alloc_granule
= 7;
1120 program
->sgpr_limit
= 104;
1123 calc_min_waves(program
);
1124 program
->vgpr_limit
= get_addr_vgpr_from_waves(program
, program
->min_waves
);
1125 program
->sgpr_limit
= get_addr_sgpr_from_waves(program
, program
->min_waves
);
1127 isel_context ctx
= {};
1128 ctx
.program
= program
;
1130 ctx
.options
= args
->options
;
1131 ctx
.stage
= program
->stage
;
1133 get_io_masks(&ctx
, shader_count
, shaders
);
1135 unsigned scratch_size
= 0;
1136 if (program
->stage
== gs_copy_vs
) {
1137 assert(shader_count
== 1);
1138 setup_vs_output_info(&ctx
, shaders
[0], false, true, &args
->shader_info
->vs
.outinfo
);
1140 for (unsigned i
= 0; i
< shader_count
; i
++) {
1141 nir_shader
*nir
= shaders
[i
];
1142 setup_nir(&ctx
, nir
);
1144 if (args
->options
->dump_preoptir
) {
1145 fprintf(stderr
, "NIR shader before instruction selection:\n");
1146 nir_print_shader(nir
, stderr
);
1150 for (unsigned i
= 0; i
< shader_count
; i
++)
1151 scratch_size
= std::max(scratch_size
, shaders
[i
]->scratch_size
);
1154 ctx
.program
->config
->scratch_bytes_per_wave
= align(scratch_size
* ctx
.program
->wave_size
, 1024);
1156 ctx
.block
= ctx
.program
->create_and_insert_block();
1157 ctx
.block
->loop_nest_depth
= 0;
1158 ctx
.block
->kind
= block_kind_top_level
;