Module: Mesa Branch: main Commit: cc67bd48d957a9402009049f31948dd71be99a92 URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=cc67bd48d957a9402009049f31948dd71be99a92
Author: Lionel Landwerlin <lionel.g.landwer...@intel.com> Date: Thu Oct 12 11:10:24 2023 +0300 anv: add max_size argument for block & state pools Not enforced yet. Signed-off-by: Lionel Landwerlin <lionel.g.landwer...@intel.com> Reviewed-by: Tapani Pälli <tapani.pa...@intel.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/25955> --- src/intel/vulkan/anv_allocator.c | 31 ++++---- src/intel/vulkan/anv_device.c | 93 +++++++++++++++------- src/intel/vulkan/anv_private.h | 20 +++-- src/intel/vulkan/tests/block_pool_grow_first.c | 3 +- src/intel/vulkan/tests/block_pool_no_free.c | 3 +- src/intel/vulkan/tests/state_pool.c | 10 ++- src/intel/vulkan/tests/state_pool_free_list_only.c | 10 ++- src/intel/vulkan/tests/state_pool_no_free.c | 10 ++- src/intel/vulkan/tests/state_pool_padding.c | 10 ++- 9 files changed, 133 insertions(+), 57 deletions(-) diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index 56073b42899..fd1bba1c5b0 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -351,7 +351,8 @@ anv_block_pool_init(struct anv_block_pool *pool, struct anv_device *device, const char *name, uint64_t start_address, - uint32_t initial_size) + uint32_t initial_size, + uint64_t max_size) { VkResult result; @@ -364,6 +365,7 @@ anv_block_pool_init(struct anv_block_pool *pool, pool->nbos = 0; pool->size = 0; pool->start_address = intel_canonical_address(start_address); + pool->max_size = max_size; pool->bo = NULL; @@ -627,23 +629,20 @@ anv_block_pool_alloc(struct anv_block_pool *pool, VkResult anv_state_pool_init(struct anv_state_pool *pool, struct anv_device *device, - const char *name, - uint64_t base_address, - int32_t start_offset, - uint32_t block_size) + const struct anv_state_pool_params *params) { - /* We don't want to ever see signed overflow */ - assert(start_offset < INT32_MAX - (int32_t)BLOCK_POOL_MEMFD_SIZE); - - uint32_t initial_size = MAX2(block_size * 16, device->info->mem_alignment); - - VkResult result = anv_block_pool_init(&pool->block_pool, device, name, - base_address + start_offset, - initial_size); + uint32_t initial_size = MAX2(params->block_size * 16, + device->info->mem_alignment); + + VkResult result = anv_block_pool_init(&pool->block_pool, device, + params->name, + params->base_address + params->start_offset, + initial_size, + params->max_size); if (result != VK_SUCCESS) return result; - pool->start_offset = start_offset; + pool->start_offset = params->start_offset; result = anv_state_table_init(&pool->table, device, 64); if (result != VK_SUCCESS) { @@ -651,8 +650,8 @@ anv_state_pool_init(struct anv_state_pool *pool, return result; } - assert(util_is_power_of_two_or_zero(block_size)); - pool->block_size = block_size; + assert(util_is_power_of_two_or_zero(params->block_size)); + pool->block_size = params->block_size; for (unsigned i = 0; i < ANV_STATE_BUCKETS; i++) { pool->buckets[i].free_list = ANV_FREE_LIST_EMPTY; pool->buckets[i].block.next = 0; diff --git a/src/intel/vulkan/anv_device.c b/src/intel/vulkan/anv_device.c index 78e1d7f5cfc..ca710fd6957 100644 --- a/src/intel/vulkan/anv_device.c +++ b/src/intel/vulkan/anv_device.c @@ -3280,14 +3280,23 @@ VkResult anv_CreateDevice( * get the correct offsets in the anv_states that get allocated from it. */ result = anv_state_pool_init(&device->general_state_pool, device, - "general pool", - 0, device->physical->va.general_state_pool.addr, 16384); + &(struct anv_state_pool_params) { + .name = "general pool", + .base_address = 0, + .start_offset = device->physical->va.general_state_pool.addr, + .block_size = 16384, + .max_size = device->physical->va.general_state_pool.size + }); if (result != VK_SUCCESS) goto fail_batch_bo_pool; result = anv_state_pool_init(&device->dynamic_state_pool, device, - "dynamic pool", - device->physical->va.dynamic_state_pool.addr, 0, 16384); + &(struct anv_state_pool_params) { + .name = "dynamic pool", + .base_address = device->physical->va.dynamic_state_pool.addr, + .block_size = 16384, + .max_size = device->physical->va.dynamic_state_pool.size, + }); if (result != VK_SUCCESS) goto fail_general_state_pool; @@ -3303,9 +3312,12 @@ VkResult anv_CreateDevice( sizeof(struct gfx8_border_color), 64); result = anv_state_pool_init(&device->instruction_state_pool, device, - "instruction pool", - device->physical->va.instruction_state_pool.addr, - 0, 16384); + &(struct anv_state_pool_params) { + .name = "instruction pool", + .base_address = device->physical->va.instruction_state_pool.addr, + .block_size = 16384, + .max_size = device->physical->va.instruction_state_pool.size, + }); if (result != VK_SUCCESS) goto fail_dynamic_state_pool; @@ -3314,31 +3326,43 @@ VkResult anv_CreateDevice( * surface state pool. */ result = anv_state_pool_init(&device->scratch_surface_state_pool, device, - "scratch surface state pool", - device->physical->va.scratch_surface_state_pool.addr, - 0, 4096); + &(struct anv_state_pool_params) { + .name = "scratch surface state pool", + .base_address = device->physical->va.scratch_surface_state_pool.addr, + .block_size = 4096, + .max_size = device->physical->va.scratch_surface_state_pool.size, + }); if (result != VK_SUCCESS) goto fail_instruction_state_pool; result = anv_state_pool_init(&device->internal_surface_state_pool, device, - "internal surface state pool", - device->physical->va.internal_surface_state_pool.addr, - device->physical->va.scratch_surface_state_pool.size, - 4096); + &(struct anv_state_pool_params) { + .name = "internal surface state pool", + .base_address = device->physical->va.internal_surface_state_pool.addr, + .start_offset = device->physical->va.scratch_surface_state_pool.size, + .block_size = 4096, + .max_size = device->physical->va.internal_surface_state_pool.size, + }); } else { result = anv_state_pool_init(&device->internal_surface_state_pool, device, - "internal surface state pool", - device->physical->va.internal_surface_state_pool.addr, - 0, 4096); + &(struct anv_state_pool_params) { + .name = "internal surface state pool", + .base_address = device->physical->va.internal_surface_state_pool.addr, + .block_size = 4096, + .max_size = device->physical->va.internal_surface_state_pool.size, + }); } if (result != VK_SUCCESS) goto fail_scratch_surface_state_pool; if (device->physical->indirect_descriptors) { result = anv_state_pool_init(&device->bindless_surface_state_pool, device, - "bindless surface state pool", - device->physical->va.bindless_surface_state_pool.addr, - 0, 4096); + &(struct anv_state_pool_params) { + .name = "bindless surface state pool", + .base_address = device->physical->va.bindless_surface_state_pool.addr, + .block_size = 4096, + .max_size = device->physical->va.bindless_surface_state_pool.size, + }); if (result != VK_SUCCESS) goto fail_internal_surface_state_pool; } @@ -3348,9 +3372,12 @@ VkResult anv_CreateDevice( * table its own base address separately from surface state base. */ result = anv_state_pool_init(&device->binding_table_pool, device, - "binding table pool", - device->physical->va.binding_table_pool.addr, 0, - BINDING_TABLE_POOL_BLOCK_SIZE); + &(struct anv_state_pool_params) { + .name = "binding table pool", + .base_address = device->physical->va.binding_table_pool.addr, + .block_size = BINDING_TABLE_POOL_BLOCK_SIZE, + .max_size = device->physical->va.binding_table_pool.size, + }); } else { /* The binding table should be in front of the surface states in virtual * address space so that all surface states can be express as relative @@ -3362,19 +3389,25 @@ VkResult anv_CreateDevice( (int64_t)device->physical->va.internal_surface_state_pool.addr; assert(INT32_MIN < bt_pool_offset && bt_pool_offset < 0); result = anv_state_pool_init(&device->binding_table_pool, device, - "binding table pool", - device->physical->va.internal_surface_state_pool.addr, - bt_pool_offset, - BINDING_TABLE_POOL_BLOCK_SIZE); + &(struct anv_state_pool_params) { + .name = "binding table pool", + .base_address = device->physical->va.internal_surface_state_pool.addr, + .start_offset = bt_pool_offset, + .block_size = BINDING_TABLE_POOL_BLOCK_SIZE, + .max_size = device->physical->va.internal_surface_state_pool.size, + }); } if (result != VK_SUCCESS) goto fail_bindless_surface_state_pool; if (device->physical->indirect_descriptors) { result = anv_state_pool_init(&device->indirect_push_descriptor_pool, device, - "indirect push descriptor pool", - device->physical->va.indirect_push_descriptor_pool.addr, - 0, 4096); + &(struct anv_state_pool_params) { + .name = "indirect push descriptor pool", + .base_address = device->physical->va.indirect_push_descriptor_pool.addr, + .block_size = 4096, + .max_size = device->physical->va.indirect_push_descriptor_pool.size, + }); if (result != VK_SUCCESS) goto fail_binding_table_pool; } diff --git a/src/intel/vulkan/anv_private.h b/src/intel/vulkan/anv_private.h index abd1d8f9a2b..c35d2b61af9 100644 --- a/src/intel/vulkan/anv_private.h +++ b/src/intel/vulkan/anv_private.h @@ -575,6 +575,10 @@ struct anv_block_pool { struct anv_bo *bo; uint32_t nbos; + /* Maximum size of the pool */ + uint64_t max_size; + + /* Current size of the pool */ uint64_t size; /* The canonical address where the start of the pool is pinned. The various bos that @@ -687,19 +691,25 @@ VkResult anv_block_pool_init(struct anv_block_pool *pool, struct anv_device *device, const char *name, uint64_t start_address, - uint32_t initial_size); + uint32_t initial_size, + uint64_t max_size); void anv_block_pool_finish(struct anv_block_pool *pool); int32_t anv_block_pool_alloc(struct anv_block_pool *pool, uint32_t block_size, uint32_t *padding); void* anv_block_pool_map(struct anv_block_pool *pool, int32_t offset, uint32_t size); +struct anv_state_pool_params { + const char *name; + uint64_t base_address; + int64_t start_offset; + uint32_t block_size; + uint64_t max_size; +}; + VkResult anv_state_pool_init(struct anv_state_pool *pool, struct anv_device *device, - const char *name, - uint64_t base_address, - int32_t start_offset, - uint32_t block_size); + const struct anv_state_pool_params *params); void anv_state_pool_finish(struct anv_state_pool *pool); struct anv_state anv_state_pool_alloc(struct anv_state_pool *pool, uint32_t state_size, uint32_t alignment); diff --git a/src/intel/vulkan/tests/block_pool_grow_first.c b/src/intel/vulkan/tests/block_pool_grow_first.c index 629d1dfcf00..49394898b89 100644 --- a/src/intel/vulkan/tests/block_pool_grow_first.c +++ b/src/intel/vulkan/tests/block_pool_grow_first.c @@ -37,13 +37,14 @@ void block_pool_grow_first_test(void) */ const uint32_t block_size = 16 * 1024; const uint32_t initial_size = block_size / 2; + const uint32_t _1Gb = 1024 * 1024 * 1024; test_device_info_init(&physical_device.info); anv_device_set_physical(&device, &physical_device); device.kmd_backend = anv_kmd_backend_get(INTEL_KMD_TYPE_STUB); pthread_mutex_init(&device.mutex, NULL); anv_bo_cache_init(&device.bo_cache, &device); - anv_block_pool_init(&pool, &device, "test", 4096, initial_size); + anv_block_pool_init(&pool, &device, "test", 4096, initial_size, _1Gb); ASSERT(pool.size == initial_size); uint32_t padding; diff --git a/src/intel/vulkan/tests/block_pool_no_free.c b/src/intel/vulkan/tests/block_pool_no_free.c index cdf8c621a31..3b1fb34c77c 100644 --- a/src/intel/vulkan/tests/block_pool_no_free.c +++ b/src/intel/vulkan/tests/block_pool_no_free.c @@ -103,13 +103,14 @@ static void run_test() struct anv_physical_device physical_device = {}; struct anv_device device = {}; struct anv_block_pool pool; + const uint32_t _1Gb = 1024 * 1024 * 1024; test_device_info_init(&physical_device.info); anv_device_set_physical(&device, &physical_device); device.kmd_backend = anv_kmd_backend_get(INTEL_KMD_TYPE_STUB); pthread_mutex_init(&device.mutex, NULL); anv_bo_cache_init(&device.bo_cache, &device); - anv_block_pool_init(&pool, &device, "test", 4096, 4096); + anv_block_pool_init(&pool, &device, "test", 4096, 4096, _1Gb); for (unsigned i = 0; i < NUM_THREADS; i++) { jobs[i].pool = &pool; diff --git a/src/intel/vulkan/tests/state_pool.c b/src/intel/vulkan/tests/state_pool.c index c54e6c971fb..20eb2a34750 100644 --- a/src/intel/vulkan/tests/state_pool.c +++ b/src/intel/vulkan/tests/state_pool.c @@ -46,8 +46,16 @@ void state_pool_test(void) anv_bo_cache_init(&device.bo_cache, &device); const unsigned num_runs = 64; + const uint32_t _1Gb = 1024 * 1024 * 1024; for (unsigned i = 0; i < num_runs; i++) { - anv_state_pool_init(&state_pool, &device, "test", 4096, 0, 256); + anv_state_pool_init(&state_pool, &device, + &(struct anv_state_pool_params) { + .name = "test", + .base_address = 4096, + .start_offset = 0, + .block_size = 256, + .max_size = _1Gb, + }); /* Grab one so a zero offset is impossible */ anv_state_pool_alloc(&state_pool, 16, 16); diff --git a/src/intel/vulkan/tests/state_pool_free_list_only.c b/src/intel/vulkan/tests/state_pool_free_list_only.c index 287384c1309..d64a8b8f827 100644 --- a/src/intel/vulkan/tests/state_pool_free_list_only.c +++ b/src/intel/vulkan/tests/state_pool_free_list_only.c @@ -34,6 +34,7 @@ void state_pool_free_list_only_test(void) { const unsigned num_threads = 8; const unsigned states_per_thread = 1 << 12; + const uint32_t _1Gb = 1024 * 1024 * 1024; struct anv_physical_device physical_device = { }; struct anv_device device = {}; @@ -44,7 +45,14 @@ void state_pool_free_list_only_test(void) device.kmd_backend = anv_kmd_backend_get(INTEL_KMD_TYPE_STUB); pthread_mutex_init(&device.mutex, NULL); anv_bo_cache_init(&device.bo_cache, &device); - anv_state_pool_init(&state_pool, &device, "test", 4096, 0, 4096); + anv_state_pool_init(&state_pool, &device, + &(struct anv_state_pool_params) { + .name = "test", + .base_address = 4096, + .start_offset = 0, + .block_size = 4096, + .max_size = _1Gb, + }); /* Grab one so a zero offset is impossible */ anv_state_pool_alloc(&state_pool, 16, 16); diff --git a/src/intel/vulkan/tests/state_pool_no_free.c b/src/intel/vulkan/tests/state_pool_no_free.c index 8777dfe0e3d..07df9b1847c 100644 --- a/src/intel/vulkan/tests/state_pool_no_free.c +++ b/src/intel/vulkan/tests/state_pool_no_free.c @@ -58,13 +58,21 @@ static void run_test() struct anv_physical_device physical_device = { }; struct anv_device device = {}; struct anv_state_pool state_pool; + const uint32_t _1Gb = 1024 * 1024 * 1024; test_device_info_init(&physical_device.info); anv_device_set_physical(&device, &physical_device); device.kmd_backend = anv_kmd_backend_get(INTEL_KMD_TYPE_STUB); pthread_mutex_init(&device.mutex, NULL); anv_bo_cache_init(&device.bo_cache, &device); - anv_state_pool_init(&state_pool, &device, "test", 4096, 0, 64); + anv_state_pool_init(&state_pool, &device, + &(struct anv_state_pool_params) { + .name = "test", + .base_address = 4096, + .start_offset = 0, + .block_size = 64, + .max_size = _1Gb, + }); pthread_barrier_init(&barrier, NULL, NUM_THREADS); diff --git a/src/intel/vulkan/tests/state_pool_padding.c b/src/intel/vulkan/tests/state_pool_padding.c index 61a4c280a3b..b9fa15f11a3 100644 --- a/src/intel/vulkan/tests/state_pool_padding.c +++ b/src/intel/vulkan/tests/state_pool_padding.c @@ -31,13 +31,21 @@ void state_pool_padding_test(void) struct anv_physical_device physical_device = {}; struct anv_device device = {}; struct anv_state_pool state_pool; + const uint32_t _1Gb = 1024 * 1024 * 1024; test_device_info_init(&physical_device.info); anv_device_set_physical(&device, &physical_device); device.kmd_backend = anv_kmd_backend_get(INTEL_KMD_TYPE_STUB); pthread_mutex_init(&device.mutex, NULL); anv_bo_cache_init(&device.bo_cache, &device); - anv_state_pool_init(&state_pool, &device, "test", 4096, 0, 4096); + anv_state_pool_init(&state_pool, &device, + &(struct anv_state_pool_params) { + .name = "test", + .base_address = 4096, + .start_offset = 0, + .block_size = 4096, + .max_size = _1Gb, + }); /* Get the size of the underlying block_pool */ struct anv_block_pool *bp = &state_pool.block_pool;