2019-09-17 13:22:17 +02:00
|
|
|
/*
|
|
|
|
|
* Copyright © 2018 Valve Corporation
|
|
|
|
|
*
|
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
|
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
|
|
|
* to deal in the Software without restriction, including without limitation
|
|
|
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
|
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
|
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
|
|
|
*
|
|
|
|
|
* The above copyright notice and this permission notice (including the next
|
|
|
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
|
|
|
* Software.
|
|
|
|
|
*
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
|
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
|
|
|
|
|
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
|
|
|
|
|
* IN THE SOFTWARE.
|
|
|
|
|
*
|
|
|
|
|
*/
|
|
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
#include "aco_instruction_selection.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
|
2021-12-12 20:20:36 -05:00
|
|
|
#include "common/ac_nir.h"
|
2021-06-10 11:33:15 +02:00
|
|
|
#include "common/sid.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
#include "nir_control_flow.h"
|
2021-06-09 15:40:03 +02:00
|
|
|
|
|
|
|
|
#include <vector>
|
2019-09-17 13:22:17 +02:00
|
|
|
|
|
|
|
|
namespace aco {
|
|
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
namespace {
|
2019-11-13 13:30:52 +01:00
|
|
|
|
2021-03-24 14:54:09 +00:00
|
|
|
bool
|
|
|
|
|
is_loop_header_block(nir_block* block)
|
|
|
|
|
{
|
|
|
|
|
return block->cf_node.parent->type == nir_cf_node_loop &&
|
|
|
|
|
block == nir_loop_first_block(nir_cf_node_as_loop(block->cf_node.parent));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* similar to nir_block_is_unreachable(), but does not require dominance information */
|
|
|
|
|
bool
|
|
|
|
|
is_block_reachable(nir_function_impl* impl, nir_block* known_reachable, nir_block* block)
|
|
|
|
|
{
|
|
|
|
|
if (block == nir_start_block(impl) || block == known_reachable)
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
/* skip loop back-edges */
|
|
|
|
|
if (is_loop_header_block(block)) {
|
|
|
|
|
nir_loop* loop = nir_cf_node_as_loop(block->cf_node.parent);
|
|
|
|
|
nir_block* preheader = nir_block_cf_tree_prev(nir_loop_first_block(loop));
|
|
|
|
|
return is_block_reachable(impl, known_reachable, preheader);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set_foreach (block->predecessors, entry) {
|
|
|
|
|
if (is_block_reachable(impl, known_reachable, (nir_block*)entry->key))
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-14 17:31:33 +02:00
|
|
|
/* Check whether the given SSA def is only used by cross-lane instructions. */
|
2021-05-28 22:08:45 +02:00
|
|
|
bool
|
2023-08-12 16:17:15 -04:00
|
|
|
only_used_by_cross_lane_instrs(nir_def* ssa, bool follow_phis = true)
|
2021-05-28 22:08:45 +02:00
|
|
|
{
|
2021-06-14 17:31:33 +02:00
|
|
|
nir_foreach_use (src, ssa) {
|
|
|
|
|
switch (src->parent_instr->type) {
|
|
|
|
|
case nir_instr_type_alu: {
|
|
|
|
|
nir_alu_instr* alu = nir_instr_as_alu(src->parent_instr);
|
|
|
|
|
if (alu->op != nir_op_unpack_64_2x32_split_x && alu->op != nir_op_unpack_64_2x32_split_y)
|
|
|
|
|
return false;
|
2023-08-14 11:43:35 -05:00
|
|
|
if (!only_used_by_cross_lane_instrs(&alu->def, follow_phis))
|
2021-06-14 17:31:33 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
case nir_instr_type_intrinsic: {
|
|
|
|
|
nir_intrinsic_instr* intrin = nir_instr_as_intrinsic(src->parent_instr);
|
|
|
|
|
if (intrin->intrinsic != nir_intrinsic_read_invocation &&
|
|
|
|
|
intrin->intrinsic != nir_intrinsic_read_first_invocation &&
|
|
|
|
|
intrin->intrinsic != nir_intrinsic_lane_permute_16_amd)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
case nir_instr_type_phi: {
|
|
|
|
|
/* Don't follow more than 1 phis, this avoids infinite loops. */
|
|
|
|
|
if (!follow_phis)
|
|
|
|
|
return false;
|
2021-05-28 22:08:45 +02:00
|
|
|
|
2021-06-14 17:31:33 +02:00
|
|
|
nir_phi_instr* phi = nir_instr_as_phi(src->parent_instr);
|
2023-08-14 11:56:00 -05:00
|
|
|
if (!only_used_by_cross_lane_instrs(&phi->def, false))
|
2021-06-14 17:31:33 +02:00
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
default: return false;
|
|
|
|
|
}
|
2021-05-28 22:08:45 +02:00
|
|
|
}
|
2021-06-14 17:31:33 +02:00
|
|
|
|
|
|
|
|
return true;
|
2021-05-28 22:08:45 +02:00
|
|
|
}
|
|
|
|
|
|
2020-02-26 13:35:26 +00:00
|
|
|
/* If one side of a divergent IF ends in a branch and the other doesn't, we
|
|
|
|
|
* might have to emit the contents of the side without the branch at the merge
|
|
|
|
|
* block instead. This is so that we can use any SGPR live-out of the side
|
|
|
|
|
* without the branch without creating a linear phi in the invert or merge block. */
|
|
|
|
|
bool
|
2019-10-15 14:48:10 -05:00
|
|
|
sanitize_if(nir_function_impl* impl, nir_if* nif)
|
2020-02-26 13:35:26 +00:00
|
|
|
{
|
2020-04-06 11:47:18 +01:00
|
|
|
// TODO: skip this if the condition is uniform and there are no divergent breaks/continues?
|
2020-02-26 13:35:26 +00:00
|
|
|
|
|
|
|
|
nir_block* then_block = nir_if_last_then_block(nif);
|
|
|
|
|
nir_block* else_block = nir_if_last_else_block(nif);
|
2021-03-24 14:54:09 +00:00
|
|
|
bool then_jump = nir_block_ends_in_jump(then_block) ||
|
|
|
|
|
!is_block_reachable(impl, nir_if_first_then_block(nif), then_block);
|
|
|
|
|
bool else_jump = nir_block_ends_in_jump(else_block) ||
|
|
|
|
|
!is_block_reachable(impl, nir_if_first_else_block(nif), else_block);
|
2020-02-26 13:35:26 +00:00
|
|
|
if (then_jump == else_jump)
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* If the continue from block is empty then return as there is nothing to
|
|
|
|
|
* move.
|
|
|
|
|
*/
|
|
|
|
|
if (nir_cf_list_is_empty_block(else_jump ? &nif->then_list : &nif->else_list))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
/* Even though this if statement has a jump on one side, we may still have
|
|
|
|
|
* phis afterwards. Single-source phis can be produced by loop unrolling
|
|
|
|
|
* or dead control-flow passes and are perfectly legal. Run a quick phi
|
|
|
|
|
* removal on the block after the if to clean up any such phis.
|
|
|
|
|
*/
|
|
|
|
|
nir_opt_remove_phis_block(nir_cf_node_as_block(nir_cf_node_next(&nif->cf_node)));
|
|
|
|
|
|
|
|
|
|
/* Finally, move the continue from branch after the if-statement. */
|
|
|
|
|
nir_block* last_continue_from_blk = else_jump ? then_block : else_block;
|
|
|
|
|
nir_block* first_continue_from_blk =
|
|
|
|
|
else_jump ? nir_if_first_then_block(nif) : nir_if_first_else_block(nif);
|
|
|
|
|
|
|
|
|
|
nir_cf_list tmp;
|
|
|
|
|
nir_cf_extract(&tmp, nir_before_block(first_continue_from_blk),
|
|
|
|
|
nir_after_block(last_continue_from_blk));
|
|
|
|
|
nir_cf_reinsert(&tmp, nir_after_cf_node(&nif->cf_node));
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool
|
2019-10-15 14:48:10 -05:00
|
|
|
sanitize_cf_list(nir_function_impl* impl, struct exec_list* cf_list)
|
2020-02-26 13:35:26 +00:00
|
|
|
{
|
|
|
|
|
bool progress = false;
|
|
|
|
|
foreach_list_typed (nir_cf_node, cf_node, node, cf_list) {
|
|
|
|
|
switch (cf_node->type) {
|
|
|
|
|
case nir_cf_node_block: break;
|
|
|
|
|
case nir_cf_node_if: {
|
|
|
|
|
nir_if* nif = nir_cf_node_as_if(cf_node);
|
2019-10-15 14:48:10 -05:00
|
|
|
progress |= sanitize_cf_list(impl, &nif->then_list);
|
|
|
|
|
progress |= sanitize_cf_list(impl, &nif->else_list);
|
|
|
|
|
progress |= sanitize_if(impl, nif);
|
2020-02-26 13:35:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_cf_node_loop: {
|
|
|
|
|
nir_loop* loop = nir_cf_node_as_loop(cf_node);
|
2021-12-02 10:31:56 +01:00
|
|
|
assert(!nir_loop_has_continue_construct(loop));
|
2019-10-15 14:48:10 -05:00
|
|
|
progress |= sanitize_cf_list(impl, &loop->body);
|
2020-02-26 13:35:26 +00:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_cf_node_function: unreachable("Invalid cf type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return progress;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-02 14:01:38 +01:00
|
|
|
void
|
2023-08-12 16:17:15 -04:00
|
|
|
apply_nuw_to_ssa(isel_context* ctx, nir_def* ssa)
|
2019-11-12 17:51:34 +00:00
|
|
|
{
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_scalar scalar;
|
2019-11-12 17:51:34 +00:00
|
|
|
scalar.def = ssa;
|
|
|
|
|
scalar.comp = 0;
|
|
|
|
|
|
2023-08-12 16:17:15 -04:00
|
|
|
if (!nir_scalar_is_alu(scalar) || nir_scalar_alu_op(scalar) != nir_op_iadd)
|
2019-11-12 17:51:34 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
nir_alu_instr* add = nir_instr_as_alu(ssa->parent_instr);
|
|
|
|
|
|
|
|
|
|
if (add->no_unsigned_wrap)
|
|
|
|
|
return;
|
|
|
|
|
|
2023-08-12 16:17:15 -04:00
|
|
|
nir_scalar src0 = nir_scalar_chase_alu_src(scalar, 0);
|
|
|
|
|
nir_scalar src1 = nir_scalar_chase_alu_src(scalar, 1);
|
2019-11-12 17:51:34 +00:00
|
|
|
|
2023-08-12 16:17:15 -04:00
|
|
|
if (nir_scalar_is_const(src0)) {
|
|
|
|
|
nir_scalar tmp = src0;
|
2019-11-12 17:51:34 +00:00
|
|
|
src0 = src1;
|
|
|
|
|
src1 = tmp;
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-02 14:01:38 +01:00
|
|
|
uint32_t src1_ub = nir_unsigned_upper_bound(ctx->shader, ctx->range_ht, src1, &ctx->ub_config);
|
|
|
|
|
add->no_unsigned_wrap =
|
|
|
|
|
!nir_addition_might_overflow(ctx->shader, ctx->range_ht, src0, src1_ub, &ctx->ub_config);
|
2019-11-12 17:51:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
apply_nuw_to_offsets(isel_context* ctx, nir_function_impl* impl)
|
|
|
|
|
{
|
|
|
|
|
nir_foreach_block (block, impl) {
|
|
|
|
|
nir_foreach_instr (instr, block) {
|
|
|
|
|
if (instr->type != nir_instr_type_intrinsic)
|
|
|
|
|
continue;
|
|
|
|
|
nir_intrinsic_instr* intrin = nir_instr_as_intrinsic(instr);
|
|
|
|
|
|
|
|
|
|
switch (intrin->intrinsic) {
|
|
|
|
|
case nir_intrinsic_load_constant:
|
|
|
|
|
case nir_intrinsic_load_uniform:
|
|
|
|
|
case nir_intrinsic_load_push_constant:
|
|
|
|
|
if (!nir_src_is_divergent(intrin->src[0]))
|
2020-11-02 14:01:38 +01:00
|
|
|
apply_nuw_to_ssa(ctx, intrin->src[0].ssa);
|
2019-11-12 17:51:34 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_ubo:
|
|
|
|
|
case nir_intrinsic_load_ssbo:
|
|
|
|
|
if (!nir_src_is_divergent(intrin->src[1]))
|
2020-11-02 14:01:38 +01:00
|
|
|
apply_nuw_to_ssa(ctx, intrin->src[1].ssa);
|
2019-11-12 17:51:34 +00:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_store_ssbo:
|
|
|
|
|
if (!nir_src_is_divergent(intrin->src[2]))
|
2020-11-02 14:01:38 +01:00
|
|
|
apply_nuw_to_ssa(ctx, intrin->src[2].ssa);
|
2019-11-12 17:51:34 +00:00
|
|
|
break;
|
2022-12-01 18:04:49 +00:00
|
|
|
case nir_intrinsic_load_scratch: apply_nuw_to_ssa(ctx, intrin->src[0].ssa); break;
|
2023-04-18 14:58:57 +01:00
|
|
|
case nir_intrinsic_store_scratch:
|
|
|
|
|
case nir_intrinsic_load_smem_amd: apply_nuw_to_ssa(ctx, intrin->src[1].ssa); break;
|
2019-11-12 17:51:34 +00:00
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-19 09:39:42 +01:00
|
|
|
RegClass
|
|
|
|
|
get_reg_class(isel_context* ctx, RegType type, unsigned components, unsigned bitsize)
|
|
|
|
|
{
|
2020-04-14 20:32:39 +01:00
|
|
|
if (bitsize == 1)
|
2020-02-19 09:39:42 +01:00
|
|
|
return RegClass(RegType::sgpr, ctx->program->lane_mask.size() * components);
|
2020-04-14 20:32:39 +01:00
|
|
|
else
|
|
|
|
|
return RegClass::get(type, components * bitsize / 8u);
|
2020-02-19 09:39:42 +01:00
|
|
|
}
|
|
|
|
|
|
2020-02-12 15:22:17 +01:00
|
|
|
void
|
2020-07-02 13:37:10 +01:00
|
|
|
setup_tcs_info(isel_context* ctx, nir_shader* nir, nir_shader* vs)
|
2020-02-12 15:22:17 +01:00
|
|
|
{
|
2022-05-05 11:32:53 +10:00
|
|
|
ctx->tcs_in_out_eq = ctx->program->info.vs.tcs_in_out_eq;
|
|
|
|
|
ctx->tcs_temp_only_inputs = ctx->program->info.vs.tcs_temp_only_input_mask;
|
2020-02-27 19:56:35 +01:00
|
|
|
}
|
|
|
|
|
|
2021-10-21 11:33:10 +02:00
|
|
|
void
|
2023-03-15 11:54:49 -07:00
|
|
|
setup_lds_size(isel_context* ctx, nir_shader* nir)
|
2021-10-21 11:33:10 +02:00
|
|
|
{
|
2023-03-15 11:54:49 -07:00
|
|
|
/* TCS and GFX9 GS are special cases, already in units of the allocation granule. */
|
|
|
|
|
if (ctx->stage.has(SWStage::TCS))
|
|
|
|
|
ctx->program->config->lds_size = ctx->program->info.tcs.num_lds_blocks;
|
|
|
|
|
else if (ctx->stage == vertex_geometry_gs || ctx->stage == tess_eval_geometry_gs)
|
|
|
|
|
ctx->program->config->lds_size = ctx->program->info.gfx9_gs_ring_lds_size;
|
|
|
|
|
else
|
2021-04-08 12:30:14 +02:00
|
|
|
ctx->program->config->lds_size =
|
|
|
|
|
DIV_ROUND_UP(nir->info.shared_size, ctx->program->dev.lds_encoding_granule);
|
2020-10-15 18:18:21 +02:00
|
|
|
|
|
|
|
|
/* Make sure we fit the available LDS space. */
|
2021-01-28 13:07:11 +00:00
|
|
|
assert((ctx->program->config->lds_size * ctx->program->dev.lds_encoding_granule) <=
|
|
|
|
|
ctx->program->dev.lds_limit);
|
2020-09-03 12:36:58 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
setup_nir(isel_context* ctx, nir_shader* nir)
|
|
|
|
|
{
|
|
|
|
|
nir_convert_to_lcssa(nir, true, false);
|
2021-06-04 11:11:52 +02:00
|
|
|
nir_lower_phis_to_scalar(nir, true);
|
2020-09-03 12:36:58 +02:00
|
|
|
|
|
|
|
|
nir_function_impl* func = nir_shader_get_entrypoint(nir);
|
|
|
|
|
nir_index_ssa_defs(func);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} /* end namespace */
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
|
init_context(isel_context* ctx, nir_shader* shader)
|
2020-04-06 11:15:00 +01:00
|
|
|
{
|
2020-09-03 12:36:58 +02:00
|
|
|
nir_function_impl* impl = nir_shader_get_entrypoint(shader);
|
|
|
|
|
ctx->shader = shader;
|
2020-11-02 14:01:38 +01:00
|
|
|
|
|
|
|
|
/* Init NIR range analysis. */
|
|
|
|
|
ctx->range_ht = _mesa_pointer_hash_table_create(NULL);
|
|
|
|
|
ctx->ub_config.min_subgroup_size = 64;
|
|
|
|
|
ctx->ub_config.max_subgroup_size = 64;
|
2022-05-05 11:32:53 +10:00
|
|
|
if (ctx->shader->info.stage == MESA_SHADER_COMPUTE && ctx->program->info.cs.subgroup_size) {
|
|
|
|
|
ctx->ub_config.min_subgroup_size = ctx->program->info.cs.subgroup_size;
|
|
|
|
|
ctx->ub_config.max_subgroup_size = ctx->program->info.cs.subgroup_size;
|
2020-11-02 14:01:38 +01:00
|
|
|
}
|
2021-06-04 12:04:15 -07:00
|
|
|
ctx->ub_config.max_workgroup_invocations = 2048;
|
|
|
|
|
ctx->ub_config.max_workgroup_count[0] = 65535;
|
|
|
|
|
ctx->ub_config.max_workgroup_count[1] = 65535;
|
|
|
|
|
ctx->ub_config.max_workgroup_count[2] = 65535;
|
|
|
|
|
ctx->ub_config.max_workgroup_size[0] = 2048;
|
|
|
|
|
ctx->ub_config.max_workgroup_size[1] = 2048;
|
|
|
|
|
ctx->ub_config.max_workgroup_size[2] = 2048;
|
2020-11-02 14:01:38 +01:00
|
|
|
|
2020-09-02 11:45:46 +01:00
|
|
|
nir_divergence_analysis(shader);
|
2023-06-07 16:37:51 +01:00
|
|
|
if (nir_opt_uniform_atomics(shader) && nir_lower_int64(shader))
|
|
|
|
|
nir_divergence_analysis(shader);
|
2020-04-06 11:15:00 +01:00
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
apply_nuw_to_offsets(ctx, impl);
|
2020-04-06 11:15:00 +01:00
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
/* sanitize control flow */
|
|
|
|
|
sanitize_cf_list(impl, &impl->body);
|
2021-04-22 14:11:39 +02:00
|
|
|
nir_metadata_preserve(impl, nir_metadata_none);
|
2020-04-06 11:15:00 +01:00
|
|
|
|
2021-04-22 14:11:39 +02:00
|
|
|
/* we'll need these for isel */
|
2021-03-24 14:56:48 +00:00
|
|
|
nir_metadata_require(impl, nir_metadata_block_index);
|
2020-09-03 12:36:58 +02:00
|
|
|
|
2022-10-17 20:26:51 +01:00
|
|
|
if (ctx->options->dump_preoptir) {
|
2020-09-03 12:36:58 +02:00
|
|
|
fprintf(stderr, "NIR shader before instruction selection:\n");
|
|
|
|
|
nir_print_shader(shader, stderr);
|
|
|
|
|
}
|
|
|
|
|
|
2020-10-08 15:11:12 +01:00
|
|
|
ctx->first_temp_id = ctx->program->peekAllocationId();
|
|
|
|
|
ctx->program->allocateRange(impl->ssa_alloc);
|
|
|
|
|
RegClass* regclasses = ctx->program->temp_rc.data() + ctx->first_temp_id;
|
2020-09-03 12:36:58 +02:00
|
|
|
|
|
|
|
|
std::unique_ptr<unsigned[]> nir_to_aco{new unsigned[impl->num_blocks]()};
|
|
|
|
|
|
2020-09-18 16:24:14 +01:00
|
|
|
/* TODO: make this recursive to improve compile times */
|
2020-09-03 12:36:58 +02:00
|
|
|
bool done = false;
|
|
|
|
|
while (!done) {
|
|
|
|
|
done = true;
|
|
|
|
|
nir_foreach_block (block, impl) {
|
|
|
|
|
nir_foreach_instr (instr, block) {
|
|
|
|
|
switch (instr->type) {
|
|
|
|
|
case nir_instr_type_alu: {
|
|
|
|
|
nir_alu_instr* alu_instr = nir_instr_as_alu(instr);
|
2023-08-14 11:43:35 -05:00
|
|
|
RegType type = alu_instr->def.divergent ? RegType::vgpr : RegType::sgpr;
|
2020-09-03 12:36:58 +02:00
|
|
|
switch (alu_instr->op) {
|
|
|
|
|
case nir_op_fmul:
|
2021-04-27 12:28:27 +01:00
|
|
|
case nir_op_fmulz:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_op_fadd:
|
|
|
|
|
case nir_op_fsub:
|
2021-03-24 17:17:38 +00:00
|
|
|
case nir_op_ffma:
|
2021-04-27 12:28:27 +01:00
|
|
|
case nir_op_ffmaz:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_op_fmax:
|
|
|
|
|
case nir_op_fmin:
|
|
|
|
|
case nir_op_fneg:
|
|
|
|
|
case nir_op_fabs:
|
|
|
|
|
case nir_op_fsat:
|
|
|
|
|
case nir_op_fsign:
|
|
|
|
|
case nir_op_frcp:
|
|
|
|
|
case nir_op_frsq:
|
|
|
|
|
case nir_op_fsqrt:
|
|
|
|
|
case nir_op_fexp2:
|
|
|
|
|
case nir_op_flog2:
|
|
|
|
|
case nir_op_ffract:
|
|
|
|
|
case nir_op_ffloor:
|
|
|
|
|
case nir_op_fceil:
|
|
|
|
|
case nir_op_ftrunc:
|
|
|
|
|
case nir_op_fround_even:
|
radv,aco,ac/llvm: use nir_op_f{sin,cos}_amd
This lets NIR optimize the multiplication, particularly sin/cos(a * #b).
fossil-db (Sienna Cichlid):
Totals from 12306 (7.58% of 162293) affected shaders:
MaxWaves: 224814 -> 224834 (+0.01%)
Instrs: 17365273 -> 17338758 (-0.15%); split: -0.16%, +0.00%
CodeSize: 93478488 -> 93354912 (-0.13%); split: -0.14%, +0.01%
VGPRs: 752080 -> 752072 (-0.00%); split: -0.00%, +0.00%
SpillSGPRs: 8440 -> 8410 (-0.36%)
Latency: 200402154 -> 200279405 (-0.06%); split: -0.06%, +0.00%
InvThroughput: 37588077 -> 37545545 (-0.11%); split: -0.11%, +0.00%
VClause: 293863 -> 293874 (+0.00%); split: -0.03%, +0.03%
SClause: 619539 -> 619064 (-0.08%); split: -0.09%, +0.01%
Copies: 1151591 -> 1151641 (+0.00%); split: -0.04%, +0.05%
Branches: 506434 -> 506437 (+0.00%); split: -0.00%, +0.00%
PreSGPRs: 877609 -> 877517 (-0.01%); split: -0.01%, +0.00%
PreVGPRs: 711938 -> 711940 (+0.00%); split: -0.00%, +0.00%
fossil-db (LLVM, Sienna Cichlid):
Totals from 4377 (3.59% of 121873) affected shaders:
SGPRs: 358960 -> 359176 (+0.06%); split: -0.18%, +0.25%
VGPRs: 319832 -> 319720 (-0.04%); split: -0.18%, +0.15%
SpillSGPRs: 46983 -> 47007 (+0.05%); split: -0.99%, +1.04%
CodeSize: 30872812 -> 30764512 (-0.35%); split: -0.39%, +0.04%
MaxWaves: 73814 -> 73904 (+0.12%); split: +0.25%, -0.13%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/10587>
2021-05-03 11:10:06 +01:00
|
|
|
case nir_op_fsin_amd:
|
|
|
|
|
case nir_op_fcos_amd:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_op_f2f16:
|
|
|
|
|
case nir_op_f2f16_rtz:
|
|
|
|
|
case nir_op_f2f16_rtne:
|
|
|
|
|
case nir_op_f2f32:
|
|
|
|
|
case nir_op_f2f64:
|
|
|
|
|
case nir_op_u2f16:
|
|
|
|
|
case nir_op_u2f32:
|
|
|
|
|
case nir_op_u2f64:
|
|
|
|
|
case nir_op_i2f16:
|
|
|
|
|
case nir_op_i2f32:
|
|
|
|
|
case nir_op_i2f64:
|
2023-01-24 19:14:47 +01:00
|
|
|
case nir_op_pack_half_2x16_rtz_split:
|
2020-09-18 17:48:36 +01:00
|
|
|
case nir_op_pack_half_2x16_split:
|
2022-03-02 15:47:03 +01:00
|
|
|
case nir_op_pack_unorm_2x16:
|
|
|
|
|
case nir_op_pack_snorm_2x16:
|
2022-03-03 08:53:06 +01:00
|
|
|
case nir_op_pack_uint_2x16:
|
|
|
|
|
case nir_op_pack_sint_2x16:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_op_unpack_half_2x16_split_x:
|
|
|
|
|
case nir_op_unpack_half_2x16_split_y:
|
|
|
|
|
case nir_op_fddx:
|
|
|
|
|
case nir_op_fddy:
|
|
|
|
|
case nir_op_fddx_fine:
|
|
|
|
|
case nir_op_fddy_fine:
|
|
|
|
|
case nir_op_fddx_coarse:
|
|
|
|
|
case nir_op_fddy_coarse:
|
|
|
|
|
case nir_op_fquantize2f16:
|
|
|
|
|
case nir_op_ldexp:
|
|
|
|
|
case nir_op_frexp_sig:
|
|
|
|
|
case nir_op_frexp_exp:
|
2023-06-29 15:04:27 +01:00
|
|
|
case nir_op_cube_amd:
|
2021-08-02 20:14:03 +01:00
|
|
|
case nir_op_sad_u8x4:
|
2021-08-02 19:42:44 +01:00
|
|
|
case nir_op_udot_4x8_uadd:
|
|
|
|
|
case nir_op_sdot_4x8_iadd:
|
2022-10-17 11:12:59 +02:00
|
|
|
case nir_op_sudot_4x8_iadd:
|
2021-08-02 19:42:44 +01:00
|
|
|
case nir_op_udot_4x8_uadd_sat:
|
|
|
|
|
case nir_op_sdot_4x8_iadd_sat:
|
2022-10-17 11:12:59 +02:00
|
|
|
case nir_op_sudot_4x8_iadd_sat:
|
2021-08-02 19:42:44 +01:00
|
|
|
case nir_op_udot_2x16_uadd:
|
|
|
|
|
case nir_op_sdot_2x16_iadd:
|
|
|
|
|
case nir_op_udot_2x16_uadd_sat:
|
|
|
|
|
case nir_op_sdot_2x16_iadd_sat: type = RegType::vgpr; break;
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_op_f2i16:
|
|
|
|
|
case nir_op_f2u16:
|
|
|
|
|
case nir_op_f2i32:
|
|
|
|
|
case nir_op_f2u32:
|
|
|
|
|
case nir_op_b2i8:
|
|
|
|
|
case nir_op_b2i16:
|
|
|
|
|
case nir_op_b2i32:
|
|
|
|
|
case nir_op_b2b32:
|
|
|
|
|
case nir_op_b2f16:
|
|
|
|
|
case nir_op_b2f32:
|
|
|
|
|
case nir_op_mov: break;
|
2022-07-09 13:32:28 +02:00
|
|
|
case nir_op_iabs:
|
2020-08-24 20:36:06 +01:00
|
|
|
case nir_op_iadd:
|
2022-01-20 20:50:15 +01:00
|
|
|
case nir_op_iadd_sat:
|
|
|
|
|
case nir_op_uadd_sat:
|
2020-08-24 20:36:06 +01:00
|
|
|
case nir_op_isub:
|
2022-01-20 20:50:15 +01:00
|
|
|
case nir_op_isub_sat:
|
|
|
|
|
case nir_op_usub_sat:
|
2020-08-24 20:36:06 +01:00
|
|
|
case nir_op_imul:
|
|
|
|
|
case nir_op_imin:
|
|
|
|
|
case nir_op_imax:
|
|
|
|
|
case nir_op_umin:
|
|
|
|
|
case nir_op_umax:
|
|
|
|
|
case nir_op_ishl:
|
|
|
|
|
case nir_op_ishr:
|
|
|
|
|
case nir_op_ushr:
|
|
|
|
|
/* packed 16bit instructions have to be VGPR */
|
2023-08-14 11:43:35 -05:00
|
|
|
type = alu_instr->def.num_components == 2 ? RegType::vgpr : type;
|
2020-12-01 09:54:31 +00:00
|
|
|
FALLTHROUGH;
|
2020-09-03 12:36:58 +02:00
|
|
|
default:
|
|
|
|
|
for (unsigned i = 0; i < nir_op_infos[alu_instr->op].num_inputs; i++) {
|
2020-10-08 15:11:12 +01:00
|
|
|
if (regclasses[alu_instr->src[i].src.ssa->index].type() == RegType::vgpr)
|
2020-09-03 12:36:58 +02:00
|
|
|
type = RegType::vgpr;
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-14 11:43:35 -05:00
|
|
|
RegClass rc =
|
|
|
|
|
get_reg_class(ctx, type, alu_instr->def.num_components, alu_instr->def.bit_size);
|
|
|
|
|
regclasses[alu_instr->def.index] = rc;
|
2020-09-03 12:36:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_instr_type_load_const: {
|
|
|
|
|
unsigned num_components = nir_instr_as_load_const(instr)->def.num_components;
|
|
|
|
|
unsigned bit_size = nir_instr_as_load_const(instr)->def.bit_size;
|
|
|
|
|
RegClass rc = get_reg_class(ctx, RegType::sgpr, num_components, bit_size);
|
2020-10-08 15:11:12 +01:00
|
|
|
regclasses[nir_instr_as_load_const(instr)->def.index] = rc;
|
2020-09-03 12:36:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_instr_type_intrinsic: {
|
|
|
|
|
nir_intrinsic_instr* intrinsic = nir_instr_as_intrinsic(instr);
|
|
|
|
|
if (!nir_intrinsic_infos[intrinsic->intrinsic].has_dest)
|
|
|
|
|
break;
|
2023-04-14 15:44:43 +01:00
|
|
|
if (intrinsic->intrinsic == nir_intrinsic_strict_wqm_coord_amd) {
|
2023-08-14 11:56:00 -05:00
|
|
|
regclasses[intrinsic->def.index] =
|
|
|
|
|
RegClass::get(RegType::vgpr, intrinsic->def.num_components * 4 +
|
2023-04-14 15:44:43 +01:00
|
|
|
nir_intrinsic_base(intrinsic))
|
|
|
|
|
.as_linear();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2020-09-03 12:36:58 +02:00
|
|
|
RegType type = RegType::sgpr;
|
|
|
|
|
switch (intrinsic->intrinsic) {
|
|
|
|
|
case nir_intrinsic_load_push_constant:
|
2021-06-04 12:04:15 -07:00
|
|
|
case nir_intrinsic_load_workgroup_id:
|
|
|
|
|
case nir_intrinsic_load_num_workgroups:
|
2023-02-21 17:12:24 +01:00
|
|
|
case nir_intrinsic_load_ray_launch_size:
|
2022-04-01 16:01:41 +02:00
|
|
|
case nir_intrinsic_load_ray_launch_size_addr_amd:
|
2022-05-12 20:22:59 +02:00
|
|
|
case nir_intrinsic_load_sbt_base_amd:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_intrinsic_load_subgroup_id:
|
|
|
|
|
case nir_intrinsic_load_num_subgroups:
|
|
|
|
|
case nir_intrinsic_load_first_vertex:
|
|
|
|
|
case nir_intrinsic_load_base_instance:
|
|
|
|
|
case nir_intrinsic_vote_all:
|
|
|
|
|
case nir_intrinsic_vote_any:
|
|
|
|
|
case nir_intrinsic_read_first_invocation:
|
|
|
|
|
case nir_intrinsic_read_invocation:
|
|
|
|
|
case nir_intrinsic_first_invocation:
|
|
|
|
|
case nir_intrinsic_ballot:
|
radv,aco: lower image descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 2926 (1.80% of 162293) affected shaders:
Instrs: 2315110 -> 2306644 (-0.37%); split: -0.37%, +0.00%
CodeSize: 12581592 -> 12546588 (-0.28%); split: -0.28%, +0.00%
VGPRs: 130216 -> 130208 (-0.01%)
SpillSGPRs: 477 -> 474 (-0.63%); split: -5.03%, +4.40%
Latency: 29686188 -> 29678804 (-0.02%); split: -0.05%, +0.02%
InvThroughput: 6926545 -> 6926286 (-0.00%); split: -0.02%, +0.02%
SClause: 73761 -> 72996 (-1.04%); split: -1.16%, +0.12%
Copies: 144068 -> 137279 (-4.71%); split: -4.78%, +0.07%
Branches: 47466 -> 47483 (+0.04%); split: -0.01%, +0.04%
PreSGPRs: 118042 -> 117377 (-0.56%); split: -1.34%, +0.77%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2020-10-21 18:12:35 +01:00
|
|
|
case nir_intrinsic_bindless_image_samples:
|
2020-09-22 15:27:26 +01:00
|
|
|
case nir_intrinsic_load_force_vrs_rates_amd:
|
|
|
|
|
case nir_intrinsic_load_scalar_arg_amd:
|
2023-04-27 17:01:56 +08:00
|
|
|
case nir_intrinsic_load_lds_ngg_scratch_base_amd:
|
|
|
|
|
case nir_intrinsic_load_lds_ngg_gs_out_vertex_base_amd:
|
2020-09-22 15:27:26 +01:00
|
|
|
case nir_intrinsic_load_smem_amd: type = RegType::sgpr; break;
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_intrinsic_load_sample_id:
|
|
|
|
|
case nir_intrinsic_load_input:
|
|
|
|
|
case nir_intrinsic_load_output:
|
|
|
|
|
case nir_intrinsic_load_input_vertex:
|
|
|
|
|
case nir_intrinsic_load_per_vertex_input:
|
|
|
|
|
case nir_intrinsic_load_per_vertex_output:
|
|
|
|
|
case nir_intrinsic_load_vertex_id_zero_base:
|
|
|
|
|
case nir_intrinsic_load_barycentric_sample:
|
|
|
|
|
case nir_intrinsic_load_barycentric_pixel:
|
|
|
|
|
case nir_intrinsic_load_barycentric_model:
|
|
|
|
|
case nir_intrinsic_load_barycentric_centroid:
|
|
|
|
|
case nir_intrinsic_load_barycentric_at_offset:
|
|
|
|
|
case nir_intrinsic_load_interpolated_input:
|
|
|
|
|
case nir_intrinsic_load_frag_coord:
|
2020-11-23 16:01:00 +01:00
|
|
|
case nir_intrinsic_load_frag_shading_rate:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_intrinsic_load_sample_pos:
|
|
|
|
|
case nir_intrinsic_load_local_invocation_id:
|
|
|
|
|
case nir_intrinsic_load_local_invocation_index:
|
|
|
|
|
case nir_intrinsic_load_subgroup_invocation:
|
2023-02-21 17:12:24 +01:00
|
|
|
case nir_intrinsic_load_ray_launch_id:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_intrinsic_load_tess_coord:
|
|
|
|
|
case nir_intrinsic_write_invocation_amd:
|
|
|
|
|
case nir_intrinsic_mbcnt_amd:
|
2021-05-28 21:57:43 +02:00
|
|
|
case nir_intrinsic_lane_permute_16_amd:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_intrinsic_load_instance_id:
|
2023-05-10 19:16:28 -04:00
|
|
|
case nir_intrinsic_ssbo_atomic:
|
|
|
|
|
case nir_intrinsic_ssbo_atomic_swap:
|
|
|
|
|
case nir_intrinsic_global_atomic_amd:
|
|
|
|
|
case nir_intrinsic_global_atomic_swap_amd:
|
|
|
|
|
case nir_intrinsic_bindless_image_atomic:
|
|
|
|
|
case nir_intrinsic_bindless_image_atomic_swap:
|
radv,aco: lower image descriptor loads in NIR
fossil-db (Sienna Cichlid):
Totals from 2926 (1.80% of 162293) affected shaders:
Instrs: 2315110 -> 2306644 (-0.37%); split: -0.37%, +0.00%
CodeSize: 12581592 -> 12546588 (-0.28%); split: -0.28%, +0.00%
VGPRs: 130216 -> 130208 (-0.01%)
SpillSGPRs: 477 -> 474 (-0.63%); split: -5.03%, +4.40%
Latency: 29686188 -> 29678804 (-0.02%); split: -0.05%, +0.02%
InvThroughput: 6926545 -> 6926286 (-0.00%); split: -0.02%, +0.02%
SClause: 73761 -> 72996 (-1.04%); split: -1.16%, +0.12%
Copies: 144068 -> 137279 (-4.71%); split: -4.78%, +0.07%
Branches: 47466 -> 47483 (+0.04%); split: -0.01%, +0.04%
PreSGPRs: 118042 -> 117377 (-0.56%); split: -1.34%, +0.77%
Signed-off-by: Rhys Perry <pendingchaos02@gmail.com>
Reviewed-by: Samuel Pitoiset <samuel.pitoiset@gmail.com>
Reviewed-by: Timur Kristóf <timur.kristof@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12773>
2020-10-21 18:12:35 +01:00
|
|
|
case nir_intrinsic_bindless_image_size:
|
2023-05-10 19:16:28 -04:00
|
|
|
case nir_intrinsic_shared_atomic:
|
|
|
|
|
case nir_intrinsic_shared_atomic_swap:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_intrinsic_load_scratch:
|
|
|
|
|
case nir_intrinsic_load_invocation_id:
|
|
|
|
|
case nir_intrinsic_load_primitive_id:
|
2023-02-03 01:03:22 +01:00
|
|
|
case nir_intrinsic_load_typed_buffer_amd:
|
2021-02-01 16:25:13 +01:00
|
|
|
case nir_intrinsic_load_buffer_amd:
|
2021-07-15 13:56:18 +02:00
|
|
|
case nir_intrinsic_load_initial_edgeflags_amd:
|
2021-04-09 16:59:30 +02:00
|
|
|
case nir_intrinsic_gds_atomic_add_amd:
|
2021-04-29 13:33:45 +02:00
|
|
|
case nir_intrinsic_bvh64_intersect_ray_amd:
|
2022-10-25 10:49:24 +02:00
|
|
|
case nir_intrinsic_load_vector_arg_amd:
|
2023-03-10 13:14:01 +01:00
|
|
|
case nir_intrinsic_load_rt_dynamic_callable_stack_base_amd:
|
2022-10-25 10:49:24 +02:00
|
|
|
case nir_intrinsic_ordered_xfb_counter_add_amd: type = RegType::vgpr; break;
|
2021-05-28 22:08:45 +02:00
|
|
|
case nir_intrinsic_load_shared:
|
2021-11-12 10:28:13 +00:00
|
|
|
case nir_intrinsic_load_shared2_amd:
|
2021-05-28 22:08:45 +02:00
|
|
|
/* When the result of these loads is only used by cross-lane instructions,
|
|
|
|
|
* it is beneficial to use a VGPR destination. This is because this allows
|
|
|
|
|
* to put the s_waitcnt further down, which decreases latency.
|
2021-06-09 10:14:54 +02:00
|
|
|
*/
|
2023-08-14 11:56:00 -05:00
|
|
|
if (only_used_by_cross_lane_instrs(&intrinsic->def)) {
|
2020-09-03 12:36:58 +02:00
|
|
|
type = RegType::vgpr;
|
|
|
|
|
break;
|
2021-06-09 10:14:54 +02:00
|
|
|
}
|
2021-05-28 22:08:45 +02:00
|
|
|
FALLTHROUGH;
|
|
|
|
|
case nir_intrinsic_shuffle:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_intrinsic_quad_broadcast:
|
|
|
|
|
case nir_intrinsic_quad_swap_horizontal:
|
|
|
|
|
case nir_intrinsic_quad_swap_vertical:
|
|
|
|
|
case nir_intrinsic_quad_swap_diagonal:
|
|
|
|
|
case nir_intrinsic_quad_swizzle_amd:
|
2021-05-28 22:08:45 +02:00
|
|
|
case nir_intrinsic_masked_swizzle_amd:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_intrinsic_inclusive_scan:
|
|
|
|
|
case nir_intrinsic_exclusive_scan:
|
2021-05-28 22:08:45 +02:00
|
|
|
case nir_intrinsic_reduce:
|
2020-09-03 12:36:58 +02:00
|
|
|
case nir_intrinsic_load_ubo:
|
2021-05-28 22:08:45 +02:00
|
|
|
case nir_intrinsic_load_ssbo:
|
2021-12-02 14:34:52 +00:00
|
|
|
case nir_intrinsic_load_global_amd:
|
2023-08-14 11:56:00 -05:00
|
|
|
type = intrinsic->def.divergent ? RegType::vgpr : RegType::sgpr;
|
2021-05-28 22:08:45 +02:00
|
|
|
break;
|
|
|
|
|
case nir_intrinsic_load_view_index:
|
|
|
|
|
type = ctx->stage == fragment_fs ? RegType::vgpr : RegType::sgpr;
|
2021-06-09 10:14:54 +02:00
|
|
|
break;
|
2021-05-28 22:08:45 +02:00
|
|
|
default:
|
2021-06-14 17:31:33 +02:00
|
|
|
for (unsigned i = 0; i < nir_intrinsic_infos[intrinsic->intrinsic].num_srcs;
|
|
|
|
|
i++) {
|
|
|
|
|
if (regclasses[intrinsic->src[i].ssa->index].type() == RegType::vgpr)
|
2021-05-28 22:08:45 +02:00
|
|
|
type = RegType::vgpr;
|
|
|
|
|
}
|
2020-09-03 12:36:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
2023-08-14 11:56:00 -05:00
|
|
|
RegClass rc =
|
|
|
|
|
get_reg_class(ctx, type, intrinsic->def.num_components, intrinsic->def.bit_size);
|
|
|
|
|
regclasses[intrinsic->def.index] = rc;
|
2020-09-03 12:36:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_instr_type_tex: {
|
|
|
|
|
nir_tex_instr* tex = nir_instr_as_tex(instr);
|
2023-08-14 11:56:00 -05:00
|
|
|
RegType type = tex->def.divergent ? RegType::vgpr : RegType::sgpr;
|
2020-04-06 11:15:00 +01:00
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
if (tex->op == nir_texop_texture_samples) {
|
2023-08-14 11:56:00 -05:00
|
|
|
assert(!tex->def.divergent);
|
2020-09-03 12:36:58 +02:00
|
|
|
}
|
2020-10-20 16:56:29 +02:00
|
|
|
|
2023-08-14 11:56:00 -05:00
|
|
|
RegClass rc = get_reg_class(ctx, type, tex->def.num_components, tex->def.bit_size);
|
|
|
|
|
regclasses[tex->def.index] = rc;
|
2020-09-03 12:36:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_instr_type_ssa_undef: {
|
|
|
|
|
unsigned num_components = nir_instr_as_ssa_undef(instr)->def.num_components;
|
|
|
|
|
unsigned bit_size = nir_instr_as_ssa_undef(instr)->def.bit_size;
|
|
|
|
|
RegClass rc = get_reg_class(ctx, RegType::sgpr, num_components, bit_size);
|
2020-10-08 15:11:12 +01:00
|
|
|
regclasses[nir_instr_as_ssa_undef(instr)->def.index] = rc;
|
2020-09-03 12:36:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
case nir_instr_type_phi: {
|
|
|
|
|
nir_phi_instr* phi = nir_instr_as_phi(instr);
|
2021-06-04 14:48:19 +02:00
|
|
|
RegType type = RegType::sgpr;
|
2023-08-14 11:56:00 -05:00
|
|
|
unsigned num_components = phi->def.num_components;
|
|
|
|
|
assert((phi->def.bit_size != 1 || num_components == 1) &&
|
2021-06-04 14:48:19 +02:00
|
|
|
"Multiple components not supported on boolean phis.");
|
2020-04-16 20:15:00 +01:00
|
|
|
|
2023-08-14 11:56:00 -05:00
|
|
|
if (phi->def.divergent) {
|
2020-09-03 12:36:58 +02:00
|
|
|
type = RegType::vgpr;
|
|
|
|
|
} else {
|
|
|
|
|
nir_foreach_phi_src (src, phi) {
|
2020-10-08 15:11:12 +01:00
|
|
|
if (regclasses[src->src.ssa->index].type() == RegType::vgpr)
|
2020-09-03 12:36:58 +02:00
|
|
|
type = RegType::vgpr;
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-04 16:03:35 +02:00
|
|
|
|
2023-08-14 11:56:00 -05:00
|
|
|
RegClass rc = get_reg_class(ctx, type, num_components, phi->def.bit_size);
|
|
|
|
|
if (rc != regclasses[phi->def.index])
|
2020-09-03 12:36:58 +02:00
|
|
|
done = false;
|
2023-08-14 11:56:00 -05:00
|
|
|
regclasses[phi->def.index] = rc;
|
2020-09-03 12:36:58 +02:00
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
default: break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-05-04 16:03:35 +02:00
|
|
|
}
|
|
|
|
|
|
2022-05-05 11:32:53 +10:00
|
|
|
ctx->program->config->spi_ps_input_ena = ctx->program->info.ps.spi_ps_input;
|
|
|
|
|
ctx->program->config->spi_ps_input_addr = ctx->program->info.ps.spi_ps_input;
|
2020-01-28 13:29:14 +00:00
|
|
|
|
2021-09-16 20:50:29 +02:00
|
|
|
ctx->cf_info.nir_to_aco = std::move(nir_to_aco);
|
2019-11-15 11:31:03 +00:00
|
|
|
|
2020-09-03 12:36:58 +02:00
|
|
|
/* align and copy constant data */
|
|
|
|
|
while (ctx->program->constant_data.size() % 4u)
|
|
|
|
|
ctx->program->constant_data.push_back(0);
|
|
|
|
|
ctx->constant_data_offset = ctx->program->constant_data.size();
|
|
|
|
|
ctx->program->constant_data.insert(ctx->program->constant_data.end(),
|
|
|
|
|
(uint8_t*)shader->constant_data,
|
|
|
|
|
(uint8_t*)shader->constant_data + shader->constant_data_size);
|
2020-03-27 15:16:39 +01:00
|
|
|
}
|
|
|
|
|
|
2020-11-02 14:01:38 +01:00
|
|
|
void
|
|
|
|
|
cleanup_context(isel_context* ctx)
|
|
|
|
|
{
|
|
|
|
|
_mesa_hash_table_destroy(ctx->range_ht, NULL);
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
isel_context
|
|
|
|
|
setup_isel_context(Program* program, unsigned shader_count, struct nir_shader* const* shaders,
|
2022-05-16 14:54:05 +10:00
|
|
|
ac_shader_config* config, const struct aco_compiler_options* options,
|
2022-05-05 13:34:41 +10:00
|
|
|
const struct aco_shader_info* info, const struct ac_shader_args* args,
|
2023-08-02 08:24:47 +02:00
|
|
|
bool is_ps_epilog, bool is_tcs_epilog)
|
2019-09-17 13:22:17 +02:00
|
|
|
{
|
2020-10-05 17:50:37 +02:00
|
|
|
SWStage sw_stage = SWStage::None;
|
2019-09-17 13:22:17 +02:00
|
|
|
for (unsigned i = 0; i < shader_count; i++) {
|
|
|
|
|
switch (shaders[i]->info.stage) {
|
2020-10-05 17:50:37 +02:00
|
|
|
case MESA_SHADER_VERTEX: sw_stage = sw_stage | SWStage::VS; break;
|
|
|
|
|
case MESA_SHADER_TESS_CTRL: sw_stage = sw_stage | SWStage::TCS; break;
|
|
|
|
|
case MESA_SHADER_TESS_EVAL: sw_stage = sw_stage | SWStage::TES; break;
|
2022-10-17 20:26:51 +01:00
|
|
|
case MESA_SHADER_GEOMETRY: sw_stage = sw_stage | SWStage::GS; break;
|
2020-10-05 17:50:37 +02:00
|
|
|
case MESA_SHADER_FRAGMENT: sw_stage = sw_stage | SWStage::FS; break;
|
2023-07-12 11:19:41 +02:00
|
|
|
case MESA_SHADER_KERNEL:
|
2020-10-05 17:50:37 +02:00
|
|
|
case MESA_SHADER_COMPUTE: sw_stage = sw_stage | SWStage::CS; break;
|
2021-10-21 11:33:10 +02:00
|
|
|
case MESA_SHADER_TASK: sw_stage = sw_stage | SWStage::TS; break;
|
|
|
|
|
case MESA_SHADER_MESH: sw_stage = sw_stage | SWStage::MS; break;
|
2022-05-13 12:06:49 +02:00
|
|
|
case MESA_SHADER_RAYGEN:
|
|
|
|
|
case MESA_SHADER_CLOSEST_HIT:
|
|
|
|
|
case MESA_SHADER_MISS:
|
|
|
|
|
case MESA_SHADER_CALLABLE:
|
|
|
|
|
case MESA_SHADER_INTERSECTION:
|
|
|
|
|
case MESA_SHADER_ANY_HIT: sw_stage = SWStage::RT; break;
|
2019-09-17 13:22:17 +02:00
|
|
|
default: unreachable("Shader stage not implemented");
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-07-14 18:53:46 +02:00
|
|
|
|
|
|
|
|
if (is_ps_epilog) {
|
|
|
|
|
assert(shader_count == 0 && !shaders);
|
|
|
|
|
sw_stage = SWStage::FS;
|
|
|
|
|
}
|
|
|
|
|
|
2023-08-02 08:24:47 +02:00
|
|
|
if (is_tcs_epilog) {
|
|
|
|
|
assert(shader_count == 0 && !shaders);
|
|
|
|
|
sw_stage = SWStage::TCS;
|
|
|
|
|
}
|
|
|
|
|
|
2023-06-12 15:55:40 +02:00
|
|
|
init_program(program, Stage{info->hw_stage, sw_stage}, info, options->gfx_level, options->family,
|
2022-05-12 02:50:17 -04:00
|
|
|
options->wgp_mode, config);
|
2019-12-18 16:18:35 +00:00
|
|
|
|
2019-09-17 13:22:17 +02:00
|
|
|
isel_context ctx = {};
|
|
|
|
|
ctx.program = program;
|
2019-11-13 13:30:52 +01:00
|
|
|
ctx.args = args;
|
2021-10-08 16:14:15 +02:00
|
|
|
ctx.options = options;
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.stage = program->stage;
|
|
|
|
|
|
2022-05-05 11:32:53 +10:00
|
|
|
program->workgroup_size = program->info.workgroup_size;
|
2021-08-11 10:09:04 +02:00
|
|
|
assert(program->workgroup_size);
|
|
|
|
|
|
2021-10-21 11:33:10 +02:00
|
|
|
/* Mesh shading only works on GFX10.3+. */
|
|
|
|
|
ASSERTED bool mesh_shading = ctx.stage.has(SWStage::TS) || ctx.stage.has(SWStage::MS);
|
2022-05-12 02:50:17 -04:00
|
|
|
assert(!mesh_shading || ctx.program->gfx_level >= GFX10_3);
|
2021-10-21 11:33:10 +02:00
|
|
|
|
2023-08-02 08:24:47 +02:00
|
|
|
if (ctx.stage == tess_control_hs && !is_tcs_epilog)
|
2020-07-02 13:37:10 +01:00
|
|
|
setup_tcs_info(&ctx, shaders[0], NULL);
|
2021-08-11 10:09:04 +02:00
|
|
|
else if (ctx.stage == vertex_tess_control_hs)
|
2020-07-02 13:37:10 +01:00
|
|
|
setup_tcs_info(&ctx, shaders[1], shaders[0]);
|
2020-03-26 17:17:38 +01:00
|
|
|
|
2020-03-12 16:28:48 +01:00
|
|
|
calc_min_waves(program);
|
|
|
|
|
|
2019-11-15 11:31:03 +00:00
|
|
|
unsigned scratch_size = 0;
|
2022-10-17 20:26:51 +01:00
|
|
|
for (unsigned i = 0; i < shader_count; i++) {
|
|
|
|
|
nir_shader* nir = shaders[i];
|
|
|
|
|
setup_nir(&ctx, nir);
|
2023-03-15 11:54:49 -07:00
|
|
|
setup_lds_size(&ctx, nir);
|
2019-09-17 13:22:17 +02:00
|
|
|
}
|
|
|
|
|
|
2022-10-17 20:26:51 +01:00
|
|
|
for (unsigned i = 0; i < shader_count; i++)
|
|
|
|
|
scratch_size = std::max(scratch_size, shaders[i]->scratch_size);
|
|
|
|
|
|
2023-01-05 14:01:21 +00:00
|
|
|
ctx.program->config->scratch_bytes_per_wave = scratch_size * ctx.program->wave_size;
|
2019-09-17 13:22:17 +02:00
|
|
|
|
2022-08-17 00:18:54 +02:00
|
|
|
unsigned nir_num_blocks = 0;
|
|
|
|
|
for (unsigned i = 0; i < shader_count; i++)
|
|
|
|
|
nir_num_blocks += nir_shader_get_entrypoint(shaders[i])->num_blocks;
|
|
|
|
|
ctx.program->blocks.reserve(nir_num_blocks * 2);
|
2019-09-17 13:22:17 +02:00
|
|
|
ctx.block = ctx.program->create_and_insert_block();
|
|
|
|
|
ctx.block->kind = block_kind_top_level;
|
|
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace aco
|