Repository navigation
D3D12.X: the null device's struct-returning methods take the buffer first or second - #1902
Merged
raylitebull merged 2 commits intoNov 25, 2026
Merged
Conversation
…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
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
approved these changes
Nov 24, 2026
Melow-code
left a comment
There was a problem hiding this comment.
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.
|
Full-suite run, since this PR has no test report yet. Tested exact head Tested
Not tested
AI use
|
Contributor
|
Verification on RTX 3060 Ti (Windows 11), branch merged with current
Thanks! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 withgraphics = "null"inxcl.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=0x100000004in 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.rsnever did.What is in it
crates/xcl/src/hle/d3d12x/null.rs:this_and_retpicks 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 ofvtable()so that it can be read there. A second commit (9eaf878) reads that first word withread_unaligned: the buffer of a 20-byte struct is aligned to 4, and the first commit's plain read stopped a debug build (below).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
x86_64-pc-windows-gnu.e22a931)cargo test --workspace -- --test-threads=4aborted in the new test:misaligned pointer dereference: address must be a multiple of 0x8atnull.rs:271, thenthread caused non-unwinding panic. On9eaf878: the fournull::tests pass, and the whole suite gives 972 passed, 4 failed, 45 ignored, against 971 passed, 4 failed, 45 ignored onmain689f2dbthere. The four aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0to_3on both.scripts/smoke.ps1there on9eaf878, 60 s: 1068 frames shown, 0 crashes, 0 device removals, exit0x0(not one of the two blocks below, which are a pair from the Linux machine).689f2dbwith only the test added: failed, the call returned the device in place of the buffer (left: 0x8aac80, right: 0x187f500). One22a931and on9eaf878: the fourhle::d3d12x::nulltests pass (release, under Wine).graphics = "null", 1 run each.mainc4d37be(with XG: fix CopyFromSubresource 7-argument ABI and guard destination span #684 merged locally):creating a FALLBACK DEVICEand 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 needsprecise, and thes_round_modeNOOPs 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 at0x800000000). So the title still does not run on the null device; what is gone is the overwritten object.e22a931(the second changes one expression and the test):cargo build --workspaceandcargo 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 withd32s8_targets_take_their_own_size_of_video_memoryandreservable_agrees_with_the_driverskipped:main689f2dbe22a931gpu::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 withxcl.exestarted through Wine, on a retail title, real backend, withXCL_PSO_PRELOAD=0. Under Wine "peak commit" reads 0 MB, andexit: 0x89is the wrapper ending Wine after XCL's ownprocess ends, not XCL's exit code. The blocks sayRTX 4060 Ti 8GBbecause 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
real::this_firstbreaks by looking at the stack: here the argument order falls back to the C++ way when both arguments look like objects. No run showed it on the null device.precise, and thes_round_modeNOOPs are not free #73.precise, and thes_round_modeNOOPs are not free #73: not part of this.Device_GetResourceAllocationInfoin the same file for another reason (a nulldescs, overflow): the two touch neighbouring lines there and I have not merged them.AI use