Skip to content

Fix DX12 tight alignment#2830

Open
locke-lunarg wants to merge 3 commits intoLunarG:devfrom
locke-lunarg:locke-fix-tight-aglin
Open

Fix DX12 tight alignment#2830
locke-lunarg wants to merge 3 commits intoLunarG:devfrom
locke-lunarg:locke-fix-tight-aglin

Conversation

@locke-lunarg
Copy link
Copy Markdown
Contributor

@locke-lunarg locke-lunarg commented Mar 30, 2026

closed: https://github.com/LunarG/Projects/issues/1125
Ref: https://microsoft.github.io/DirectX-Specs/d3d/D3D12TightPlacedResourceAlignment.html

Regularly, the alignment of the resource should be D3D12_DEFAULT_RESOURCE_PLACEMENT_ALIGNMENT(64KB). But when it uses tight alignment, it becomes 8B ~ 256B. It's smaller than a page size(system_page_size_: 4KB). In this case, one page could have two resources. For WriteWatch case, in LoadActiveWriteStates, if it resets WriteWatch on GetWriteWatch, another resource on the same page will miss its update. Although GetWriteWatch could set precise address, it operates on page by page. It shouldn't have reset WriteWatch until all memory infos get updated.

There are the other two solutions that could fix it.

  1. Force ID3D12Device_Wrapper::GetResourceAllocationInfo to return alignment to multiple of a page size, so a page won't have two resources. But we shouldn't change the original value.

  2. GFXRECON_PAGE_GUARD_EXTERNAL_MEMORY set false could disable WriteWatch. It will use shadow memory, instead of WriteWatch. But shadow memory consumes huge memory. And PageGuardManager::HandleGuardPageViolation interrupts the process to update memory info. It could impact the performance.

@locke-lunarg locke-lunarg added approved-to-run-ci Can run CI check on internal LunarG machines and removed approved-to-run-ci Can run CI check on internal LunarG machines labels Mar 30, 2026
Comment on lines +1330 to +1336
#if defined(WIN32)
for (auto& entry : memory_info_)
{
auto& info = entry.second;
ResetWriteWatch(info.aligned_address, info.mapped_range + info.aligned_offset);
}
#endif
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Could this introduce a race condition in processing modified pages? For example:

  1. PageGuardManager::ProcessMemoryEntries is called. Memory A is found to be modified and is processed. ProcessMemoryEntries continues to processing the remaining modified pages.
  2. After memory A is processed, but before ProcessMemoryEntries calls ResetAllWriteWatch(); (it could be processing other modified memory pages), the application completes another write to memory A.
  3. ResetAllWriteWatch(); is called, clearing the new write watch flag on memory A, causing the application's latest write to be skipped at the next call to ProcessMemoryEntries.

@locke-lunarg locke-lunarg force-pushed the locke-fix-tight-aglin branch 2 times, most recently from 4750a87 to 7df7643 Compare March 30, 2026 16:05
When it uses DX12 tight alignment, the alignment could be 8B~256B.
It's much smaller than a page of memory, like 4KB.
One page could have two resources, so if it reset the WriteWatch, the
another resource on the same page will miss its update.
@locke-lunarg locke-lunarg force-pushed the locke-fix-tight-aglin branch 2 times, most recently from 558327b to 3129b5d Compare March 31, 2026 06:39
@locke-lunarg locke-lunarg force-pushed the locke-fix-tight-aglin branch from 3129b5d to fd0628c Compare March 31, 2026 06:40
@locke-lunarg
Copy link
Copy Markdown
Contributor Author

locke-lunarg commented Mar 31, 2026

@davidd-lunarg Upload a new solution. It updates the memory info on the same page in PageGuardManager::LoadActiveWriteStates, so it doesn't need to delay reset WriteWatch.

@locke-lunarg locke-lunarg marked this pull request as ready for review March 31, 2026 06:44
@locke-lunarg locke-lunarg requested a review from a team as a code owner March 31, 2026 06:44
@locke-lunarg locke-lunarg added the approved-to-run-ci Can run CI check on internal LunarG machines label Mar 31, 2026
Copy link
Copy Markdown
Contributor

@MarkY-LunarG MarkY-LunarG left a comment

Choose a reason for hiding this comment

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

Good catch. I think this is a bug that has been bugging us for a while. So good thing you ran into it in this scenario.

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

Labels

approved-to-run-ci Can run CI check on internal LunarG machines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants