Skip to content

Implement RenderGraph Memory aliasing #312

Description

@JeanPhilippeKernel

What this is (and isn't)

RGTransientPool::TryAlias (ZEngine/ZEngine/Rendering/Renderers/RenderGraph.h/.cpp) already does exact-match slot reuse: a freed transient resource's handle/VkImage gets handed to a new resource only when format, dimensions, and layer count match exactly, and their lifetimes don't overlap. That is not memory aliasing.

Real aliasing means multiple transient resources with different sizes/formats sharing the same underlying VkDeviceMemory region — binding several VkImages to overlapping offsets within one shared block (vkBindImageMemory against a block sized for the largest resource, or a VmaVirtualBlock-style sub-allocator), with explicit VkMemoryBarriers enforcing that a later-lifetime resource's first write happens-after the earlier-lifetime resource's last read/write. Get a barrier wrong and the failure mode is silent GPU corruption, not a crash — this needs to be built carefully, not bolted on.

What's already in place

The scaffolding this needs already landed as part of the RenderGraph topological-sort work (PR #748): RGResource::FirstPassIndex/LastPassIndex are computed off real sorted execution order (not raw declaration order), so lifetime non-overlap can be determined correctly. That's necessary but not sufficient — it tells you when two resources could alias, not how to actually bind them to shared memory or insert the hazard barriers between them.

What's still needed

  • A GpuAllocator pool variant that supports sub-allocating/overlapping regions for aliasing candidates, rather than the current domain-segregated fixed/auto-sized pools (ZEngine/ZEngine/Core/Memory/GpuAllocator.h/.cpp).
  • Hazard-barrier insertion at alias boundaries, threaded through RenderGraph's existing barrier-emission path.
  • A real test strategy for a class of bug (aliasing hazards) that's easy to get wrong in a way normal rendering output won't reveal.

Recommendation

Don't start on spec — this is real complexity for a payoff (memory savings on transient render targets) that only matters under actual GPU memory pressure. Worth revisiting once a real scene/profile demonstrates that pressure; until then this stays a documented, deliberate gap rather than a silent one.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Projects

Relationships

None yet

Development

No branches or pull requests

Issue actions