Repository navigation
Fix calculation of memory footprint for images. - #53
Open
jimblacklercorp wants to merge 3 commits into
Open
jimblacklercorp wants to merge 3 commits into
jimblacklercorp wants to merge 3 commits into
Conversation
olehkuznetsov
requested changes
Oct 27, 2026
Clamp bound suballocation sizes and BIND trace events to the backing VkDeviceMemory allocation size both at bind time and when the allocation size arrives later via VK_EXT_device_memory_report or vkAllocateMemory. Bindings recorded against a placeholder that extend past the allocation are unbound and re-bound through the regular bind path once the size is known, after the CREATE event, so trace consumers see a balancing DESTROY followed by the clamped BIND. Stored bindings now always lie within their allocation; assert this when computing the unbound counter while still clamping in release builds. BUG=b/578430447
Route vkBindBufferMemory and vkBindImageMemory through the same RecordBufferBindings / RecordImageBinds helpers as vkBindBufferMemory2 and vkBindImageMemory2, using a single-element bind info after the downstream bind succeeds. The fallback vkGet*MemoryRequirements query for resources with an unknown size now runs only after binding, and the query-after-bind ordering lives in one place per resource type. BUG=b/578430447
Stop calling vkGetImageMemoryRequirements from vkCreateImage. Images created with VK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROID must be bound before their memory requirements are queried (VUID-vkGetImageMemoryRequirements-image-04004), and drivers otherwise return a worst-case size. Every bind path already queries an unknown image size after a successful bind, and nothing reads the size between creation and binding, so the create-time query is unnecessary. BUG=b/578430447
jimblacklercorp
force-pushed
the
fix-ahb-size-and-clamp-b578430447
branch
from
October 27, 2026 23:59
6882171 to
119943d
Compare
olehkuznetsov
self-requested a review
October 28, 2026 17:24
olehkuznetsov
approved these changes
Oct 28, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes over-reporting of bound resource sizes in
VkLayer_DeviceMemoryReportwhenvkGet*MemoryRequirementsreturns a worst-case upper bound larger than the backingVkDeviceMemoryallocation (such as forAHardwareBuffer-backed images).VkDeviceMemoryallocation: Clamp suballocation sizes, usage counters (vulkan.mem.app.usage.*), andBINDtrace events toallocation.total_size - offsetat bind time, and retroactively clamp already-bound suballocations (emitting a balancingDESTROY+ clampedBINDevent) if the backing allocation size is reported after the bind call.vkBind*Memory: Move the fallbackvkGetBufferMemoryRequirementsandvkGetImageMemoryRequirementscalls invkBindBufferMemoryandvkBindImageMemoryto run after the downstream bind call succeeds, matchingvkBindBufferMemory2andvkBindImageMemory2.vkGetImageMemoryRequirementsforAHardwareBufferimages: Avoid callingvkGetImageMemoryRequirementsduringvkCreateImagewhenVK_EXTERNAL_MEMORY_HANDLE_TYPE_ANDROID_HARDWARE_BUFFER_BIT_ANDROIDis present (VUID-vkGetImageMemoryRequirements-image-04004), deferring the query until the image is bound to memory.