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

Closed
MeNoSkills wants to merge 1 commit from upstream-pr/171 into main
MeNoSkills commented 2026-11-22 17:41:55 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by MeNoSkills on 2026-11-22T17:41:55Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:issue:6545589900 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/171). Originally posted by [MeNoSkills](https://github.com/MeNoSkills) on 2026-11-22T17:41:55Z. --- 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.
omonkeyz commented 2026-11-22 17:59:07 +00:00 (Migrated from github.com)

Imported from omonkeyz/xbox-emulator. Originally posted by omonkeyz on 2026-11-22T17:59:07Z.


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.

<!-- greyfinch-sync:omonkeyz/xbox-emulator:comment:7083253109 --> Imported from [omonkeyz/xbox-emulator](https://github.com/omonkeyz/xbox-emulator/pull/171#issuecomment-7083253109). Originally posted by [omonkeyz](https://github.com/omonkeyz) on 2026-11-22T17:59:07Z. --- 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

Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
omonkeyz/xbox-emulator!171
No description provided.