Commit d51b6011 authored by Timur Kristóf's avatar Timur Kristóf
Browse files

working in progress mess

parent a323b74a
Pipeline #338123 waiting for manual action with stages
......@@ -76,6 +76,19 @@ typedef struct {
nir_variable *pos_value_replacement;
} remove_extra_position_output_state;
#define REPACK_CSE_FLAG_SELECTED 1
#define REPACK_CSE_FLAG_USED_BY_POS 2
#define REPACK_CSE_FLAG_USED_BY_OTHER 4
#define REPACK_CSE_FLAG_USED_BY_OTHER_DIRECTLY 8
#define REPACK_CSE_FLAG_CONTAINS_MEM_LOAD 16
#define REPACK_CSE_NUM_MAX_SUBEXPRS 5
typedef struct {
struct {
unsigned instr_order;
} subexprs[REPACK_CSE_NUM_MAX_SUBEXPRS];
} repack_common_subexpressions_state;
typedef struct {
nir_ssa_def *reduction_result;
nir_ssa_def *excl_scan_result;
......@@ -513,6 +526,100 @@ remove_extra_pos_outputs(nir_shader *shader, lower_ngg_nogs_state *nogs_state)
nir_metadata_block_index | nir_metadata_dominance, &s);
}
static void
analyze_repackable_common_subexpressions_walk(nir_ssa_def *ssa,
nir_io_semantics *out_io_sem,
uint8_t *child_flags,
repack_common_subexpressions_state *s)
{
nir_instr *instr = ssa->parent_instr;
if (out_io_sem->location == VARYING_SLOT_POS)
instr->pass_flags |= REPACK_CSE_FLAG_USED_BY_POS;
else
instr->pass_flags |= REPACK_CSE_FLAG_USED_BY_OTHER;
switch (instr->type) {
case nir_instr_type_intrinsic: {
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
/* Note: VS input loads are actually VRAM loads on AMD HW. */
switch (intrin->intrinsic) {
case nir_intrinsic_load_input:
case nir_intrinsic_load_ssbo:
case nir_intrinsic_load_ubo:
instr->pass_flags |= REPACK_CSE_FLAG_CONTAINS_MEM_LOAD;
break;
default:
break;
}
break;
}
case nir_instr_type_alu: {
nir_alu_instr *alu = nir_instr_as_alu(instr);
unsigned num_srcs = nir_op_infos[alu->op].num_inputs;
for (unsigned i = 0; i < num_srcs; ++i)
analyze_repackable_common_subexpressions_walk(alu->src[i].src.ssa, out_io_sem,
&instr->pass_flags, s);
break;
}
case nir_instr_type_phi:
/* TODO: support phis? */
break;
default:
/* Nothing to do here */
break;
}
if (child_flags)
*child_flags |= instr->pass_flags;
else if (instr->pass_flags & REPACK_CSE_FLAG_USED_BY_OTHER)
instr->pass_flags |= REPACK_CSE_FLAG_USED_BY_OTHER_DIRECTLY;
}
static bool
analyze_repackable_common_subexpressions_pass(UNUSED nir_builder *b, nir_instr *instr, void *state)
{
repack_common_subexpressions_state *s = (repack_common_subexpressions_state *) state;
instr->pass_flags = 0;
if (instr->type != nir_instr_type_intrinsic)
return false;
nir_intrinsic_instr *intrin = nir_instr_as_intrinsic(instr);
if (intrin->intrinsic != nir_intrinsic_store_output)
return false;
nir_io_semantics io_sem = nir_intrinsic_io_semantics(intrin);
nir_ssa_def *store_val = intrin->src[0].ssa;
analyze_repackable_common_subexpressions_walk(store_val, &io_sem, NULL, s);
return false;
}
static void
analyze_repackable_common_subexpressions(nir_shader *shader, lower_ngg_nogs_state *nogs_state)
{
repack_common_subexpressions_state s = {
};
nir_shader_instructions_pass(shader, analyze_repackable_common_subexpressions_pass,
nir_metadata_all, &s);
nir_foreach_function(func, shader) {
nir_foreach_block_reverse(block, func->impl) {
nir_foreach_instr_reverse(instr, block) {
}
}
}
}
static void
add_deferred_attribute_culling(nir_builder *b, nir_cf_list *original_extracted_cf, lower_ngg_nogs_state *nogs_state)
{
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment