gallium/pb_cache: check parameters that are more likely to fail first
authorMarek Olšák <marek.olsak@amd.com>
Sun, 17 Jul 2016 09:59:40 +0000 (11:59 +0200)
committerMarek Olšák <marek.olsak@amd.com>
Tue, 19 Jul 2016 21:45:06 +0000 (23:45 +0200)
This makes Bioshock Infinite with deferred flushing 2% faster.

Reviewed-by: Nicolai Hähnle <nicolai.haehnle@amd.com>
src/gallium/auxiliary/pipebuffer/pb_cache.c

index ebd06b0e030048bc4b8bb67fb2510fa0eb6af829..6a43cbc85becb21df10a6d4d676e8f1fa4fad5fb 100644 (file)
@@ -114,25 +114,24 @@ static int
 pb_cache_is_buffer_compat(struct pb_cache_entry *entry,
                           pb_size size, unsigned alignment, unsigned usage)
 {
+   struct pb_cache *mgr = entry->mgr;
    struct pb_buffer *buf = entry->buffer;
 
-   if (usage & entry->mgr->bypass_usage)
-      return 0;
-
-   if (buf->size < size)
+   if (!pb_check_usage(usage, buf->usage))
       return 0;
 
    /* be lenient with size */
-   if (buf->size > (unsigned) (entry->mgr->size_factor * size))
+   if (buf->size < size ||
+       buf->size > (unsigned) (mgr->size_factor * size))
       return 0;
 
-   if (!pb_check_alignment(alignment, buf->alignment))
+   if (usage & mgr->bypass_usage)
       return 0;
 
-   if (!pb_check_usage(usage, buf->usage))
+   if (!pb_check_alignment(alignment, buf->alignment))
       return 0;
 
-   return entry->mgr->can_reclaim(buf) ? 1 : -1;
+   return mgr->can_reclaim(buf) ? 1 : -1;
 }
 
 /**