d3d12: handle AMD-only clzero, monitorx and mwaitx on Intel CPUs #146

Merged
JeffreyBytes merged 1 commit from upstream-pr/146 into main 2026-11-25 07:28:02 +00:00
JeffreyBytes commented 2026-11-25 05:23:04 +00:00 (Migrated from github.com)

Imported from brcly/TuxBox. Originally posted by JeffreyBytes on 2026-11-25T05:23:04Z.


Summary

Fixes #145.

ProjectScarlett 1.0.2.1 uses three AMD-only instructions that raise EXCEPTION_ILLEGAL_INSTRUCTION on Intel CPUs (exit code 29). This adds handlers for them next to the clwb one from #80, called from the vectored exception handler in survey.rs:

  • clzero (runtime/d3d12/src/clzero.rs): zero the 64-byte line at RAX and resume after the instruction. When the title's clzero; add rax,0x40; cmp rax,rN; jb loop follows the fault, one trap clears the whole range and execution resumes at the cmp. Memory that isn't writable is left to fault, as it would on hardware.
  • monitorx / mwaitx (runtime/d3d12/src/mwaitx.rs): on first fault, rewrite the second opcode byte 01 → 1F, giving the same-length reserved NOP 0F 1F /r. It's a single atomic byte store, so later iterations of the wait loop run natively. Neither instruction has architectural side effects, and mwaitx may return at any time, so a NOP is valid. If the page can't be made writable, the handler steps over the instruction instead.

Both act only when CPUID reports the instruction missing and the fault is inside the title image. clwb.rs only changes read_code_bytes to pub(crate) so the new handlers can share it.

On an i5-12600K, every AMD-only site the title reaches is now handled. After the rewrite, each wait site traps once and the rest of the loop runs natively. What remains is one clzero trap per clearing loop (about 250 a second). This fixes the CPU crashes only: on RADV the window stays black at a low frame rate for a separate GPU-side reason, which I'll report on its own.

Checks

All commands from CONTRIBUTING.md pass:

  • python -m unittest discover -s tests -q
  • cargo test for tools/shader-compiler, tuxbox-dxbc (with native-bindings) and tuxbox-xg-layout
  • cargo check --target x86_64-pc-windows-msvc -p tuxbox-d3d12

The new unit tests are Windows-only, like the existing clwb ones. I ran the full tuxbox-d3d12 test binary under Proton's Wine: 86/86 passed. One test executes the rewritten 0F 1F FA / 0F 1F FB natively on the Intel host.

No evidence JSON changed.

<!-- greyfinch-sync:brcly/TuxBox:issue:6597822057 --> Imported from [brcly/TuxBox](https://github.com/brcly/TuxBox/pull/146). Originally posted by [JeffreyBytes](https://github.com/JeffreyBytes) on 2026-11-25T05:23:04Z. --- ## Summary Fixes #145. ProjectScarlett 1.0.2.1 uses three AMD-only instructions that raise `EXCEPTION_ILLEGAL_INSTRUCTION` on Intel CPUs (exit code 29). This adds handlers for them next to the `clwb` one from #80, called from the vectored exception handler in `survey.rs`: - **`clzero`** (`runtime/d3d12/src/clzero.rs`): zero the 64-byte line at `RAX` and resume after the instruction. When the title's `clzero; add rax,0x40; cmp rax,rN; jb` loop follows the fault, one trap clears the whole range and execution resumes at the `cmp`. Memory that isn't writable is left to fault, as it would on hardware. - **`monitorx` / `mwaitx`** (`runtime/d3d12/src/mwaitx.rs`): on first fault, rewrite the second opcode byte `01` → `1F`, giving the same-length reserved NOP `0F 1F /r`. It's a single atomic byte store, so later iterations of the wait loop run natively. Neither instruction has architectural side effects, and `mwaitx` may return at any time, so a NOP is valid. If the page can't be made writable, the handler steps over the instruction instead. Both act only when CPUID reports the instruction missing and the fault is inside the title image. `clwb.rs` only changes `read_code_bytes` to `pub(crate)` so the new handlers can share it. On an i5-12600K, every AMD-only site the title reaches is now handled. After the rewrite, each wait site traps once and the rest of the loop runs natively. What remains is one `clzero` trap per clearing loop (about 250 a second). This fixes the CPU crashes only: on RADV the window stays black at a low frame rate for a separate GPU-side reason, which I'll report on its own. ## Checks All commands from CONTRIBUTING.md pass: - `python -m unittest discover -s tests -q` - `cargo test` for `tools/shader-compiler`, `tuxbox-dxbc` (with `native-bindings`) and `tuxbox-xg-layout` - `cargo check --target x86_64-pc-windows-msvc -p tuxbox-d3d12` The new unit tests are Windows-only, like the existing `clwb` ones. I ran the full `tuxbox-d3d12` test binary under Proton's Wine: 86/86 passed. One test executes the rewritten `0F 1F FA` / `0F 1F FB` natively on the Intel host. No evidence JSON changed.
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
brcly/TuxBox!146
No description provided.