Skip to content

d3d12: a buffer on a device without a GPU address arena answers GetGPUVirtualAddress with a real non-zero address, not 0 - #7015

Open
tedin7 wants to merge 3 commits into
ItsNotRexed:mainfrom
tedin7:fast-gpuva
Open

tedin7 wants to merge 3 commits into
ItsNotRexed:mainfrom
tedin7:fast-gpuva

Conversation

@tedin7

@tedin7 tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor

Claimed in #6910 (comment)

@ItsNotRexed: an exe PR, as you asked.

What

ID3D12Resource::GetGPUVirtualAddress on a buffer returns a non-zero, 64 KiB-aligned, unique address on a device that has no GPU address arena (no bufferDeviceAddress). Such a buffer used to answer 0. It now answers its raw device address when the driver gives one, else a synthetic address from a never-reused range (DeviceState::synthetic_va_allocate, 2^36 to 2^47). The address is also the buffer's binding.va, so the context finds the buffer by it.

New test d3d12_gpuva_test: 1 KiB buffers through the Xbox device proxy in 8 heap/state/flag combinations, on a device with and without bufferDeviceAddress. Each must answer non-zero, 256-byte aligned (64 KiB without an arena), and not overlap another live buffer.

Why

A title builds root descriptors and V#s from this address, so 0 points the GPU at address 0. It is not state-dependent: the reported COMMON and COPY_DEST cases are two of the eight; on a device without an arena every default, upload and readback buffer answered 0, in every state. With the arena (the device the game gets) all eight were already right, so this changes nothing there. The cause was in Resource::create_buffer: the non-arena path set va_ only when the arena existed, and GetGPUVirtualAddress returns va_, never the buffer_va_ it had just fetched. d3d12_descriptor_test builds such a device, so this is the setup where it showed up.

Open PRs checked (gh pr list --search for "GetGPUVirtualAddress", "buffer device address", "GPU virtual address"), none fixes this: #5456 (docs), #157 and #334 (GFX10 descriptor views), #770 (placed texture aliasing), #4609, #6168 (WriteBufferImmediate Close parity), #3293 (DRED) do not touch the non-arena buffer path.

Tested

On pod p2 (RTX 4090, Wine, /root/fast_test_exe.sh):

  • Before the fix, d3d12_gpuva_test exits 1: the eight arena cases print 0x10000 to 0x60000 (default) and 0x10000000, 0x10010000 (upload, readback), then no bda: default COMMON -> 0x0, line 90: address != 0.
  • After the fix, it exits 0: the no-arena addresses are 0x1000000000 to 0x1000070000 in steps of 0x10000; the arena addresses are unchanged.
  • d3d12_descriptor_test, d3d12_vulkan_device_test and d3d12_buffer_uav_test exit 0 after the fix.

@thehollowedone

Copy link
Copy Markdown

Independent Windows check of 43510c6a. RTX 3080 Ti, NVIDIA 621.35, MSVC 19.44, Vulkan SDK 1.4.363.0.

The stock d3d12_gpuva test passed. All eight live buffers with the address arena and all eight with the arena disabled had nonzero, aligned addresses that did not overlap within their configuration. The no-arena addresses were all 64 KiB-aligned. The fixture disabled the layer's arena on this adapter and checked the returned addresses without dereferencing them. Khronos core and synchronization validation reported zero errors.

AI-assisted.

… synthetic, aligned VA below 2^47

Without the arena the raw Vulkan device address was returned. It can be above 48 bits (a V# keeps 48, so a UAV
clear decoded an address below the resource base and Close failed with E_INVALIDARG) and is aligned only as the
driver likes (not the 64 KiB promised). Every buffer now takes a synthetic address. The allocator moves to
src/synthetic_va.h and only advances its counter on success, so a refused 65,537-byte request no longer makes the
next 64 KiB request fail.

d3d12_gpuva_test now also runs a device whose arena is refused while the driver answers raw addresses above 48
bits, and records a UAV clear and a WriteBufferImmediate at address + 4 on each device. synthetic_va_test covers
the allocator without a GPU.
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

Thanks, all four were right. Fixed in 3ef855a (new commit, no force):

  1. A raw address above 48 bits broke UAV clears. Without an arena a buffer now always gets a synthetic address (1<<36 up to 1<<47), so a V# can hold it. I made the driver answer 0x1000000100100 and refuse the arena: before the fix the list's Close returned E_INVALIDARG (0x80070057), after it returns S_OK.
  2. The 64 KiB alignment promise: the raw branch is gone, so every no-arena address is a multiple of 64 KiB. The test now checks this on the refused-arena device too (the old code answered 0x10000000100100, which failed the check).
  3. A refused request no longer uses up space. The allocator is now in src/synthetic_va.h and only advances its counter with a compare-and-swap on success. New synthetic_va_test (no GPU): in a 192 KiB range, a 65,537-byte request is refused and the following 64 KiB request still succeeds. It failed with the old fetch_add logic.
  4. Tests: d3d12_gpuva_test now runs three devices (arena, no bufferDeviceAddress, arena refused with raw addresses above 48 bits through hooked vkCreateBuffer and vkGetBufferDeviceAddress). Each one also records a UAV clear at byte 256 and a WriteBufferImmediate at address + 4 and requires Close to succeed, so binding.va left at 0 now fails. It checks addresses stay below 2^48 and that the hooks were actually reached.

Tested on the RTX 4090 pod under Wine: d3d12_gpuva_test exit 0 after the fix; with the old shim the same test fails (alignment, then 48 bits, then Close E_INVALIDARG). synthetic_va_test passes.

AI-assisted.

@DeSunShine

Copy link
Copy Markdown

Tested 3ef855a24 merged into main 8714c3503 on NVIDIA GeForce RTX 4090 (driver 621.24), Windows 11 Pro 26200, MSVC (VS Build Tools 18) + Ninja, Vulkan SDK 1.4.363: fail (the new d3d12_gpuva test).

  • ctest -R "gpuva|synthetic_va|xs_proxy|device_proxy" --output-on-failure: 9/10 passed; synthetic_va, device_proxy* and xs_proxy_mock* pass; d3d12_gpuva FAILS (exit 1).
  • Failing line: line 173: address + kBytes <= (UINT64(1) << 48), in the first mode (arena, the device with its GPU address arena). Output just before it: arena: upload GENERIC_READ -> 0xffffffffff7c0000; the five DEFAULT-heap cases are fine (0x10000 .. 0x60000). So here an UPLOAD-heap buffer reports an address above 2^48 while the arena is active ([rt] d3d12: upload heaps in VRAM (DEVICE_LOCAL | HOST_VISIBLE, Resizable BAR)). The no_device_address and arena_refused modes never ran because the test exits at the first failure.
  • Same on plain main: d3d12_gpuva does not exist there (new test in this PR). The diff only changes the !addressable (no arena) path, so this arena-mode result looks pre-existing on this GPU/ReBAR setup rather than caused by the change, but I did not verify that separately.

AI-assisted (Claude Code).

@DeSunShine

Copy link
Copy Markdown

Context for the RTX 4090 failure reported above (line 173: address + kBytes <= (UINT64(1) << 48), arena: upload GENERIC_READ -> 0xffffffffff7c0000): it is not this PR's no-arena change. It is the known arena-mode gap documented in docs/d3d12_vulkan.md §3.3 ("Measured (D3D-53…)"). An upload buffer keeps its own memory, and its VA is vkGetBufferDeviceAddress - arena.address. That goes negative whenever the allocator places it below the arena. The doc records 0xffffffffffce0000 on a Radeon 880M and 0xffffffffffedc000 on an RTX 5070 Laptop; here it is -0x840000 with upload heaps in VRAM (Resizable BAR). The fix is D3D-516 (#5052, "Keep committed buffer addresses within the V# range", currently conflicting). So the new upload case will fail on any device where that happens until #5052 (or an equivalent) lands. You may want to mark that case as expected-to-fail / skip with a pointer to D3D-516, or to stack this on #5052. AI-assisted (Claude Code).

…e own memory is the open D3D-516 gap (ItsNotRexed#5052), as measured on an RTX 4090 with ReBAR
@tedin7

tedin7 commented Nov 23, 2026

Copy link
Copy Markdown
Contributor Author

@DeSunShine thanks for the run and the diagnosis. You're right that it's the arena's own upload-buffer gap (D3D-516 / #5052), not this change. In d9e614a, the 48-bit check skips only arena-mode UPLOAD/READBACK buffers, with a pointer to D3D-516. DEFAULT buffers in arena mode, and every buffer on the no-arena paths this PR changes, are still checked. Under Wine on an RTX 4090 (p2): exit 0, all three modes run, and the no-arena addresses are 64 KiB aligned from 0x1000000000. When #5052 lands, the exception can go. AI-assisted.

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.

3 participants