From fed51585c4acf4e4d10a466e2ad198f4009e9e85 Mon Sep 17 00:00:00 2001 From: Iago Toral Quiroga Date: Thu, 3 Mar 2022 12:18:02 +0100 Subject: [PATCH] nir/schedule: allow drivers to decide about instruction latency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On V3D reading UBOs from uniform addresses uses a more efficient mechanism with lower latency. On other platforms there may be simular scenarios. Reviewed-by: Alejandro PiƱeiro Part-of: --- src/compiler/nir/nir_schedule.c | 9 +++++++-- src/compiler/nir/nir_schedule.h | 10 +++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/src/compiler/nir/nir_schedule.c b/src/compiler/nir/nir_schedule.c index d9aca42f9c5..b1109347972 100644 --- a/src/compiler/nir/nir_schedule.c +++ b/src/compiler/nir/nir_schedule.c @@ -1002,8 +1002,13 @@ nir_schedule_instructions(nir_schedule_scoreboard *scoreboard, nir_block *block) } static uint32_t -nir_schedule_get_delay(nir_instr *instr) +nir_schedule_get_delay(nir_schedule_scoreboard *scoreboard, nir_instr *instr) { + if (scoreboard->options->instr_delay_cb) { + void *cb_data = scoreboard->options->instr_delay_cb_data; + return scoreboard->options->instr_delay_cb(instr, cb_data); + } + switch (instr->type) { case nir_instr_type_ssa_undef: case nir_instr_type_load_const: @@ -1065,7 +1070,7 @@ nir_schedule_block(nir_schedule_scoreboard *scoreboard, nir_block *block) rzalloc(mem_ctx, nir_schedule_node); n->instr = instr; - n->delay = nir_schedule_get_delay(instr); + n->delay = nir_schedule_get_delay(scoreboard, instr); dag_init_node(scoreboard->dag, &n->dag); _mesa_hash_table_insert(scoreboard->instr_map, instr, n); diff --git a/src/compiler/nir/nir_schedule.h b/src/compiler/nir/nir_schedule.h index d9cf417e906..263136e0955 100644 --- a/src/compiler/nir/nir_schedule.h +++ b/src/compiler/nir/nir_schedule.h @@ -71,8 +71,16 @@ typedef struct nir_schedule_options { bool (* intrinsic_cb)(nir_intrinsic_instr *intr, nir_schedule_dependency *dep, void *user_data); - /* Data to pass to the callback */ + + /* Data to pass to the intrinsic callback */ void *intrinsic_cb_data; + + /* Callback used to specify instruction delays */ + unsigned (* instr_delay_cb)(nir_instr *instr, void *user_data); + + /* Data to pass to the instruction delay callback */ + void *instr_delay_cb_data; + } nir_schedule_options; void nir_schedule(nir_shader *shader, const nir_schedule_options *options);