[Mesa-dev] [PATCH 2/3] intel: rework regions hash.

Gwenole Beauchesne gb.devel at gmail.com
Fri Apr 20 09:39:04 PDT 2012


This is preparatory work for multiple region hashing from a single
(name) key. In particular, this will be useful to lookup for a region
offset by a certain amount of bytes.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne at intel.com>
---
 src/mesa/drivers/dri/intel/intel_regions.c |   61 +++++++++++++++++++++++++--
 src/mesa/drivers/dri/intel/intel_regions.h |    8 ++++
 src/mesa/drivers/dri/intel/intel_screen.c  |   13 +-----
 3 files changed, 66 insertions(+), 16 deletions(-)

diff --git a/src/mesa/drivers/dri/intel/intel_regions.c b/src/mesa/drivers/dri/intel/intel_regions.c
index 25780b9..235c2cd 100644
--- a/src/mesa/drivers/dri/intel/intel_regions.c
+++ b/src/mesa/drivers/dri/intel/intel_regions.c
@@ -104,7 +104,17 @@ debug_backtrace(void)
 
 #endif
 
+/* Forward declarations */
+static struct intel_region *
+intel_region_hash_lookup(struct _mesa_HashTable *h, uint32_t name);
+
+static void
+intel_region_hash_insert(struct _mesa_HashTable *h,
+                         struct intel_region *region);
 
+static void
+intel_region_hash_remove(struct _mesa_HashTable *h,
+                         struct intel_region *region);
 
 /* XXX: Thread safety?
  */
@@ -221,8 +231,7 @@ intel_region_flink(struct intel_region *region, uint32_t *name)
       if (drm_intel_bo_flink(region->bo, &region->name))
 	 return false;
       
-      _mesa_HashInsert(region->screen->named_regions,
-		       region->name, region);
+      intel_region_hash_insert(region->screen->named_regions, region);
    }
 
    *name = region->name;
@@ -241,7 +250,7 @@ intel_region_alloc_for_handle(struct intel_screen *screen,
    int ret;
    uint32_t bit_6_swizzle, tiling;
 
-   region = _mesa_HashLookup(screen->named_regions, handle);
+   region = intel_region_hash_lookup(screen->named_regions, handle);
    if (region != NULL) {
       dummy = NULL;
       if (region->width != width || region->height != height ||
@@ -274,7 +283,7 @@ intel_region_alloc_for_handle(struct intel_screen *screen,
    }
 
    region->name = handle;
-   _mesa_HashInsert(screen->named_regions, handle, region);
+   intel_region_hash_insert(screen->named_regions, region);
 
    return region;
 }
@@ -316,7 +325,7 @@ intel_region_release(struct intel_region **region_handle)
       drm_intel_bo_unreference(region->bo);
 
       if (region->name > 0)
-	 _mesa_HashRemove(region->screen->named_regions, region->name);
+	 intel_region_hash_remove(region->screen->named_regions, region);
 
       free(region);
    }
@@ -391,3 +400,45 @@ intel_region_copy(struct intel_context *intel,
 			    srcx, srcy, dstx, dsty, width, height,
 			    logicop);
 }
+
+static void
+intel_region_hash_destroy_callback(GLuint key, void *data, void *userData)
+{
+}
+
+struct _mesa_HashTable *
+intel_region_hash_new(void)
+{
+    return _mesa_NewHashTable();
+}
+
+void
+intel_region_hash_destroy(struct _mesa_HashTable **h_ptr)
+{
+    struct _mesa_HashTable * const h = *h_ptr;
+
+   /* Some regions may still have references to them at this point, so
+    * flush the hash table to prevent _mesa_DeleteHashTable() from
+    * complaining about the hash not being empty; */
+   _mesa_HashDeleteAll(h, intel_region_hash_destroy_callback, NULL);
+   _mesa_DeleteHashTable(h);
+   *h_ptr = NULL;
+}
+
+static struct intel_region *
+intel_region_hash_lookup(struct _mesa_HashTable *h, uint32_t name)
+{
+    return _mesa_HashLookup(h, name);
+}
+
+static void
+intel_region_hash_insert(struct _mesa_HashTable *h, struct intel_region *region)
+{
+    _mesa_HashInsert(h, region->name, region);
+}
+
+static void
+intel_region_hash_remove(struct _mesa_HashTable *h, struct intel_region *region)
+{
+    _mesa_HashRemove(h, region->name);
+}
diff --git a/src/mesa/drivers/dri/intel/intel_regions.h b/src/mesa/drivers/dri/intel/intel_regions.h
index f1f9ae9..b5170c1 100644
--- a/src/mesa/drivers/dri/intel/intel_regions.h
+++ b/src/mesa/drivers/dri/intel/intel_regions.h
@@ -139,4 +139,12 @@ struct __DRIimageRec {
    void *data;
 };
 
+struct _mesa_HashTable;
+
+struct _mesa_HashTable *
+intel_region_hash_new(void);
+
+void
+intel_region_hash_destroy(struct _mesa_HashTable **h);
+
 #endif
diff --git a/src/mesa/drivers/dri/intel/intel_screen.c b/src/mesa/drivers/dri/intel/intel_screen.c
index f28619f..5f8d850 100644
--- a/src/mesa/drivers/dri/intel/intel_screen.c
+++ b/src/mesa/drivers/dri/intel/intel_screen.c
@@ -456,11 +456,6 @@ intel_get_boolean(__DRIscreen *psp, int param)
 }
 
 static void
-nop_callback(GLuint key, void *data, void *userData)
-{
-}
-
-static void
 intelDestroyScreen(__DRIscreen * sPriv)
 {
    struct intel_screen *intelScreen = sPriv->driverPrivate;
@@ -468,11 +463,7 @@ intelDestroyScreen(__DRIscreen * sPriv)
    dri_bufmgr_destroy(intelScreen->bufmgr);
    driDestroyOptionInfo(&intelScreen->optionCache);
 
-   /* Some regions may still have references to them at this point, so
-    * flush the hash table to prevent _mesa_DeleteHashTable() from
-    * complaining about the hash not being empty; */
-   _mesa_HashDeleteAll(intelScreen->named_regions, nop_callback, NULL);
-   _mesa_DeleteHashTable(intelScreen->named_regions);
+   intel_region_hash_destroy(&intelScreen->named_regions);
 
    FREE(intelScreen);
    sPriv->driverPrivate = NULL;
@@ -678,7 +669,7 @@ intel_init_bufmgr(struct intel_screen *intelScreen)
 
    drm_intel_bufmgr_gem_enable_fenced_relocs(intelScreen->bufmgr);
 
-   intelScreen->named_regions = _mesa_NewHashTable();
+   intelScreen->named_regions = intel_region_hash_new();
 
    intelScreen->relaxed_relocations = 0;
    intelScreen->relaxed_relocations |=
-- 
1.7.5.4



More information about the mesa-dev mailing list