Path: blob/21.2-virgl/src/intel/vulkan/tests/state_pool_padding.c
4547 views
/*1* Copyright © 2018 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_state_pool state_pool;3536pthread_mutex_init(&device.mutex, NULL);37anv_bo_cache_init(&device.bo_cache);38anv_state_pool_init(&state_pool, &device, "test", 4096, 0, 4096);3940/* Get the size of the underlying block_pool */41struct anv_block_pool *bp = &state_pool.block_pool;42uint64_t pool_size = bp->size;4344/* Grab one so the pool has some initial usage */45anv_state_pool_alloc(&state_pool, 16, 16);4647/* Grab a state that is the size of the initial allocation */48struct anv_state state = anv_state_pool_alloc(&state_pool, pool_size, 16);4950/* The pool must have grown */51ASSERT(bp->size > pool_size);5253/* And the state must have been allocated at the end of the original size */54ASSERT(state.offset == pool_size);5556/* A new allocation that fits into the returned empty space should have an57* offset within the original pool size58*/59state = anv_state_pool_alloc(&state_pool, 4096, 16);60ASSERT(state.offset + state.alloc_size <= pool_size);6162/* We should be able to allocate pool->block_size'd chunks in the returned area63*/64int left_chunks = pool_size / 4096 - 2;65for (int i = 0; i < left_chunks; i++) {66state = anv_state_pool_alloc(&state_pool, 4096, 16);67ASSERT(state.offset + state.alloc_size <= pool_size);68}6970/* Now the next chunk to be allocated should make the pool grow again */71pool_size = bp->size;72state = anv_state_pool_alloc(&state_pool, 4096, 16);73ASSERT(bp->size > pool_size);74ASSERT(state.offset == pool_size);7576anv_state_pool_finish(&state_pool);77}787980