Skip to content

d3d12: arena AS resources take their address from vkGetAccelerationStructureDeviceAddressKHR - #8414

Open
aslan2142 wants to merge 2 commits into
ItsNotRexed:mainfrom
aslan2142:gpuav-as-type
Open

aslan2142 wants to merge 2 commits into
ItsNotRexed:mainfrom
aslan2142:gpuav-as-type

Conversation

@aslan2142

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue: #8186 (comment) (marso006's findings: #8186 (comment)). The #313 table lists this one as D3D-883.

Depends on: none. It builds on main.

What and why

An acceleration-structure resource in the default heap lives in the GPU address arena. It is a GENERIC structure over its arena range. Its GPU VA was arena.address + offset, and the driver was never asked for the structure's address. Instance descriptors then hold that computed value.

  • An instance must name its BLAS by "a value obtained from vkGetAccelerationStructureDeviceAddressKHR" (VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281).
  • For GENERIC, the spec only promises that these addresses keep the offsets between structures in the same buffer (vkGetAccelerationStructureDeviceAddressKHR, resources chapter). That the address equals buffer address + offset is only in a non-normative note.
  • The committed-buffer path below it already queries the address and uses it. vkd3d-proton queries it too and logs a FIXME when it differs (libs/vkd3d/resource.c, vkd3d_create_acceleration_structure_view).

The change:

  • The arena path now calls vkGetAccelerationStructureDeviceAddressKHR, the same way the committed path does.
  • If a driver returns a different address, the driver's address becomes the GPU VA. The arena address stays registered too, the resource unregisters both, and one log line reports it. RADV returns the same address, so nothing changes there.
  • d3d12_indirect_rt now checks that each AS resource's GetGPUVirtualAddress() equals the driver's address for the VkAccelerationStructureKHR behind it.

This is what GPU-assisted validation tripped on in marso006's run:

  • GPU-AV only accepts addresses it has seen vkGetAccelerationStructureDeviceAddressKHR return. Every arena BLAS was therefore "an invalid acceleration structure reference".
  • GPU-AV then rewrites the rejected instance in place to point at its own dummy BLAS, so both rays miss (hit=0 miss=0).
  • d3d12_indirect_rt shares one instance buffer between the ARRAY and the ARRAY_OF_POINTERS TLAS. The second build therefore reads GPU-AV's dummy address and gets a second, follow-on message.

This does not make the GPU-AV run pass. With the address queried, GPU-AV reports the remaining cause instead: "is not a bottom level acceleration structure, but has type VK_ACCELERATION_STRUCTURE_TYPE_GENERIC_KHR".

  • The spec allows that: GENERIC is "intended to be used by API translation layers", and the real type is the one given at build time.
  • VVL 1.4.363.1 compares the creation type only (AccelerationStructureKHR::GetType() returns create_info.type; gpuav/shaders/validation_cmd/tlas.slang requires BUILD_AS_METADATA_AS_TYPE_BLAS). That is a layer false positive, to report to Khronos.
  • Creating typed structures instead is not a safe fix here. With vkCreateAccelerationStructureKHR a typed structure's address may differ from buffer address + offset, but the D3D12 VA is fixed when the resource is created. vkd3d-proton uses GENERIC for the same reason.

A standalone Vulkan check (no D3D12, one triangle) shows the same split on RADV with VVL 1.4.363.1 and GPU-AV:

BLAS created as address queried GPU-AV
BOTTOM_LEVEL yes clean
GENERIC yes "not a bottom level ... GENERIC"
GENERIC no (buffer address + offset) "invalid acceleration structure reference"

In both GENERIC cases, the instance reads back afterwards with GPU-AV's dummy BLAS address. The queried and computed addresses were equal in every case.

Tested

Linux, Wine 11.22 (staging), host Vulkan validation layer 1.4.363.1 through winevulkan (VK_LOADER_LAYERS_ENABLE=*validation, GPU-AV with VK_KHRONOS_VALIDATION_GPUAV_ENABLE=1), Mesa 26.3.1 RADV. The tests were built with clang 23 for the mingw target, not MSVC: this is a local check, and the MSVC /W4 /permissive- build is CI's.

