i965: Replace open-coded linked list with exec_list.
authorMatt Turner <mattst88@gmail.com>
Tue, 10 Jun 2014 09:08:10 +0000 (02:08 -0700)
committerMatt Turner <mattst88@gmail.com>
Tue, 10 Jun 2014 20:05:51 +0000 (13:05 -0700)
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/mesa/drivers/dri/i965/intel_mipmap_tree.c
src/mesa/drivers/dri/i965/intel_mipmap_tree.h
src/mesa/drivers/dri/i965/intel_resolve_map.c
src/mesa/drivers/dri/i965/intel_resolve_map.h

index dd7e57aea84f77a7c9ad143eda80b6c92d4c45cd..a0e637a9095f4b64b4dcd8e35ed4a75e797afd16 100644 (file)
@@ -261,6 +261,7 @@ intel_miptree_create_layout(struct brw_context *brw,
    mt->logical_height0 = height0;
    mt->logical_depth0 = depth0;
    mt->fast_clear_state = INTEL_FAST_CLEAR_STATE_NO_MCS;
+   exec_list_make_empty(&mt->hiz_map);
 
    /* The cpp is bytes per (1, blockheight)-sized block for compressed
     * textures.  This is why you'll see divides by blockheight all over
@@ -1400,20 +1401,18 @@ intel_miptree_alloc_hiz(struct brw_context *brw,
       return false;
 
    /* Mark that all slices need a HiZ resolve. */
-   struct intel_resolve_map *head = &mt->hiz_map;
    for (int level = mt->first_level; level <= mt->last_level; ++level) {
       if (!intel_miptree_level_enable_hiz(brw, mt, level))
          continue;
 
       for (int layer = 0; layer < mt->level[level].depth; ++layer) {
-        head->next = malloc(sizeof(*head->next));
-        head->next->prev = head;
-        head->next->next = NULL;
-        head = head->next;
-
-        head->level = level;
-        head->layer = layer;
-        head->need = GEN6_HIZ_OP_HIZ_RESOLVE;
+         struct intel_resolve_map *m = malloc(sizeof(struct intel_resolve_map));
+         exec_node_init(&m->link);
+         m->level = level;
+         m->layer = layer;
+         m->need = GEN6_HIZ_OP_HIZ_RESOLVE;
+
+         exec_list_push_tail(&mt->hiz_map, &m->link);
       }
    }
 
@@ -1513,15 +1512,15 @@ intel_miptree_all_slices_resolve(struct brw_context *brw,
                                 enum gen6_hiz_op need)
 {
    bool did_resolve = false;
-   struct intel_resolve_map *i, *next;
 
-   for (i = mt->hiz_map.next; i; i = next) {
-      next = i->next;
-      if (i->need != need)
+   foreach_list_safe(node, &mt->hiz_map) {
+      struct intel_resolve_map *map = (struct intel_resolve_map *)node;
+
+      if (map->need != need)
         continue;
 
-      intel_hiz_exec(brw, mt, i->level, i->layer, need);
-      intel_resolve_map_remove(i);
+      intel_hiz_exec(brw, mt, map->level, map->layer, need);
+      intel_resolve_map_remove(map);
       did_resolve = true;
    }
 
index 6a918848de2517da826f7405b5fe332b494fe0f3..bb040845d51dd5478c911a069d8586bd279ad114 100644 (file)
@@ -381,7 +381,7 @@ struct intel_mipmap_tree
     * \c mt->hiz_map. The resolve map of the child HiZ miptree, \c
     * mt->hiz_mt->hiz_map, is unused.
     */
-   struct intel_resolve_map hiz_map;
+   struct exec_list hiz_map; /* List of intel_resolve_map. */
 
    /**
     * \brief Stencil miptree for depthstencil textures.
index 04b5c9424323953fec307e5204b41bfc339c5cf5..a37afa684ddb3552be7a965f4b697dc702dc2ee7 100644 (file)
  * changed to the given value of \c need.
  */
 void
-intel_resolve_map_set(struct intel_resolve_map *head,
+intel_resolve_map_set(struct exec_list *resolve_map,
                      uint32_t level,
                      uint32_t layer,
                      enum gen6_hiz_op need)
 {
-   struct intel_resolve_map **tail = &head->next;
-   struct intel_resolve_map *prev = head;
-
-   while (*tail) {
-      if ((*tail)->level == level && (*tail)->layer == layer) {
-         (*tail)->need = need;
+   foreach_list_typed(struct intel_resolve_map, map, link, resolve_map) {
+      if (map->level == level && map->layer == layer) {
+         map->need = need;
         return;
       }
-      prev = *tail;
-      tail = &(*tail)->next;
    }
 
-   *tail = malloc(sizeof(**tail));
-   (*tail)->prev = prev;
-   (*tail)->next = NULL;
-   (*tail)->level = level;
-   (*tail)->layer = layer;
-   (*tail)->need = need;
+   struct intel_resolve_map *m = malloc(sizeof(struct intel_resolve_map));
+   exec_node_init(&m->link);
+   m->level = level;
+   m->layer = layer;
+   m->need = need;
+
+   exec_list_push_tail(resolve_map, &m->link);
 }
 
 /**
  * \brief Get an element from the map.
  * \return null if element is not contained in map.
  */
-struct intel_resolve_map*
-intel_resolve_map_get(struct intel_resolve_map *head,
+struct intel_resolve_map *
+intel_resolve_map_get(struct exec_list *resolve_map,
                      uint32_t level,
                      uint32_t layer)
 {
-   struct intel_resolve_map *item = head->next;
-
-   while (item) {
-      if (item->level == level && item->layer == layer)
-        break;
-      else
-        item = item->next;
+   foreach_list_typed(struct intel_resolve_map, map, link, resolve_map) {
+      if (map->level == level && map->layer == layer)
+         return map;
    }
 
-   return item;
+   return NULL;
 }
 
 /**
@@ -85,10 +77,7 @@ intel_resolve_map_get(struct intel_resolve_map *head,
 void
 intel_resolve_map_remove(struct intel_resolve_map *elem)
 {
-   if (elem->prev)
-      elem->prev->next = elem->next;
-   if (elem->next)
-      elem->next->prev = elem->prev;
+   exec_node_remove(&elem->link);
    free(elem);
 }
 
@@ -96,16 +85,11 @@ intel_resolve_map_remove(struct intel_resolve_map *elem)
  * \brief Remove and free all elements of the map.
  */
 void
-intel_resolve_map_clear(struct intel_resolve_map *head)
+intel_resolve_map_clear(struct exec_list *resolve_map)
 {
-   struct intel_resolve_map *next = head->next;
-   struct intel_resolve_map *trash;
-
-   while (next) {
-      trash = next;
-      next = next->next;
-      free(trash);
+   foreach_list_safe(node, resolve_map) {
+      free(node);
    }
 
-   head->next = NULL;
+   exec_list_make_empty(resolve_map);
 }
index 8504271f5cbd61424bcb6d7640e9ca305a98b2e1..9bb9fca045522ddfc22c71de7679b8d19e400b40 100644 (file)
@@ -24,6 +24,7 @@
 #pragma once
 
 #include <stdint.h>
+#include "glsl/list.h"
 
 #ifdef __cplusplus
 extern "C" {
@@ -73,30 +74,29 @@ enum gen6_hiz_op {
  *     necessary.
  */
 struct intel_resolve_map {
+   struct exec_node link;
+
    uint32_t level;
    uint32_t layer;
    enum gen6_hiz_op need;
-
-   struct intel_resolve_map *next;
-   struct intel_resolve_map *prev;
 };
 
 void
-intel_resolve_map_set(struct intel_resolve_map *head,
+intel_resolve_map_set(struct exec_list *resolve_map,
                      uint32_t level,
                      uint32_t layer,
                      enum gen6_hiz_op need);
 
-struct intel_resolve_map*
-intel_resolve_map_get(struct intel_resolve_map *head,
+struct intel_resolve_map *
+intel_resolve_map_get(struct exec_list *resolve_map,
                      uint32_t level,
                      uint32_t layer);
 
 void
-intel_resolve_map_remove(struct intel_resolve_map *elem);
+intel_resolve_map_remove(struct intel_resolve_map *resolve_map);
 
 void
-intel_resolve_map_clear(struct intel_resolve_map *head);
+intel_resolve_map_clear(struct exec_list *resolve_map);
 
 #ifdef __cplusplus
 } /* extern "C" */