pco: primitive bool support

Just expanding to 32-bit for now.

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Acked-by: Erik Faye-Lund <erik.faye-lund@collabora.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36412>
This commit is contained in:
Simon Perretta 2025-01-01 14:04:33 +00:00 committed by Marge Bot
parent 2db53101c1
commit 61602bb08d
5 changed files with 101 additions and 8 deletions

View file

@ -6,6 +6,7 @@ inc_powervr_compiler = include_directories(['.'])
libpowervr_compiler_files = files(
'pco.c',
'pco_binary.c',
'pco_bool.c',
'pco_const_imms.c',
'pco_debug.c',
'pco_end.c',

View file

@ -0,0 +1,73 @@
/*
* Copyright © 2025 Imagination Technologies Ltd.
*
* SPDX-License-Identifier: MIT
*/
/**
* \file pco_bool.c
*
* \brief PCO bool passes.
*/
#include "pco.h"
#include "pco_builder.h"
#include "util/bitscan.h"
#include "util/bitset.h"
#include "util/macros.h"
#include "util/ralloc.h"
#include "util/u_dynarray.h"
#include <assert.h>
#include <stdbool.h>
static bool lower_bools(pco_func *func)
{
bool progress = false;
/* Update to 32-bit. */
pco_foreach_instr_in_func (instr, func) {
pco_foreach_instr_dest_ssa (pdest, instr) {
if (pco_ref_get_bits(*pdest) != 1)
continue;
*pdest = pco_ref_bits(*pdest, 32);
progress = true;
}
pco_foreach_instr_src_ssa (psrc, instr) {
if (pco_ref_get_bits(*psrc) != 1)
continue;
*psrc = pco_ref_bits(*psrc, 32);
progress = true;
}
}
pco_foreach_ssa_bool_if_in_func (pif, func) {
pif->cond = pco_ref_bits(pif->cond, 32);
progress = true;
}
return progress;
}
/**
* \brief Bool lowering pass.
*
* \param[in,out] shader PCO shader.
* \return True if the pass made progress.
*/
bool pco_bool(pco_shader *shader)
{
bool progress = false;
pco_foreach_func_in_shader (func, shader) {
progress |= lower_bools(func);
}
return progress;
}

View file

@ -1522,6 +1522,7 @@ static inline bool pco_should_print_binary(pco_shader *shader)
/* PCO IR passes. */
bool pco_const_imms(pco_shader *shader);
bool pco_bool(pco_shader *shader);
bool pco_dce(pco_shader *shader);
bool pco_end(pco_shader *shader);
bool pco_group_instrs(pco_shader *shader);
@ -2366,6 +2367,19 @@ static inline pco_ref pco_ref_chans(pco_ref ref, unsigned chans)
return ref;
}
/**
* \brief Updates a reference to set the bit width.
*
* \param[in] ref Base reference.
* \param[in] bits New bit width.
* \return Updated reference.
*/
static inline pco_ref pco_ref_bits(pco_ref ref, unsigned bits)
{
ref.bits = pco_bits(bits);
return ref;
}
/**
* \brief Updates a reference value with the provided offset.
*

View file

@ -35,6 +35,7 @@ void pco_process_ir(pco_ctx *ctx, pco_shader *shader)
PCO_PASS(progress, shader, pco_dce);
} while (progress);
PCO_PASS(_, shader, pco_bool);
/* TODO: schedule after RA instead as e.g. vecs may no longer be the first
* time a drc result is used.
*/

View file

@ -763,10 +763,6 @@ static inline enum pco_tst_op_main to_tst_op_main(nir_op op)
static inline enum pco_tst_type_main to_tst_type_main(nir_op op, pco_ref src)
{
ASSERTED unsigned bits = pco_ref_get_bits(src);
assert(bits == 32);
switch (op) {
case nir_op_slt:
case nir_op_sge:
@ -865,9 +861,8 @@ static pco_instr *trans_logical(trans_ctx *tctx,
{
ASSERTED unsigned bits = pco_ref_get_bits(dest);
/* TODO: bool support. */
/* TODO: 8/16-bit support via masking. */
assert(bits == 32);
assert(bits == 1 || bits == 32);
enum pco_logiop logiop;
switch (op) {
@ -1281,11 +1276,20 @@ static pco_instr *trans_const(trans_ctx *tctx, nir_load_const_instr *nconst)
unsigned num_bits = nconst->def.bit_size;
unsigned chans = nconst->def.num_components;
pco_ref dest = pco_ref_nir_def_t(&nconst->def, tctx);
if (num_bits == 1) {
assert(chans == 1);
bool val = nir_const_value_as_bool(nconst->value[0], 1);
pco_ref imm_reg = pco_ref_bits(val ? pco_true : pco_zero, 1);
return pco_mov(&tctx->b, dest, imm_reg);
}
/* TODO: support more bit sizes/components. */
assert(num_bits == 32);
pco_ref dest = pco_ref_nir_def_t(&nconst->def, tctx);
if (pco_ref_is_scalar(dest)) {
assert(chans == 1);