Skip to content

Commit 594d4bc

Browse files
committed
Port Vulkan backend to in-tree suballocator
Port the Vulkan backend off gpu-allocator onto the new in-repo wgpu-block-pool / wgpu-offset-allocator crates via a new vulkan/suballocation.rs (VMA-style memory-type selection, per-heap block sizing, dedicated-allocation heuristics, budget gating, persistent mapping). Vulkan no longer references lib.rs's shared AllocationSizes; it uses a local BlockSizePolicy instead. Also hardens acceleration-structure buffer alignment and fixes device-memory leaks on error paths. The dx12 backend still uses gpu-allocator, so the shared gpu_allocator glue in lib.rs (gated on any(dx12, vulkan)) is kept; the gpu-allocator crate remains a wgpu-hal dependency (its vulkan feature is dropped, its d3d12 feature retained). Removing that glue is a follow-up once dx12 is ported too.
1 parent 47c2eca commit 594d4bc

6 files changed

Lines changed: 2091 additions & 263 deletions

File tree

Cargo.lock

Lines changed: 2 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

wgpu-hal/Cargo.toml

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,12 @@ vulkan = [
9494
"dep:arrayvec",
9595
"dep:ash",
9696
"dep:bytemuck",
97+
# The vulkan backend no longer uses gpu-allocator, but the shared
98+
# `gpu_allocator`-based glue in `lib.rs` is still gated on `any(dx12, vulkan)`
99+
# (the dx12 backend continues to use it). Keep the crate available - without its
100+
# `vulkan` feature - so `lib.rs` compiles in vulkan-only builds. Removing that glue
101+
# (and this dependency) is a follow-up once dx12 is ported too.
102+
"dep:gpu-allocator",
97103
"dep:libc",
98104
"dep:libloading",
99105
"dep:ordered-float",
@@ -103,7 +109,8 @@ vulkan = [
103109
"dep:smallvec",
104110
"dep:windows",
105111
"dep:windows-core",
106-
"gpu-allocator/vulkan",
112+
"dep:wgpu-block-pool",
113+
"dep:wgpu-offset-allocator",
107114
"windows/Win32",
108115
"windows/Win32_Devices_Display",
109116
"windows/Win32_Foundation",
@@ -211,6 +218,9 @@ naga.workspace = true
211218
wgpu-naga-bridge.workspace = true
212219
naga-types = { workspace = true }
213220
wgpu-types = { workspace = true, default-features = false }
221+
# Backend: Vulkan (in-repo suballocator)
222+
wgpu-block-pool = { workspace = true, optional = true }
223+
wgpu-offset-allocator = { workspace = true, optional = true }
214224

215225
# Dependencies in the lib and empty backend
216226
bitflags.workspace = true

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ use core::{ffi::CStr, marker::PhantomData};
44
use ash::{ext, google, khr, vk};
55
use parking_lot::Mutex;
66

7-
use crate::{vulkan::semaphore_list::SemaphoreList, AllocationSizes};
7+
use crate::vulkan::semaphore_list::SemaphoreList;
88

99
use super::semaphore_list::SemaphoreListMode;
1010

@@ -2910,6 +2910,7 @@ impl super::Adapter {
29102910
drop_guard,
29112911
instance: Arc::clone(&self.instance),
29122912
physical_device: self.raw,
2913+
device_api_version: self.phd_capabilities.device_api_version,
29132914
enabled_extensions: enabled_extensions.into(),
29142915
extension_fns: super::DeviceExtensionFunctions {
29152916
debug_utils: debug_utils_fn,
@@ -2948,19 +2949,18 @@ impl super::Adapter {
29482949
wait_semaphores: Mutex::new(SemaphoreList::new(SemaphoreListMode::Wait)),
29492950
};
29502951

2951-
let allocation_sizes = AllocationSizes::from_memory_hints(memory_hints).into();
2952-
2952+
let memory_budget_supported = enabled_extensions.contains(&ext::memory_budget::NAME);
29532953
let buffer_device_address = enabled_extensions.contains(&khr::buffer_device_address::NAME);
29542954

2955-
let mem_allocator =
2956-
gpu_allocator::vulkan::Allocator::new(&gpu_allocator::vulkan::AllocatorCreateDesc {
2957-
instance: self.instance.raw.clone(),
2958-
device: shared.raw.clone(),
2959-
physical_device: self.raw,
2960-
debug_settings: Default::default(),
2961-
buffer_device_address,
2962-
allocation_sizes,
2963-
})?;
2955+
let mem_allocator = super::suballocation::Allocator::new(
2956+
&mem_properties,
2957+
&self.phd_capabilities.properties.limits,
2958+
valid_ash_memory_types,
2959+
memory_hints,
2960+
self.instance.memory_budget_thresholds,
2961+
memory_budget_supported,
2962+
buffer_device_address,
2963+
);
29642964

29652965
let desc_allocator = super::descriptor::DescriptorAllocator::new(
29662966
if let Some(di) = self.phd_capabilities.descriptor_indexing {
@@ -2974,7 +2974,6 @@ impl super::Adapter {
29742974
shared,
29752975
mem_allocator: Mutex::new(mem_allocator),
29762976
desc_allocator: Mutex::new(desc_allocator),
2977-
valid_ash_memory_types,
29782977
naga_options,
29792978
#[cfg(feature = "renderdoc")]
29802979
render_doc: Default::default(),

0 commit comments

Comments
 (0)