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 option to disallow increasing capacity when allocating #267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

ftilde
Copy link
Contributor

@ftilde ftilde commented Feb 28, 2025

As it turns out, exposing the capacity (#266) is not quite enough for my use case to restrict the size of the capacity (because I don't know when a new allocation would increase the capacity).

There are multiple ways I can think of on how to achieve that:

  • Adding an API to give the allocator a maximum capacity. Since there are multiple memory heaps, whose sizes and properties are not exposed to the user, I'm not sure how that should look like exactly.
  • Enabling the user to control whether (or not) the allocator increases the capacity on allocation (via a mutable property on the allocator).
  • Enabling the user to control whether a specific allocation is allowed to increase the capacity.

I the PR I (for now) implemented the latter option since I consider it to be the most flexible. I'm open to changing the implementation to one of the other options (or another idea), however.

Also note that I have only implemented the proposed change for Vulkan so far. If you like the proposed change I can add the same for D3D12 and metal.

As another motivation for my use case: I just tried to use the allocator without any upper bound on the total allocation size or capacity, and it just keeps allocating until, first, VRAM memory is swapped to GTT (with huge slowdowns) and finally (when the GTT is full) the compositor becomes unresponsive, i.e. my graphical session freezes. It seems like some drivers just never return ERROR_OUT_OF_DEVICE_MEMORY.

@Jasper-Bekkers
Copy link
Member

Can't you just use the dedicated memory feature at that point?

@MarijnS95
Copy link
Member

MarijnS95 commented Feb 28, 2025

Just noting that for the title, I'd have expected this to say something like Add an option to disallow allocating new blocks or similar, since we already support "increasing capacity" through various ways (new blocks, even growing blocks with #254) and the goal of this PR is to have an option to disable that :)

This allows the user to bound the growth of the capacity without relying
on the driver to return ERROR_OUT_OF_DEVICE_MEMORY (which they sometimes
don't).
@ftilde ftilde force-pushed the control-capacity-increase branch from 562b463 to 0f0661d Compare February 28, 2025 13:11
@MarijnS95 MarijnS95 changed the title Add allow_capacity_increase option to AllocationCreateDesc Add option to disallow increasing capacity when allocating Feb 28, 2025
@ftilde
Copy link
Contributor Author

ftilde commented Feb 28, 2025 via email

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.

3 participants