-
Notifications
You must be signed in to change notification settings - Fork 437
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
Switch to a more expressive way to specify memory usage #2264
Conversation
vulkano/src/memory/allocator/mod.rs
Outdated
} | ||
HostAccessType::RandomAccess => { | ||
filter.required_flags |= | ||
MemoryPropertyFlags::HOST_VISIBLE | MemoryPropertyFlags::HOST_CACHED; |
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 HOST_CACHED
be a strict requirement here?
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.
I don't like it either, but I think it's needed because of this scenario:
DEVICE_LOCAL
DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT
HOST_VISIBLE | HOST_COHERENT
HOST_VISIBLE | HOST_COHERENT | HOST_CACHED
Here, preferring DEVICE_LOCAL
and HOST_CACHED
would result in a tie, and you would get the memory type at index 1 which is, quite literally, the worst possible choice here.
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.
Not every device is required to have HOST_CACHED
memory, so asking for RandomAccess
would fail on such a device, which is bad.
The problem I also see is that you're treating both flags as equally important, when they aren't necessarily. Is the caching more important, or being on the device?
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.
I'm aware that it's not required by the spec, however in practice they all have it. Maybe we should ask the VMA guys why they thought its ok?
The problem I also see is that you're treating both flags as equally important, when they aren't necessarily.
Well yes, that is an inherent problem coming from the fact that MemoryTypeFilter::preferred_flags
is just a list of flags, no weights.
So I thought about it some more, and since I plan on adding a This might be a bit hard to understand for the user, which is why I think we could simplify this even more and only have the |
How does this look? AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::PREFER_HOST | MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
..Default::default()
} Or maybe even AllocationCreateInfo {
memory_type_filter: MemoryTypeFilter::STAGING,
..Default::default()
} I would prefer not to complicate things at the possible prospect of doing more black magic inside the allocator. I don't think that's that useful anyway. If we ever need to create a |
Nice, I like it! Using Rust features in ways that don't work for a C API! |
Everything good, thanks! |
Previously there were these memory usages:
MemoryUsage
DeviceOnly
DEVICE_LOCAL
Upload
DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT
Download
HOST_VISIBLE | HOST_CACHED
However, almost all PC and laptop implementations also have a memory type that is
HOST_VISIBLE | HOST_COHERENT
, which was not possible to request using those, which is the biggest reason for this change. However, some other implementations have more quirky memory types as well, such aDEVICE_LOCAL | HOST_VISIBLE | HOST_CACHED
memory type on MacOS and mobile devices. It was also not possible to distinguish between that and the non-device-local host-cached one.Here's all the combinations possible now, using the presets available as associated constants of
MemoryTypeFilter
:MemoryTypeFilter
PREFER_DEVICE
DEVICE_LOCAL
PREFER_DEVICE | HOST_SEQUENTIAL_WRITE
DEVICE_LOCAL | HOST_VISIBLE | HOST_COHERENT
PREFER_DEVICE | HOST_RANDOM_ACCESS
DEVICE_LOCAL | HOST_VISIBLE | HOST_CACHED
PREFER_HOST
PREFER_HOST | HOST_SEQUENTIAL_WRITE
HOST_VISIBLE | HOST_COHERENT
PREFER_HOST | HOST_RANDOM_ACCESS
HOST_VISIBLE | HOST_CACHED
There are of course still some memory types that can't be differentiated, such as in the case of
MemoryTypeFilter::HOST_RANDOM_ACCESS
, there might be bothHOST_VISIBLE | HOST_CACHED
andHOST_VISIBLE | HOST_COHERENT | HOST_CACHED
around. If the user truly needs something that specialized, then they should specify the memory type filter manually.Changelog: