Skip to content

d3d12_vulkan.md: an exactly-256 MiB BAR window is tried for the default arena; memory_type_order case for that layout - #4712

Open
etcetera-yt wants to merge 2 commits into
ItsNotRexed:mainfrom
etcetera-yt:arena-256mib-bar-window-docs
Open

etcetera-yt wants to merge 2 commits into
ItsNotRexed:mainfrom
etcetera-yt:arena-256mib-bar-window-docs

Conversation

@etcetera-yt

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: new D3D item (claim), from @wilu222's finding. It's a follow-up of my D3D-96 code (#815).

What and why

docs/d3d12_vulkan.md said that without Resizable BAR "the 256 MiB default arena lands in system memory". That holds where the BAR window is smaller than the arena: 214 MiB on an RTX 3090, which d3d12_state_map_test already covers. memory_type_order (runtime/src/vulkan_memory.h) leaves out only a heap smaller than the allocation, though. So where the window is exactly 256 MiB (AMD without Smart Access Memory, RADV without Resizable BAR), the arena fits and tries the window first. It moves on to system memory only if that vkAllocateMemory fails, for example because the driver already uses part of the window.

  • docs/d3d12_vulkan.md (memory type policy) now describes both layouts, and says that which outcome the exactly-256 MiB case gets hasn't been measured.
  • d3d12_state_map_test gets the 256 MiB layout next to the RTX 3090 one. It checks three things:
    • resizable_bar() is false there, so upload heaps stay in system memory;
    • the 256 MiB arena gets order {3, 1, 2}, window first;
    • one page more gets {1, 2}.

No behaviour change. Whether the arena should take the whole 256 MiB window on those GPUs is a separate question that needs an AMD/RADV machine without SAM/ReBAR (LEONIDA_ARENA_LOG=1). This PR only makes the doc and tests match the code.

Tested

NVIDIA GeForce RTX 5060 Ti, driver 621.14, Windows 10 19045, MSVC (VS 2022 Build Tools), RelWithDebInfo, branch on main 98fa503f. The new case is CPU-only: it fakes VkPhysicalDeviceMemoryProperties, so this GPU's layout doesn't matter.

  • ctest -R "^d3d12_state_map$": passed. d3d12_state_map_test.exe: exit 0.
  • Negative control: in memory_type_order I added the doc's old model, "a heap no larger than the 256 MiB window is never offered to an allocation of 256 MiB or more" (if (heap.size <= kBarWindowBytes && size >= kBarWindowBytes) continue;).
    • main's test still passes (exit 0), so nothing pinned this case.
    • With this PR's case, it fails at line 712: memory_type_order(memory, 0xF, host, local, 256 * mib) == (order{3, 1, 2}).
    • Mutation reverted.
  • pytest tests/test_docs_links.py tests/test_docs_repo_paths.py tests/test_docs_design_rows.py: 12 passed.
  • Full runtime build and full ctest (with and without LEONIDA_VK_VALIDATION=1): running now. I'll post the results here, against the baseline (main 03b09a08: 145/147, with the 2 known Windows 10 failures d3d12_vulkan_device and d3d12_conservative_raster, TEST-907).

Not tested: a real AMD or RADV GPU without Smart Access Memory/Resizable BAR, to see where the arena actually lands there.

AI-assisted: yes (Claude Code).

Checklist

  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (not a translator change)

🤖 Generated with Claude Code

https://claude.ai/code/session_01GZEZyXGTTXs4V33hrBw1tD

…lt arena, with a memory_type_order case

The doc said the 256 MiB default arena lands in system memory without Resizable BAR. memory_type_order only
leaves out a heap smaller than the allocation, so where the BAR window is exactly 256 MiB (AMD without Smart
Access Memory, RADV without Resizable BAR) the arena tries the window first and moves on to system memory only
if that allocation fails (found by @wilu222). The doc now says so, and d3d12_state_map_test pins that layout:
not Resizable BAR, the 256 MiB arena tries the window first, one page more skips it. No behaviour change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZEZyXGTTXs4V33hrBw1tD

@Kam471 Kam471 left a comment

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.

Built and ran d3d12_state_map_test at ff199b9c7 on Windows 11: exit 0, state map, enhanced barriers, subresource decoding, layout tracking, discard ranges, block formats, BAR detection and memory types OK.

The test now covers the memory_type_order case for an exactly-256 MiB BAR window, and the docs say the default arena tries that window; the rest of the BAR/memory-type suite is unchanged. git diff --check clean. No blocking issue.

@etcetera-yt

Copy link
Copy Markdown
Contributor Author

Full runtime build and full ctest on this branch (ff199b9c, on main 98fa503f), RTX 5060 Ti, driver 621.14, Windows 10 19045, RelWithDebInfo:

  • ctest -j2: 163/166, and the same 163/166 with LEONIDA_VK_VALIDATION=1. d3d12_state_map passes in both.

  • The 3 failures are all on the Windows 10 host side, not this PR (it only changes d3d12_state_map_test.cpp and a doc):

    • d3d12_conservative_raster (TEST-907);
    • root_signature_oracle: the Windows 10 d3d12.dll serializer refuses 1.1 with every root-signature flag with Unsupported bit-flag set (root signature flags c7f);
    • d3d12_indirect_dispatch_count: count 0 update 1: host 0/0, layer 6/10, expected 6/10.

    I'm checking whether the last two are already reported and will post them on the coordination issue if not.

  • Build: 6 warnings, none in this PR's files (C4456 in d3d12_vulkan_device_test.cpp and xgameruntime_test.cpp, C4996 fopen in xgameruntime_test.cpp).

AI-assisted (Claude Code).

@tupacfan04

Copy link
Copy Markdown
Contributor

APPROVE, no issues. Built the changed test directly (cl /std:c++20 /W4): clean, exit 0; 14 docs tests and compileall pass; merge clean.

Negative control reproduced exactly: restoring the "skip a heap <= 256 MiB for size >= 256 MiB" rule in runtime/src/vulkan_memory.h:52 fails runtime/test/d3d12_state_map_test.cpp:712 (memory_type_order(..., 256*mib) == order{3,1,2}), and reverting passes. The doc claim also matches the code: vulkan_memory.h:44-56 offers the exactly-256 MiB heap first, and d3d12_vulkan_device.cpp:1199-1231 falls through on a failed vkAllocateMemory, as docs/d3d12_vulkan.md:1299-1302 says.

Nit: d3d12_state_map_test.cpp:711 re-asserts the 256 MiB resizable_bar case already at :651.

Approve. AI-assisted review, no game files.

…review)

