@@ -2255,87 +2255,42 @@ impl super::Adapter {
22552255 signal_semaphores : Default :: default ( ) ,
22562256 } ;
22572257
2258- let mem_allocator = {
2259- let limits = self . phd_capabilities . properties . limits ;
2260-
2261- // Note: the parameters here are not set in stone nor where they picked with
2262- // strong confidence.
2263- // `final_free_list_chunk` should be bigger than starting_free_list_chunk if
2264- // we want the behavior of starting with smaller block sizes and using larger
2265- // ones only after we observe that the small ones aren't enough, which I think
2266- // is a good "I don't know what the workload is going to be like" approach.
2267- //
2268- // For reference, `VMA`, and `gpu_allocator` both start with 256 MB blocks
2269- // (then VMA doubles the block size each time it needs a new block).
2270- // At some point it would be good to experiment with real workloads
2271- //
2272- // TODO(#5925): The plan is to switch the Vulkan backend from `gpu_alloc` to
2273- // `gpu_allocator` which has a different (simpler) set of configuration options.
2274- //
2275- // TODO: These parameters should take hardware capabilities into account.
2276- let mb = 1024 * 1024 ;
2277- let perf_cfg = gpu_alloc:: Config {
2278- starting_free_list_chunk : 128 * mb,
2279- final_free_list_chunk : 512 * mb,
2280- minimal_buddy_size : 1 ,
2281- initial_buddy_dedicated_size : 8 * mb,
2282- dedicated_threshold : 32 * mb,
2283- preferred_dedicated_threshold : mb,
2284- transient_dedicated_threshold : 128 * mb,
2285- } ;
2286- let mem_usage_cfg = gpu_alloc:: Config {
2287- starting_free_list_chunk : 8 * mb,
2288- final_free_list_chunk : 64 * mb,
2289- minimal_buddy_size : 1 ,
2290- initial_buddy_dedicated_size : 8 * mb,
2291- dedicated_threshold : 8 * mb,
2292- preferred_dedicated_threshold : mb,
2293- transient_dedicated_threshold : 16 * mb,
2294- } ;
2295- let config = match memory_hints {
2296- wgt:: MemoryHints :: Performance => perf_cfg,
2297- wgt:: MemoryHints :: MemoryUsage => mem_usage_cfg,
2298- wgt:: MemoryHints :: Manual {
2299- suballocated_device_memory_block_size,
2300- } => gpu_alloc:: Config {
2301- starting_free_list_chunk : suballocated_device_memory_block_size. start ,
2302- final_free_list_chunk : suballocated_device_memory_block_size. end ,
2303- initial_buddy_dedicated_size : suballocated_device_memory_block_size. start ,
2304- ..perf_cfg
2305- } ,
2306- } ;
2307-
2308- let max_memory_allocation_size =
2309- if let Some ( maintenance_3) = self . phd_capabilities . maintenance_3 {
2310- maintenance_3. max_memory_allocation_size
2311- } else {
2312- u64:: MAX
2313- } ;
2314- let properties = gpu_alloc:: DeviceProperties {
2315- max_memory_allocation_count : limits. max_memory_allocation_count ,
2316- max_memory_allocation_size,
2317- non_coherent_atom_size : limits. non_coherent_atom_size ,
2318- memory_types : memory_types
2319- . iter ( )
2320- . map ( |memory_type| gpu_alloc:: MemoryType {
2321- props : gpu_alloc:: MemoryPropertyFlags :: from_bits_truncate (
2322- memory_type. property_flags . as_raw ( ) as u8 ,
2323- ) ,
2324- heap : memory_type. heap_index ,
2325- } )
2326- . collect ( ) ,
2327- memory_heaps : mem_properties
2328- . memory_heaps_as_slice ( )
2329- . iter ( )
2330- . map ( |& memory_heap| gpu_alloc:: MemoryHeap {
2331- size : memory_heap. size ,
2332- } )
2333- . collect ( ) ,
2334- buffer_device_address : enabled_extensions
2335- . contains ( & khr:: buffer_device_address:: NAME ) ,
2336- } ;
2337- gpu_alloc:: GpuAllocator :: new ( config, properties)
2258+ // TODO: the allocator's configuration should take hardware capability into
2259+ // account.
2260+ const MB : u64 = 1024 * 1024 ;
2261+ let allocation_sizes = match memory_hints {
2262+ wgt:: MemoryHints :: Performance => gpu_allocator:: AllocationSizes :: new ( 128 * MB , 64 * MB )
2263+ . with_max_device_memblock_size ( 256 * MB )
2264+ . with_max_host_memblock_size ( 128 * MB ) ,
2265+ wgt:: MemoryHints :: MemoryUsage => gpu_allocator:: AllocationSizes :: new ( 8 * MB , 4 * MB )
2266+ . with_max_device_memblock_size ( 64 * MB )
2267+ . with_max_host_memblock_size ( 32 * MB ) ,
2268+ wgt:: MemoryHints :: Manual {
2269+ suballocated_device_memory_block_size,
2270+ } => {
2271+ // TODO: Would it be useful to expose the host size in memory hints
2272+ // instead of always using half of the device size?
2273+ let device_size = suballocated_device_memory_block_size;
2274+ let host_size = device_size. start / 2 ..device_size. end / 2 ;
2275+
2276+ gpu_allocator:: AllocationSizes :: new ( device_size. start , host_size. start )
2277+ . with_max_device_memblock_size ( device_size. end )
2278+ . with_max_host_memblock_size ( host_size. end )
2279+ }
23382280 } ;
2281+
2282+ let buffer_device_address = enabled_extensions. contains ( & khr:: buffer_device_address:: NAME ) ;
2283+
2284+ let mem_allocator =
2285+ gpu_allocator:: vulkan:: Allocator :: new ( & gpu_allocator:: vulkan:: AllocatorCreateDesc {
2286+ instance : self . instance . raw . clone ( ) ,
2287+ device : shared. raw . clone ( ) ,
2288+ physical_device : self . raw ,
2289+ debug_settings : Default :: default ( ) ,
2290+ buffer_device_address,
2291+ allocation_sizes,
2292+ } ) ?;
2293+
23392294 let desc_allocator = gpu_descriptor:: DescriptorAllocator :: new (
23402295 if let Some ( di) = self . phd_capabilities . descriptor_indexing {
23412296 di. max_update_after_bind_descriptors_in_all_pools
0 commit comments