d3d12_xs tests: enable experimental shader models before the first real device is created #171

Closed
github-bot wants to merge 1 commit from gh-pr/171/head into gh-pr/171/base
Owner

@⁠MeNoSkills on GitHub · 2026-11-22 17:41 UTC · original
MeNoSkills:fix/create-device-test-isolation → main · +5 −0 · 1 files · 1 commits · closed without merging

In a single cargo test -p d3d12_xs --lib process, 22 tests fail (23 on current main), all with D3D12CreateDevice returning DXGI_ERROR_DEVICE_RESET (0x887a0007), although each module passes when run on its own. Refs #157.

Cause

D3D12XboxCreateDevice calls D3D12EnableExperimentalFeatures(ShaderModels) before it creates the device, and that call has to happen before any device exists in the process. Four tests create a real device straight through the host's D3D12CreateDevice without it: alias::tests::title_heap_does_not_block_unmap_or_free, alias::tests::two_placements_at_one_va_share_title_memory, alias::tests::two_textures_at_one_va_share_gpu_local_heap and cl2_state::tests::real_device_query_spanning_a_split_resolves_the_whole_total. When create_device_tests::create_device_returns_wrapped_device later goes through the emulator's export, the late enable call makes every creation after it in that process fail with DEVICE_RESET. With parallel threads the same race fails 5 more tests (the four above and alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement).

How I found it: I paired each of the 128 tests that run before create_device_returns_wrapped_device with it in one process (--exact, one thread). The four tests above are the only ones that make it print "no D3D12 device on this machine (hr=0x887a0007)". Releasing the queue and device at the end of the cl2_state test did not help, ruling out a leak. A probe that creates 400 devices without releasing them worked, ruling out a device count limit.

Change

In host_proc (lib.rs), under #[cfg(test)], the first time a test resolves D3D12CreateDevice it runs enable_experimental_shader_models() once (std::sync::Once). Production code is unchanged.

Results

Windows 10 build 19045, NVIDIA GeForce RTX 4070 Ti, MSVC, on upstream main 9cd1305:

without with
cargo test --locked -p d3d12_xs --lib -- --test-threads=1 490 passed, 23 failed 512 passed, 1 failed
cargo test --locked -p d3d12_xs --lib 484 passed, 29 failed 512 passed, 1 failed

The remaining failure is xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs, which needs a console d3d12_xs.dll in D:\xbox-pc-port\games. cargo test --locked -p d3d12_xs --lib hw_ -- --ignored --test-threads=1 is still 38 passed. python .github/scripts/pr_gate.py --base upstream/main --head HEAD: 0 problems.

Environment dependence

I reproduce the failures on Windows 10 build 19045 (D3D12 runtime 10.0.19041) with an NVIDIA RTX 4070 Ti. In #157 another contributor reports 512 passed, 1 failed on current main in both modes on an RTX 5070 with Windows 11 26H2, so on that runtime the late enable call does not poison later device creation. This change therefore mainly helps developers on Windows 10; on Windows 11 it should be a no-op (the enable call is made once, before the first device, which is what the D3D12 documentation requires). I have not run it on Windows 11 myself.

**@⁠MeNoSkills** on GitHub · 2026-11-22 17:41 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/171) `MeNoSkills:fix/create-device-test-isolation` → `main` · +5 −0 · 1 files · 1 commits · closed without merging In a single `cargo test -p d3d12_xs --lib` process, 22 tests fail (23 on current main), all with `D3D12CreateDevice` returning DXGI_ERROR_DEVICE_RESET (0x887a0007), although each module passes when run on its own. Refs #157. ## Cause `D3D12XboxCreateDevice` calls `D3D12EnableExperimentalFeatures(ShaderModels)` before it creates the device, and that call has to happen before any device exists in the process. Four tests create a real device straight through the host's `D3D12CreateDevice` without it: `alias::tests::title_heap_does_not_block_unmap_or_free`, `alias::tests::two_placements_at_one_va_share_title_memory`, `alias::tests::two_textures_at_one_va_share_gpu_local_heap` and `cl2_state::tests::real_device_query_spanning_a_split_resolves_the_whole_total`. When `create_device_tests::create_device_returns_wrapped_device` later goes through the emulator's export, the late enable call makes every creation after it in that process fail with DEVICE_RESET. With parallel threads the same race fails 5 more tests (the four above and `alias::tests::msaa_depth_with_a_larger_pc_layout_never_overlaps_the_next_title_placement`). How I found it: I paired each of the 128 tests that run before `create_device_returns_wrapped_device` with it in one process (`--exact`, one thread). The four tests above are the only ones that make it print "no D3D12 device on this machine (hr=0x887a0007)". Releasing the queue and device at the end of the `cl2_state` test did not help, ruling out a leak. A probe that creates 400 devices without releasing them worked, ruling out a device count limit. ## Change In `host_proc` (lib.rs), under `#[cfg(test)]`, the first time a test resolves `D3D12CreateDevice` it runs `enable_experimental_shader_models()` once (`std::sync::Once`). Production code is unchanged. ## Results Windows 10 build 19045, NVIDIA GeForce RTX 4070 Ti, MSVC, on upstream main 9cd1305: | | without | with | |---|---|---| | `cargo test --locked -p d3d12_xs --lib -- --test-threads=1` | 490 passed, 23 failed | 512 passed, 1 failed | | `cargo test --locked -p d3d12_xs --lib` | 484 passed, 29 failed | 512 passed, 1 failed | The remaining failure is `xs_exports::console_fixed_tests::fixed_result_dxgix_exports_match_every_console_d3d12_xs`, which needs a console d3d12_xs.dll in `D:\xbox-pc-port\games`. `cargo test --locked -p d3d12_xs --lib hw_ -- --ignored --test-threads=1` is still 38 passed. `python .github/scripts/pr_gate.py --base upstream/main --head HEAD`: 0 problems. ## Environment dependence I reproduce the failures on Windows 10 build 19045 (D3D12 runtime 10.0.19041) with an NVIDIA RTX 4070 Ti. In #157 another contributor reports 512 passed, 1 failed on current main in both modes on an RTX 5070 with Windows 11 26H2, so on that runtime the late enable call does not poison later device creation. This change therefore mainly helps developers on Windows 10; on Windows 11 it should be a no-op (the enable call is made once, before the first device, which is what the D3D12 documentation requires). I have not run it on Windows 11 myself.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 06:12:38 +00:00
github-bot closed this pull request 2026-11-26 06:12:38 +00:00
Author
Owner

@⁠omonkeyz on GitHub · 2026-11-22 17:59 UTC · original

Applied in fa28145 (merged in 202c763) with your authorship kept, thanks. Nice find. The merge note records your 512/1 result in both test modes and the matching RTX 5070 confirmation from #157.

**@⁠omonkeyz** on GitHub · 2026-11-22 17:59 UTC · [original](https://github.com/omonkeyz/xbox-emulator/pull/171#issuecomment-7083253109) Applied in fa28145 (merged in 202c763) with your authorship kept, thanks. Nice find. The merge note records your 512/1 result in both test modes and the matching RTX 5070 confirmation from #157.

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No description provided.