From @tupacfan04's review of ItsNotRexed#4712: the not-Resizable-BAR case of an exactly-256 MiB window is already checked
in the resizable_bar block above, so the memory type case only checks the order.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01GZEZyXGTTXs4V33hrBw1tD
@etcetera-yt

Copy link
Copy Markdown
Contributor Author

Thanks @tupacfan04 for the review and for reproducing the negative control. Second commit ead9b37d drops the repeated resizable_bar check. The exactly-256 MiB window case is already checked in the resizable_bar block, and the comment now points there. Rebuilt d3d12_state_map_test (no warnings): ctest -R "^d3d12_state_map$" 1/1. The new order check moved from line 712 to 711. AI-assisted (Claude Code).

@kapitche

Copy link
Copy Markdown
Contributor

Tested ead9b37 merged with main 98fa503 on Linux (Python 3.12.16) and Windows (MSVC 14.51): pass

  • tests/test_docs_*.py: all pass.
  • d3d12_state_map_test (CPU only, no GPU) built and run on Windows with the PR's test file: passes, including the two new memory_type_order checks (exactly-256 MiB heap -> {3,1,2}; 256 MiB + 4096 -> {1,2}).
  • The doc claim matches runtime/src/vulkan_memory.h: the heap filter is size < allocation, so a heap of exactly 256 MiB is tried first for a 256 MiB arena.
  • Negative control: not applicable, the PR changes only docs and a test; the new checks also pass against main's code (they pin existing behavior, no fix to demonstrate).

@0klavair

Copy link
Copy Markdown
Contributor

Tested ead9b37d (merged onto main 98fa503f, clean merge) on NVIDIA GeForce RTX 5060, driver 621.01, Windows 11 23H2 22631.6199, MSVC 19.44, Vulkan SDK 1.4.363: pass.

No game files. AI-assisted: the run was done by an agent on this machine, and I checked its output.

@etcetera-yt

Copy link
Copy Markdown
Contributor Author

Thanks @kapitche (Linux and Windows) and @0klavair (RTX 5060, Windows 11 23H2, 162/165, the same failures as main there) for the runs. AI-assisted (Claude Code).

@memorypressure

Copy link
Copy Markdown

Verified on Linux, CPU-only. The four new memory_type_order/resizable_bar CHECKs match the implementation in runtime/src/vulkan_memory.h (strict > for the 256 MiB Resizable-BAR window, heap.size < size filter), so the exactly-256 MiB case keeps type 3 for a 256 MiB request and drops it one page larger; compileall and the docs repo-paths/table-rows guards pass merged with current main (re-run here). The C++ test itself needs a cmake build and was not built or run here, and the hardware figures in the doc text are as reported. Overlap note: #3634 edits the same doc; the two auto-merge cleanly in the doc itself. AI-assisted: yes. Tested on Linux (RTX 5080 host, CPU-only run).

@etcetera-yt

Copy link
Copy Markdown
Contributor Author

Thanks @memorypressure for the check and the overlap note on #3634. AI-assisted (Claude Code).

@vibryxcx

Copy link
Copy Markdown

Tested ead9b37 on AMD Radeon RX 6800 (RDNA2, discrete, gfx1030), AMD 26.8.1 (Windows 32.0.21045.5002), Windows 11 Pro 25H2 (build 26200), MSVC 14.44, RelWithDebInfo: pass.

  • d3d12_state_map passes, including the new exactly-256 MiB memory_type_order checks; full ctest and run_gpu_tests.py (201/217, 16 skipped) identical to main here.
  • On the open question in the description (what an AMD card with an exactly-256 MiB BAR window does): this card can't answer it as configured. Smart Access Memory is on, so vulkaninfo shows the device-local heap as host-visible at full size (heap 0: 15.95 GiB) and there is no 256 MiB window to measure. Someone with SAM / Resizable BAR off on an RDNA card, or RADV without ReBAR, is what that measurement needs.

No game files. AI-assisted (Claude Code).

@etcetera-yt

Copy link
Copy Markdown
Contributor Author

Thanks @vibryxcx for the RX 6800 run, and for checking the 256 MiB question. Agreed, it needs SAM off (or RADV without ReBAR) to measure. AI-assisted (Claude Code).

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.

7 participants