D3D12.X: the null device's struct-returning methods take the buffer first or second #1892
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1902"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from ivall/xcl. Originally posted by Royalflamejlh on 2026-11-24T22:52:29Z.
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 #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 #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 #684 merged locally):creating a FALLBACK DEVICEand the exception above at 1.206 s.e22a931: both calls of #26 return; the title goes on to device #48 and #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, #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:
689f2db477gpu: 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:
9eaf87810dgpu: 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.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
Imported from ivall/xcl. Originally posted by Melow-code on 2026-11-24T23:10:38Z.
Review: APPROVED
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.
Imported from ivall/xcl. Originally posted by futurepro62 on 2026-11-25T00:14:19Z.
Full-suite run, since this PR has no test report yet. Tested exact head
9eaf878(on its base689f2db).Tested
cargo build --workspace, thenXCL_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.struct_returning_methods_take_the_buffer_first_or_second.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 #1426 semantics differ from the console's))),f16_programs_on_the_gpu(f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its #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 #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 #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 #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 #1426 semantics differ from the console's))),heap_window_out_of_memory_falls_back_to_the_switch_form(no heap windows).--skipleaves out tests that fail on main62265d3too, not because of this PR. On NVIDIA:heap_window_out_of_memory_falls_back_to_the_switch_form(#1651) and the fourgpu::recomp::lower_dxil::tests::*_programs_on_the_gputests (follow-up on #1651) fail becauserunner::skip_testturns their skips into failures underXCL_REQUIRE_GPU=mesh, andgpu::dxil::fuzz_testsseeds 70, 545, 1019 and 1507 failCreateComputePipelineStatewithE_OUTOFMEMORYon this card (drivers 616.64 and 621.40). On AMD:fuzz_validate_and_gpu_1fails on seed 540 (res[833]0x7 vs CPU 0x6). The AMD run does not setXCL_REQUIRE_GPU.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
AI use
Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-25T02:07:25Z.
Verification on RTX 3060 Ti (Windows 11), branch merged with current
main:cargo test -p xcl --lib: all passed, 0 failed, ~26 ignored. (Intermittent single-test flake / 0xc0000005 abort under parallel scheduling — tracked in #1978; clean on single-threaded rerun.)Thanks!
upstream-sync referenced this pull request2026-11-25 14:08:42 +00:00