r300: add r300_is_only_used_as_float helper

This is slightly different from the stock is_only_used_as_float since
that one will return false when called for uses of bcsel if any of the
uses actually uses uint, like vec or another bcsel. This version will
recursivelly go further in such cases and return false only if it sees
any instructions specifically neededing bools or ints.

Signed-off-by: Pavel Ondračka <pavel.ondracka@gmail.com>
Reviewed-by: Filip Gawin <filip.gawin@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/27089>
This commit is contained in:
Pavel Ondračka 2024-01-16 10:08:30 +01:00 committed by Marge Bot
parent b1a669be75
commit bdf42690f6
2 changed files with 37 additions and 0 deletions

View file

@ -25,6 +25,41 @@
#include "compiler/nir/nir_builder.h"
#include "r300_screen.h"
bool
r300_is_only_used_as_float(const nir_alu_instr *instr)
{
nir_foreach_use(src, &instr->def) {
if (nir_src_is_if(src))
return false;
nir_instr *user_instr = nir_src_parent_instr(src);
if (user_instr->type == nir_instr_type_alu) {
nir_alu_instr *alu = nir_instr_as_alu(user_instr);
switch (alu->op) {
case nir_op_mov:
case nir_op_vec2:
case nir_op_vec3:
case nir_op_vec4:
case nir_op_bcsel:
case nir_op_b32csel:
if (!r300_is_only_used_as_float(alu))
return false;
break;
default:
break;
}
const nir_op_info *info = &nir_op_infos[alu->op];
nir_alu_src *alu_src = exec_node_data(nir_alu_src, src, src);
int src_idx = alu_src - &alu->src[0];
if ((info->input_types[src_idx] & nir_type_int) ||
(info->input_types[src_idx] & nir_type_bool))
return false;
}
}
return true;
}
static unsigned char
r300_should_vectorize_instr(const nir_instr *instr, const void *data)
{

View file

@ -65,6 +65,8 @@ is_only_used_by_load_ubo_vec4(const nir_alu_instr *instr)
return true;
}
bool r300_is_only_used_as_float(const nir_alu_instr *instr);
char *r300_finalize_nir(struct pipe_screen *pscreen, void *nir);
extern bool r300_transform_vs_trig_input(struct nir_shader *shader);