diff --git a/src/backend/vulkan/Cargo.toml b/src/backend/vulkan/Cargo.toml index cff5f3068cc..70a55946bf7 100644 --- a/src/backend/vulkan/Cargo.toml +++ b/src/backend/vulkan/Cargo.toml @@ -29,6 +29,7 @@ ash = "0.29.0" gfx-hal = { path = "../../hal", version = "0.2" } smallvec = "0.6" winit = { version = "0.19", optional = true } +#vk-mem = { version = "0.1", optional = true } [target.'cfg(windows)'.dependencies] winapi = { version = "0.3", features = ["libloaderapi", "windef", "winuser"] } diff --git a/src/hal/src/device.rs b/src/hal/src/device.rs index 88076fc70f1..2ab3cd50ba3 100644 --- a/src/hal/src/device.rs +++ b/src/hal/src/device.rs @@ -411,6 +411,24 @@ pub trait Device: fmt::Debug + Any + Send + Sync { buf: &mut B::Buffer, ) -> Result<(), BindError>; + /// Create a dedicated allocation for a buffer. + /// + /// Returns a memory object that can't be used for binding any resources. + unsafe fn allocate_buffer_memory( + &self, + memory_type: MemoryTypeId, + buffer: &mut B::Buffer, + ) -> Result { + let req = self.get_buffer_requirements(buffer); + let memory = self.allocate_memory(memory_type, req.size) + .map_err(|err| match err { + AllocationError::OutOfMemory(oom) => BindError::OutOfMemory(oom), + AllocationError::TooManyObjects => BindError::OutOfBounds, + })?; + self.bind_buffer_memory(&memory, 0, buffer) + .map(|()| memory) + } + /// Destroy a buffer. /// /// The buffer shouldn't be destroyed before any submitted command buffer, @@ -457,6 +475,24 @@ pub trait Device: fmt::Debug + Any + Send + Sync { image: &mut B::Image, ) -> Result<(), BindError>; + /// Create a dedicated allocation for an image. + /// + /// Returns a memory object that can't be used for binding any resources. + unsafe fn allocate_image_memory( + &self, + memory_type: MemoryTypeId, + image: &mut B::Image, + ) -> Result { + let req = self.get_image_requirements(image); + let memory = self.allocate_memory(memory_type, req.size) + .map_err(|err| match err { + AllocationError::OutOfMemory(oom) => BindError::OutOfMemory(oom), + AllocationError::TooManyObjects => BindError::OutOfBounds, + })?; + self.bind_image_memory(&memory, 0, image) + .map(|()| memory) + } + /// Destroy an image. /// /// The image shouldn't be destroyed before any submitted command buffer,