diff options
author | Lionel Landwerlin <lionel.g.landwerlin@intel.com> | 2022-11-16 20:34:24 +0200 |
---|---|---|
committer | Eric Engestrom <eric@engestrom.ch> | 2022-11-23 19:11:58 +0000 |
commit | 9476566032083aca02e01f78425ec28dca15e9ad (patch) | |
tree | 65233a80d754a140ddd11dfc09e2f41882545fb5 | |
parent | 9a31d05b011b15ebbc6c241882345408e502b77d (diff) | |
download | mesa-9476566032083aca02e01f78425ec28dca15e9ad.tar.gz |
anv: get rid of ilog2_round_up
__builtin_clz(value - 1) is undefined for with value=1 (because
__builtin_clz(0) is undefined).
Because we set rt_pipeline->stack_size = 1 when a ray tracing pipeline
doesn't need any stack allocation to differentiate from a dynamic size
(rt_pipeline->stack_size = 0) we can run into this undefinied behavior
issue.
Signed-off-by: Lionel Landwerlin <lionel.g.landwerlin@intel.com>
Fixes: f68d64dac015 ("anv: Add support for vkCmdSetRayTracingPipelineStackSizeKHR")
Reviewed-by: Marcin Ĺšlusarz <marcin.slusarz@intel.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/19781>
(cherry picked from commit 440da44a84022ec63e87e2c5a55ad03a244697a4)
-rw-r--r-- | .pick_status.json | 2 | ||||
-rw-r--r-- | src/intel/vulkan/anv_allocator.c | 21 | ||||
-rw-r--r-- | src/intel/vulkan/anv_cmd_buffer.c | 11 |
3 files changed, 7 insertions, 27 deletions
diff --git a/.pick_status.json b/.pick_status.json index 789b6ea4159..0c2032d79d9 100644 --- a/.pick_status.json +++ b/.pick_status.json @@ -2677,7 +2677,7 @@ "description": "anv: get rid of ilog2_round_up", "nominated": true, "nomination_type": 1, - "resolution": 0, + "resolution": 1, "main_sha": null, "because_sha": "f68d64dac01505560a53aabe2b8616685cace0c2" }, diff --git a/src/intel/vulkan/anv_allocator.c b/src/intel/vulkan/anv_allocator.c index 57c554d63b1..12f502f40be 100644 --- a/src/intel/vulkan/anv_allocator.c +++ b/src/intel/vulkan/anv_allocator.c @@ -113,19 +113,6 @@ #define PAGE_SIZE 4096 #endif -static inline uint32_t -ilog2_round_up(uint32_t value) -{ - assert(value != 0); - return 32 - __builtin_clz(value - 1); -} - -static inline uint32_t -round_to_power_of_two(uint32_t value) -{ - return 1 << ilog2_round_up(value); -} - struct anv_state_table_cleanup { void *map; size_t size; @@ -734,7 +721,7 @@ anv_fixed_size_state_pool_alloc_new(struct anv_fixed_size_state_pool *pool, static uint32_t anv_state_pool_get_bucket(uint32_t size) { - unsigned size_log2 = ilog2_round_up(size); + unsigned size_log2 = util_logbase2_ceil(size); assert(size_log2 <= ANV_MAX_STATE_SIZE_LOG2); if (size_log2 < ANV_MIN_STATE_SIZE_LOG2) size_log2 = ANV_MIN_STATE_SIZE_LOG2; @@ -1023,7 +1010,7 @@ anv_state_stream_alloc(struct anv_state_stream *stream, if (offset + size > stream->block.alloc_size) { uint32_t block_size = stream->block_size; if (block_size < size) - block_size = round_to_power_of_two(size); + block_size = util_next_power_of_two(size); stream->block = anv_state_pool_alloc_no_vg(stream->state_pool, block_size, PAGE_SIZE); @@ -1143,7 +1130,7 @@ VkResult anv_bo_pool_alloc(struct anv_bo_pool *pool, uint32_t size, struct anv_bo **bo_out) { - const unsigned size_log2 = size < 4096 ? 12 : ilog2_round_up(size); + const unsigned size_log2 = size < 4096 ? 12 : util_logbase2_ceil(size); const unsigned pow2_size = 1 << size_log2; const unsigned bucket = size_log2 - 12; assert(bucket < ARRAY_SIZE(pool->free_list)); @@ -1180,7 +1167,7 @@ anv_bo_pool_free(struct anv_bo_pool *pool, struct anv_bo *bo) VG(VALGRIND_MEMPOOL_FREE(pool, bo->map)); assert(util_is_power_of_two_or_zero(bo->size)); - const unsigned size_log2 = ilog2_round_up(bo->size); + const unsigned size_log2 = util_logbase2_ceil(bo->size); const unsigned bucket = size_log2 - 12; assert(bucket < ARRAY_SIZE(pool->free_list)); diff --git a/src/intel/vulkan/anv_cmd_buffer.c b/src/intel/vulkan/anv_cmd_buffer.c index 8a41e0c3cd7..e116ae3746c 100644 --- a/src/intel/vulkan/anv_cmd_buffer.c +++ b/src/intel/vulkan/anv_cmd_buffer.c @@ -318,13 +318,6 @@ set_dirty_for_bind_map(struct anv_cmd_buffer *cmd_buffer, cmd_buffer->state.push_constants_dirty |= mesa_to_vk_shader_stage(stage); } -static inline uint32_t -ilog2_round_up(uint32_t value) -{ - assert(value != 0); - return 32 - __builtin_clz(value - 1); -} - static void anv_cmd_buffer_set_ray_query_buffer(struct anv_cmd_buffer *cmd_buffer, struct anv_cmd_pipeline_state *pipeline_state, @@ -340,7 +333,7 @@ anv_cmd_buffer_set_ray_query_buffer(struct anv_cmd_buffer *cmd_buffer, if (ray_shadow_size > 0 && (!cmd_buffer->state.ray_query_shadow_bo || cmd_buffer->state.ray_query_shadow_bo->size < ray_shadow_size)) { - unsigned shadow_size_log2 = MAX2(ilog2_round_up(ray_shadow_size), 16); + unsigned shadow_size_log2 = MAX2(util_logbase2_ceil(ray_shadow_size), 16); unsigned bucket = shadow_size_log2 - 16; assert(bucket < ARRAY_SIZE(device->ray_query_shadow_bos)); @@ -1076,7 +1069,7 @@ void anv_CmdSetRayTracingPipelineStackSizeKHR( uint32_t stack_ids_per_dss = 2048; /* TODO */ - unsigned stack_size_log2 = ilog2_round_up(pipelineStackSize); + unsigned stack_size_log2 = util_logbase2_ceil(pipelineStackSize); if (stack_size_log2 < 10) stack_size_log2 = 10; |