The integrated GPU (Ryzen 9 7950X3D, gfx1036 RDNA2) ran all four tests. The RX 7900 XTX (RDNA3) ran three, after they had run clean on the integrated GPU. Results before (main dde82f27e) and after:

test plain validation, before / after GPU-AV, before GPU-AV, after
d3d12_dxr_validation (XDXR) pass / pass, 0 errors pass, 0 errors pass, 0 errors
d3d12_dxr_validation_khr pass / pass, 0 errors 1 × 12281 "invalid reference" 1 × 12281 "GENERIC type"
d3d12_xdxr_rt pass / pass, 0 errors pass, 0 errors pass, 0 errors
d3d12_indirect_rt (integrated GPU only) fails before and after, see below 2 × 12281 "invalid reference" 1 × "GENERIC type" + 1 follow-on
  • The new address check in d3d12_indirect_rt passes on the integrated GPU, with and without GPU-AV.
  • The only messages besides 12281 are Wine's own VUID-vkCreateDevice-ppEnabledExtensionNames-01387, which every Wine run shows.
  • No GPU resets in the kernel log.

d3d12_indirect_rt fails on main too in this Wine setup, without GPU-AV. The RT build list is refused ("ExecuteCommandLists failed: invalid copy or resolve"), from the ARRAY_OF_POINTERS instance staging. That is the known ARRAY_OF_POINTERS problem (#4301 and related), not this change.

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. (No translator change.)

AI-assisted (Claude Code, Claude Opus 5.5).

…ructureDeviceAddressKHR

A default-heap acceleration-structure resource in the GPU address arena handed out buffer address + offset as its
GPU VA without asking the driver. An instance must name its BLAS by a value obtained from
vkGetAccelerationStructureDeviceAddressKHR (VUID-vkCmdBuildAccelerationStructuresKHR-pInfos-12281), and for a GENERIC
structure the spec only promises consistent offsets between structures of one buffer, not equality with the buffer
address. Query it as the committed path does; if a driver ever returns a different address, use the driver's and
keep the arena address registered too.

GPU-assisted validation only knows addresses it has seen that call return, so it reported every arena BLAS as "an
invalid acceleration structure reference" and rewrote the instance to its dummy BLAS (the ray-query miss marso006
saw). It now reports the remaining layer limitation instead: a GENERIC structure built as bottom level is "not a
bottom level acceleration structure", which the spec allows.

d3d12_indirect_rt checks that every AS resource's GPU VA is the driver's address for the structure behind it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@thehollowedone

Copy link
Copy Markdown

Independent native Windows check of 08c19978 on an RTX 3080 Ti (driver 621.35, MSVC 19.44, Vulkan SDK 1.4.363.0).

In the focused d3d12_indirect_rt run with the KHR ARRAY case alone, the build submitted successfully. Both the BLAS and TLAS returned nonzero D3D12 GPU addresses that matched vkGetAccelerationStructureDeviceAddressKHR. The ray query returned the expected hit=1, miss=0. The shader passed spirv-val, and Vulkan core and synchronization validation reported zero errors.

A separate run that also included the stock ARRAY_OF_POINTERS case matched all three address comparisons, but the runtime rejected the combined submission with invalid copy or resolve. The ray query then read 0/0. That is consistent with the symptom in #6010. I did not isolate the cause on this revision.

Synthetic geometry only. AI-assisted.

@Envyre

Envyre commented Nov 23, 2026

Copy link
Copy Markdown

Code read of the PR head: looks right. The arena path (d3d12_vulkan_device.cpp:1799-1819) now matches the committed path (:1874-1890); ~Resource (:1720-1723) already unregisters both gpu_va_ and buffer_va_, so cleanup on free is covered; XDXR isn't affected since info.ray_tracing is false there (:8979). On the KHR path instance descs pass the BLAS VA through, Dest/Source go through resolve_acceleration_structure (vulkan_replay.h:3039-3042), and copy/postbuild aren't used (:3050-3070), so GetGPUVirtualAddress() is the only source of the address and it now returns the driver's value.

Two notes, neither blocking:

  • The as_va != gpu_va_ branch (:1810-1815) only runs on a driver that returns a different address, so CI never exercises it; a comment that it's defensive, or a fake device-address hook in the test, would help.
  • acceleration_structures_ matches exact keys only (vulkan_backend.h:1354-1358), so an app that suballocates several BLAS in one AS resource (GetGPUVirtualAddress() + N) still gets unresolved_resource on build, and its instances would hold an address no driver query returned. Pre-existing, but the new test (d3d12_indirect_rt_test.cpp:778-797) only checks base addresses; worth a TODO or tracking issue.

AI-assisted (Claude Code).

…ss is not buffer address + offset

Envyre's review of ItsNotRexed#8414: the branch that takes the driver's address when it differs only ran on such a driver. The
test creates a second device whose get_instance_proc hands out a vkGetAccelerationStructureDeviceAddressKHR that
answers the real address plus 256 MiB (the device's existing function-lookup hook, no change to the runtime), creates
one AS resource on it and checks that its GPU VA is the driver's address, that the arena address still names the
structure, and that releasing the resource forgets both. No builds run on that device.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@aslan2142

Copy link
Copy Markdown
Contributor Author

Thanks @Envyre for the careful read.

  • Note 1: done in b9e0544, as a test rather than a comment. d3d12_indirect_rt creates a second device whose get_instance_proc hands out a vkGetAccelerationStructureDeviceAddressKHR that returns the real address + 256 MiB. This goes through the device's existing function lookup, so the runtime itself doesn't change.
    • On that device it creates one AS resource and checks three things:
      • GetGPUVirtualAddress() is the driver's address.
      • The arena address still resolves to the same structure.
      • After Release, neither address resolves.
    • No builds run on that device.
    • Integrated GPU (RADV, Wine, plain validation): the new check passes and the log line for a differing address appears. d3d12_dxr_validation_khr is unchanged.
  • Note 2: confirmed. The lookup is exact-key only, and DXR allows any 256-byte-aligned AS inside an AS-state resource. Placed AS buffers get no VkAccelerationStructureKHR on the KHR path either. I've posted it as a finding in the coordination issue (Coordinating who works on what (52) #8504 (comment)) and left it out of this PR.

AI-assisted (Claude Code, Claude Opus 5.5).

@Sangonapou

Copy link
Copy Markdown

Tested b9e0544 (with the shifted-address test) on NVIDIA GeForce RTX 3080 Ti Laptop (Ampere), NVIDIA 621.24, Vulkan 1.4.357, Windows 11 Pro (build 26300), native Windows: pass

Built with scripts\build_runtime.ps1 (MSVC 19.51, VS Build Tools 2026, Windows SDK 10.0.26100, Vulkan SDK 1.4.363.0). The earlier RTX 3080 Ti check above was of 08c19978; this is the current head.

  • d3d12_indirect_rt_test on this branch: exit 0, PASS (0 validation errors), including [PASS] AS resource GPU VAs are the driver's acceleration structure addresses and [PASS] a driver address other than buffer address + offset is the GPU VA; both freed. The runtime logs GENERIC acceleration structure address is not its buffer address + offset; arena offset in KiB: 64 for the shifted device.
  • Same with LEONIDA_VK_VALIDATION=1: exit 0, the test reports validation on, 0 validation errors.
  • Base dde82f27: exit 0 (without the new cases).
  • Negative check: this branch's test with the base's runtime/shims/d3d12_vulkan_device.cpp swapped back in fails, exit 1: FAIL: shifted AS: GPU VA 0x300020000, driver address 0x310020000. In that same run the real-driver case AS resource GPU VAs are the driver's acceleration structure addresses still passes. On this NVIDIA driver the real address happens to equal buffer address + offset, so only the shifted device from b9e05449 tells the two versions apart here.

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.

4 participants