Skip to content

D3D12.X: the null device's struct-returning methods take the buffer first or second - #1902

Merged
raylitebull merged 2 commits into
xcl-dev:mainfrom
Royalflamejlh:fix/null-device-struct-returns
Nov 25, 2026
Merged

raylitebull merged 2 commits into
xcl-dev:mainfrom
Royalflamejlh:fix/null-device-struct-returns

Conversation

@Royalflamejlh

@Royalflamejlh Royalflamejlh commented Nov 24, 2026 •

Copy link
Copy Markdown
Contributor

When XCL cannot create a D3D12 device it switches to its null device, and a retail title then ended in the same millisecond: unhandled exception 0xc0000005 in 0x0 (execute at address 0x0). The same happens with graphics = "null" in xcl.toml. The cause is in the null device: its methods that return a struct through a hidden pointer took the second argument for the return buffer, and the title calls them the C way (buffer first, then the object).

The title's first such call is device #26 (GetCustomHeapProperties): the null device wrote the 20 bytes of its result over the device object, vtable pointer first, and the title's second call of #26 jumped through them (rax=0x100000004 in the exception line is the heap type and CPU page property that call had written). The real backend already tells the two orders apart (real::this_first, "a retail game's call … the C way"); null.rs never did.

What is in it

  • crates/xcl/src/hle/d3d12x/null.rs: this_and_ret picks the object as the argument whose first word is one of the null device's own vtables; the seven struct-returning methods use it (Hidden_ZeroDesc16, Hidden_ZeroDesc40, Device_GetResourceAllocationInfo, Device_GetCustomHeapProperties, Device_GetAdapterLuid, Heap_GetDesc16, Resource_GetDesc). The vtable list moves out of vtable() so that it can be read there. A second commit (9eaf878) reads that first word with read_unaligned: the buffer of a 20-byte struct is aligned to 4, and the first commit's plain read stopped a debug build (below).
  • A test in the same file, struct_returning_methods_take_the_buffer_first_or_second: device D3D12.X & GPU: raytracing SRVs, 64-bit multi-window BVH traversal, and title-list BVH builder slots #26 called both ways gives the same result and leaves the device's vtable pointer alone (with the C way's buffer 4 past a multiple of 8), and resource Olympus: harden GameSave read results #10 (GetDesc) called the C way returns the resource's description.

Tested

  • Linux through Wine and vkd3d-proton: NVIDIA GeForce RTX 4060 Ti 16 GB (driver 615.71.09), Ryzen 9 9950X3D, Fedora 44, Wine 11.21 Staging, vkd3d-proton v3.1-90-g30b0eb9b, rustc 1.98.0, release, x86_64-pc-windows-gnu.
  • Native Windows: NVIDIA GeForce RTX 5070 Ti 16 GB (driver 621.24), Ryzen 7 9800X3D, Windows 11 Pro 26300, rustc 1.99.1, debug. On the first commit (e22a931) cargo test --workspace -- --test-threads=4 aborted in the new test: misaligned pointer dereference: address must be a multiple of 0x8 at null.rs:271, then thread caused non-unwinding panic. On 9eaf878: the four null:: tests pass, and the whole suite gives 972 passed, 4 failed, 45 ignored, against 971 passed, 4 failed, 45 ignored on main 689f2db there. The four are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0 to _3 on both. scripts/smoke.ps1 there on 9eaf878, 60 s: 1068 frames shown, 0 crashes, 0 device removals, exit 0x0 (not one of the two blocks below, which are a pair from the Linux machine).
  • The new test on 689f2db with only the test added: failed, the call returned the device in place of the buffer (left: 0x8aac80, right: 0x187f500). On e22a931 and on 9eaf878: the four hle::d3d12x::null tests pass (release, under Wine).
  • A retail title with graphics = "null", 1 run each. main c4d37be (with XG: fix CopyFromSubresource 7-argument ABI and guard destination span #684 merged locally): creating a FALLBACK DEVICE and the exception above at 1.206 s. e22a931: both calls of D3D12.X & GPU: raytracing SRVs, 64-bit multi-window BVH traversal, and title-list BVH builder slots #26 return; the title goes on to device Config: the Series S title memory for every Series S spelling #48 and Floating-point modes: the non-fused MAD/MAC family needs precise, and the s_round_mode NOOPs are not free #73 ([STUB] d3d12_xs.dll!ID3D12Device::#73 … returning 0x0), which the null device does not implement, and faults there at 1.247 s (gta6.exe+0x2478b96, read at 0x800000000). So the title still does not run on the null device; what is gone is the overwritten object.
  • Under Wine, on the first commit e22a931 (the second changes one expression and the test): cargo build --workspace and cargo test --workspace --release --target x86_64-pc-windows-gnu --no-fail-fast -- --test-threads=4, with the tests pinned to the Linux card above. On both trees the lib test binary does not finish under Wine on NVIDIA (the D32S8 test, Tests: the D32S8 target test waits at most 10 s for its list #1706), so the lib counts are from a second pass with d32s8_targets_take_their_own_size_of_video_memory and reservable_agrees_with_the_driver skipped:
lib, the two skipped other test binaries
main 689f2db 921 passed, 3 failed, 25 ignored 46 passed, 3 failed, 20 ignored
e22a931 922 passed, 3 failed, 25 ignored 46 passed, 3 failed, 20 ignored
  • The same six fail on both: gpu::dxil::round_tests::directed_reference_basics, gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu, gpu_depth_buffer_created_for_unordered_access_is_placed (lib); test_title_runs_and_game_folder_is_untouched ("W: not cloaked"), disk_free_space_ex_reports_pls_quota, set_predication_buffer_state_and_kickoff. Tests that print SKIPPED are the same on both (no wave64 on this card, and f16 forms the direct backend refuses).

Regression run
Both blocks are from scripts/smoke.ps1, unchanged, run by PowerShell 7 on Linux with xcl.exe started through Wine, on a retail title, real backend, with XCL_PSO_PRELOAD=0. Under Wine "peak commit" reads 0 MB, and exit: 0x89 is the wrapper ending Wine after XCL's own process ends, not XCL's exit code. The blocks say RTX 4060 Ti 8GB because that is the name vkd3d-proton gives this 16 GB card. The real backend does not use the changed file.

main:

xcl-smoke v1
commit: 689f2db
gpu: NVIDIA GeForce RTX 4060 Ti 8GB
title: 1253b9d5
seconds: 60
exit: 0x89
frames shown: 1539 (PresentX 1539)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

PR:

xcl-smoke v1
commit: 9eaf878
gpu: NVIDIA GeForce RTX 4060 Ti 8GB
title: 1253b9d5
seconds: 60
exit: 0x89
frames shown: 1560 (PresentX 1560)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 0 MB

Not tested

AI use

  • Claude Code (Claude Fable 5.2) found the fault in this machine's runs, traced it to the argument order, wrote the change and the test, ran the suite and the regression runs, and wrote this description.

…irst or second

A retail title calls the device's struct-returning methods the C way
(return buffer, then the object). The null device took the second
argument for the buffer in all seven of its such methods, so the title's
first call of device xcl-dev#26 (GetCustomHeapProperties) wrote the 20 bytes of
its result over the device object, vtable pointer first, and the second
call jumped through it: `unhandled exception 0xc0000005 in 0x0 (execute
at address 0x0)` in the same millisecond as "creating a FALLBACK DEVICE".
That is what a run ends in when no D3D12 device can be created, or with
`graphics = "null"`.

The seven methods now find the object as the argument whose first word
is one of the null device's own vtables, as `real::this_first` does for
the real backend.

`struct_returning_methods_take_the_buffer_first_or_second` failed before
(the device came back in place of the buffer). The title with
`graphics = "null"`: before, the fault above at 1.2 s; after, both calls
return and it goes on to device xcl-dev#48 and xcl-dev#73, which the null device does
not implement, and stops there.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
@Royalflamejlh
Royalflamejlh marked this pull request as ready for review November 24, 2026 22:59
…unaligned

`this_and_ret` looked at the first word of both arguments through a
`*const usize`. One of them is the return buffer, and the buffer of a
20-byte struct is aligned to 4: a debug build stops there with
"misaligned pointer dereference" and aborts the test binary (native
Windows, RTX 5070 Ti, `cargo test --workspace`, at the new test). A
release build reads it without complaint, which is how it passed under
Wine.

The word is read with `read_unaligned`, and the test puts the C way's
buffer 4 past a multiple of 8.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>

@Melow-code Melow-code left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The vtable-pointer lookup for the return buffer position is correct — the seven struct-returning methods had a swapped argument order that corrupted the null device object.

@futurepro62

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 9eaf878 (on its base 689f2db).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::dxil::fuzz_tests: 966 passed, 0 failed, 43 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: struct_returning_methods_take_the_buffer_first_or_second.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 975 passed, 0 failed, 45 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 62265d3 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651) and the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.
  • The first NVIDIA run, alongside another test run on the same machine, failed only hle::kernelx::tests::fine_timer_makes_short_sleeps_short (917 passed, 1 failed). The run above is the rerun alone on the machine, where it passes. That timing test has failed the same way under load before, on other PRs.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@raylitebull
raylitebull merged commit 94193f0 into xcl-dev:main Nov 25, 2026
4 of 5 checks passed
@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@Royalflamejlh
Royalflamejlh deleted the fix/null-device-struct-returns branch November 25, 2026 02:11
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.

5 participants