Skip to content

device_memory_report: key resources by object type, emit object_type, clamp bindings - #44

Merged
jimblacklercorp merged 2 commits into
mainfrom
push-kkrqmvkompvk
Oct 15, 2026
Merged

jimblacklercorp merged 2 commits into
mainfrom
push-kkrqmvkompvk

Conversation

@jimblacklercorp

Copy link
Copy Markdown

Two commits:

device_memory_report: key resources by object type and emit object_type on allocation events

VkBuffer and VkImage handles are only unique within their object type,
but resources_ and resource_to_memory_map_ were keyed by bare handle. A
buffer and an image sharing a handle value could overwrite each other's
usage, size and binding, and a binding's DESTROY source was derived from
whichever resource last claimed the handle.

  • Key resources_ by ObjectKey (std::pair<VkObjectType, uint64_t>, the
    same key as debug_object_names_) and store the object type on
    SubAllocation.
  • Fold resource_to_memory_map_ into Resource::bound_memory so the
    binding lives with the resource it describes.
  • OnRecordResourceSize and GetRecordedResourceSize take the object type.
  • Emit an object_type (VkObjectType) annotation on every
    VulkanMemoryAllocation event: VK_OBJECT_TYPE_DEVICE_MEMORY for memory
    blocks, VK_OBJECT_TYPE_BUFFER / VK_OBJECT_TYPE_IMAGE for bindings, and
    the driver-reported objectType for driver allocations, so consumers
    can key allocations and join debug names without inferring the type.
  • Add BufferAndImageWithCollidingHandlesAreTrackedIndependently test.

device_memory_report: clamp bindings to their allocation in the unbound counter

UpdateAllocationUnboundCounter merged each binding's [offset,
offset + size) interval without regard to the allocation's bounds, so a
binding that extended past the end of its VkDeviceMemory counted bytes
outside the allocation as bound, and unbound_memory under-reported.

Clamp each interval to [0, total_size) when the counter is computed, so
only the part of a binding inside the allocation counts as bound.
Clamping at compute time rather than bind time keeps bindings recorded
against a not-yet-reported allocation correct once its size arrives.
bound_size can then no longer exceed total_size, so the unbound
subtraction needs no guard. This matches the Sherlock snapshot, which
clamps the same way.

  • Add BindingsAreClampedToTheirAllocation test.

…pe on allocation events

VkBuffer and VkImage handles are only unique within their object type,
but resources_ and resource_to_memory_map_ were keyed by bare handle. A
buffer and an image sharing a handle value could overwrite each other's
usage, size and binding, and a binding's DESTROY source was derived from
whichever resource last claimed the handle.

- Key resources_ by ObjectKey (std::pair<VkObjectType, uint64_t>, the
  same key as debug_object_names_) and store the object type on
  SubAllocation.
- Fold resource_to_memory_map_ into Resource::bound_memory so the
  binding lives with the resource it describes.
- OnRecordResourceSize and GetRecordedResourceSize take the object type.
- Emit an object_type (VkObjectType) annotation on every
  VulkanMemoryAllocation event: VK_OBJECT_TYPE_DEVICE_MEMORY for memory
  blocks, VK_OBJECT_TYPE_BUFFER / VK_OBJECT_TYPE_IMAGE for bindings, and
  the driver-reported objectType for driver allocations, so consumers
  can key allocations and join debug names without inferring the type.
- Add BufferAndImageWithCollidingHandlesAreTrackedIndependently test.
…nd counter

UpdateAllocationUnboundCounter merged each binding's [offset,
offset + size) interval without regard to the allocation's bounds, so a
binding that extended past the end of its VkDeviceMemory counted bytes
outside the allocation as bound, and unbound_memory under-reported.

Clamp each interval to [0, total_size) when the counter is computed, so
only the part of a binding inside the allocation counts as bound.
Clamping at compute time rather than bind time keeps bindings recorded
against a not-yet-reported allocation correct once its size arrives.
bound_size can then no longer exceed total_size, so the unbound
subtraction needs no guard. This matches the Sherlock snapshot, which
clamps the same way.

- Add BindingsAreClampedToTheirAllocation test.
@jimblacklercorp
jimblacklercorp merged commit 555ae0d into main Oct 15, 2026
23 checks passed
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.

2 participants