Skip to content
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

Add support for growing the memory block sizes #254

Merged
merged 1 commit into from
Dec 3, 2024

Conversation

nical
Copy link
Contributor

@nical nical commented Nov 5, 2024

Fixes #235.

This PR extends the AllocationsSizes configuration to define ranges of block sizes. The allocators start by allocating blocks with the minimum size and each new allocation for the same memory type doubles the block size.

This allows applications to scale memory usage more organically based on demand. While it is typically not an optimal choice for most games, it allows other types of apps that don't have well defined memory budgets to strike a good tradeoff. My own motivation comes from Firefox's WebGPU implementation. See #235 for more details.

While writing this I found out that the vulkan allocator was not taking the allocation_size parameter from its descritptor, so I fixed that along the way.

I, m not sure about how to expose this in the API. In its current state, this PR only adds to the current API and does not change anything for folks who want to stick with the current behavior (fixed block sizes).

Example:

const MB: u64 = 1024 * 1024;
// This configuration uses fixed memory block sizes.
let fixed = AllocationSizes::new(256 * MB, 64 * MB);
// This configuration starts with 8MB memory blocks
// and grows the block size of a given memory type each
// time a new allocation is needed, up to a limit of
// 256MB for device memory and 64MB for host memory.
let growing = AllocationSizes::new(8 * MB, 8 * MB)
    .with_max_device_memblock_size(256 * MB)
    .with_max_host_memblock_size(64 * MB);

But it looks a bit quirky. One might prefer to simply spell out the ranges when creating AllocationSizes. let me know what you prefer.

@nical nical force-pushed the grow branch 3 times, most recently from ee4313e to b68e05e Compare November 6, 2024 10:47
@Jasper-Bekkers
Copy link
Member

@nical Please sign the commits so they can be merged.

And fix the vulkan allocator ignoring the allocation_sizes parameter.
@nical
Copy link
Contributor Author

nical commented Dec 2, 2024

There you go!

@Jasper-Bekkers Jasper-Bekkers merged commit e6dbe11 into Traverse-Research:main Dec 3, 2024
13 checks passed
Copy link
Member

@MarijnS95 MarijnS95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for the late review, I missed this while not being able to work on Rust projects for a while. Code looks good, thanks! Just found a few typos and broken field references. Would you be able to provide a follow-up or should I?

src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
src/vulkan/mod.rs Show resolved Hide resolved
Comment on lines -464 to +466
let memblock_size = if self
let is_host = self
.memory_properties
.contains(vk::MemoryPropertyFlags::HOST_VISIBLE)
{
allocation_sizes.host_memblock_size
} else {
allocation_sizes.device_memblock_size
};
.contains(vk::MemoryPropertyFlags::HOST_VISIBLE);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm I wonder if is_host is the correct moniker for something that's HOST_VISIBLE but could just as well have DEVICE_LOCAL. That's the original logic though, but then this struct was always default()ed before it seems.

Same in Metal, we probably need to start representing UMA better.

src/lib.rs Show resolved Hide resolved
src/lib.rs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for growing the memory block size
3 participants