From 4bfaecc340e4f5eb0d2e73f4c810ac008f89fa82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cle=CC=81ment=20Foucault?= Date: Mon, 2 Dec 2024 17:34:28 +0100 Subject: [PATCH] Fix #131212: Metal: Non-aligned circular buffer allocation logic The new buffer size could have been non aligned when using the fractional growing heuristic. This non aligned allocation would then trigger an assert at the SSBO constructor. Aligning the alocation size fixes the issue. --- source/blender/gpu/metal/mtl_memory.mm | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/blender/gpu/metal/mtl_memory.mm b/source/blender/gpu/metal/mtl_memory.mm index ff0da6a6657..6a77df92c5e 100644 --- a/source/blender/gpu/metal/mtl_memory.mm +++ b/source/blender/gpu/metal/mtl_memory.mm @@ -990,9 +990,9 @@ MTLTemporaryBuffer MTLCircularBuffer::allocate_range_aligned(uint64_t alloc_size /* Resize to the maximum of basic resize heuristic OR the size of the current offset + * requested allocation -- we want the buffer to grow to a large enough size such that it * does not need to resize mid-frame. */ - new_size = max_ulul( - min_ulul(MTLScratchBufferManager::mtl_scratch_buffer_max_size_, new_size * 1.2), - aligned_current_offset + aligned_alloc_size); + new_size = max_ulul(min_ulul(MTLScratchBufferManager::mtl_scratch_buffer_max_size_, + ceil_to_multiple_ul(new_size * 1.2f, 256)), + aligned_current_offset + aligned_alloc_size); #ifdef MTL_SCRATCH_BUFFER_ALLOW_TEMPORARY_EXPANSION /* IF a requested allocation EXCEEDS the maximum supported size, temporarily allocate up to