diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/glsl/nir/nir.c | 56 | ||||
-rw-r--r-- | src/glsl/nir/nir_dominance.c | 3 | ||||
-rw-r--r-- | src/glsl/nir/nir_from_ssa.c | 19 | ||||
-rw-r--r-- | src/glsl/nir/nir_lower_vars_to_ssa.c | 21 | ||||
-rw-r--r-- | src/glsl/nir/nir_opt_copy_propagate.c | 12 | ||||
-rw-r--r-- | src/glsl/nir/nir_print.c | 8 | ||||
-rw-r--r-- | src/glsl/nir/nir_remove_dead_variables.c | 16 | ||||
-rw-r--r-- | src/glsl/nir/nir_to_ssa.c | 6 | ||||
-rw-r--r-- | src/glsl/nir/nir_validate.c | 38 | ||||
-rw-r--r-- | src/mesa/drivers/dri/i965/intel_fbo.c | 7 | ||||
-rw-r--r-- | src/mesa/main/shared.c | 3 | ||||
-rw-r--r-- | src/mesa/main/syncobj.c | 12 | ||||
-rw-r--r-- | src/mesa/main/vdpau.c | 17 | ||||
-rw-r--r-- | src/util/set.c | 47 | ||||
-rw-r--r-- | src/util/set.h | 12 |
15 files changed, 145 insertions, 132 deletions
diff --git a/src/glsl/nir/nir.c b/src/glsl/nir/nir.c index da9b7a1d3b6..f112db8dd56 100644 --- a/src/glsl/nir/nir.c +++ b/src/glsl/nir/nir.c @@ -61,9 +61,12 @@ reg_create(void *mem_ctx, struct exec_list *list) { nir_register *reg = ralloc(mem_ctx, nir_register); - reg->uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal); - reg->defs = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal); - reg->if_uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal); + reg->uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer, + _mesa_key_pointer_equal); + reg->defs = _mesa_set_create(mem_ctx, _mesa_hash_pointer, + _mesa_key_pointer_equal); + reg->if_uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer, + _mesa_key_pointer_equal); reg->num_components = 0; reg->num_array_elems = 0; @@ -175,7 +178,7 @@ nir_dest nir_dest_copy(nir_dest dest, void *mem_ctx) static inline void block_add_pred(nir_block *block, nir_block *pred) { - _mesa_set_add(block->predecessors, _mesa_hash_pointer(pred), pred); + _mesa_set_add(block->predecessors, pred); } static void @@ -208,8 +211,7 @@ unlink_blocks(nir_block *pred, nir_block *succ) pred->successors[1] = NULL; } - struct set_entry *entry = _mesa_set_search(succ->predecessors, - _mesa_hash_pointer(pred), pred); + struct set_entry *entry = _mesa_set_search(succ->predecessors, pred); assert(entry); @@ -274,9 +276,11 @@ nir_block_create(void *mem_ctx) cf_init(&block->cf_node, nir_cf_node_block); block->successors[0] = block->successors[1] = NULL; - block->predecessors = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal); + block->predecessors = _mesa_set_create(mem_ctx, _mesa_hash_pointer, + _mesa_key_pointer_equal); block->imm_dom = NULL; - block->dom_frontier = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal); + block->dom_frontier = _mesa_set_create(mem_ctx, _mesa_hash_pointer, + _mesa_key_pointer_equal); exec_list_make_empty(&block->instr_list); @@ -1001,7 +1005,7 @@ update_if_uses(nir_cf_node *node) if_stmt->condition.ssa->if_uses : if_stmt->condition.reg.reg->uses; - _mesa_set_add(if_uses_set, _mesa_hash_pointer(if_stmt), if_stmt); + _mesa_set_add(if_uses_set, if_stmt); } void @@ -1168,7 +1172,7 @@ add_use_cb(nir_src *src, void *state) struct set *uses_set = src->is_ssa ? src->ssa->uses : src->reg.reg->uses; - _mesa_set_add(uses_set, _mesa_hash_pointer(instr), instr); + _mesa_set_add(uses_set, instr); return true; } @@ -1194,7 +1198,7 @@ add_reg_def_cb(nir_dest *dest, void *state) nir_instr *instr = (nir_instr *) state; if (!dest->is_ssa) - _mesa_set_add(dest->reg.reg->defs, _mesa_hash_pointer(instr), instr); + _mesa_set_add(dest->reg.reg->defs, instr); return true; } @@ -1313,9 +1317,7 @@ remove_use_cb(nir_src *src, void *state) struct set *uses_set = src->is_ssa ? src->ssa->uses : src->reg.reg->uses; - struct set_entry *entry = _mesa_set_search(uses_set, - _mesa_hash_pointer(instr), - instr); + struct set_entry *entry = _mesa_set_search(uses_set, instr); if (entry) _mesa_set_remove(uses_set, entry); @@ -1332,9 +1334,7 @@ remove_def_cb(nir_dest *dest, void *state) nir_register *reg = dest->reg.reg; - struct set_entry *entry = _mesa_set_search(reg->defs, - _mesa_hash_pointer(instr), - instr); + struct set_entry *entry = _mesa_set_search(reg->defs, instr); if (entry) _mesa_set_remove(reg->defs, entry); @@ -1741,9 +1741,7 @@ nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src) nir_ssa_def *old_ssa = src->ssa; *src = new_src; if (old_ssa && nir_foreach_src(instr, src_does_not_use_def, old_ssa)) { - struct set_entry *entry = _mesa_set_search(old_ssa->uses, - _mesa_hash_pointer(instr), - instr); + struct set_entry *entry = _mesa_set_search(old_ssa->uses, instr); assert(entry); _mesa_set_remove(old_ssa->uses, entry); } @@ -1754,9 +1752,7 @@ nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src) nir_register *old_reg = src->reg.reg; *src = new_src; if (old_reg && nir_foreach_src(instr, src_does_not_use_reg, old_reg)) { - struct set_entry *entry = _mesa_set_search(old_reg->uses, - _mesa_hash_pointer(instr), - instr); + struct set_entry *entry = _mesa_set_search(old_reg->uses, instr); assert(entry); _mesa_set_remove(old_reg->uses, entry); } @@ -1764,10 +1760,10 @@ nir_instr_rewrite_src(nir_instr *instr, nir_src *src, nir_src new_src) if (new_src.is_ssa) { if (new_src.ssa) - _mesa_set_add(new_src.ssa->uses, _mesa_hash_pointer(instr), instr); + _mesa_set_add(new_src.ssa->uses, instr); } else { if (new_src.reg.reg) - _mesa_set_add(new_src.reg.reg->uses, _mesa_hash_pointer(instr), instr); + _mesa_set_add(new_src.reg.reg->uses, instr); } } @@ -1779,8 +1775,10 @@ nir_ssa_def_init(nir_instr *instr, nir_ssa_def *def, def->name = name; def->parent_instr = instr; - def->uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal); - def->if_uses = _mesa_set_create(mem_ctx, _mesa_key_pointer_equal); + def->uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer, + _mesa_key_pointer_equal); + def->if_uses = _mesa_set_create(mem_ctx, _mesa_hash_pointer, + _mesa_key_pointer_equal); def->num_components = num_components; if (instr->block) { @@ -1835,7 +1833,7 @@ nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src, void *mem_ctx) _mesa_set_remove(def->uses, entry); nir_foreach_src(instr, ssa_def_rewrite_uses_src, &state); - _mesa_set_add(new_uses, _mesa_hash_pointer(instr), instr); + _mesa_set_add(new_uses, instr); } set_foreach(def->if_uses, entry) { @@ -1843,7 +1841,7 @@ nir_ssa_def_rewrite_uses(nir_ssa_def *def, nir_src new_src, void *mem_ctx) _mesa_set_remove(def->if_uses, entry); if_use->condition = nir_src_copy(new_src, mem_ctx); - _mesa_set_add(new_if_uses, _mesa_hash_pointer(if_use), if_use); + _mesa_set_add(new_if_uses, if_use); } } diff --git a/src/glsl/nir/nir_dominance.c b/src/glsl/nir/nir_dominance.c index 76847847d64..67fdcc69725 100644 --- a/src/glsl/nir/nir_dominance.c +++ b/src/glsl/nir/nir_dominance.c @@ -113,8 +113,7 @@ calc_dom_frontier_cb(nir_block *block, void *state) set_foreach(block->predecessors, entry) { nir_block *runner = (nir_block *) entry->key; while (runner != block->imm_dom) { - _mesa_set_add(runner->dom_frontier, _mesa_hash_pointer(block), - block); + _mesa_set_add(runner->dom_frontier, block); runner = runner->imm_dom; } } diff --git a/src/glsl/nir/nir_from_ssa.c b/src/glsl/nir/nir_from_ssa.c index 97c09b3b880..025869921f7 100644 --- a/src/glsl/nir/nir_from_ssa.c +++ b/src/glsl/nir/nir_from_ssa.c @@ -353,16 +353,14 @@ isolate_phi_nodes_block(nir_block *block, void *void_state) exec_list_push_tail(&pcopy->entries, &entry->node); entry->src = nir_src_copy(src->src, state->dead_ctx); - _mesa_set_add(src->src.ssa->uses, - _mesa_hash_pointer(&pcopy->instr), &pcopy->instr); + _mesa_set_add(src->src.ssa->uses, &pcopy->instr); entry->dest.is_ssa = true; nir_ssa_def_init(&pcopy->instr, &entry->dest.ssa, phi->dest.ssa.num_components, src->src.ssa->name); struct set_entry *use_entry = - _mesa_set_search(src->src.ssa->uses, - _mesa_hash_pointer(instr), instr); + _mesa_set_search(src->src.ssa->uses, instr); if (use_entry) /* It is possible that a phi node can use the same source twice * but for different basic blocks. If that happens, entry will @@ -374,7 +372,7 @@ isolate_phi_nodes_block(nir_block *block, void *void_state) _mesa_set_remove(src->src.ssa->uses, use_entry); src->src.ssa = &entry->dest.ssa; - _mesa_set_add(entry->dest.ssa.uses, _mesa_hash_pointer(instr), instr); + _mesa_set_add(entry->dest.ssa.uses, instr); } nir_parallel_copy_entry *entry = ralloc(state->dead_ctx, @@ -393,9 +391,7 @@ isolate_phi_nodes_block(nir_block *block, void *void_state) entry->src.is_ssa = true; entry->src.ssa = &phi->dest.ssa; - _mesa_set_add(phi->dest.ssa.uses, - _mesa_hash_pointer(&block_pcopy->instr), - &block_pcopy->instr); + _mesa_set_add(phi->dest.ssa.uses, &block_pcopy->instr); } return true; @@ -545,7 +541,7 @@ rewrite_ssa_src(nir_src *src, void *void_state) /* We don't need to remove it from the uses set because that is going * away. We just need to add it to the one for the register. */ - _mesa_set_add(reg->uses, _mesa_hash_pointer(state->instr), state->instr); + _mesa_set_add(reg->uses, state->instr); } return true; @@ -570,7 +566,7 @@ rewrite_ssa_dest(nir_dest *dest, void *void_state) memset(dest, 0, sizeof *dest); dest->reg.reg = reg; - _mesa_set_add(reg->defs, _mesa_hash_pointer(state->instr), state->instr); + _mesa_set_add(reg->defs, state->instr); } return true; @@ -605,8 +601,7 @@ resolve_registers_block(nir_block *block, void *void_state) memset(&following_if->condition, 0, sizeof following_if->condition); following_if->condition.reg.reg = reg; - _mesa_set_add(reg->if_uses, _mesa_hash_pointer(following_if), - following_if); + _mesa_set_add(reg->if_uses, following_if); } else { /* FIXME: We really shouldn't hit this. We should be doing * constant control flow propagation. diff --git a/src/glsl/nir/nir_lower_vars_to_ssa.c b/src/glsl/nir/nir_lower_vars_to_ssa.c index e331bcdabc3..4df9bdd8897 100644 --- a/src/glsl/nir/nir_lower_vars_to_ssa.c +++ b/src/glsl/nir/nir_lower_vars_to_ssa.c @@ -443,10 +443,10 @@ register_load_instr(nir_intrinsic_instr *load_instr, return; if (node->loads == NULL) - node->loads = _mesa_set_create(state->dead_ctx, + node->loads = _mesa_set_create(state->dead_ctx, _mesa_hash_pointer, _mesa_key_pointer_equal); - _mesa_set_add(node->loads, _mesa_hash_pointer(load_instr), load_instr); + _mesa_set_add(node->loads, load_instr); } static void @@ -458,10 +458,10 @@ register_store_instr(nir_intrinsic_instr *store_instr, return; if (node->stores == NULL) - node->stores = _mesa_set_create(state->dead_ctx, + node->stores = _mesa_set_create(state->dead_ctx, _mesa_hash_pointer, _mesa_key_pointer_equal); - _mesa_set_add(node->stores, _mesa_hash_pointer(store_instr), store_instr); + _mesa_set_add(node->stores, store_instr); } static void @@ -476,10 +476,10 @@ register_copy_instr(nir_intrinsic_instr *copy_instr, continue; if (node->copies == NULL) - node->copies = _mesa_set_create(state->dead_ctx, + node->copies = _mesa_set_create(state->dead_ctx, _mesa_hash_pointer, _mesa_key_pointer_equal); - _mesa_set_add(node->copies, _mesa_hash_pointer(copy_instr), copy_instr); + _mesa_set_add(node->copies, copy_instr); } } @@ -539,9 +539,7 @@ lower_copies_to_load_store(struct deref_node *node, if (arg_node == NULL) continue; - struct set_entry *arg_entry = _mesa_set_search(arg_node->copies, - copy_entry->hash, - copy); + struct set_entry *arg_entry = _mesa_set_search(arg_node->copies, copy); assert(arg_entry); _mesa_set_remove(node->copies, arg_entry); } @@ -714,7 +712,7 @@ add_phi_sources(nir_block *block, nir_block *pred, src->src.is_ssa = true; src->src.ssa = get_ssa_def_for_block(node, pred, state); - _mesa_set_add(src->src.ssa->uses, _mesa_hash_pointer(instr), instr); + _mesa_set_add(src->src.ssa->uses, instr); exec_list_push_tail(&phi->srcs, &src->node); } @@ -1039,6 +1037,7 @@ nir_lower_vars_to_ssa_impl(nir_function_impl *impl) nir_foreach_block(impl, register_variable_uses_block, &state); struct set *outputs = _mesa_set_create(state.dead_ctx, + _mesa_hash_pointer, _mesa_key_pointer_equal); bool progress = false; @@ -1075,7 +1074,7 @@ nir_lower_vars_to_ssa_impl(nir_function_impl *impl) } if (deref->var->data.mode == nir_var_shader_out) - _mesa_set_add(outputs, _mesa_hash_pointer(node), node); + _mesa_set_add(outputs, node); foreach_deref_node_match(deref, lower_copies_to_load_store, &state); } diff --git a/src/glsl/nir/nir_opt_copy_propagate.c b/src/glsl/nir/nir_opt_copy_propagate.c index aa2df1be857..dd0ec01efd6 100644 --- a/src/glsl/nir/nir_opt_copy_propagate.c +++ b/src/glsl/nir/nir_opt_copy_propagate.c @@ -114,15 +114,12 @@ rewrite_src_instr(nir_src *src, nir_ssa_def *new_def, nir_instr *parent_instr) search_state.found = false; nir_foreach_src(parent_instr, search_def, &search_state); if (!search_state.found) { - struct set_entry *entry = - _mesa_set_search(old_def->uses, _mesa_hash_pointer(parent_instr), - parent_instr); + struct set_entry *entry = _mesa_set_search(old_def->uses, parent_instr); assert(entry); _mesa_set_remove(old_def->uses, entry); } - _mesa_set_add(new_def->uses, _mesa_hash_pointer(parent_instr), - parent_instr); + _mesa_set_add(new_def->uses, parent_instr); } static void @@ -132,12 +129,11 @@ rewrite_src_if(nir_if *if_stmt, nir_ssa_def *new_def) if_stmt->condition.ssa = new_def; - struct set_entry *entry = - _mesa_set_search(old_def->if_uses, _mesa_hash_pointer(if_stmt), if_stmt); + struct set_entry *entry = _mesa_set_search(old_def->if_uses, if_stmt); assert(entry); _mesa_set_remove(old_def->if_uses, entry); - _mesa_set_add(new_def->if_uses, _mesa_hash_pointer(if_stmt), if_stmt); + _mesa_set_add(new_def->if_uses, if_stmt); } static bool diff --git a/src/glsl/nir/nir_print.c b/src/glsl/nir/nir_print.c index fe5ceeaf035..84bb97957ba 100644 --- a/src/glsl/nir/nir_print.c +++ b/src/glsl/nir/nir_print.c @@ -210,8 +210,7 @@ print_var_decl(nir_variable *var, print_var_state *state, FILE *fp) glsl_print_type(var->type, fp); - struct set_entry *entry = - _mesa_set_search(state->syms, _mesa_hash_string(var->name), var->name); + struct set_entry *entry = _mesa_set_search(state->syms, var->name); char *name; @@ -232,7 +231,7 @@ print_var_decl(nir_variable *var, print_var_state *state, FILE *fp) fprintf(fp, "\n"); - _mesa_set_add(state->syms, _mesa_hash_string(name), name); + _mesa_set_add(state->syms, name); _mesa_hash_table_insert(state->ht, var, name); } @@ -818,7 +817,8 @@ init_print_state(print_var_state *state) { state->ht = _mesa_hash_table_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal); - state->syms = _mesa_set_create(NULL, _mesa_key_string_equal); + state->syms = _mesa_set_create(NULL, _mesa_key_hash_string, + _mesa_key_string_equal); state->index = 0; } diff --git a/src/glsl/nir/nir_remove_dead_variables.c b/src/glsl/nir/nir_remove_dead_variables.c index 38b291ca04b..e37535f7988 100644 --- a/src/glsl/nir/nir_remove_dead_variables.c +++ b/src/glsl/nir/nir_remove_dead_variables.c @@ -33,7 +33,7 @@ add_var_use_intrinsic(nir_intrinsic_instr *instr, struct set *live) unsigned num_vars = nir_intrinsic_infos[instr->intrinsic].num_variables; for (unsigned i = 0; i < num_vars; i++) { nir_variable *var = instr->variables[i]->var; - _mesa_set_add(live, _mesa_hash_pointer(var), var); + _mesa_set_add(live, var); } } @@ -42,12 +42,12 @@ add_var_use_call(nir_call_instr *instr, struct set *live) { if (instr->return_deref != NULL) { nir_variable *var = instr->return_deref->var; - _mesa_set_add(live, _mesa_hash_pointer(var), var); + _mesa_set_add(live, var); } for (unsigned i = 0; i < instr->num_params; i++) { nir_variable *var = instr->params[i]->var; - _mesa_set_add(live, _mesa_hash_pointer(var), var); + _mesa_set_add(live, var); } } @@ -56,7 +56,7 @@ add_var_use_tex(nir_tex_instr *instr, struct set *live) { if (instr->sampler != NULL) { nir_variable *var = instr->sampler->var; - _mesa_set_add(live, _mesa_hash_pointer(var), var); + _mesa_set_add(live, var); } } @@ -101,8 +101,7 @@ static void remove_dead_local_vars(nir_function_impl *impl, struct set *live) { foreach_list_typed_safe(nir_variable, var, node, &impl->locals) { - struct set_entry *entry = - _mesa_set_search(live, _mesa_hash_pointer(var), var); + struct set_entry *entry = _mesa_set_search(live, var); if (entry == NULL) exec_node_remove(&var->node); } @@ -112,8 +111,7 @@ static void remove_dead_global_vars(nir_shader *shader, struct set *live) { foreach_list_typed_safe(nir_variable, var, node, &shader->globals) { - struct set_entry *entry = - _mesa_set_search(live, _mesa_hash_pointer(var), var); + struct set_entry *entry = _mesa_set_search(live, var); if (entry == NULL) exec_node_remove(&var->node); } @@ -123,7 +121,7 @@ void nir_remove_dead_variables(nir_shader *shader) { struct set *live = - _mesa_set_create(NULL, _mesa_key_pointer_equal); + _mesa_set_create(NULL, _mesa_hash_pointer, _mesa_key_pointer_equal); add_var_use_shader(shader, live); diff --git a/src/glsl/nir/nir_to_ssa.c b/src/glsl/nir/nir_to_ssa.c index 58e8829e1c4..03cce9266ff 100644 --- a/src/glsl/nir/nir_to_ssa.c +++ b/src/glsl/nir/nir_to_ssa.c @@ -194,11 +194,9 @@ rewrite_use(nir_src *src, void *_state) src->ssa = get_ssa_src(src->reg.reg, state); if (state->parent_instr) - _mesa_set_add(src->ssa->uses, _mesa_hash_pointer(state->parent_instr), - state->parent_instr); + _mesa_set_add(src->ssa->uses, state->parent_instr); else - _mesa_set_add(src->ssa->if_uses, _mesa_hash_pointer(state->parent_if), - state->parent_if); + _mesa_set_add(src->ssa->if_uses, state->parent_if); return true; } diff --git a/src/glsl/nir/nir_validate.c b/src/glsl/nir/nir_validate.c index 0d267baa21f..77bc5afa38e 100644 --- a/src/glsl/nir/nir_validate.c +++ b/src/glsl/nir/nir_validate.c @@ -92,9 +92,7 @@ validate_reg_src(nir_reg_src *src, validate_state *state) { assert(src->reg != NULL); - struct set_entry *entry = - _mesa_set_search(src->reg->uses, _mesa_hash_pointer(state->instr), - state->instr); + struct set_entry *entry = _mesa_set_search(src->reg->uses, state->instr); assert(entry && "use not in nir_register.uses"); struct hash_entry *entry2; @@ -103,8 +101,7 @@ validate_reg_src(nir_reg_src *src, validate_state *state) assert(entry2); reg_validate_state *reg_state = (reg_validate_state *) entry2->data; - _mesa_set_add(reg_state->uses, _mesa_hash_pointer(state->instr), - state->instr); + _mesa_set_add(reg_state->uses, state->instr); if (!src->reg->is_global) { assert(reg_state->where_defined == state->impl && @@ -137,8 +134,7 @@ validate_ssa_src(nir_ssa_def *def, validate_state *state) struct set_entry *entry2; - entry2 = _mesa_set_search(def->uses, _mesa_hash_pointer(state->instr), - state->instr); + entry2 = _mesa_set_search(def->uses, state->instr); assert(entry2 && "SSA use missing"); @@ -183,9 +179,7 @@ validate_reg_dest(nir_reg_dest *dest, validate_state *state) { assert(dest->reg != NULL); - struct set_entry *entry = - _mesa_set_search(dest->reg->defs, _mesa_hash_pointer(state->instr), - state->instr); + struct set_entry *entry = _mesa_set_search(dest->reg->defs, state->instr); assert(entry && "definition not in nir_register.defs"); struct hash_entry *entry2; @@ -194,8 +188,7 @@ validate_reg_dest(nir_reg_dest *dest, validate_state *state) assert(entry2); reg_validate_state *reg_state = (reg_validate_state *) entry2->data; - _mesa_set_add(reg_state->defs, _mesa_hash_pointer(state->instr), - state->instr); + _mesa_set_add(reg_state->defs, state->instr); if (!dest->reg->is_global) { assert(reg_state->where_defined == state->impl && @@ -553,8 +546,7 @@ validate_block(nir_block *block, validate_state *state) for (unsigned i = 0; i < 2; i++) { if (block->successors[i] != NULL) { struct set_entry *entry = - _mesa_set_search(block->successors[i]->predecessors, - _mesa_hash_pointer(block), block); + _mesa_set_search(block->successors[i]->predecessors, block); assert(entry); validate_phi_srcs(block, block->successors[i], state); @@ -585,13 +577,11 @@ validate_if(nir_if *if_stmt, validate_state *state) if (!if_stmt->condition.is_ssa) { nir_register *reg = if_stmt->condition.reg.reg; - struct set_entry *entry = - _mesa_set_search(reg->if_uses, _mesa_hash_pointer(if_stmt), if_stmt); + struct set_entry *entry = _mesa_set_search(reg->if_uses, if_stmt); assert(entry); } else { nir_ssa_def *def = if_stmt->condition.ssa; - struct set_entry *entry = - _mesa_set_search(def->if_uses, _mesa_hash_pointer(if_stmt), if_stmt); + struct set_entry *entry = _mesa_set_search(def->if_uses, if_stmt); assert(entry); } @@ -679,8 +669,10 @@ prevalidate_reg_decl(nir_register *reg, bool is_global, validate_state *state) BITSET_SET(state->regs_found, reg->index); reg_validate_state *reg_state = ralloc(state->regs, reg_validate_state); - reg_state->uses = _mesa_set_create(reg_state, _mesa_key_pointer_equal); - reg_state->defs = _mesa_set_create(reg_state, _mesa_key_pointer_equal); + reg_state->uses = _mesa_set_create(reg_state, _mesa_hash_pointer, + _mesa_key_pointer_equal); + reg_state->defs = _mesa_set_create(reg_state, _mesa_hash_pointer, + _mesa_key_pointer_equal); reg_state->where_defined = is_global ? NULL : state->impl; @@ -699,8 +691,7 @@ postvalidate_reg_decl(nir_register *reg, validate_state *state) struct set_entry *entry; set_foreach(reg->uses, entry) { struct set_entry *entry2 = - _mesa_set_search(reg_state->uses, _mesa_hash_pointer(entry->key), - entry->key); + _mesa_set_search(reg_state->uses, entry->key); if (entry2 == NULL) { printf("%p\n", entry->key); @@ -715,8 +706,7 @@ postvalidate_reg_decl(nir_register *reg, validate_state *state) struct set_entry *entry; set_foreach(reg->defs, entry) { struct set_entry *entry2 = - _mesa_set_search(reg_state->defs, _mesa_hash_pointer(entry->key), - entry->key); + _mesa_set_search(reg_state->defs, entry->key); if (entry2 == NULL) { printf("%p\n", entry->key); diff --git a/src/mesa/drivers/dri/i965/intel_fbo.c b/src/mesa/drivers/dri/i965/intel_fbo.c index 77d128200d9..d12f4ae0821 100644 --- a/src/mesa/drivers/dri/i965/intel_fbo.c +++ b/src/mesa/drivers/dri/i965/intel_fbo.c @@ -1008,7 +1008,7 @@ brw_render_cache_set_clear(struct brw_context *brw) void brw_render_cache_set_add_bo(struct brw_context *brw, drm_intel_bo *bo) { - _mesa_set_add(brw->render_cache, _mesa_hash_pointer(bo), bo); + _mesa_set_add(brw->render_cache, bo); } /** @@ -1026,7 +1026,7 @@ brw_render_cache_set_add_bo(struct brw_context *brw, drm_intel_bo *bo) void brw_render_cache_set_check_flush(struct brw_context *brw, drm_intel_bo *bo) { - if (!_mesa_set_search(brw->render_cache, _mesa_hash_pointer(bo), bo)) + if (!_mesa_set_search(brw->render_cache, bo)) return; intel_batchbuffer_emit_mi_flush(brw); @@ -1050,5 +1050,6 @@ intel_fbo_init(struct brw_context *brw) dd->EGLImageTargetRenderbufferStorage = intel_image_target_renderbuffer_storage; - brw->render_cache = _mesa_set_create(brw, _mesa_key_pointer_equal); + brw->render_cache = _mesa_set_create(brw, _mesa_hash_pointer, + _mesa_key_pointer_equal); } diff --git a/src/mesa/main/shared.c b/src/mesa/main/shared.c index 2389c13159e..ccf5355f3c4 100644 --- a/src/mesa/main/shared.c +++ b/src/mesa/main/shared.c @@ -119,7 +119,8 @@ _mesa_alloc_shared_state(struct gl_context *ctx) shared->FrameBuffers = _mesa_NewHashTable(); shared->RenderBuffers = _mesa_NewHashTable(); - shared->SyncObjects = _mesa_set_create(NULL, _mesa_key_pointer_equal); + shared->SyncObjects = _mesa_set_create(NULL, _mesa_hash_pointer, + _mesa_key_pointer_equal); return shared; } diff --git a/src/mesa/main/syncobj.c b/src/mesa/main/syncobj.c index 8832775ebb8..c1b2d3bed54 100644 --- a/src/mesa/main/syncobj.c +++ b/src/mesa/main/syncobj.c @@ -173,9 +173,7 @@ _mesa_validate_sync(struct gl_context *ctx, const struct gl_sync_object *syncObj) { return (syncObj != NULL) - && _mesa_set_search(ctx->Shared->SyncObjects, - _mesa_hash_pointer(syncObj), - syncObj) != NULL + && _mesa_set_search(ctx->Shared->SyncObjects, syncObj) != NULL && (syncObj->Type == GL_SYNC_FENCE) && !syncObj->DeletePending; } @@ -198,9 +196,7 @@ _mesa_unref_sync_object(struct gl_context *ctx, struct gl_sync_object *syncObj) mtx_lock(&ctx->Shared->Mutex); syncObj->RefCount--; if (syncObj->RefCount == 0) { - entry = _mesa_set_search(ctx->Shared->SyncObjects, - _mesa_hash_pointer(syncObj), - syncObj); + entry = _mesa_set_search(ctx->Shared->SyncObjects, syncObj); assert (entry != NULL); _mesa_set_remove(ctx->Shared->SyncObjects, entry); mtx_unlock(&ctx->Shared->Mutex); @@ -289,9 +285,7 @@ _mesa_FenceSync(GLenum condition, GLbitfield flags) ctx->Driver.FenceSync(ctx, syncObj, condition, flags); mtx_lock(&ctx->Shared->Mutex); - _mesa_set_add(ctx->Shared->SyncObjects, - _mesa_hash_pointer(syncObj), - syncObj); + _mesa_set_add(ctx->Shared->SyncObjects, syncObj); mtx_unlock(&ctx->Shared->Mutex); return (GLsync) syncObj; diff --git a/src/mesa/main/vdpau.c b/src/mesa/main/vdpau.c index 89d731b6e74..0efa56e4f41 100644 --- a/src/mesa/main/vdpau.c +++ b/src/mesa/main/vdpau.c @@ -73,7 +73,8 @@ _mesa_VDPAUInitNV(const GLvoid *vdpDevice, const GLvoid *getProcAddress) ctx->vdpDevice = vdpDevice; ctx->vdpGetProcAddress = getProcAddress; - ctx->vdpSurfaces = _mesa_set_create(NULL, _mesa_key_pointer_equal); + ctx->vdpSurfaces = _mesa_set_create(NULL, _mesa_hash_pointer, + _mesa_key_pointer_equal); } static void @@ -179,7 +180,7 @@ register_surface(struct gl_context *ctx, GLboolean isOutput, _mesa_reference_texobj(&surf->textures[i], tex); } - _mesa_set_add(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf); + _mesa_set_add(ctx->vdpSurfaces, surf); return (GLintptr)surf; } @@ -227,7 +228,7 @@ _mesa_VDPAUIsSurfaceNV(GLintptr surface) return false; } - if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + if (!_mesa_set_search(ctx->vdpSurfaces, surf)) { return false; } @@ -251,7 +252,7 @@ _mesa_VDPAUUnregisterSurfaceNV(GLintptr surface) if (surface == 0) return; - entry = _mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf); + entry = _mesa_set_search(ctx->vdpSurfaces, surf); if (!entry) { _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUUnregisterSurfaceNV"); return; @@ -280,7 +281,7 @@ _mesa_VDPAUGetSurfaceivNV(GLintptr surface, GLenum pname, GLsizei bufSize, return; } - if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + if (!_mesa_set_search(ctx->vdpSurfaces, surf)) { _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUGetSurfaceivNV"); return; } @@ -312,7 +313,7 @@ _mesa_VDPAUSurfaceAccessNV(GLintptr surface, GLenum access) return; } - if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + if (!_mesa_set_search(ctx->vdpSurfaces, surf)) { _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV"); return; } @@ -346,7 +347,7 @@ _mesa_VDPAUMapSurfacesNV(GLsizei numSurfaces, const GLintptr *surfaces) for (i = 0; i < numSurfaces; ++i) { struct vdp_surface *surf = (struct vdp_surface *)surfaces[i]; - if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + if (!_mesa_set_search(ctx->vdpSurfaces, surf)) { _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV"); return; } @@ -400,7 +401,7 @@ _mesa_VDPAUUnmapSurfacesNV(GLsizei numSurfaces, const GLintptr *surfaces) for (i = 0; i < numSurfaces; ++i) { struct vdp_surface *surf = (struct vdp_surface *)surfaces[i]; - if (!_mesa_set_search(ctx->vdpSurfaces, _mesa_hash_pointer(surf), surf)) { + if (!_mesa_set_search(ctx->vdpSurfaces, surf)) { _mesa_error(ctx, GL_INVALID_VALUE, "VDPAUSurfaceAccessNV"); return; } diff --git a/src/util/set.c b/src/util/set.c index 3f4a4acb2ce..d170b5007bd 100644 --- a/src/util/set.c +++ b/src/util/set.c @@ -33,6 +33,7 @@ */ #include <stdlib.h> +#include <assert.h> #include "macros.h" #include "ralloc.h" @@ -103,6 +104,7 @@ entry_is_present(struct set_entry *entry) struct set * _mesa_set_create(void *mem_ctx, + uint32_t (*key_hash_function)(const void *key), bool (*key_equals_function)(const void *a, const void *b)) { @@ -116,6 +118,7 @@ _mesa_set_create(void *mem_ctx, ht->size = hash_sizes[ht->size_index].size; ht->rehash = hash_sizes[ht->size_index].rehash; ht->max_entries = hash_sizes[ht->size_index].max_entries; + ht->key_hash_function = key_hash_function; ht->key_equals_function = key_equals_function; ht->table = rzalloc_array(ht, struct set_entry, ht->size); ht->entries = 0; @@ -157,8 +160,8 @@ _mesa_set_destroy(struct set *ht, void (*delete_function)(struct set_entry *entr * * Returns NULL if no entry is found. */ -struct set_entry * -_mesa_set_search(const struct set *ht, uint32_t hash, const void *key) +static struct set_entry * +set_search(const struct set *ht, uint32_t hash, const void *key) { uint32_t hash_address; @@ -184,6 +187,25 @@ _mesa_set_search(const struct set *ht, uint32_t hash, const void *key) return NULL; } +struct set_entry * +_mesa_set_search(const struct set *set, const void *key) +{ + assert(set->key_hash_function); + return set_search(set, set->key_hash_function(key), key); +} + +struct set_entry * +_mesa_set_search_pre_hashed(const struct set *set, uint32_t hash, + const void *key) +{ + assert(set->key_hash_function == NULL || + hash == set->key_hash_function(key)); + return set_search(set, hash, key); +} + +static struct set_entry * +set_add(struct set *ht, uint32_t hash, const void *key); + static void set_rehash(struct set *ht, int new_size_index) { @@ -212,7 +234,7 @@ set_rehash(struct set *ht, int new_size_index) entry != old_ht.table + old_ht.size; entry++) { if (entry_is_present(entry)) { - _mesa_set_add(ht, entry->hash, entry->key); + set_add(ht, entry->hash, entry->key); } } @@ -225,8 +247,8 @@ set_rehash(struct set *ht, int new_size_index) * Note that insertion may rearrange the table on a resize or rehash, * so previously found hash_entries are no longer valid after this function. */ -struct set_entry * -_mesa_set_add(struct set *ht, uint32_t hash, const void *key) +static struct set_entry * +set_add(struct set *ht, uint32_t hash, const void *key) { uint32_t hash_address; @@ -277,6 +299,21 @@ _mesa_set_add(struct set *ht, uint32_t hash, const void *key) return NULL; } +struct set_entry * +_mesa_set_add(struct set *set, const void *key) +{ + assert(set->key_hash_function); + return set_add(set, set->key_hash_function(key), key); +} + +struct set_entry * +_mesa_set_add_pre_hashed(struct set *set, uint32_t hash, const void *key) +{ + assert(set->key_hash_function == NULL || + hash == set->key_hash_function(key)); + return set_add(set, hash, key); +} + /** * This function deletes the given hash table entry. * diff --git a/src/util/set.h b/src/util/set.h index 206d0c4d24f..9acd2c28c9f 100644 --- a/src/util/set.h +++ b/src/util/set.h @@ -43,6 +43,7 @@ struct set_entry { struct set { void *mem_ctx; struct set_entry *table; + uint32_t (*key_hash_function)(const void *key); bool (*key_equals_function)(const void *a, const void *b); uint32_t size; uint32_t rehash; @@ -54,6 +55,7 @@ struct set { struct set * _mesa_set_create(void *mem_ctx, + uint32_t (*key_hash_function)(const void *key), bool (*key_equals_function)(const void *a, const void *b)); void @@ -61,11 +63,15 @@ _mesa_set_destroy(struct set *set, void (*delete_function)(struct set_entry *entry)); struct set_entry * -_mesa_set_add(struct set *set, uint32_t hash, const void *key); +_mesa_set_add(struct set *set, const void *key); +struct set_entry * +_mesa_set_add_pre_hashed(struct set *set, uint32_t hash, const void *key); struct set_entry * -_mesa_set_search(const struct set *set, uint32_t hash, - const void *key); +_mesa_set_search(const struct set *set, const void *key); +struct set_entry * +_mesa_set_search_pre_hashed(const struct set *set, uint32_t hash, + const void *key); void _mesa_set_remove(struct set *set, struct set_entry *entry); |