mesa/src/asahi/compiler/agx_nir_opt_preamble.c

97 lines
2.4 KiB
C
Raw Normal View History

/*
asahi: Convert to SPDX headers Also drop my email address in the copyright lines and fix some "Copyright 208 Alyssa Rosenzweig" lines, I'm not *that* old. Together this drops a lot of boilerplate without losing any meaningful licensing information. SPDX is already in use for the MIT-licensed code in turnip, venus, and a few other scattered parts of the tree, so this should be ok from a Mesa licensing standpoint. This reduces friction to create new files, by parsing the copy/paste boilerplate and being short enough you can easily type it out if you want. It makes new files seem less daunting: 20 lines of header for 30 lines of code is discouraging, but 2 lines of header for 30 lines of code is reasonable for a simple compiler pass. This has technical effects, as lowering the barrier to making new files should encourage people to split code into more modular files with (hopefully positive) effects on project compile time. This helps with consistency between files. Across the tree we have at least a half dozen variants of the MIT license text (probably more), plus code that uses SPDX headers instead. I've already been using SPDX headers in Asahi manually, so you can tell old vs new code based on the headers. Finally, it means less for reviewers to scroll through adding files. Minimal actual cognitive burden for reviewers thanks to banner blindness, but the big headers still bloat diffs that add/delete files. I originally proposed this in December (for much more of the tree) but someone requested I wait until January to discuss. I've been trying to get in touch with them since then. It is now almost April and, with still no response, I'd like to press forward with this. So with a joint sign-off from the major authors of the code in question, let's do this. Signed-off-by: Asahi Lina <lina@asahilina.net> Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Acked-by: Emma Anholt <emma@anholt.net> Acked-by: Daniel Stone <daniels@collabora.com> Reviewed-by: Eric Engestrom <eric@igalia.com> Acked-by: Kenneth Graunke <kenneth@whitecape.org> Acked-by: Rose Hudson <rose@krx.sh> Acked-by: Lyude Paul [over IRC: "yes I'm fine with that"] Meh'd-by: Rob Clark <robdclark@chromium.org> Signed-off-by: Alyssa Rosenzweig <alyssa@rosenzweig.io> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/22062>
2023-03-15 21:36:17 +00:00
* Copyright 2022 Alyssa Rosenzweig
* Copyright 2021 Valve Corporation
* SPDX-License-Identifier: MIT
*/
#include "compiler/nir/nir_builder.h"
#include "agx_compiler.h"
static void
def_size(nir_ssa_def *def, unsigned *size, unsigned *align)
{
unsigned bit_size = MAX2(def->bit_size, 16);
*size = (bit_size * def->num_components) / 16;
*align = bit_size / 16;
}
static float
instr_cost(nir_instr *instr, const void *data)
{
switch (instr->type) {
case nir_instr_type_intrinsic:
switch (nir_instr_as_intrinsic(instr)->intrinsic) {
case nir_intrinsic_load_global:
case nir_intrinsic_load_agx:
case nir_intrinsic_load_global_constant:
case nir_intrinsic_load_constant_agx:
case nir_intrinsic_load_ubo:
return 10.0;
default:
/* Assume it's a sysval or something */
return 0.0;
}
case nir_instr_type_tex:
/* Texturing involes lots of memory bandwidth */
return 20.0;
case nir_instr_type_alu:
/* We optimistically assume that moves get coalesced */
if (nir_op_is_vec(nir_instr_as_alu(instr)->op))
return 0.0;
else
return 2.0;
default:
return 1.0;
}
}
static float
rewrite_cost(nir_ssa_def *def, const void *data)
{
bool mov_needed = false;
nir_foreach_use(use, def) {
nir_instr *parent_instr = use->parent_instr;
if (parent_instr->type != nir_instr_type_alu) {
mov_needed = true;
break;
} else {
nir_alu_instr *alu = nir_instr_as_alu(parent_instr);
if (alu->op == nir_op_vec2 || alu->op == nir_op_vec3 ||
alu->op == nir_op_vec4 || alu->op == nir_op_mov) {
mov_needed = true;
break;
} else {
/* Assume for non-moves that the const is folded into the src */
}
}
}
return mov_needed ? def->num_components : 0;
}
static bool
avoid_instr(const nir_instr *instr, const void *data)
{
return false;
}
static const nir_opt_preamble_options preamble_options = {
.drawid_uniform = true,
.subgroup_size_uniform = true,
.def_size = def_size,
.instr_cost_cb = instr_cost,
.rewrite_cost_cb = rewrite_cost,
.avoid_instr_cb = avoid_instr,
.preamble_storage_size = 512,
};
bool
agx_nir_opt_preamble(nir_shader *nir, unsigned *preamble_size)
{
return nir_opt_preamble(nir, &preamble_options, preamble_size);
}