-
Notifications
You must be signed in to change notification settings - Fork 546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
hal: dedicated buffer/image memory #2929
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -411,6 +411,24 @@ pub trait Device<B: Backend>: 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( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To actually do that more efficiently, the function must return a view into memory with offset and size. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The user is expected to still call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh, so this will work only for dedicated allocations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I thought we want to integrate vma into vulkan backend this way There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think what we can do with VMA is:
Does that sound reasonable? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So the memory type exposed by the Vulkan backend would be: enum Memory {
Physical(vk::Memory),
SubAllocated(vma::Allocation),
} Mapping a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If VMA has no limitations here. Rendy has to map all non-dedicated mappable memory persistently to allow this, which is not optimal. I wonder how VMA does that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Is it, really? My understanding is that it's both optimal and recommended for CPU-visible memory. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's not a problem when RAM is abundant, like on typical modern PC. But in other cases it may be not the best approach. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks like it doesn't map memory by default on creation, unless there is a specific flag provided. Relevant docs - https://gpuopen-librariesandsdks.github.io/VulkanMemoryAllocator/html/memory_mapping.html |
||
&self, | ||
memory_type: MemoryTypeId, | ||
buffer: &mut B::Buffer, | ||
) -> Result<B::Memory, BindError> { | ||
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<B: Backend>: 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<B::Memory, BindError> { | ||
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, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should be removed