i965: Fix INTEL_DEBUG=bat
authorCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Mon, 10 Jun 2019 21:23:34 +0000 (14:23 -0700)
committerCaio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
Wed, 12 Jun 2019 22:57:16 +0000 (15:57 -0700)
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: b38dab101ca "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>
src/mesa/drivers/dri/i965/brw_context.h
src/mesa/drivers/dri/i965/intel_batchbuffer.c
src/util/hash_table.c
src/util/hash_table.h

index 46791c7d2c808a3b5311b2391ff79e0fa57d1bc6..25ae25e06ffc729f0f5d50b5f83eb7d1ab52ac9c 100644 (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;
 };
index a701f3bd353de09cf11f3ededb66c05e6f4f3f7d..af076f65f0b29bc21613f2d650fe054ca24f3327 100644 (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;
index 58104abd739e44f1e0f74fab7f9b806d9ad9e0d0..f58575de558f174ecba4d8083cefb29152b21403 100644 (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);
 }
index be7b50ff1fea57374bf71693f45d0c207b6b7938..87b1409c4574b0a6b790131767400864e405501d 100644 (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