[Mesa-dev] [PATCH 074/133] i965/fs_nir: Use an array rather than a hash table for register lookup
Connor Abbott
cwabbott0 at gmail.com
Wed Dec 17 17:23:01 PST 2014
We shouldn't ever have global registers until we start dealing with
subroutines, so you don't need to handle them here.
On Tue, Dec 16, 2014 at 1:05 AM, Jason Ekstrand <jason at jlekstrand.net> wrote:
> ---
> src/mesa/drivers/dri/i965/brw_fs.h | 4 +--
> src/mesa/drivers/dri/i965/brw_fs_nir.cpp | 46 +++++++++++++++-------------
> src/mesa/drivers/dri/i965/brw_fs_visitor.cpp | 5 +--
> 3 files changed, 30 insertions(+), 25 deletions(-)
>
> diff --git a/src/mesa/drivers/dri/i965/brw_fs.h b/src/mesa/drivers/dri/i965/brw_fs.h
> index c244781..6b50c7d 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs.h
> +++ b/src/mesa/drivers/dri/i965/brw_fs.h
> @@ -572,7 +572,6 @@ public:
> void nir_setup_inputs(nir_shader *shader);
> void nir_setup_outputs(nir_shader *shader);
> void nir_setup_uniforms(nir_shader *shader);
> - void nir_setup_registers(exec_list *regs);
> void nir_setup_uniform(nir_variable *var);
> void nir_setup_builtin_uniform(nir_variable *var);
> void nir_emit_impl(nir_function_impl *impl);
> @@ -698,7 +697,8 @@ public:
> fs_reg *fp_temp_regs;
> fs_reg *fp_input_regs;
>
> - struct hash_table *nir_reg_ht;
> + fs_reg *nir_locals;
> + fs_reg *nir_globals;
> fs_reg nir_inputs;
> fs_reg nir_outputs;
> fs_reg nir_uniforms;
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> index 5703225..3ec2fa6 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_nir.cpp
> @@ -98,7 +98,13 @@ fs_visitor::emit_nir_code()
> nir_setup_uniforms(nir);
> }
>
> - nir_setup_registers(&nir->registers);
> + nir_globals = ralloc_array(mem_ctx, fs_reg, nir->reg_alloc);
> + foreach_list_typed(nir_register, reg, node, &nir->registers) {
> + unsigned array_elems =
> + reg->num_array_elems == 0 ? 1 : reg->num_array_elems;
> + unsigned size = array_elems * reg->num_components;
> + nir_globals[reg->index] = fs_reg(GRF, virtual_grf_alloc(size));
> + }
>
> /* get the main function and emit it */
> nir_foreach_overload(nir, overload) {
> @@ -276,22 +282,16 @@ fs_visitor::nir_setup_builtin_uniform(nir_variable *var)
> }
>
> void
> -fs_visitor::nir_setup_registers(exec_list *list)
> +fs_visitor::nir_emit_impl(nir_function_impl *impl)
> {
> - foreach_list_typed(nir_register, nir_reg, node, list) {
> + nir_locals = reralloc(mem_ctx, nir_locals, fs_reg, impl->reg_alloc);
> + foreach_list_typed(nir_register, reg, node, &impl->registers) {
> unsigned array_elems =
> - nir_reg->num_array_elems == 0 ? 1 : nir_reg->num_array_elems;
> - unsigned size = array_elems * nir_reg->num_components;
> - fs_reg *reg = new(mem_ctx) fs_reg(GRF, virtual_grf_alloc(size));
> - _mesa_hash_table_insert(this->nir_reg_ht, _mesa_hash_pointer(nir_reg),
> - nir_reg, reg);
> + reg->num_array_elems == 0 ? 1 : reg->num_array_elems;
> + unsigned size = array_elems * reg->num_components;
> + nir_locals[reg->index] = fs_reg(GRF, virtual_grf_alloc(size));
> }
> -}
>
> -void
> -fs_visitor::nir_emit_impl(nir_function_impl *impl)
> -{
> - nir_setup_registers(&impl->registers);
> nir_emit_cf_list(&impl->body);
> }
>
> @@ -981,10 +981,12 @@ fs_visitor::nir_emit_alu(nir_alu_instr *instr)
> fs_reg
> fs_visitor::get_nir_src(nir_src src)
> {
> - struct hash_entry *entry =
> - _mesa_hash_table_search(this->nir_reg_ht, _mesa_hash_pointer(src.reg.reg),
> - src.reg.reg);
> - fs_reg reg = *((fs_reg *) entry->data);
> + fs_reg reg;
> + if (src.reg.reg->is_global)
> + reg = nir_globals[src.reg.reg->index];
> + else
> + reg = nir_locals[src.reg.reg->index];
> +
> /* to avoid floating-point denorm flushing problems, set the type by
> * default to D - instructions that need floating point semantics will set
> * this to F if they need to
> @@ -1042,10 +1044,12 @@ fs_visitor::get_nir_alu_src(nir_alu_instr *instr, unsigned src)
> fs_reg
> fs_visitor::get_nir_dest(nir_dest dest)
> {
> - struct hash_entry *entry =
> - _mesa_hash_table_search(this->nir_reg_ht,
> - _mesa_hash_pointer(dest.reg.reg), dest.reg.reg);
> - fs_reg reg = *((fs_reg *) entry->data);
> + fs_reg reg;
> + if (dest.reg.reg->is_global)
> + reg = nir_globals[dest.reg.reg->index];
> + else
> + reg = nir_locals[dest.reg.reg->index];
> +
> reg.reg_offset = dest.reg.base_offset;
> if (dest.reg.indirect) {
> reg.reladdr = new(mem_ctx) fs_reg();
> diff --git a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> index fd7dd43..9b73595 100644
> --- a/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> +++ b/src/mesa/drivers/dri/i965/brw_fs_visitor.cpp
> @@ -3820,7 +3820,9 @@ fs_visitor::init()
> this->variable_ht = hash_table_ctor(0,
> hash_table_pointer_hash,
> hash_table_pointer_compare);
> - this->nir_reg_ht = _mesa_hash_table_create(NULL, _mesa_key_pointer_equal);
> +
> + this->nir_locals = NULL;
> + this->nir_globals = NULL;
>
> memset(&this->payload, 0, sizeof(this->payload));
> memset(this->outputs, 0, sizeof(this->outputs));
> @@ -3856,5 +3858,4 @@ fs_visitor::init()
> fs_visitor::~fs_visitor()
> {
> hash_table_dtor(this->variable_ht);
> - _mesa_hash_table_destroy(this->nir_reg_ht, NULL);
> }
> --
> 2.2.0
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list