Path: blob/21.2-virgl/src/intel/vulkan/tests/block_pool_grow_first.c
4547 views
/*1* Copyright © 2015 Intel Corporation2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING19* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS20* IN THE SOFTWARE.21*/2223#include "anv_private.h"24#include "test_common.h"2526int main(void)27{28struct anv_physical_device physical_device = {29.use_softpin = true,30};31struct anv_device device = {32.physical = &physical_device,33};34struct anv_block_pool pool;3536/* Create a pool with initial size smaller than the block allocated, so37* that it must grow in the first allocation.38*/39const uint32_t block_size = 16 * 1024;40const uint32_t initial_size = block_size / 2;4142pthread_mutex_init(&device.mutex, NULL);43anv_bo_cache_init(&device.bo_cache);44anv_block_pool_init(&pool, &device, "test", 4096, initial_size);45ASSERT(pool.size == initial_size);4647uint32_t padding;48int32_t offset = anv_block_pool_alloc(&pool, block_size, &padding);4950/* Pool will have grown at least space to fit the new allocation. */51ASSERT(pool.size > initial_size);52ASSERT(pool.size >= initial_size + block_size);5354/* The whole initial size is considered padding and the allocation should be55* right next to it.56*/57ASSERT(padding == initial_size);58ASSERT(offset == initial_size);5960/* Use the memory to ensure it is valid. */61void *map = anv_block_pool_map(&pool, offset, block_size);62memset(map, 22, block_size);6364anv_block_pool_finish(&pool);65}666768