From 5f57ff7e18c1c545aafcdc267bc22594cef81d3c Mon Sep 17 00:00:00 2001 From: Jason Ekstrand Date: Tue, 15 Sep 2015 17:46:09 -0700 Subject: anv/allocator: Make the block pool double-ended This allows us to allocate from either side of the block pool in a consistent way. If you use the previous block_pool_alloc function, you will get offsets from the start of the pool as normal. If you use the new block_pool_alloc_back function, you will get a negative index that corresponds to something in the "back" of the pool. --- src/vulkan/tests/block_pool_no_free.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) (limited to 'src/vulkan/tests') diff --git a/src/vulkan/tests/block_pool_no_free.c b/src/vulkan/tests/block_pool_no_free.c index 71eb90103ef..01c23e21b2d 100644 --- a/src/vulkan/tests/block_pool_no_free.c +++ b/src/vulkan/tests/block_pool_no_free.c @@ -34,14 +34,18 @@ struct job { unsigned id; struct anv_block_pool *pool; uint32_t blocks[BLOCKS_PER_THREAD]; + uint32_t back_blocks[BLOCKS_PER_THREAD]; } jobs[NUM_THREADS]; + static void *alloc_blocks(void *_job) { struct job *job = _job; - for (unsigned i = 0; i < BLOCKS_PER_THREAD; i++) + for (unsigned i = 0; i < BLOCKS_PER_THREAD; i++) { job->blocks[i] = anv_block_pool_alloc(job->pool); + job->back_blocks[i] = -anv_block_pool_alloc_back(job->pool); + } return NULL; } @@ -98,10 +102,15 @@ static void run_test() for (unsigned i = 0; i < NUM_THREADS; i++) pthread_join(jobs[i].thread, NULL); + /* Validate that the block allocations were monotonic */ uint32_t *block_ptrs[NUM_THREADS]; for (unsigned i = 0; i < NUM_THREADS; i++) block_ptrs[i] = jobs[i].blocks; + validate_monotonic(block_ptrs); + /* Validate that the back block allocations were monotonic */ + for (unsigned i = 0; i < NUM_THREADS; i++) + block_ptrs[i] = jobs[i].back_blocks; validate_monotonic(block_ptrs); anv_block_pool_finish(&pool); -- cgit v1.2.3