diff options
author | Rafael Antognolli <[email protected]> | 2018-12-07 16:46:37 -0800 |
---|---|---|
committer | Rafael Antognolli <[email protected]> | 2019-01-17 15:08:26 -0800 |
commit | 927ba12b53c90ebd8a2c4e3806d1052e7d604ded (patch) | |
tree | c23411f92a16dbebdf5443d1e1d80af09d4eae5a /src/intel | |
parent | 731c4adcf9b11d07e36e915ac17936259648c0c9 (diff) |
anv/tests: Adding test for the state_pool padding.
Add a test that checks that we can use the extra space allocated for
padding while allocating larger anv_states.
Reviewed-by: Jason Ekstrand <[email protected]>
Diffstat (limited to 'src/intel')
-rw-r--r-- | src/intel/vulkan/meson.build | 3 | ||||
-rw-r--r-- | src/intel/vulkan/tests/state_pool_padding.c | 73 |
2 files changed, 75 insertions, 1 deletions
diff --git a/src/intel/vulkan/meson.build b/src/intel/vulkan/meson.build index 15da828ca80..05fdeca8c25 100644 --- a/src/intel/vulkan/meson.build +++ b/src/intel/vulkan/meson.build @@ -227,7 +227,8 @@ if with_tests ) foreach t : ['block_pool_no_free', 'state_pool_no_free', - 'state_pool_free_list_only', 'state_pool'] + 'state_pool_free_list_only', 'state_pool', + 'state_pool_padding'] test( 'anv_@0@'.format(t), executable( diff --git a/src/intel/vulkan/tests/state_pool_padding.c b/src/intel/vulkan/tests/state_pool_padding.c new file mode 100644 index 00000000000..7e9c4898e78 --- /dev/null +++ b/src/intel/vulkan/tests/state_pool_padding.c @@ -0,0 +1,73 @@ +/* + * Copyright © 2018 Intel Corporation + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), + * to deal in the Software without restriction, including without limitation + * the rights to use, copy, modify, merge, publish, distribute, sublicense, + * and/or sell copies of the Software, and to permit persons to whom the + * Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice (including the next + * paragraph) shall be included in all copies or substantial portions of the + * Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS + * IN THE SOFTWARE. + */ + +#include "anv_private.h" + +int main(int argc, char **argv) +{ + struct anv_instance instance; + struct anv_device device = { + .instance = &instance, + }; + struct anv_state_pool state_pool; + + anv_state_pool_init(&state_pool, &device, 4096, 4096, EXEC_OBJECT_PINNED); + + /* Get the size of the underlying block_pool */ + struct anv_block_pool *bp = &state_pool.block_pool; + uint64_t pool_size = bp->size; + + /* Grab one so the pool has some initial usage */ + anv_state_pool_alloc(&state_pool, 16, 16); + + /* Grab a state that is the size of the initial allocation */ + struct anv_state state = anv_state_pool_alloc(&state_pool, pool_size, 16); + + /* The pool must have grown */ + assert(bp->size > pool_size); + + /* And the state must have been allocated at the end of the original size */ + assert(state.offset == pool_size); + + /* A new allocation that fits into the returned empty space should have an + * offset within the original pool size + */ + state = anv_state_pool_alloc(&state_pool, 4096, 16); + assert(state.offset + state.alloc_size <= pool_size); + + /* We should be able to allocate pool->block_size'd chunks in the returned area + */ + int left_chunks = pool_size / 4096 - 2; + for (int i = 0; i < left_chunks; i++) { + state = anv_state_pool_alloc(&state_pool, 4096, 16); + assert(state.offset + state.alloc_size <= pool_size); + } + + /* Now the next chunk to be allocated should make the pool grow again */ + pool_size = bp->size; + state = anv_state_pool_alloc(&state_pool, 4096, 16); + assert(bp->size > pool_size); + assert(state.offset == pool_size); + + anv_state_pool_finish(&state_pool); +} |