i965: Fix INTEL_DEBUG=bat

Use hash_table_u64 instead of hash_table directly, since the former
will also handle the special keys (deleted and freed) and allow use
the whole u64 space.

Fixes crash in INTEL_DEBUG=bat when using a key with value 0 -- the
current value for a freed key.

Fixes: b38dab101c "util/hash_table: Assert that keys are not reserved pointers"
Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
This commit is contained in:
Caio Marcelo de Oliveira Filho
2019-06-10 14:23:34 -07:00
parent eb41ce1b01
commit 608257cf82
4 changed files with 26 additions and 25 deletions

View File

@@ -524,7 +524,7 @@ struct intel_batchbuffer {
} saved;
/** Map from batch offset to brw_state_batch data (with DEBUG_BATCH) */
struct hash_table *state_batch_sizes;
struct hash_table_u64 *state_batch_sizes;
struct gen_batch_decode_ctx decoder;
};

View File

@@ -108,22 +108,9 @@ decode_get_state_size(void *v_brw, uint32_t offset_from_dsba)
{
struct brw_context *brw = v_brw;
struct intel_batchbuffer *batch = &brw->batch;
struct hash_entry *entry =
_mesa_hash_table_search(batch->state_batch_sizes,
(void *) (uintptr_t) offset_from_dsba);
return entry ? (uintptr_t) entry->data : 0;
}
static bool
uint_key_compare(const void *a, const void *b)
{
return a == b;
}
static uint32_t
uint_key_hash(const void *key)
{
return (uintptr_t) key;
unsigned size = (uintptr_t) _mesa_hash_table_u64_search(
batch->state_batch_sizes, offset_from_dsba);
return size;
}
static void
@@ -158,7 +145,7 @@ intel_batchbuffer_init(struct brw_context *brw)
if (INTEL_DEBUG & DEBUG_BATCH) {
batch->state_batch_sizes =
_mesa_hash_table_create(NULL, uint_key_hash, uint_key_compare);
_mesa_hash_table_u64_create(NULL);
const unsigned decode_flags =
GEN_BATCH_DECODE_FULL |
@@ -284,7 +271,7 @@ intel_batchbuffer_reset(struct brw_context *brw)
batch->state_base_address_emitted = false;
if (batch->state_batch_sizes)
_mesa_hash_table_clear(batch->state_batch_sizes, NULL);
_mesa_hash_table_u64_clear(batch->state_batch_sizes, NULL);
}
static void
@@ -346,7 +333,7 @@ intel_batchbuffer_free(struct intel_batchbuffer *batch)
brw_bo_unreference(batch->batch.bo);
brw_bo_unreference(batch->state.bo);
if (batch->state_batch_sizes) {
_mesa_hash_table_destroy(batch->state_batch_sizes, NULL);
_mesa_hash_table_u64_destroy(batch->state_batch_sizes, NULL);
gen_batch_decode_ctx_finish(&batch->decoder);
}
}
@@ -1052,9 +1039,8 @@ brw_state_batch(struct brw_context *brw,
}
if (unlikely(INTEL_DEBUG & DEBUG_BATCH)) {
_mesa_hash_table_insert(batch->state_batch_sizes,
(void *) (uintptr_t) offset,
(void *) (uintptr_t) size);
_mesa_hash_table_u64_insert(batch->state_batch_sizes,
offset, (void *) (uintptr_t) size);
}
batch->state_used = offset + size;

View File

@@ -655,8 +655,8 @@ _mesa_hash_table_u64_create(void *mem_ctx)
}
void
_mesa_hash_table_u64_destroy(struct hash_table_u64 *ht,
void (*delete_function)(struct hash_entry *entry))
_mesa_hash_table_u64_clear(struct hash_table_u64 *ht,
void (*delete_function)(struct hash_entry *entry))
{
if (!ht)
return;
@@ -691,6 +691,17 @@ _mesa_hash_table_u64_destroy(struct hash_table_u64 *ht,
ht->freed_key_data = NULL;
}
_mesa_hash_table_clear(ht->table, delete_function);
}
void
_mesa_hash_table_u64_destroy(struct hash_table_u64 *ht,
void (*delete_function)(struct hash_entry *entry))
{
if (!ht)
return;
_mesa_hash_table_u64_clear(ht, delete_function);
_mesa_hash_table_destroy(ht->table, delete_function);
free(ht);
}

View File

@@ -194,6 +194,10 @@ _mesa_hash_table_u64_search(struct hash_table_u64 *ht, uint64_t key);
void
_mesa_hash_table_u64_remove(struct hash_table_u64 *ht, uint64_t key);
void
_mesa_hash_table_u64_clear(struct hash_table_u64 *ht,
void (*delete_function)(struct hash_entry *entry));
#ifdef __cplusplus
} /* extern C */
#endif