[Mesa-dev] [PATCH 02/18] anv/allocator: Return a null state for zero-size allocations

Jason Ekstrand jason at jlekstrand.net
Wed Apr 26 14:35:01 UTC 2017


---
 src/intel/vulkan/anv_allocator.c | 9 +++++++++
 src/intel/vulkan/anv_private.h   | 2 ++
 2 files changed, 11 insertions(+)

diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c
index 594cf49..d93d4c9 100644
--- a/src/intel/vulkan/anv_allocator.c
+++ b/src/intel/vulkan/anv_allocator.c
@@ -705,6 +705,9 @@ anv_state_pool_alloc_no_vg(struct anv_state_pool *pool,
 struct anv_state
 anv_state_pool_alloc(struct anv_state_pool *pool, size_t size, size_t align)
 {
+   if (size == 0)
+      return ANV_STATE_NULL;
+
    struct anv_state state = anv_state_pool_alloc_no_vg(pool, size, align);
    VG(VALGRIND_MEMPOOL_ALLOC(pool, state.map, size));
    return state;
@@ -726,6 +729,9 @@ anv_state_pool_free_no_vg(struct anv_state_pool *pool, struct anv_state state)
 void
 anv_state_pool_free(struct anv_state_pool *pool, struct anv_state state)
 {
+   if (state.alloc_size == 0)
+      return;
+
    VG(VALGRIND_MEMPOOL_FREE(pool, state.map));
    anv_state_pool_free_no_vg(pool, state);
 }
@@ -786,6 +792,9 @@ struct anv_state
 anv_state_stream_alloc(struct anv_state_stream *stream,
                        uint32_t size, uint32_t alignment)
 {
+   if (size == 0)
+      return ANV_STATE_NULL;
+
    struct anv_state_stream_block *sb = stream->block;
 
    struct anv_state state;
diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h
index dbe1e04..6ee8f54 100644
--- a/src/intel/vulkan/anv_private.h
+++ b/src/intel/vulkan/anv_private.h
@@ -490,6 +490,8 @@ struct anv_state {
    void *map;
 };
 
+#define ANV_STATE_NULL ((struct anv_state) { .alloc_size = 0 })
+
 struct anv_fixed_size_state_pool {
    size_t state_size;
    union anv_free_list free_list;
-- 
2.5.0.400.gff86faf



More information about the mesa-dev mailing list