pco: commonise pass macro, use on opt subpasses

Signed-off-by: Simon Perretta <simon.perretta@imgtec.com>
Acked-by: Frank Binns <frank.binns@imgtec.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/33998>
This commit is contained in:
Simon Perretta 2024-11-19 12:33:06 +00:00 committed by Marge Bot
parent 765e9d837d
commit b13fe4e7a7
3 changed files with 41 additions and 39 deletions

View file

@ -24,6 +24,7 @@
#include "util/hash_table.h"
#include "util/macros.h"
#include "util/list.h"
#include "util/u_debug.h"
#include "util/u_dynarray.h"
#include "util/u_math.h"
@ -2150,6 +2151,32 @@ static inline pco_instr *find_parent_instr_from(pco_ref src, pco_instr *from)
return NULL;
}
static inline bool pco_should_skip_pass(const char *pass)
{
return comma_separated_list_contains(pco_skip_passes, pass);
}
#define PCO_PASS(progress, shader, pass, ...) \
do { \
if (pco_should_skip_pass(#pass)) { \
fprintf(stdout, "Skipping pass '%s'\n", #pass); \
break; \
} \
\
if (pass(shader, ##__VA_ARGS__)) { \
UNUSED bool _; \
progress = true; \
\
if (PCO_DEBUG(REINDEX)) \
pco_index(shader, false); \
\
pco_validate_shader(shader, "after " #pass); \
\
if (pco_should_print_shader_pass(shader)) \
pco_print_shader(shader, stdout, "after " #pass); \
} \
} while (0)
/* Common hw constants. */
/** Integer/float zero. */

View file

@ -12,37 +12,10 @@
#include "pco.h"
#include "pco_internal.h"
#include "util/u_debug.h"
#include <stdbool.h>
#include <stdio.h>
static inline bool pco_should_skip_pass(const char *pass)
{
return comma_separated_list_contains(pco_skip_passes, pass);
}
#define PCO_PASS(progress, shader, pass, ...) \
do { \
if (pco_should_skip_pass(#pass)) { \
fprintf(stdout, "Skipping pass '%s'\n", #pass); \
break; \
} \
\
if (pass(shader, ##__VA_ARGS__)) { \
UNUSED bool _; \
progress = true; \
\
if (PCO_DEBUG(REINDEX)) \
pco_index(shader, false); \
\
pco_validate_shader(shader, "after " #pass); \
\
if (pco_should_print_shader_pass(shader)) \
pco_print_shader(shader, stdout, "after " #pass); \
} \
} while (0)
/**
* \brief Runs passes on a PCO shader.
*

View file

@ -44,7 +44,8 @@ struct pco_opt_ctx {
* \param[in,out] ctx Shared optimization context.
* \return True if any instructions were modified.
*/
static inline bool prep_mods(pco_shader *shader, struct pco_opt_ctx *ctx)
static inline bool pco_opt_prep_mods(pco_shader *shader,
struct pco_opt_ctx *ctx)
{
bool progress = false;
@ -161,7 +162,8 @@ static inline bool prep_mods(pco_shader *shader, struct pco_opt_ctx *ctx)
* \param[in,out] ctx Shared optimization context.
* \return True if any instructions were modified.
*/
static inline bool lower_mods(pco_shader *shader, struct pco_opt_ctx *ctx)
static inline bool pco_opt_lower_mods(pco_shader *shader,
struct pco_opt_ctx *ctx)
{
bool progress = false;
@ -276,7 +278,7 @@ static inline bool try_back_prop_instr(struct pco_use *uses, pco_instr *instr)
* \param[in,out] shader PCO shader.
* \return True if any back-propagations were performed.
*/
static inline bool back_prop(pco_shader *shader)
static inline bool pco_opt_back_prop(pco_shader *shader)
{
bool progress = false;
struct pco_use *uses;
@ -400,7 +402,7 @@ static inline bool try_fwd_prop_instr(pco_instr **writes, pco_instr *instr)
* \param[in,out] shader PCO shader.
* \return True if any forward-propagations were performed.
*/
static inline bool fwd_prop(pco_shader *shader)
static inline bool pco_opt_fwd_prop(pco_shader *shader)
{
bool progress = false;
pco_instr **writes;
@ -464,7 +466,7 @@ static inline bool try_prop_hw_comp(pco_ref src, pco_ref repl, pco_instr *from)
* \param[in,out] shader PCO shader.
* \return True if any hw reg propagations were performed.
*/
static inline bool prop_hw_comps(pco_shader *shader)
static inline bool pco_opt_prop_hw_comps(pco_shader *shader)
{
bool progress = false;
pco_foreach_func_in_shader (func, shader) {
@ -506,17 +508,17 @@ bool pco_opt(pco_shader *shader)
bool progress = false;
struct pco_opt_ctx ctx = { .mem_ctx = ralloc_context(NULL) };
progress |= prep_mods(shader, &ctx);
progress |= back_prop(shader);
progress |= fwd_prop(shader);
PCO_PASS(progress, shader, pco_opt_prep_mods, &ctx);
PCO_PASS(progress, shader, pco_opt_back_prop);
PCO_PASS(progress, shader, pco_opt_fwd_prop);
/* TODO: Track whether there are any comp instructions referencing hw
* registers resulting from the previous passes, and only run prop_hw_comps
* if this is the case.
* registers resulting from the previous passes, and only run
* pco_opt_prop_hw_comps if this is the case.
*/
progress |= prop_hw_comps(shader);
progress |= lower_mods(shader, &ctx);
PCO_PASS(progress, shader, pco_opt_prop_hw_comps);
PCO_PASS(progress, shader, pco_opt_lower_mods, &ctx);
ralloc_free(ctx.mem_ctx);
return progress;
}