示例#1
0
int
main(int argc, char **argv)
{
	struct hash_table *ht;
	const char *str1 = "test1";
	const char *str2 = "test2";
	struct hash_entry *entry;

	ht = _mesa_hash_table_create(NULL, badhash, _mesa_key_string_equal);

	_mesa_hash_table_insert(ht, str1, NULL);
	_mesa_hash_table_insert(ht, str2, NULL);

	entry = _mesa_hash_table_search(ht, str2);
	assert(strcmp(entry->key, str2) == 0);

	entry = _mesa_hash_table_search(ht, str1);
	assert(strcmp(entry->key, str1) == 0);

	_mesa_hash_table_remove(ht, entry);

	entry = _mesa_hash_table_search(ht, str1);
	assert(entry == NULL);

	entry = _mesa_hash_table_search(ht, str2);
	assert(strcmp(entry->key, str2) == 0);

	_mesa_hash_table_destroy(ht, NULL);

	return 0;
}
示例#2
0
int
main(int argc, char **argv)
{
   struct hash_table *ht;
   char *str1 = strdup("test1");
   char *str2 = strdup("test1");
   struct hash_entry *entry;

   (void) argc;
   (void) argv;

   assert(str1 != str2);

   ht = _mesa_hash_table_create(NULL, _mesa_key_hash_string,
                                _mesa_key_string_equal);

   _mesa_hash_table_insert(ht, str1, str1);
   _mesa_hash_table_insert(ht, str2, str2);

   entry = _mesa_hash_table_search(ht, str1);
   assert(entry);
   assert(entry->data == str2);

   _mesa_hash_table_remove(ht, entry);

   entry = _mesa_hash_table_search(ht, str1);
   assert(!entry);

   _mesa_hash_table_destroy(ht, NULL);
   free(str1);
   free(str2);

   return 0;
}
示例#3
0
static uintptr_t
write_lookup_object(write_ctx *ctx, const void *obj)
{
   struct hash_entry *entry = _mesa_hash_table_search(ctx->remap_table, obj);
   assert(entry);
   return (uintptr_t) entry->data;
}
示例#4
0
static void
validate_ssa_src(nir_src *src, validate_state *state,
                 unsigned bit_size, unsigned num_components)
{
   validate_assert(state, src->ssa != NULL);

   struct hash_entry *entry = _mesa_hash_table_search(state->ssa_defs, src->ssa);

   validate_assert(state, entry);

   if (!entry)
      return;

   ssa_def_validate_state *def_state = (ssa_def_validate_state *)entry->data;

   validate_assert(state, def_state->where_defined == state->impl &&
          "using an SSA value defined in a different function");

   if (state->instr) {
      _mesa_set_add(def_state->uses, src);
   } else {
      validate_assert(state, state->if_stmt);
      _mesa_set_add(def_state->if_uses, src);
   }

   if (bit_size)
      validate_assert(state, src->ssa->bit_size == bit_size);
   if (num_components)
      validate_assert(state, src->ssa->num_components == num_components);

   /* TODO validate that the use is dominated by the definition */
}
link_uniform_block_active *
process_block(void *mem_ctx, struct hash_table *ht, ir_variable *var)
{
   const hash_entry *const existing_block =
      _mesa_hash_table_search(ht, var->get_interface_type()->name);

   const glsl_type *const block_type = var->is_interface_instance()
      ? var->type : var->get_interface_type();


   /* If a block with this block-name has not previously been seen, add it.
    * If a block with this block-name has been seen, it must be identical to
    * the block currently being examined.
    */
   if (existing_block == NULL) {
      link_uniform_block_active *const b =
	 rzalloc(mem_ctx, struct link_uniform_block_active);

      b->type = block_type;
      b->has_instance_name = var->is_interface_instance();

      if (var->data.explicit_binding) {
         b->has_binding = true;
         b->binding = var->data.binding;
      } else {
         b->has_binding = false;
         b->binding = 0;
      }

      _mesa_hash_table_insert(ht, var->get_interface_type()->name, (void *) b);
      return b;
   } else {
示例#6
0
static void
validate_reg_src(nir_src *src, validate_state *state)
{
   assert(src->reg.reg != NULL);

   struct hash_entry *entry;
   entry = _mesa_hash_table_search(state->regs, src->reg.reg);
   assert(entry);

   reg_validate_state *reg_state = (reg_validate_state *) entry->data;

   if (state->instr) {
      _mesa_set_add(reg_state->uses, src);
   } else {
      assert(state->if_stmt);
      _mesa_set_add(reg_state->if_uses, src);
   }

   if (!src->reg.reg->is_global) {
      assert(reg_state->where_defined == state->impl &&
             "using a register declared in a different function");
   }

   assert((src->reg.reg->num_array_elems == 0 ||
          src->reg.base_offset < src->reg.reg->num_array_elems) &&
          "definitely out-of-bounds array access");

   if (src->reg.indirect) {
      assert(src->reg.reg->num_array_elems != 0);
      assert((src->reg.indirect->is_ssa ||
              src->reg.indirect->reg.indirect == NULL) &&
             "only one level of indirection allowed");
      validate_src(src->reg.indirect, state);
   }
}
示例#7
0
ir_visitor_status
output_read_remover::visit(ir_dereference_variable *ir)
{
   if (ir->var->data.mode != ir_var_shader_out)
      return visit_continue;
   if (stage == MESA_SHADER_TESS_CTRL)
      return visit_continue;

   hash_entry *entry = _mesa_hash_table_search(replacements, ir->var);
   ir_variable *temp = entry ? (ir_variable *) entry->data : NULL;

   /* If we don't have an existing temporary, create one. */
   if (temp == NULL) {
      void *var_ctx = ralloc_parent(ir->var);
      temp = new(var_ctx) ir_variable(ir->var->type, ir->var->name,
                                      ir_var_temporary);
      _mesa_hash_table_insert(replacements, ir->var, temp);
      ir->var->insert_after(temp);
   }

   /* Update the dereference to use the temporary */
   ir->var = temp;

   return visit_continue;
}
示例#8
0
int
main(int argc, char **argv)
{
   struct hash_table *ht;
   struct hash_entry *entry;
   unsigned size = 10000;
   uint32_t keys[size];
   uint32_t i;

   (void) argc;
   (void) argv;

   ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals);

   for (i = 0; i < size; i++) {
      keys[i] = i;

      _mesa_hash_table_insert(ht, keys + i, NULL);
   }

   for (i = 0; i < size; i++) {
      entry = _mesa_hash_table_search(ht, keys + i);
      assert(entry);
      assert(key_value(entry->key) == i);
   }
   assert(ht->entries == size);

   _mesa_hash_table_destroy(ht, NULL);

   return 0;
}
示例#9
0
static void
validate_reg_dest(nir_reg_dest *dest, validate_state *state)
{
   assert(dest->reg != NULL);

   assert(dest->parent_instr == state->instr);

   struct hash_entry *entry2;
   entry2 = _mesa_hash_table_search(state->regs, dest->reg);

   assert(entry2);

   reg_validate_state *reg_state = (reg_validate_state *) entry2->data;
   _mesa_set_add(reg_state->defs, dest);

   if (!dest->reg->is_global) {
      assert(reg_state->where_defined == state->impl &&
             "writing to a register declared in a different function");
   }

   assert((dest->reg->num_array_elems == 0 ||
          dest->base_offset < dest->reg->num_array_elems) &&
          "definitely out-of-bounds array access");

   if (dest->indirect) {
      assert(dest->reg->num_array_elems != 0);
      assert((dest->indirect->is_ssa || dest->indirect->reg.indirect == NULL) &&
             "only one level of indirection allowed");
      validate_src(dest->indirect, state);
   }
}
示例#10
0
int main()
{
   struct hash_table *ht;
   struct hash_entry *entry;
   const uint32_t size = 1000;
   bool flags[size];
   uint32_t i;

   ht = _mesa_hash_table_create(NULL, key_hash, key_equal);

   for (i = 0; i < size; ++i) {
      flags[i] = false;
      _mesa_hash_table_insert(ht, make_key(i), &flags[i]);
   }

   _mesa_hash_table_clear(ht, delete_function);
   assert(_mesa_hash_table_next_entry(ht, NULL) == NULL);

   /* Check that delete_function was called and that repopulating the table
    * works. */
   for (i = 0; i < size; ++i) {
      assert(flags[i]);
      flags[i] = false;
      _mesa_hash_table_insert(ht, make_key(i), &flags[i]);
   }

   /* Check that exactly the right set of entries is in the table. */
   for (i = 0; i < size; ++i) {
      assert(_mesa_hash_table_search(ht, make_key(i)));
   }

   hash_table_foreach(ht, entry) {
      assert(key_id(entry->key) < size);
   }
示例#11
0
uint32_t
brw_state_batch_size(struct brw_context *brw, uint32_t offset)
{
   struct hash_entry *entry =
      _mesa_hash_table_search(brw->batch.state_batch_sizes,
                              (void *) (uintptr_t) offset);
   return entry ? (uintptr_t) entry->data : 0;
}
示例#12
0
static void
validate_var_use(nir_variable *var, validate_state *state)
{
   if (var->data.mode == nir_var_local) {
      struct hash_entry *entry = _mesa_hash_table_search(state->var_defs, var);

      assert(entry);
      assert((nir_function_impl *) entry->data == state->impl);
   }
}
示例#13
0
int
main(int argc, char **argv)
{
   struct hash_table *ht;
   struct hash_entry *entry;
   int size = 10000;
   uint32_t keys[size];
   uint32_t i;

   ht = _mesa_hash_table_create(NULL, key_value, uint32_t_key_equals);

   for (i = 0; i < size; i++) {
      keys[i] = i;

      _mesa_hash_table_insert(ht, keys + i, NULL);

      if (i >= 100) {
         uint32_t delete_value = i - 100;
         entry = _mesa_hash_table_search(ht, &delete_value);
         _mesa_hash_table_remove(ht, entry);
      }
   }

   /* Make sure that all our entries were present at the end. */
   for (i = size - 100; i < size; i++) {
      entry = _mesa_hash_table_search(ht, keys + i);
      assert(entry);
      assert(key_value(entry->key) == i);
   }

   /* Make sure that no extra entries got in */
   for (entry = _mesa_hash_table_next_entry(ht, NULL);
        entry != NULL;
        entry = _mesa_hash_table_next_entry(ht, entry)) {
      assert(key_value(entry->key) >= size - 100 &&
             key_value(entry->key) < size);
   }
   assert(ht->entries == 100);

   _mesa_hash_table_destroy(ht, NULL);

   return 0;
}
示例#14
0
static void
remove_uniform(struct hash_table *ht, struct qreg reg)
{
        struct hash_entry *entry;
        void *key = (void *)(uintptr_t)reg.index;

        entry = _mesa_hash_table_search(ht, key);
        assert(entry);
        entry->data--;
        if (entry->data == NULL)
                _mesa_hash_table_remove(ht, entry);
}
ir_variable_refcount_entry *
ir_variable_refcount_visitor::find_variable_entry(ir_variable *var)
{
    assert(var);
    struct hash_entry *e = _mesa_hash_table_search(this->ht,
                           _mesa_hash_pointer(var),
                           var);
    if (e)
        return (ir_variable_refcount_entry *)e->data;

    return NULL;
}
   function *get_function(ir_function_signature *sig)
   {
      function *f;
      hash_entry *entry = _mesa_hash_table_search(this->function_hash, sig);
      if (entry == NULL) {
         f = new(mem_ctx) function(sig);
         _mesa_hash_table_insert(this->function_hash, sig, f);
      } else {
         f = (function *) entry->data;
      }

      return f;
   }
示例#17
0
static void
add_uniform(struct hash_table *ht, struct qreg reg)
{
        struct hash_entry *entry;
        void *key = (void *)(uintptr_t)reg.index;

        entry = _mesa_hash_table_search(ht, key);
        if (entry) {
                entry->data++;
        } else {
                _mesa_hash_table_insert(ht, key, (void *)(uintptr_t)1);
        }
}
示例#18
0
/**
 * Replaces dereferences of ACP RHS variables with ACP LHS variables.
 *
 * This is where the actual copy propagation occurs.  Note that the
 * rewriting of ir_dereference means that the ir_dereference instance
 * must not be shared by multiple IR operations!
 */
ir_visitor_status
ir_copy_propagation_visitor::visit(ir_dereference_variable *ir)
{
   if (this->in_assignee)
      return visit_continue;

   struct hash_entry *entry = _mesa_hash_table_search(acp, ir->var);
   if (entry) {
      ir->var = (ir_variable *) entry->data;
      progress = true;
   }

   return visit_continue;
}
示例#19
0
static struct wsi_x11_connection *
wsi_x11_get_connection(struct wsi_device *wsi_dev,
		       const VkAllocationCallbacks *alloc,
                       xcb_connection_t *conn)
{
   struct wsi_x11 *wsi =
      (struct wsi_x11 *)wsi_dev->wsi[VK_ICD_WSI_PLATFORM_XCB];

   pthread_mutex_lock(&wsi->mutex);

   struct hash_entry *entry = _mesa_hash_table_search(wsi->connections, conn);
   if (!entry) {
      /* We're about to make a bunch of blocking calls.  Let's drop the
       * mutex for now so we don't block up too badly.
       */
      pthread_mutex_unlock(&wsi->mutex);

      struct wsi_x11_connection *wsi_conn =
         wsi_x11_connection_create(alloc, conn);
      if (!wsi_conn)
         return NULL;

      pthread_mutex_lock(&wsi->mutex);

      entry = _mesa_hash_table_search(wsi->connections, conn);
      if (entry) {
         /* Oops, someone raced us to it */
         wsi_x11_connection_destroy(alloc, wsi_conn);
      } else {
         entry = _mesa_hash_table_insert(wsi->connections, conn, wsi_conn);
      }
   }

   pthread_mutex_unlock(&wsi->mutex);

   return entry->data;
}
示例#20
0
void gp_ir_visitor::rewrite_phi_source(lima_gp_ir_phi_node_src_t* src,
									   lima_gp_ir_block_t* block,
									   ir_variable* var)
{
	if (var)
	{
		struct hash_entry* entry =
			_mesa_hash_table_search(this->var_to_reg, _mesa_hash_pointer(var),
									var);
		src->reg = (lima_gp_ir_reg_t*) entry->data;
	}
	else
		src->reg = NULL;
	src->pred = block;
}
示例#21
0
void gp_ir_visitor::rewrite_phi_jump_srcs(lima_gp_ir_phi_node_t* phi,
										  exec_list* srcs, unsigned start)
{
	unsigned i = start;
	foreach_list(node, srcs)
	{
		ir_phi_jump_src* src = (ir_phi_jump_src*) node;
		struct hash_entry* entry =
			_mesa_hash_table_search(this->loop_jump_to_block,
									_mesa_hash_pointer(src->jump), src->jump);
		
		lima_gp_ir_block_t* pred = (lima_gp_ir_block_t*) entry->data;
		this->rewrite_phi_source(&phi->sources[i], pred, src->src);
		i++;
	}
struct iris_compiled_shader *
iris_find_cached_shader(struct iris_context *ice,
                        enum iris_program_cache_id cache_id,
                        uint32_t key_size,
                        const void *key)
{
   struct keybox *keybox =
      make_keybox(ice->shaders.cache, cache_id, key, key_size);
   struct hash_entry *entry =
      _mesa_hash_table_search(ice->shaders.cache, keybox);

   ralloc_free(keybox);

   return entry ? entry->data : NULL;
}
示例#23
0
TEST_F(link_varyings, one_interface_and_one_simple_input)
{
   ir_variable *const v =
      new(mem_ctx) ir_variable(glsl_type::vec(4),
                               "a",
                               ir_var_shader_in);


   ir.push_tail(v);

   ir_variable *const iface =
      new(mem_ctx) ir_variable(simple_interface->fields.structure[0].type,
                               simple_interface->fields.structure[0].name,
                               ir_var_shader_in);

   iface->init_interface_type(simple_interface);

   ir.push_tail(iface);

   linker::populate_consumer_input_sets(mem_ctx,
                                        &ir,
                                        consumer_inputs,
                                        consumer_interface_inputs,
                                        junk);

   char *const iface_field_name = interface_field_name(simple_interface);

   hash_entry *entry = _mesa_hash_table_search(consumer_interface_inputs,
                                               iface_field_name);
   EXPECT_EQ((void *) iface, entry->data);
   EXPECT_EQ(1u, consumer_interface_inputs->entries);

   entry = _mesa_hash_table_search(consumer_inputs, "a");
   EXPECT_EQ((void *) v, entry->data);
   EXPECT_EQ(1u, consumer_inputs->entries);
}
ir_variable_refcount_entry *
ir_variable_refcount_visitor::get_variable_entry(ir_variable *var)
{
   assert(var);

   struct hash_entry *e = _mesa_hash_table_search(this->ht, var);
   if (e)
      return (ir_variable_refcount_entry *)e->data;

   ir_variable_refcount_entry *entry = new ir_variable_refcount_entry(var);
   assert(entry->referenced_count == 0);
   _mesa_hash_table_insert(this->ht, var, entry);

   return entry;
}
static struct assignment_entry *
get_assignment_entry(ir_variable *var, struct hash_table *ht)
{
   struct hash_entry *hte = _mesa_hash_table_search(ht, var);
   struct assignment_entry *entry;

   if (hte) {
      entry = (struct assignment_entry *) hte->data;
   } else {
      entry = (struct assignment_entry *) calloc(1, sizeof(*entry));
      entry->var = var;
      _mesa_hash_table_insert(ht, var, entry);
   }

   return entry;
}
示例#26
0
/* Returns the deref node associated with the given variable.  This will be
 * the root of the tree representing all of the derefs of the given variable.
 */
static struct deref_node *
get_deref_node_for_var(nir_variable *var, struct lower_variables_state *state)
{
   struct deref_node *node;

   struct hash_entry *var_entry =
      _mesa_hash_table_search(state->deref_var_nodes, var);

   if (var_entry) {
      return var_entry->data;
   } else {
      node = deref_node_create(NULL, var->type, state->dead_ctx);
      _mesa_hash_table_insert(state->deref_var_nodes, var, node);
      return node;
   }
}
示例#27
0
static struct partial_update_state *
get_partial_update_state(struct hash_table *partial_update_ht,
                         struct qinst *inst)
{
        struct hash_entry *entry =
                _mesa_hash_table_search(partial_update_ht,
                                        &inst->dst.index);
        if (entry)
                return entry->data;

        struct partial_update_state *state =
                rzalloc(partial_update_ht, struct partial_update_state);

        _mesa_hash_table_insert(partial_update_ht, &inst->dst.index, state);

        return state;
}
static void
register_var_use(nir_variable *var, nir_function_impl *impl,
                 struct hash_table *var_func_table)
{
   if (var->data.mode != nir_var_global)
      return;

   struct hash_entry *entry =
      _mesa_hash_table_search(var_func_table, var);

   if (entry) {
      if (entry->data != impl)
         entry->data = NULL;
   } else {
      _mesa_hash_table_insert(var_func_table, var, impl);
   }
}
示例#29
0
static inline void *
_lookup_ptr(clone_state *state, const void *ptr, bool global)
{
    struct hash_entry *entry;

    if (!ptr)
        return NULL;

    if (!state->global_clone && global)
        return (void *)ptr;

    entry = _mesa_hash_table_search(state->remap_table, ptr);
    assert(entry && "Failed to find pointer!");
    if (!entry)
        return NULL;

    return entry->data;
}
示例#30
0
static inline void *
_lookup_ptr(clone_state *state, const void *ptr, bool global)
{
   struct hash_entry *entry;

   if (!ptr)
      return NULL;

   if (!state->global_clone && global)
      return (void *)ptr;

   entry = _mesa_hash_table_search(state->remap_table, ptr);
   if (!entry) {
      assert(state->allow_remap_fallback);
      return (void *)ptr;
   }

   return entry->data;
}